]> andersk Git - splint.git/blobdiff - src/sRef.c
Fixes for win32
[splint.git] / src / sRef.c
index 1934a9d42c68102053a7adf9f775faf7c5989799..b7504360ab463c4a74d77cc54d45f0d178e08804 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -62,6 +62,7 @@ static void sRef_updateNullState (sRef p_res, sRef p_other) /*@modifies p_res@*/
 
 static bool sRef_isAllocatedStorage (sRef p_s) /*@*/ ;
 static void sRef_setNullErrorLoc (sRef p_s, fileloc) /*@*/ ;
+static void sRef_setNullStateN (sRef p_s, nstate p_n) /*@modifies p_s@*/ ;
 
 static int sRef_depth (sRef p_s) /*@*/ ;
 
@@ -92,10 +93,77 @@ static void sRef_resetAliasKind (/*@notnull@*/ sRef s) /*@modifies s->aliaskind@
     }
 }
 
+# ifdef DEBUGSPLINT
+extern void sRef_checkCompletelyReasonable (sRef s) /*@*/ 
+{
+  DPRINTF (("Check sRef: [%p] %s / %s", s, sRef_unparse (s),
+           sRefSet_unparse (sRef_derivedFields (s))));
+
+  if (sRef_isReasonable (s))
+    {
+      sRefSet_elements (s->deriv, el)
+       {
+         llassert (el != s);
+         sRef_checkCompletelyReasonable (el);
+       } end_sRefSet_elements ;
+    }
+}
+# endif
+
+/*@falsewhennull@*/ bool sRef_isReasonable (sRef s) /*@*/
+{
+  if (sRef_isValid (s))
+    {
+# ifdef DEBUGSPLINT
+      if (!bool_isReasonable (s->safe)
+         || !bool_isReasonable (s->modified)
+         || !bool_isReasonable (s->immut))
+       {
+         llcontbug (message ("Unreasonable sRef [%p]", s));
+         return FALSE;
+       }
+
+      if (!sstate_isValid (s->defstate))
+       {
+         llcontbug (message ("Unreasonable sRef [%p]", s));
+         return FALSE;
+       }
+
+      if (!nstate_isValid (s->nullstate))
+       {
+         llcontbug (message ("Unreasonable sRef [%p]", s));
+         return FALSE;
+       }
+
+      if (!alkind_isValid (s->aliaskind)
+         || !alkind_isValid (s->oaliaskind))
+       {
+         llcontbug (message ("Unreasonable sRef [%p]", s));
+         return FALSE;
+       }
+
+      if (!exkind_isValid (s->expkind)
+         || !exkind_isValid (s->oexpkind))
+       {
+         llcontbug (message ("Unreasonable sRef [%p]", s));
+         return FALSE;
+       }
+# endif
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static /*@nullwhentrue@*/ bool sRef_isUnreasonable (sRef s) /*@*/
+{
+  return (!sRef_isReasonable (s));
+}
+
 static void sRef_checkMutable (/*@unused@*/ sRef s)
 {
-  /*@i235@*/
-  if (sRef_isValid (s) && s->immut)
+  if (sRef_isReasonable (s) && s->immut)
     {
       llcontbug (message ("Modification to sRef marked immutable: %q", 
                          sRef_unparseFull (s)));
@@ -121,7 +189,8 @@ static void sinfo_free (/*@special@*/ /*@temp@*/ /*@notnull@*/ sRef p_s)
 static /*@null@*/ sinfo sinfo_copy (/*@notnull@*/ sRef p_s) /*@*/ ;
 static void sRef_setPartsFromUentry (sRef p_s, uentry p_ue)
    /*@modifies p_s@*/ ;
-static bool checkDeadState (/*@notnull@*/ sRef p_el, bool p_tbranch, fileloc p_loc);
+static bool checkDeadState (/*@notnull@*/ sRef p_el, /*@null@*/ sRef p_e2, 
+                           bool p_tbranch, fileloc p_loc);
 static /*@dependent@*/ sRef sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef p_t) /*@*/ ;
 
 static void 
@@ -250,7 +319,7 @@ static void sRef_checkValidAux (sRef s, sRefSet checkedsofar)
 {
   llassert (FALSE);
 
-  if (!sRef_isValid (s)) return;
+  if (!sRef_isReasonable (s)) return;
 
   if (sRefSet_containsSameObject (checkedsofar, s))
     {
@@ -274,7 +343,7 @@ static void sRef_checkValidAux (sRef s, sRefSet checkedsofar)
 
     case SK_PARAM:
       llassert (s->info->paramno >= -1);
-      llassert (s->info->paramno <= 50); /*@i32 bogus...*/
+      llassert (s->info->paramno <= 999); /* sanity check */
       break;
 
     case SK_ARRAYFETCH:
@@ -369,6 +438,8 @@ static /*@dependent@*/ /*@notnull@*/ /*@special@*/ sRef
 
   /* start modifications */
   s->bufinfo.bufstate = BB_NOTNULLTERMINATED;
+  s->bufinfo.size = -1; 
+  s->bufinfo.len = -1; 
   /* end modifications */
 
   s->aliaskind = AK_UNKNOWN;
@@ -435,7 +506,7 @@ sRef_isRecursiveField (sRef s)
          fieldname = sRef_getField (s);
          base = sRef_getBase (s);
          
-         while (sRef_isValid (base))
+         while (sRef_isReasonable (base))
            {
              if (sRef_isField (base))
                {
@@ -458,8 +529,8 @@ sRef_addDeriv (/*@notnull@*/ sRef s, /*@notnull@*/ /*@exposed@*/ sRef t)
 {
   if (!context_inProtectVars () 
       && !protectDerivs
-      && sRef_isValid (s)
-      && sRef_isValid (t)
+      && sRef_isReasonable (s)
+      && sRef_isReasonable (t)
       && !sRef_isConst (s))
     {
       int sd = sRef_depth (s);
@@ -504,6 +575,10 @@ sRef_addDeriv (/*@notnull@*/ sRef s, /*@notnull@*/ /*@exposed@*/ sRef t)
                }
              else
                {
+                 DPRINTF (("Add deriv: [%p] %s / [%p] %s",
+                           s, sRef_unparse (s),
+                           t, sRef_unparse (t)));
+                 
                  s->deriv = sRefSet_insert (s->deriv, t);
                }
            }
@@ -522,7 +597,7 @@ sRef_addDeriv (/*@notnull@*/ sRef s, /*@notnull@*/ /*@exposed@*/ sRef t)
 bool
 sRef_deepPred (bool (predf) (sRef), sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if ((*predf)(s)) return TRUE;
 
@@ -552,7 +627,7 @@ bool sRef_modInFunction (void)
 
 void sRef_setStateFromType (sRef s, ctype ct)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (ctype_isUser (ct))
        {
@@ -575,30 +650,27 @@ void sRef_setStateFromType (sRef s, ctype ct)
 
 static void sRef_setTypeState (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_setStateFromType (s, s->type);
     }
 }
 
-static bool
-  sRef_hasAliasInfoLoc (sRef s)
+bool sRef_hasAliasInfoLoc (sRef s)
 {
-  return (sRef_isValid (s) && (s->aliasinfo != NULL)
+  return (sRef_isReasonable (s) && (s->aliasinfo != NULL)
          && (fileloc_isDefined (s->aliasinfo->loc)));
 }
 
-static /*@falsewhennull@*/ bool
-sRef_hasStateInfoLoc (sRef s)
+/*@falsewhennull@*/ bool sRef_hasStateInfoLoc (sRef s)
 {
-  return (sRef_isValid (s) && (s->definfo != NULL) 
+  return (sRef_isReasonable (s) && (s->definfo != NULL) 
          && (fileloc_isDefined (s->definfo->loc)));
 }
 
-static /*@falsewhennull@*/ bool
-sRef_hasExpInfoLoc (sRef s)
+/*@falsewhennull@*/ bool sRef_hasExpInfoLoc (sRef s)
 {
-  return (sRef_isValid (s) 
+  return (sRef_isReasonable (s) 
          && (s->expinfo != NULL) && (fileloc_isDefined (s->expinfo->loc)));
 }
 
@@ -607,7 +679,7 @@ static /*@observer@*/ /*@unused@*/ stateInfo sRef_getInfo (sRef s, cstring key)
 {
   stateValue sv;
   
-  if (!sRef_isValid (s)) {
+  if (!sRef_isReasonable (s)) {
     return stateInfo_undefined;
   }
   
@@ -625,21 +697,21 @@ static /*@observer@*/ /*@unused@*/ stateInfo sRef_getInfo (sRef s, cstring key)
 static bool
 sRef_hasNullInfoLoc (sRef s)
 {
-  return (sRef_isValid (s) && s->nullinfo != NULL
+  return (sRef_isReasonable (s) && s->nullinfo != NULL
          && (fileloc_isDefined (s->nullinfo->loc)));
 }
 
 bool
 sRef_hasAliasInfoRef (sRef s)
 {
-  return (sRef_isValid (s) && (s->aliasinfo != NULL) 
-         && (sRef_isValid (s->aliasinfo->ref)));
+  return (sRef_isReasonable (s) && (s->aliasinfo != NULL) 
+         && (sRef_isReasonable (s->aliasinfo->ref)));
 }
 
 static /*@observer@*/ fileloc
 sRef_getAliasInfoLoc (/*@exposed@*/ sRef s)
 {
-  llassert (sRef_isValid (s) && s->aliasinfo != NULL
+  llassert (sRef_isReasonable (s) && s->aliasinfo != NULL
            && (fileloc_isDefined (s->aliasinfo->loc)));
   return (s->aliasinfo->loc);
 }
@@ -647,7 +719,7 @@ sRef_getAliasInfoLoc (/*@exposed@*/ sRef s)
 static /*@observer@*/ fileloc
 sRef_getStateInfoLoc (/*@exposed@*/ sRef s)
 {
-  llassert (sRef_isValid (s) && s->definfo != NULL 
+  llassert (sRef_isReasonable (s) && s->definfo != NULL 
            && (fileloc_isDefined (s->definfo->loc)));
   return (s->definfo->loc);
 }
@@ -655,7 +727,7 @@ sRef_getStateInfoLoc (/*@exposed@*/ sRef s)
 static /*@observer@*/ fileloc
 sRef_getExpInfoLoc (/*@exposed@*/ sRef s)
 {
-  llassert (sRef_isValid (s) && s->expinfo != NULL 
+  llassert (sRef_isReasonable (s) && s->expinfo != NULL 
            && (fileloc_isDefined (s->expinfo->loc)));
   return (s->expinfo->loc);
 }
@@ -663,7 +735,7 @@ sRef_getExpInfoLoc (/*@exposed@*/ sRef s)
 static /*@observer@*/ fileloc
 sRef_getNullInfoLoc (/*@exposed@*/ sRef s)
 {
-  llassert (sRef_isValid (s) && s->nullinfo != NULL 
+  llassert (sRef_isReasonable (s) && s->nullinfo != NULL 
            && (fileloc_isDefined (s->nullinfo->loc)));
   return (s->nullinfo->loc);
 }
@@ -671,7 +743,7 @@ sRef_getNullInfoLoc (/*@exposed@*/ sRef s)
 /*@observer@*/ sRef
   sRef_getAliasInfoRef (/*@temp@*/ sRef s)
 {
-  llassert (sRef_isValid (s) && s->aliasinfo != NULL);
+  llassert (sRef_isReasonable (s) && s->aliasinfo != NULL);
   return (s->aliasinfo->ref);
 }
 
@@ -750,6 +822,7 @@ void sRef_exitFunctionScope ()
     {
       DPRINTF (("Exit function scope."));
       sRefTable_clear (allRefs);
+      DPRINTF (("Exit function scope done."));
       inFunction = FALSE;
     }
   else
@@ -777,7 +850,7 @@ sRef_fixConj (/*@notnull@*/ sRef s)
        s = sRef_getConjA (s);
       } while (sRef_isConj (s));
       
-      llassert (sRef_isValid (s));
+      llassert (sRef_isReasonable (s));
       return s; /* don't need to ref */
     }
   else
@@ -792,7 +865,7 @@ sRef_isExternallyVisibleAux (sRef s)
   bool res = FALSE;
   sRef base = sRef_getRootBase (s);
 
-  if (sRef_isValid (base))
+  if (sRef_isReasonable (base))
     {
       res = sRef_isParam (base) || sRef_isFileOrGlobalScope (base) || sRef_isExternal (base);
     }
@@ -812,12 +885,12 @@ sRef_getBaseUentry (sRef s)
   sRef base = sRef_getRootBase (s);
   uentry res = uentry_undefined;
   
-  if (sRef_isValid (base))
+  if (sRef_isReasonable (base))
     {
       switch (base->kind)
        {
        case SK_PARAM:
-         res = usymtab_getRefQuiet (paramsScope, base->info->paramno);
+         res = usymtab_getRefQuiet (paramsScope, usymId_fromInt (base->info->paramno));
          break;
 
        case SK_CVAR:
@@ -845,7 +918,7 @@ sRef_updateSref (sRef s)
   sRef ret;
   sRef res;
 
-  if (!sRef_isValid (s)) return sRef_undefined;
+  if (!sRef_isReasonable (s)) return sRef_undefined;
   
   switch (s->kind)
     {
@@ -975,12 +1048,12 @@ sRef_updateSref (sRef s)
 uentry
 sRef_getUentry (sRef s)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   switch (s->kind)
     {
     case SK_PARAM:
-      return (usymtab_getRefQuiet (paramsScope, s->info->paramno));
+      return (usymtab_getRefQuiet (paramsScope, usymId_fromInt (s->info->paramno)));
     case SK_CVAR:
       return (usymtab_getRefQuiet (s->info->cvar->lexlevel, s->info->cvar->index));
     case SK_CONJ:
@@ -995,6 +1068,7 @@ sRef_getUentry (sRef s)
            return sRef_getUentry (s->info->conj->b);
          }
       }
+    case SK_FIELD: /* evans 2002-07-17: added case for SK_FIELD */
     case SK_UNKNOWN:
     case SK_SPECIAL:
       return uentry_undefined;
@@ -1005,7 +1079,7 @@ sRef_getUentry (sRef s)
 int
 sRef_getParam (sRef s)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   llassert (s->kind == SK_PARAM);
 
   return s->info->paramno;
@@ -1014,12 +1088,12 @@ sRef_getParam (sRef s)
 bool
 sRef_isModified (sRef s)
 {
-    return (!sRef_isValid (s) || s->modified);
+    return (!sRef_isReasonable (s) || s->modified);
 }
 
 void sRef_setModified (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       s->modified = TRUE;
 
@@ -1165,7 +1239,7 @@ bool sRef_checkModifyVal (sRef s, sRefSet sl)
 
 static bool sRef_checkModify (sRef s, sRefSet sl)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   switch (s->kind)
     {
@@ -1290,7 +1364,7 @@ cstring sRef_stateAltVerb (sRef s)
 static 
 bool sRef_doModifyVal (sRef s, sRefSet sl)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   
   switch (s->kind)
@@ -1379,7 +1453,7 @@ bool sRef_doModifyVal (sRef s, sRefSet sl)
 static 
 bool sRef_doModify (sRef s, sRefSet sl)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   
   switch (s->kind)
     {
@@ -1461,8 +1535,8 @@ static /*@exposed@*/ sRef
 {
   llassert (sRef_similar (s1, s2));
   
-  if (!sRef_isValid (s1)) return s1;
-  if (!sRef_isValid (s2)) return s1;
+  if (!sRef_isReasonable (s1)) return s1;
+  if (!sRef_isReasonable (s2)) return s1;
 
   sRef_combineDefState (s1, s2);
   sRef_combineNullState (s1, s2);
@@ -1957,8 +2031,13 @@ sRef_includedBy (sRef small, sRef big)
 bool
 sRef_realSame (sRef s1, sRef s2)
 {
-  if (s1 == s2) return TRUE;  
-  if (sRef_isInvalid (s1) || sRef_isInvalid (s2)) return FALSE;
+  if (s1 == s2) return TRUE;
+  
+  if (sRef_isUnreasonable (s1) 
+      || sRef_isUnreasonable (s2)) 
+    {
+      return FALSE;
+    }
 
   switch (s1->kind)
     {
@@ -2177,7 +2256,6 @@ sRef_closeEnough (sRef s1, sRef s2)
     {
     case SK_RESULT:
       {
-       /* s = sRef_saveCopy(s); */ /*@i523@*/
        ce = constraintExpr_makeTermsRef (s);
        return ce;
       }
@@ -2194,7 +2272,6 @@ sRef_closeEnough (sRef s1, sRef s2)
       {
        sRef temp;
        temp = (sRef_makePointer (sRef_fixBaseParam (s->info->ref, args)));
-       /* temp = sRef_saveCopy(temp); */ /*@i523@*/
        ce = constraintExpr_makeTermsRef (temp);
        return ce;
       }
@@ -2218,14 +2295,15 @@ sRef_closeEnough (sRef s1, sRef s2)
        return ce;
       }
     case SK_PARAM:
-      llassert(exprNodeList_size (args) > s->info->paramno);
-       {
-         exprNode e = exprNodeList_nth (args, s->info->paramno);
-
-         llassert( !(exprNode_isError (e)) );
-         ce = constraintExpr_makeExprNode (e);
-         return ce;
-       }
+      {
+       exprNode e;
+       llassert (exprNodeList_size (args) > s->info->paramno);
+       e = exprNodeList_nth (args, s->info->paramno);
+       
+       llassert (!(exprNode_isError (e)));
+       ce = constraintExpr_makeExprNode (e);
+       return ce;
+      }
 
     default:
       {
@@ -2239,9 +2317,6 @@ sRef_closeEnough (sRef s1, sRef s2)
       return ce;
       }
     }
-
-  
-
 }
 
 /*@exposed@*/ sRef
@@ -2286,9 +2361,14 @@ sRef_fixBaseParam (/*@returned@*/ sRef s, exprNodeList args)
                  (sRef_fixBaseParam (s->info->arrayfetch->arr, args)));
        }
     case SK_FIELD:
-      return (sRef_makeField (sRef_fixBaseParam (s->info->field->rec, args),
-                             s->info->field->field));
-
+      {
+       sRef res;
+       DPRINTF (("Fix field: %s", sRef_unparseFull (s)));
+       res = sRef_makeField (sRef_fixBaseParam (s->info->field->rec, args),
+                             s->info->field->field);
+       DPRINTF (("Returns: %s", sRef_unparseFull (res)));
+       return res;
+      }
     case SK_PTR:
       return (sRef_makePointer (sRef_fixBaseParam (s->info->ref, args)));
 
@@ -2376,9 +2456,11 @@ static /*@exposed@*/ sRef sRef_undumpBody (char **c)
   switch (p)
     {
     case 'g':
-      return (sRef_makeGlobal (usymId_fromInt (reader_getInt (c)), ctype_unknown, stateInfo_currentLoc ()));
+      return (sRef_makeGlobal (usymId_fromInt (reader_getInt (c)), 
+                              ctype_unknown, stateInfo_currentLoc ()));
     case 'p':
-      return (sRef_makeParam (reader_getInt (c), ctype_unknown, stateInfo_makeLoc (g_currentloc)));
+      return (sRef_makeParam (reader_getInt (c), ctype_unknown, 
+                             stateInfo_makeLoc (g_currentloc, SA_DECLARED)));
     case 'r':
       return (sRef_makeResult (ctype_undump (c)));
     case 'a':
@@ -3095,7 +3177,7 @@ sRef_unparseNoArgs (sRef s)
 
   s->kind = SK_UNCONSTRAINED;
   s->info = (sinfo) dmalloc (sizeof (*s->info));
-  s->info->fname = fname;
+  s->info->fname = cstring_copy (fname); /* evans 2002-07-12: this was exposed, causing memory errors */
 
   return (s);
 }
@@ -3109,7 +3191,7 @@ cstring sRef_unconstrainedName (sRef s)
 
 bool sRef_isUnconstrained (sRef s) 
 {
-  return (sRef_isValid(s) && s->kind == SK_UNCONSTRAINED);
+  return (sRef_isReasonable(s) && s->kind == SK_UNCONSTRAINED);
 }
 
 static /*@dependent@*/ /*@notnull@*/ sRef 
@@ -3165,14 +3247,14 @@ static /*@dependent@*/ /*@notnull@*/ sRef
 
 int sRef_lexLevel (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef conj;
 
       conj = sRef_fixConj (s);
       s = sRef_getRootBase (conj);
       
-      if (sRef_isValid (s) && s->kind == SK_CVAR)
+      if (sRef_isReasonable (s) && s->kind == SK_CVAR)
        {
          return (s->info->cvar->lexlevel);
        }
@@ -3190,7 +3272,7 @@ sRef_makeGlobal (usymId l, ctype ct, /*@only@*/ stateInfo stinfo)
 void
 sRef_setParamNo (sRef s, int l)
 {
-  llassert (sRef_isValid (s) && s->kind == SK_PARAM);
+  llassert (sRef_isReasonable (s) && s->kind == SK_PARAM);
   s->info->paramno = l;
   llassert (l >= -1);
 }
@@ -3219,7 +3301,7 @@ sRef_isIndexKnown (sRef arr)
 {
   bool res;
 
-  llassert (sRef_isValid (arr));
+  llassert (sRef_isReasonable (arr));
   arr = sRef_fixConj (arr);
   
   llassert (arr->kind == SK_ARRAYFETCH);  
@@ -3232,7 +3314,7 @@ sRef_getIndex (sRef arr)
 {
   int result;
 
-  llassert (sRef_isValid (arr));
+  llassert (sRef_isReasonable (arr));
   arr = sRef_fixConj (arr);
 
   llassert (arr->kind == SK_ARRAYFETCH);  
@@ -3277,7 +3359,7 @@ static bool sRef_isZerothArrayFetch (/*@notnull@*/ sRef s)
       s->kind = SK_ADR;
       s->type = ctype_makePointer (t->type);
       s->info = (sinfo) dmalloc (sizeof (*s->info));
-      s->info->ref = t; /* sRef_copy (t);  */ /*@i32@*/
+      s->info->ref = t; 
       
       if (t->defstate == SS_UNDEFINED) 
        /* no! it is allocated even still: && !ctype_isPointer (t->type)) */
@@ -3298,7 +3380,8 @@ static bool sRef_isZerothArrayFetch (/*@notnull@*/ sRef s)
        }
 
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+      s->state = context_createValueTable (s, 
+                                          stateInfo_makeLoc (g_currentloc, SA_CREATED));
       return s;
     }
 }
@@ -3307,10 +3390,10 @@ cstring sRef_getField (sRef s)
 {
   cstring res;
 
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   s = sRef_fixConj (s);
 
-  llassertprint (sRef_isValid (s) && (s->kind == SK_FIELD),
+  llassertprint (sRef_isReasonable (s) && (s->kind == SK_FIELD),
                 ("s = %s", sRef_unparseDebug (s)));
 
   res = s->info->field->field;
@@ -3465,13 +3548,13 @@ static int sRef_depth (sRef s)
 sRef
 sRef_makeObject (ctype o)
 {
-  sRef s = sRef_newRef (); /*@i423 same line is bad...@*/
+  sRef s = sRef_newRef (); 
 
   s->kind = SK_OBJECT;
   s->info = (sinfo) dmalloc (sizeof (*s->info));
   s->info->object = o;
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
   return s;
 }
 
@@ -3483,30 +3566,30 @@ sRef sRef_makeExternal (sRef t)
 {
   sRef s = sRef_newRef ();
 
-  llassert (sRef_isValid (t));
+  llassert (sRef_isReasonable (t));
 
   s->kind = SK_EXTERNAL;
   s->info = (sinfo) dmalloc (sizeof (*s->info));
   s->type = t->type;
-  s->info->ref = t; /* sRef_copy (t); */ /*@i32 was exposed@*/
+  s->info->ref = t;
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_DECLARED));
   return s;
 }
 
 /*@dependent@*/ sRef sRef_makeDerived (/*@exposed@*/ sRef t)
 {
-  if (sRef_isValid (t))
+  if (sRef_isReasonable (t))
     {
       sRef s = sRef_newRef ();
       
       s->kind = SK_DERIVED;
       s->info = (sinfo) dmalloc (sizeof (*s->info));
-      s->info->ref = t; /* sRef_copy (t); */ /*@i32@*/ 
+      s->info->ref = t;
       
       s->type = t->type;
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
       return s;
     }
   else
@@ -3524,8 +3607,8 @@ sRef sRef_makeExternal (sRef t)
 void
 sRef_mergeStateQuiet (sRef res, sRef other)
 {
-  llassert (sRef_isValid (res));
-  llassert (sRef_isValid (other));
+  llassert (sRef_isReasonable (res));
+  llassert (sRef_isReasonable (other));
 
   res->modified = res->modified || other->modified;
   res->safe = res->safe && other->safe;
@@ -3584,8 +3667,8 @@ sRef_mergeStateQuietReverse (/*@dependent@*/ sRef res, /*@dependent@*/ sRef othe
 {
   bool changed = FALSE;
 
-  llassert (sRef_isValid (res));
-  llassert (sRef_isValid (other));
+  llassert (sRef_isReasonable (res));
+  llassert (sRef_isReasonable (other));
   sRef_checkMutable (res);
 
   if (res->kind != other->kind)
@@ -3644,6 +3727,7 @@ sRef_mergeStateQuietReverse (/*@dependent@*/ sRef res, /*@dependent@*/ sRef othe
       if (other->defstate != SS_UNKNOWN)
        {
          res->defstate = other->defstate;
+         res->definfo = stateInfo_update (res->definfo, other->definfo);
        }
     }
 
@@ -3657,7 +3741,8 @@ sRef_mergeStateQuietReverse (/*@dependent@*/ sRef res, /*@dependent@*/ sRef othe
     }
   else
     {
-      if (sRef_getNullState (other) != NS_UNKNOWN && sRef_getNullState (other) != sRef_getNullState (res))
+      if (sRef_getNullState (other) != NS_UNKNOWN 
+         && sRef_getNullState (other) != sRef_getNullState (res))
        {
          changed = TRUE;
          sRef_updateNullState (res, other);
@@ -3673,7 +3758,7 @@ sRef_mergeStateQuietReverse (/*@dependent@*/ sRef res, /*@dependent@*/ sRef othe
 void 
 sRef_mergeState (sRef res, sRef other, clause cl, fileloc loc)
 {
-  if (sRef_isValid (res) && sRef_isValid (other))
+  if (sRef_isReasonable (res) && sRef_isReasonable (other))
     {
       sRef_mergeStateAux (res, other, cl, FALSE, loc, TRUE);
     }
@@ -3695,7 +3780,7 @@ sRef_mergeState (sRef res, sRef other, clause cl, fileloc loc)
 void 
 sRef_mergeOptState (sRef res, sRef other, clause cl, fileloc loc)
 {
-  if (sRef_isValid (res) && sRef_isValid (other))
+  if (sRef_isReasonable (res) && sRef_isReasonable (other))
     {
       sRef_mergeStateAux (res, other, cl, TRUE, loc, TRUE);
     }
@@ -3720,12 +3805,12 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
                    bool doDerivs)
    /*@modifies res@*/ 
 {
-  llassertfatal (sRef_isValid (res));
-  llassertfatal (sRef_isValid (other));
+  llassertfatal (sRef_isReasonable (res));
+  llassertfatal (sRef_isReasonable (other));
   
   DPRINTF (("Merge aux: %s / %s",
-           bool_unparse (sRef_isDefinitelyNull (res)),
-           bool_unparse (sRef_isDefinitelyNull (other))));
+           sRef_unparseFull (res),
+           sRef_unparseFull (other)));
 
   sRef_checkMutable (res);
   sRef_checkMutable (other);
@@ -3779,6 +3864,7 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
              res->defstate = SS_DEAD;
            }
          
+         res->definfo = stateInfo_update (res->definfo, other->definfo);
          sRef_clearDerived (other);
          sRef_clearDerived (res);
        }
@@ -3939,7 +4025,7 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
        {
          sRef nother = sRef_buildPointer (sRef_getBase (other));
 
-         if (sRef_isValid (nother))
+         if (sRef_isReasonable (nother))
            {
              sRef_copyState (nother, other);
              sRef_mergeStateAux (res, nother, cl, opt, loc, doDerivs);
@@ -3957,8 +4043,6 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
   ** Merge value table states
   */
 
-
-  /*@i3245@*/
 # if 0
   /*
   ** This doesn't do anything.  And its broken too...
@@ -3985,6 +4069,9 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
   } end_valueTable_elements ; 
 # endif
 
+  DPRINTF (("Merge aux: %s / %s",
+           sRef_unparseFull (res),
+           sRef_unparseFull (other)));
 }
 
 static sRefSet
@@ -4000,11 +4087,11 @@ sRef_mergeUnionDerivs (/*@only@*/ sRefSet res,
     {
       sRefSet_allElements (other, el)
        {
-         if (sRef_isValid (el))
+         if (sRef_isReasonable (el))
            {
              sRef e2 = sRefSet_lookupMember (other, el);
              
-             if (sRef_isValid (e2))
+             if (sRef_isReasonable (e2))
                {
                  sRef_mergeStateAux (el, e2, cl, opt, loc, FALSE);
                }
@@ -4027,11 +4114,11 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
 
   sRefSet_allElements (res, el)
     {
-      if (sRef_isValid (el))
+      if (sRef_isReasonable (el))
        {
          sRef e2 = sRefSet_lookupMember (other, el);
 
-         if (sRef_isValid (e2))
+         if (sRef_isReasonable (e2))
            {
              if (el->defstate == SS_ALLOCATED &&
                  e2->defstate == SS_PDEFINED)
@@ -4042,13 +4129,16 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
                       el->defstate == SS_PDEFINED)
                {
                  el->defstate = SS_ALLOCATED;
+                 el->definfo = stateInfo_update (el->definfo, e2->definfo);
                  sRef_clearDerived (el);
                }
              else if ((el->defstate == SS_DEAD || sRef_isKept (el)) &&
                       (e2->defstate == SS_DEFINED && !sRef_isKept (e2)))
                {
-                 
-                 if (checkDeadState (el, TRUE, loc))
+                 DPRINTF (("Checking dead: %s / %s", sRef_unparseFull (el),
+                           sRef_unparseFull (e2)));
+
+                 if (checkDeadState (el, e2, TRUE, loc))
                    {
                      if (sRef_isThroughArrayFetch (el))
                        {
@@ -4060,8 +4150,10 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
              else if ((e2->defstate == SS_DEAD || sRef_isKept (e2)) &&
                       (el->defstate == SS_DEFINED && !sRef_isKept (el)))
                {
-                 
-                 if (checkDeadState (e2, FALSE, loc))
+                 DPRINTF (("Checking dead: %s / %s", sRef_unparseFull (el),
+                           sRef_unparseFull (e2)));
+
+                 if (checkDeadState (e2, el, FALSE, loc))
                    {
                      if (sRef_isThroughArrayFetch (el))
                        {
@@ -4075,12 +4167,14 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
                {
                  DPRINTF (("set pdefined: %s", sRef_unparseFull (el)));
                  el->defstate = SS_PDEFINED;
+                 el->definfo = stateInfo_update (el->definfo, e2->definfo);
                }
              else if (e2->defstate == SS_DEFINED &&
                       el->defstate == SS_PDEFINED)
                {
                  DPRINTF (("set pdefined: %s", sRef_unparseFull (e2)));
                  e2->defstate = SS_PDEFINED;
+                 e2->definfo = stateInfo_update (e2->definfo, el->definfo);
                }
              else
                {
@@ -4105,7 +4199,7 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
                {
                  sRef sr = sRef_leastCommon (el, e2);
 
-                 if (sRef_isValid (sr))
+                 if (sRef_isReasonable (sr))
                    {
                      ret = sRefSet_insert (ret, sr);
                    }
@@ -4119,16 +4213,18 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
            }
          else /* not defined */
            {
-             (void) checkDeadState (el, TRUE, loc);
+             DPRINTF (("Checking dead: %s", sRef_unparseFull (el)));
+             (void) checkDeadState (el, e2, TRUE, loc);
            }
        }
     } end_sRefSet_allElements;
 
   sRefSet_allElements (other, el)
     {
-      if (sRef_isValid (el))
+      if (sRef_isReasonable (el))
        {
-         (void) checkDeadState (el, FALSE, loc);
+         DPRINTF (("Checking dead: %s", sRef_unparseFull (el)));
+         (void) checkDeadState (el, sRef_undefined, FALSE, loc);
        }
     } end_sRefSet_allElements;
     
@@ -4140,7 +4236,7 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other,
 ** Returns TRUE is there is an error.
 */
 
-static bool checkDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc)
+static bool checkDeadState (/*@notnull@*/ sRef el, sRef e2, bool tbranch, fileloc loc)
 {
   /*
   ** usymtab_isGuarded --- the utab should still be in the
@@ -4157,7 +4253,8 @@ static bool checkDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc)
 
   
   if ((sRef_isDead (el) || sRef_isKept (el))
-      && !sRef_isDeepUnionField (el) && !sRef_isThroughArrayFetch (el))
+      && !sRef_isDeepUnionField (el) 
+      && !sRef_isThroughArrayFetch (el))
     {
        
       if (!tbranch)
@@ -4192,10 +4289,21 @@ static bool checkDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc)
              sRef_showStateInfo (el);
            }
 
+         if (sRef_isValid (e2))
+           {
+             if (sRef_isKept (e2))
+               {
+                 sRef_showAliasInfo (e2);      
+               }
+             else
+               {
+                 sRef_showStateInfo (e2);
+               }
+           }
+
          /* prevent further errors */
          el->defstate = SS_UNKNOWN; 
-         sRef_setAliasKind (el, AK_ERROR, fileloc_undefined);
-         
+         sRef_setAliasKind (el, AK_ERROR, fileloc_undefined);    
          return FALSE;
        }
     }
@@ -4206,14 +4314,13 @@ static bool checkDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc)
 static void 
 checkDerivDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc)
 {
-  
-  if (checkDeadState (el, tbranch, loc))
+  if (checkDeadState (el, sRef_undefined, tbranch, loc))
     {
       sRefSet_allElements (el->deriv, t)
        {
-         if (sRef_isValid (t))
+         if (sRef_isReasonable (t))
            {
-                     checkDerivDeadState (t, tbranch, loc);
+             checkDerivDeadState (t, tbranch, loc);
            }
        } end_sRefSet_allElements;
     }
@@ -4227,11 +4334,11 @@ static sRefSet
 
   sRefSet_allElements (res, el)
     {
-      if (sRef_isValid (el))
+      if (sRef_isReasonable (el))
        {
          sRef e2 = sRefSet_lookupMember (other, el);
          
-         if (sRef_isValid (e2))
+         if (sRef_isReasonable (e2))
            {
              if (sRef_isAllocated (el) && !sRef_isAllocated (e2))
                {
@@ -4256,7 +4363,7 @@ static sRefSet
            {
              if (!opt)
                {
-                                 checkDerivDeadState (el, (cl == FALSECLAUSE), loc);
+                 checkDerivDeadState (el, (cl == FALSECLAUSE), loc);
                }
 
              ret = sRefSet_insert (ret, el);
@@ -4266,7 +4373,7 @@ static sRefSet
   
   sRefSet_allElements (other, el)
     {
-      if (sRef_isValid (el))
+      if (sRef_isReasonable (el))
        {
          if (!sRefSet_member (ret, el))
            {
@@ -4289,8 +4396,8 @@ static sRefSet
 
 sRef sRef_makeConj (/*@exposed@*/ /*@returned@*/ sRef a, /*@exposed@*/ sRef b)
 {
-  llassert (sRef_isValid (a));
-  llassert (sRef_isValid (b));
+  llassert (sRef_isReasonable (a));
+  llassert (sRef_isReasonable (b));
       
   if (!sRef_equivalent (a, b))
     {
@@ -4299,8 +4406,8 @@ sRef sRef_makeConj (/*@exposed@*/ /*@returned@*/ sRef a, /*@exposed@*/ sRef b)
       s->kind = SK_CONJ;
       s->info = (sinfo) dmalloc (sizeof (*s->info));
       s->info->conj = (cjinfo) dmalloc (sizeof (*s->info->conj));
-      s->info->conj->a = a; /* sRef_copy (a) */ /*@i32*/ ;
-      s->info->conj->b = b; /* sRef_copy (b);*/ /*@i32@*/ ;
+      s->info->conj->a = a;
+      s->info->conj->b = b;
       
       if (ctype_equal (a->type, b->type)) s->type = a->type;
       else s->type = ctype_makeConj (a->type, b->type);
@@ -4308,6 +4415,8 @@ sRef sRef_makeConj (/*@exposed@*/ /*@returned@*/ sRef a, /*@exposed@*/ sRef b)
       if (a->defstate == b->defstate)
        {
          s->defstate = a->defstate;
+         s->definfo = stateInfo_update (s->definfo, a->definfo);
+         s->definfo = stateInfo_update (s->definfo, b->definfo);
        }
       else
        {
@@ -4320,7 +4429,7 @@ sRef sRef_makeConj (/*@exposed@*/ /*@returned@*/ sRef a, /*@exposed@*/ sRef b)
       s->aliaskind = alkind_resolve (a->aliaskind, b->aliaskind);
 
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_MERGED));
       return s;
     }
   else
@@ -4338,7 +4447,7 @@ sRef_makeUnknown ()
   return s;
 }
 
-static /*@owned@*/ sRef
+static /*@owned@*/ /*@notnull@*/ sRef
 sRef_makeSpecial (speckind sk) /*@*/
 {
   sRef s = sRef_new ();
@@ -4420,7 +4529,7 @@ sRef_makeResult (ctype c)
   s->aliaskind = AK_UNKNOWN;
   sRef_setNullStateN (s, NS_UNKNOWN);
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_DECLARED));
 
   DPRINTF (("Result: [%p] %s", s, sRef_unparseFull (s)));
   return s;
@@ -4455,7 +4564,7 @@ sRef_isSpecState (sRef s)
 bool
 sRef_isResult (sRef s)
 {
-  return (sRef_isValid (s) && s->kind == SK_RESULT);
+  return (sRef_isReasonable (s) && s->kind == SK_RESULT);
 }
 
 bool
@@ -4473,7 +4582,7 @@ sRef_isGlobalMarker (sRef s)
 usymId
 sRef_getScopeIndex (sRef s)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   llassert (sRef_isCvar (s));
 
   return (s->info->cvar->index);
@@ -4482,7 +4591,7 @@ sRef_getScopeIndex (sRef s)
 void
 sRef_makeSafe (sRef s)
 {
-  if (sRef_isValid (s)) 
+  if (sRef_isReasonable (s)) 
     {
       s->safe = TRUE;
     }
@@ -4491,7 +4600,7 @@ sRef_makeSafe (sRef s)
 void
 sRef_makeUnsafe (sRef s)
 {
-  if (sRef_isValid (s)) 
+  if (sRef_isReasonable (s)) 
     {
       s->safe = FALSE;
     }
@@ -4505,10 +4614,11 @@ sRef_makeUnsafe (sRef s)
 {
   if (sRef_isInvalid (s)) return (cstring_undefined);
 
-  return (message ("[%d] %q - %q [%s] { %q } < %q >", 
-                  (int) s,
+  return (message ("[%p] %q - %q { %q } [%s] { %q } < %q >", 
+                  s,
                   sRef_unparseDebug (s), 
                   sRef_unparseState (s),
+                  stateInfo_unparse (s->definfo),
                   exkind_unparse (s->oexpkind),
                   sRefSet_unparseDebug (s->deriv),
                   valueTable_unparse (s->state)));
@@ -4520,7 +4630,7 @@ sRef_makeUnsafe (sRef s)
 
   st = message ("%q:", sRef_unparseFull (s));
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRefSet_allElements (s->deriv, el)
        {
@@ -4729,7 +4839,7 @@ static /*@exposed@*/ sRef whatUndefined (/*@exposed@*/ sRef fref, int depth)
                    {
                      sRef wdef = whatUndefined (fldref, depth + 1);
 
-                     if (sRef_isValid (wdef))
+                     if (sRef_isReasonable (wdef))
                        {
                          return wdef;
                        }
@@ -4795,7 +4905,7 @@ static bool checkDefined (/*@temp@*/ sRef sr)
 
 bool sRef_isReallyDefined (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (sRef_isAnyDefined (s))
        {
@@ -4821,7 +4931,7 @@ bool sRef_isReallyDefined (sRef s)
 
 void sRef_showNotReallyDefined (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (sRef_isAnyDefined (s))
        {
@@ -4834,7 +4944,7 @@ void sRef_showNotReallyDefined (sRef s)
              /*@-temptrans@*/ /* the result of whatUndefined is lost */
              sRef ref = whatUndefined (s, 0);
 
-             llassert (sRef_isValid (ref));
+             llassert (sRef_isReasonable (ref));
 
              if (ref != s)
                {
@@ -4890,14 +5000,14 @@ void sRef_setAliasKind (sRef s, alkind kind, fileloc loc)
 {
   sRef_checkMutable (s);  
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_clearDerived (s);
 
       if ((kind != s->aliaskind && kind != s->oaliaskind)
          && fileloc_isDefined (loc))
        {
-         s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
+         s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, stateAction_fromAlkind (kind), loc);
        }
       
       s->aliaskind = kind;
@@ -4908,7 +5018,7 @@ void sRef_setOrigAliasKind (sRef s, alkind kind)
 {
   sRef_checkMutable (s);  
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       s->oaliaskind = kind;
     }
@@ -4916,7 +5026,7 @@ void sRef_setOrigAliasKind (sRef s, alkind kind)
 
 exkind sRef_getExKind (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       return (s->expkind);
     }
@@ -4928,7 +5038,7 @@ exkind sRef_getExKind (sRef s)
 
 exkind sRef_getOrigExKind (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       return (s->oexpkind);
     }
@@ -4965,11 +5075,11 @@ void sRef_setExKind (sRef s, exkind exp, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (s->expkind != exp)
        {
-         s->expinfo = stateInfo_updateLoc (s->expinfo, loc);
+         s->expinfo = stateInfo_updateLoc (s->expinfo, stateAction_fromExkind (exp), loc);
        }
       
       s->expkind = exp;
@@ -4985,7 +5095,7 @@ static void sRef_copyRealDerived (sRef s1, sRef s2)
   DPRINTF (("Copy real: %s / %s", sRef_unparse (s1), sRef_unparse (s2)));
   sRef_checkMutable (s1);
 
-  if (sRef_isValid (s1) && sRef_isValid (s2))
+  if (sRef_isReasonable (s1) && sRef_isReasonable (s2))
     {
       sRef sb = sRef_getRootBase (s1);
 
@@ -4993,7 +5103,7 @@ static void sRef_copyRealDerived (sRef s1, sRef s2)
 
       sRefSet_allElements (s2->deriv, el)
        {
-         if (sRef_isValid (el))
+         if (sRef_isReasonable (el))
            {
              sRef rb = sRef_getRootBase (el);
              
@@ -5001,7 +5111,7 @@ static void sRef_copyRealDerived (sRef s1, sRef s2)
                {
                  sRef fb = sRef_fixDirectBase (el, s1);
                  
-                 if (sRef_isValid (fb))
+                 if (sRef_isReasonable (fb))
                    {
                      sRef_copyRealDerived (fb, el);
                      sRef_addDeriv (s1, fb);
@@ -5026,14 +5136,10 @@ void sRef_setUndefined (sRef s, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       s->defstate = SS_UNDEFINED;
-
-      if (fileloc_isDefined (loc))
-       {
-         s->definfo = stateInfo_updateLoc (s->definfo, loc);
-       }
+      s->definfo = stateInfo_updateLoc (s->definfo, SA_UNDEFINED, loc);
 
       sRef_clearDerived (s);
     }
@@ -5046,11 +5152,7 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
 
   DPRINTF (("Set defined: %s", sRef_unparseFull (s)));
 
-  if (s->defstate != SS_DEFINED && fileloc_isDefined (loc))
-    {
-      s->definfo = stateInfo_updateLoc (s->definfo, loc);
-    }
-  
+  s->definfo = stateInfo_updateLoc (s->definfo, SA_DEFINED, loc);  
   s->defstate = SS_DEFINED;
   
   DPRINTF (("Set defined: %s", sRef_unparseFull (s)));
@@ -5074,7 +5176,7 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
 
       arr = sRef_findDerivedArrayFetch (p, FALSE, 0, FALSE);
 
-      if (sRef_isValid (arr))
+      if (sRef_isReasonable (arr))
        {
          sRef_setDefinedAux (arr, loc, clear);
        }
@@ -5087,7 +5189,7 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
          sRef p = s->info->arrayfetch->arr;
          sRef ptr = sRef_constructPointer (p);
 
-         if (sRef_isValid (ptr))
+         if (sRef_isReasonable (ptr))
            {
              if (ptr->defstate == SS_ALLOCATED 
                  || ptr->defstate == SS_UNDEFINED
@@ -5115,7 +5217,7 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
     {
       sRef parent = s->info->field->rec;
       
-      if (sRef_isValid (parent))
+      if (sRef_isReasonable (parent))
        {
          if (ctype_isUnion (ctype_realType (parent->type)))
            {
@@ -5146,10 +5248,11 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
       /* evans 2001-07-12: need to define the derived references */
       sRefSet_elements (s->deriv, el)
        {
+         llassert (sRef_isReasonable (el));
          el->defstate = SS_DEFINED;
        } end_sRefSet_elements ;
     }
-
+  
   DPRINTF (("Set defined: %s", sRef_unparseFull (s)));
 }
 
@@ -5185,7 +5288,7 @@ void sRef_setDefinedCompleteDirect (sRef s, fileloc loc)
 
   sRefSet_realElements (aliases, current)
     {
-      if (sRef_isValid (current))
+      if (sRef_isReasonable (current))
        {
          current = sRef_updateSref (current);
          sRef_setDefined (current, loc);
@@ -5225,7 +5328,7 @@ static bool sRef_isDeepUnionField (sRef s)
 
 bool sRef_isUnionField (sRef s)
 {
-  if (sRef_isValid (s) && s->kind == SK_FIELD)
+  if (sRef_isReasonable (s) && s->kind == SK_FIELD)
     {
       /*
        ** defining one field of a union defines the union
@@ -5233,7 +5336,7 @@ bool sRef_isUnionField (sRef s)
       
       sRef base = s->info->field->rec;
 
-      if (sRef_isValid (base))
+      if (sRef_isReasonable (base))
        {
          return (ctype_isUnion (ctype_realType (base->type)));
        }
@@ -5245,7 +5348,7 @@ bool sRef_isUnionField (sRef s)
 void sRef_setPdefined (sRef s, fileloc loc)
 {
   sRef_checkMutable (s);
-  if (sRef_isValid (s) && !sRef_isPartial (s))
+  if (sRef_isReasonable (s) && !sRef_isPartial (s))
     {
       sRef base = sRef_getBaseSafe (s);
 
@@ -5254,17 +5357,12 @@ void sRef_setPdefined (sRef s, fileloc loc)
          return;
        }
       
-      if (s->defstate != SS_PDEFINED && fileloc_isDefined (loc))
-       {
-         s->definfo = stateInfo_updateLoc (s->definfo, loc);
-       }
-
-      DPRINTF (("set pdefined: %s", sRef_unparseFull (s)));
+      s->definfo = stateInfo_updateLoc (s->definfo, SA_PDEFINED, loc);
       s->defstate = SS_PDEFINED;
       
       /* e.g., if x is allocated, *x = 3 defines x */
       
-      while (sRef_isValid (base) && sRef_isKnown (base))
+      while (sRef_isReasonable (base) && sRef_isKnown (base))
        {
          if (base->defstate == SS_DEFINED)
            { 
@@ -5287,13 +5385,16 @@ static void sRef_setStateAux (sRef s, sstate ss, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  DPRINTF (("Set state: %s => %s", sRef_unparseFull (s), sstate_unparse (ss)));
+
+  if (sRef_isReasonable (s))
     {
       /* if (s->defstate == SS_RELDEF) return; */
 
       if (s->defstate != ss && fileloc_isDefined (loc))
        {
-         s->definfo = stateInfo_updateLoc (s->definfo, loc);
+         s->definfo = stateInfo_updateLoc (s->definfo, 
+                                           stateAction_fromSState (ss), loc);
        }
 
       s->defstate = ss;
@@ -5303,7 +5404,7 @@ static void sRef_setStateAux (sRef s, sstate ss, fileloc loc)
        {
          sRef base = sRef_getBaseSafe (s);
          
-         while (sRef_isValid (base) && sRef_isKnown (base))
+         while (sRef_isReasonable (base) && sRef_isKnown (base))
            {
              if (base->defstate == SS_DEFINED) 
                { 
@@ -5332,16 +5433,12 @@ static void sRef_setAllocatedShallow (sRef s, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (s->defstate == SS_DEAD || s->defstate == SS_UNDEFINED)
        {
          s->defstate = SS_ALLOCATED;
-         
-         if (fileloc_isDefined (loc))
-           {
-             s->definfo = stateInfo_updateLoc (s->definfo, loc);
-           }
+         s->definfo = stateInfo_updateLoc (s->definfo, SA_ALLOCATED, loc);
        }
     }
 }
@@ -5367,11 +5464,11 @@ void sRef_setShared (sRef s, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (s->aliaskind != AK_SHARED && fileloc_isDefined (loc))
        {
-         s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
+         s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, SA_SHARED, loc);
        }
 
       s->aliaskind = AK_SHARED;
@@ -5383,30 +5480,29 @@ void sRef_setLastReference (sRef s, /*@exposed@*/ sRef ref, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       s->aliaskind = sRef_getAliasKind (ref);
-      s->aliasinfo = stateInfo_updateRefLoc (s->aliasinfo, ref, loc);
+      s->aliasinfo = stateInfo_updateRefLoc (s->aliasinfo, ref, stateAction_fromAlkind (s->aliaskind), loc);
     }
 }
 
 static
 void sRef_setNullStateAux (/*@notnull@*/ sRef s, nstate ns, fileloc loc)
 {
-  DPRINTF (("Set null state: %s / %s", sRef_unparse (s), nstate_unparse (ns)));
   sRef_checkMutable (s);
   s->nullstate = ns;
   sRef_resetAliasKind (s);
 
   if (fileloc_isDefined (loc))
     {
-      s->nullinfo = stateInfo_updateLoc (s->nullinfo, loc);
+      s->nullinfo = stateInfo_updateLoc (s->nullinfo, stateAction_fromNState (ns), loc);
     }
 }
 
 void sRef_setNotNull (sRef s, fileloc loc)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_setNullStateAux (s, NS_NOTNULL, loc);
     }
@@ -5414,14 +5510,17 @@ void sRef_setNotNull (sRef s, fileloc loc)
 
 void sRef_setNullStateN (sRef s, nstate n)
 {
-  sRef_checkMutable (s);
-  s->nullstate = n;
-  sRef_resetAliasKind (s);
+  if (sRef_isReasonable (s))
+    {
+      sRef_checkMutable (s);
+      s->nullstate = n;
+      sRef_resetAliasKind (s);
+    }
 }
 
 void sRef_setNullState (sRef s, nstate n, fileloc loc)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_setNullStateAux (s, n, loc);
     }
@@ -5430,19 +5529,20 @@ void sRef_setNullState (sRef s, nstate n, fileloc loc)
 void sRef_setNullTerminatedStateInnerComplete (sRef s, struct s_bbufinfo b, /*@unused@*/ fileloc loc) 
 {
   switch (b.bufstate) {
-     case BB_NULLTERMINATED:
-         sRef_setNullTerminatedState (s);
-          sRef_setLen (s, b.len);
-          break;
-     case BB_POSSIBLYNULLTERMINATED:
-          sRef_setPossiblyNullTerminatedState(s);
-          break;
-     case BB_NOTNULLTERMINATED:
-          sRef_setNotNullTerminatedState (s);
-          break;
+  case BB_NULLTERMINATED:
+    sRef_setNullTerminatedState (s);
+    sRef_setLen (s, b.len);
+    break;
+  case BB_POSSIBLYNULLTERMINATED:
+    sRef_setPossiblyNullTerminatedState(s);
+    break;
+  case BB_NOTNULLTERMINATED:
+    sRef_setNotNullTerminatedState (s);
+    break;
   }
-  sRef_setSize (s, b.size);
 
+  sRef_setSize (s, b.size);
+  
   /* PL: TO BE DONE : Aliases are not modified right now, have to be similar to
    * setNullStateInnerComplete.
    */
@@ -5488,7 +5588,7 @@ void sRef_setNullStateInnerComplete (sRef s, nstate n, fileloc loc)
 
 void sRef_setPosNull (sRef s, fileloc loc)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_setNullStateAux (s, NS_POSNULL, loc);
     }
@@ -5496,7 +5596,7 @@ void sRef_setPosNull (sRef s, fileloc loc)
   
 void sRef_setDefNull (sRef s, fileloc loc)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_setNullStateAux (s, NS_DEFNULL, loc);
     }
@@ -5504,7 +5604,7 @@ void sRef_setDefNull (sRef s, fileloc loc)
 
 void sRef_setNullUnknown (sRef s, fileloc loc)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef_setNullStateAux (s, NS_UNKNOWN, loc);
     }
@@ -5512,63 +5612,62 @@ void sRef_setNullUnknown (sRef s, fileloc loc)
 
 void sRef_setNullError (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s) && !sRef_isConst (s))
     {
       sRef_setNullStateAux (s, NS_UNKNOWN, fileloc_undefined);
     }
 }
 
-void sRef_setNullErrorLoc (sRef s, /*@unused@*/ fileloc loc)
+void sRef_setNullErrorLoc (sRef s, fileloc loc)
 {
-  sRef_setNullError (s);
+  if (sRef_isReasonable (s) && !sRef_isConst (s))
+    {
+      sRef_setNullStateAux (s, NS_UNKNOWN, loc);
+    }
 }
 
 void sRef_setOnly (sRef s, fileloc loc)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s) && s->aliaskind != AK_ONLY)
+  if (sRef_isReasonable (s) && s->aliaskind != AK_ONLY)
     {
+      sRef_checkMutable (s);
       s->aliaskind = AK_ONLY;
-      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
-          }
+      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, SA_ONLY, loc);
+    }
 }
 
 void sRef_setDependent (sRef s, fileloc loc)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s) && !sRef_isConst (s) && (s->aliaskind != AK_DEPENDENT))
+  if (sRef_isReasonable (s) && !sRef_isConst (s) && (s->aliaskind != AK_DEPENDENT))
     {
+      sRef_checkMutable (s);
       DPRINTF (("Setting dependent: %s", sRef_unparseFull (s)));
       s->aliaskind = AK_DEPENDENT;
-      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
+      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, SA_DEPENDENT, loc);
     }
 }
 
 void sRef_setOwned (sRef s, fileloc loc)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s) && !sRef_isConst (s) && (s->aliaskind != AK_OWNED))
+  if (sRef_isReasonable (s) && !sRef_isConst (s) && (s->aliaskind != AK_OWNED))
     {
+      sRef_checkMutable (s);
       s->aliaskind = AK_OWNED;
-      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
+      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, SA_OWNED, loc);
     }
 }
 
 void sRef_setKept (sRef s, fileloc loc)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s) && !sRef_isConst (s) && (s->aliaskind != AK_KEPT))
+  if (sRef_isReasonable (s) && !sRef_isConst (s) && (s->aliaskind != AK_KEPT))
     {
       sRef base = sRef_getBaseSafe (s);  
-      
-      while (sRef_isValid (base) && sRef_isKnown (base))
+      while (sRef_isReasonable (base) && sRef_isKnown (base))
        {
          if (base->defstate == SS_DEFINED) 
            {
+             sRef_checkMutable (base);
              base->defstate = SS_PDEFINED; 
              base = sRef_getBaseSafe (base); 
            }
@@ -5578,8 +5677,9 @@ void sRef_setKept (sRef s, fileloc loc)
            }
        }
 
+      sRef_checkMutable (s);
       s->aliaskind = AK_KEPT;
-      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
+      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, SA_KEPT, loc);
     }
 }
 
@@ -5611,28 +5711,29 @@ void sRef_setDependentComplete (sRef s, fileloc loc)
 
 void sRef_setFresh (sRef s, fileloc loc)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s) && !sRef_isConst (s))
     {
+      sRef_checkMutable (s);
       s->aliaskind = AK_FRESH;
-      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc);
+      s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, SA_CREATED, loc);
+      DPRINTF (("SetFresh: %s", sRef_unparseFull (s)));
     }
 }
 
 void sRef_kill (sRef s, fileloc loc)
 {
   DPRINTF (("Kill: %s", sRef_unparseFull (s)));
-  sRef_checkMutable (s);
 
-  if (sRef_isValid (s) && !sRef_isShared (s) && !sRef_isConst (s))
+  if (sRef_isReasonable (s) && !sRef_isShared (s) && !sRef_isConst (s))
     {
       sRef base = sRef_getBaseSafe (s);  
-      
-      while (sRef_isValid (base) && sRef_isKnown (base))
+      sRef_checkMutable (s);
+       
+      while (sRef_isReasonable (base) && sRef_isKnown (base))
        {
          if (base->defstate == SS_DEFINED) 
            {
+             sRef_checkMutable (base);
              base->defstate = SS_PDEFINED; 
              base = sRef_getBaseSafe (base); 
            }
@@ -5644,25 +5745,24 @@ void sRef_kill (sRef s, fileloc loc)
       
       s->aliaskind = s->oaliaskind;
       s->defstate = SS_DEAD;
-      s->definfo = stateInfo_updateLoc (s->definfo, loc);
-
+      s->definfo = stateInfo_updateLoc (s->definfo, SA_KILLED, loc);
+      DPRINTF (("State info: %s", stateInfo_unparse (s->definfo)));
       sRef_clearDerived (s);
     }
 }
 
 void sRef_maybeKill (sRef s, fileloc loc)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef base = sRef_getBaseSafe (s);  
-
+      sRef_checkMutable (s);
             
-      while (sRef_isValid (base) && sRef_isKnown (base))
+      while (sRef_isReasonable (base) && sRef_isKnown (base))
        {
          if (base->defstate == SS_DEFINED || base->defstate == SS_RELDEF)
            {
+             sRef_checkMutable (base);
              base->defstate = SS_PDEFINED; 
              base = sRef_getBaseSafe (base); 
            }
@@ -5675,7 +5775,9 @@ void sRef_maybeKill (sRef s, fileloc loc)
       
       s->aliaskind = s->oaliaskind;
       s->defstate = SS_HOFFA; 
-      s->definfo = stateInfo_updateLoc (s->definfo, loc);
+      s->definfo = stateInfo_updateLoc (s->definfo, SA_PKILLED, loc);
+      DPRINTF (("State info: %s / %s", sRef_unparse (s), 
+               stateInfo_unparse (s->definfo)));
       sRef_clearDerived (s); 
     }
 
@@ -5687,7 +5789,7 @@ void sRef_maybeKill (sRef s, fileloc loc)
 
 static void sRef_killAux (sRef s, fileloc loc)
 {
-  if (sRef_isValid (s) && !sRef_isShared (s))
+  if (sRef_isReasonable (s) && !sRef_isShared (s))
     {
       if (sRef_isUnknownArrayFetch (s))
        {
@@ -5723,7 +5825,7 @@ static bool sRef_equivalent (sRef s1, sRef s2)
 {
   sRef ret;
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       bool old = inFunction;
 
@@ -5757,7 +5859,7 @@ sRef sRef_copy (sRef s)
       /*@=retalias@*/
     }
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef t = sRef_alloc ();
 
@@ -5794,8 +5896,8 @@ sRef sRef_copy (sRef s)
 
       t->deriv = sRefSet_newDeepCopy (s->deriv);
       t->state = valueTable_copy (s->state);
-
-      DPRINTF (("Made copy: [%p] %s", t, sRef_unparse (t)));
+      
+      DPRINTF (("Made copy: %s => %s", sRef_unparseFull (s), sRef_unparseFull (t)));
       return t;
     }
   else
@@ -5823,7 +5925,7 @@ bool sRef_isAddress (sRef s)
 
 bool sRef_isThroughArrayFetch (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef tref = s;
 
@@ -5838,7 +5940,7 @@ bool sRef_isThroughArrayFetch (sRef s)
          
          lt = sRef_getBase (tref);
          tref = lt;
-       } while (sRef_isValid (tref));
+       } while (sRef_isReasonable (tref));
     } 
 
   return FALSE;
@@ -5926,7 +6028,7 @@ bool sRef_isDirectParam (sRef s)
   return ((s->kind == SK_CVAR) &&
          (s->info->cvar->lexlevel == functionScope) &&
          (context_inFunction () && 
-          (s->info->cvar->index <= uentryList_size (context_getParams ()))));
+          (s->info->cvar->index <= usymId_fromInt (uentryList_size (context_getParams ())))));
 }
 
 bool sRef_isPointer (sRef s)
@@ -5989,6 +6091,8 @@ void sRef_free (/*@only@*/ sRef s)
       DPRINTF (("Free sref: [%p]", s));
 
       sRef_checkValid (s);
+      
+      multiVal_free (s->val); /* evans 2002-07-12 */
 
       stateInfo_free (s->expinfo);
       stateInfo_free (s->aliasinfo);
@@ -5998,7 +6102,7 @@ void sRef_free (/*@only@*/ sRef s)
       sRefSet_free (s->deriv);
       s->deriv = sRefSet_undefined;
 
-      /*@i43@*/ /* valueTable_free (s->state); */
+      valueTable_free (s->state); 
       sinfo_free (s);
       
       
@@ -6008,26 +6112,24 @@ void sRef_free (/*@only@*/ sRef s)
       s->definfo = stateInfo_undefined;
       s->nullinfo = stateInfo_undefined;
 
-      /*@i32@*/ sfree (s);
+      sfree (s);
     }
 }
 
 void sRef_setType (sRef s, ctype t)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
+      sRef_checkMutable (s); 
       s->type = t;
     }
 }
 
 void sRef_setTypeFull (sRef s, ctype t)
 {
-  sRef_checkMutable (s);
-
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
+      sRef_checkMutable (s);
       s->type = t;
 
       sRefSet_allElements (s->deriv, current)
@@ -6046,17 +6148,24 @@ void sRef_setTypeFull (sRef s, ctype t)
 static /*@exposed@*/ sRef
 sRef_findDerivedField (/*@notnull@*/ sRef rec, cstring f)
 {
-  sRefSet_allElements (rec->deriv, sr)
+  sRefSet_allElements (sRef_derivedFields (rec), sr)
     {
-      if (sRef_isValid (sr))
+      if (sRef_isReasonable (sr))
        {
-         if (sr->info != NULL) 
+         if (sRef_isReasonable (sr))
            {
-             if (sr->kind == SK_FIELD && cstring_equal (sr->info->field->field, f))
+             if (sr->info != NULL) 
                {
-                 return sr;
+                 if (sr->kind == SK_FIELD && cstring_equal (sr->info->field->field, f))
+                   {
+                     return sr;
+                   }
                }
            }
+         else
+           {
+             llcontbug (message ("Invalid sRef as derived field of %s", sRef_unparse (rec)));
+           }
        }
     } end_sRefSet_allElements;
 
@@ -6065,7 +6174,7 @@ sRef_findDerivedField (/*@notnull@*/ sRef rec, cstring f)
 
 /*@dependent@*/ /*@observer@*/ sRefSet sRef_derivedFields (/*@temp@*/ sRef rec)
 {
-  if (sRef_isValid (rec))
+  if (sRef_isReasonable (rec))
     {
       sRefSet ret;
       ret = rec->deriv;
@@ -6080,11 +6189,11 @@ sRef_findDerivedField (/*@notnull@*/ sRef rec, cstring f)
 static /*@exposed@*/ sRef
   sRef_findDerivedPointer (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRefSet_realElements (s->deriv, sr)
        {
-         if (sRef_isValid (sr) && sr->kind == SK_PTR)
+         if (sRef_isReasonable (sr) && sr->kind == SK_PTR)
            {
              return sr;
            }
@@ -6097,7 +6206,7 @@ static /*@exposed@*/ sRef
 bool
 sRef_isUnknownArrayFetch (sRef s)
 {
-  return (sRef_isValid (s) 
+  return (sRef_isReasonable (s) 
          && s->kind == SK_ARRAYFETCH
          && !s->info->arrayfetch->indknown);
 }
@@ -6110,7 +6219,7 @@ sRef_findDerivedArrayFetch (/*@notnull@*/ sRef s, bool isknown, int idx, bool de
     {
       sRefSet_realElements (s->deriv, sr)
        {
-         if (sRef_isValid (sr)
+         if (sRef_isReasonable (sr)
              && sr->kind == SK_ARRAYFETCH
              && sr->info->arrayfetch->indknown
              && (sr->info->arrayfetch->ind == idx))
@@ -6123,7 +6232,7 @@ sRef_findDerivedArrayFetch (/*@notnull@*/ sRef s, bool isknown, int idx, bool de
     {
       sRefSet_realElements (s->deriv, sr)
        {
-         if (sRef_isValid (sr)
+         if (sRef_isReasonable (sr)
              && sr->kind == SK_ARRAYFETCH
              && (!sr->info->arrayfetch->indknown
                  || (sr->info->arrayfetch->indknown && 
@@ -6166,7 +6275,7 @@ sRef_buildNCField (/*@exposed@*/ sRef rec, /*@exposed@*/ cstring f)
 
   s = sRef_findDerivedField (rec, f);
   
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       return s;
     }
@@ -6180,7 +6289,7 @@ sRef_buildNCField (/*@exposed@*/ sRef rec, /*@exposed@*/ cstring f)
       s->kind = SK_FIELD;
       s->info = (sinfo) dmalloc (sizeof (*s->info));
       s->info->field = (fldinfo) dmalloc (sizeof (*s->info->field));
-      s->info->field->rec = rec; /* sRef_copy (rec); */ /*@i32@*/
+      s->info->field->rec = rec;
       s->info->field->field = f; /* doesn't copy f */
       
       if (ctype_isKnown (ct) && ctype_isSU (ct))
@@ -6217,7 +6326,7 @@ sRef_buildNCField (/*@exposed@*/ sRef rec, /*@exposed@*/ cstring f)
              
              s->oaliaskind = s->aliaskind;
              s->oexpkind = s->expkind;
-             
+
              DPRINTF (("sref: %s", sRef_unparseFull (s)));
            }
          else
@@ -6293,7 +6402,7 @@ sRef_buildNCField (/*@exposed@*/ sRef rec, /*@exposed@*/ cstring f)
 bool
 sRef_isStackAllocated (sRef s)
 {
-  return (sRef_isValid(s) 
+  return (sRef_isReasonable(s) 
          && s->defstate == SS_ALLOCATED && ctype_isStackAllocated (s->type));
 }
          
@@ -6326,14 +6435,16 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
     {
       sRef sp = sRef_findDerivedPointer (arr);
       
-      if (sRef_isValid (sp))
+      if (sRef_isReasonable (sp))
        {
          
          if (ctype_isMutable (s->type))
            {
-             sRef_setExKind (s, sRef_getExKind (sp), fileloc_undefined);
-                     
+             s->expkind = sRef_getExKind (sp);
+             s->expinfo = stateInfo_copy (sp->expinfo);
+             
              s->aliaskind = sp->aliaskind;
+             s->aliasinfo = stateInfo_copy (sp->aliasinfo);
            }
 
          s->defstate = sp->defstate;
@@ -6346,6 +6457,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
                }
            }
 
+         DPRINTF (("Set null state: %s / %s", sRef_unparseFull (s), sRef_unparseFull (sp)));
          sRef_setNullStateN (s, sRef_getNullState (sp));
        }
       else
@@ -6376,8 +6488,9 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
              */
            }
 
-         sRef_setExKind (s, sRef_getExKind (arr), g_currentloc);
-
+         s->expkind = sRef_getExKind (arr);
+         s->expinfo = stateInfo_copy (arr->expinfo);
+         
          if (arr->aliaskind == AK_LOCAL || arr->aliaskind == AK_FRESH)
            {
              s->aliaskind = AK_LOCAL;
@@ -6428,32 +6541,38 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
                  
                  sRefSet_allElements (arr->deriv, sr)
                    {
-                     if (sRef_isValid (sr))
+                     if (sRef_isReasonable (sr))
                        {
-                         if (sr->defstate == SS_ALLOCATED)
-                           {
-                             s->defstate = SS_ALLOCATED;
-                           }
-                         else 
+                         if (sRef_isReasonable (sr))
                            {
-                             if (sr->defstate == SS_DEFINED)
+                             if (sr->defstate == SS_ALLOCATED)
                                {
-                                 if (context_getFlag (FLG_STRICTDESTROY))
-                                   {
-                                     s->defstate = SS_DEFINED;
-                                   }
-                                 else
+                                 s->defstate = SS_ALLOCATED;
+                               }
+                             else 
+                               {
+                                 if (sr->defstate == SS_DEFINED)
                                    {
-                                     s->defstate = SS_PARTIAL;
+                                     if (context_getFlag (FLG_STRICTDESTROY))
+                                       {
+                                         s->defstate = SS_DEFINED;
+                                       }
+                                     else
+                                       {
+                                         s->defstate = SS_PARTIAL;
+                                       }
+                                     
+                                     break;
                                    }
-
-                                 break;
                                }
                            }
+                         else
+                           {
+                             llcontbug (message ("Invalid sRef as derived element of %s", sRef_unparse (arr)));
+                           }
                        }
                    } end_sRefSet_allElements;
-                 
-                               }
+               }
              else
                {
                  s->defstate = SS_UNDEFINED;
@@ -6488,6 +6607,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
   if (sRef_isObserver (arr)) 
     {
       s->expkind = XO_OBSERVER;
+      s->expinfo = stateInfo_copy (arr->expinfo);
     }
 }  
 
@@ -6495,7 +6615,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
 {
   sRef s;
 
-  if (!sRef_isValid (arr)) {
+  if (!sRef_isReasonable (arr)) {
     /*@-nullret@*/ return arr /*@=nullret@*/;
   }
 
@@ -6506,7 +6626,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
   
   s = sRef_findDerivedArrayFetch (arr, FALSE, 0, FALSE);
   
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       /* evans 2001-07-12: this is bogus, clean-up hack */
       if (s->info->arrayfetch->arr != arr)
@@ -6519,7 +6639,9 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
          return res;
        }
 
-      sRef_setExKind (s, sRef_getExKind (arr), g_currentloc);
+      s->expkind = sRef_getExKind (arr);
+      s->expinfo = stateInfo_copy (arr->expinfo);
+
       return s;
     }
   else
@@ -6531,8 +6653,10 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
       s->info->arrayfetch = (ainfo) dmalloc (sizeof (*s->info->arrayfetch));
       s->info->arrayfetch->indknown = FALSE;
       s->info->arrayfetch->ind = 0;
-      s->info->arrayfetch->arr = arr; /* sRef_copy (arr); */ /*@i32@*/
+      s->info->arrayfetch->arr = arr;
+
       sRef_setArrayFetchState (s, arr);
+
       s->oaliaskind = s->aliaskind;
       s->oexpkind = s->expkind;
 
@@ -6543,9 +6667,10 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
       
       if (valueTable_isUndefined (s->state))
        {
-         s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+         s->state = context_createValueTable 
+           (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
        }
-
+      
       return (s);
     }
 }
@@ -6555,7 +6680,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
 {
   sRef s;
 
-  if (!sRef_isValid (arr)) {
+  if (!sRef_isReasonable (arr)) {
     /*@-nullret@*/ return arr /*@=nullret@*/;
   }
 
@@ -6566,7 +6691,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
 
   s = sRef_findDerivedArrayFetch (arr, TRUE, i, FALSE);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       /* evans 2001-07-12: this is bogus, clean-up hack */
       if (s->info->arrayfetch->arr != arr)
@@ -6582,7 +6707,9 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
          return res;
        }
 
-      sRef_setExKind (s, sRef_getExKind (arr), g_currentloc);      
+      s->expkind = sRef_getExKind (arr);
+      s->expinfo = stateInfo_copy (arr->expinfo);
+
       llassert (s->info->arrayfetch->arr == arr);
       return s;
     }
@@ -6593,7 +6720,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
       s->kind = SK_ARRAYFETCH;
       s->info = (sinfo) dmalloc (sizeof (*s->info));
       s->info->arrayfetch = (ainfo) dmalloc (sizeof (*s->info->arrayfetch));
-      s->info->arrayfetch->arr = arr; /* sRef_copy (arr); */ /*@i32@*/
+      s->info->arrayfetch->arr = arr;
       s->info->arrayfetch->indknown = TRUE;
       s->info->arrayfetch->ind = i;
 
@@ -6605,7 +6732,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
       sRef_addDeriv (arr, s);
 
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
       return (s);
     }
 }
@@ -6619,7 +6746,7 @@ sRef_setPartsFromUentry (sRef s, uentry ue)
 {    
   sRef uref = uentry_getSref (ue);
 
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   s->aliaskind = alkind_derive (s->aliaskind, uentry_getAliasKind (ue));
   s->oaliaskind = s->aliaskind;
@@ -6633,7 +6760,7 @@ sRef_setPartsFromUentry (sRef s, uentry ue)
   
   if (sRef_getNullState (s) == NS_UNKNOWN)
     {
-      DPRINTF (("Setting null state!"));
+      DPRINTF (("Set null state: %s / %s", sRef_unparseFull (s), uentry_unparseFull (ue)));
       sRef_setNullStateN (s, sRef_getNullState (uentry_getSref (ue)));
     }
   else
@@ -6646,7 +6773,7 @@ sRef_setPartsFromUentry (sRef s, uentry ue)
       s->oaliaskind = s->aliaskind = AK_IMPDEPENDENT;
     } 
 
-  if (sRef_isValid (uref))
+  if (sRef_isReasonable (uref))
     {
       valueTable utable = uref->state;
       valueTable_free (s->state);
@@ -6657,7 +6784,7 @@ sRef_setPartsFromUentry (sRef s, uentry ue)
 static void
 sRef_setStateFromAbstractUentry (sRef s, uentry ue)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   sRef_checkMutable (s);
 
   sRef_setPartsFromUentry (s, ue);
@@ -6679,7 +6806,7 @@ sRef_setStateFromUentry (sRef s, uentry ue)
   sstate defstate;
 
   sRef_checkMutable (s);
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   
   sRef_setPartsFromUentry (s, ue);
 
@@ -6713,10 +6840,11 @@ sRef_setStateFromUentry (sRef s, uentry ue)
 
       DPRINTF (("find derived: %s", sRef_unparse (s)));
 
-      if (sRef_isValid (s))
+      if (sRef_isReasonable (s))
        {
-         
-         sRef_setExKind (s, sRef_getExKind (t), g_currentloc);
+         s->expkind = sRef_getExKind (t);
+         s->expinfo = stateInfo_copy (t->expinfo);       
+
          s->oaliaskind = s->aliaskind;
          s->oexpkind = s->expkind;
 
@@ -6728,7 +6856,7 @@ sRef_setStateFromUentry (sRef s, uentry ue)
          
          DPRINTF (("construct: %s", sRef_unparse (s)));
 
-         if (sRef_isValid (s))
+         if (sRef_isReasonable (s))
            {
              sRef_addDeriv (t, s);
 
@@ -6750,7 +6878,7 @@ sRef_constructPointer (/*@exposed@*/ sRef t)
 
 static /*@exposed@*/ sRef sRef_constructDerefAux (sRef t, bool isdead)
 {
-  if (sRef_isValid (t))
+  if (sRef_isReasonable (t))
     {
       sRef s;
       
@@ -6760,7 +6888,7 @@ static /*@exposed@*/ sRef sRef_constructDerefAux (sRef t, bool isdead)
       
       s = sRef_findDerivedArrayFetch (t, FALSE, 0, isdead);
       
-      if (sRef_isValid (s))
+      if (sRef_isReasonable (s))
        {
          DPRINTF (("Found array fetch: %s", sRef_unparseFull (s)));
          return s;
@@ -6801,7 +6929,7 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
 
   s->kind = SK_PTR;
   s->info = (sinfo) dmalloc (sizeof (*s->info));
-  s->info->ref = t; /* sRef_copy (t); */ /*@i32*/
+  s->info->ref = t; 
   
   if (ctype_isRealAP (rt))
     {
@@ -6813,14 +6941,17 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
   if (t->defstate == SS_UNDEFINED)
     {
       s->defstate = SS_UNUSEABLE;
+      s->definfo = stateInfo_copy (t->definfo);
     }
   else if ((t->defstate == SS_ALLOCATED) && !ctype_isSU (st))
     {
       s->defstate = SS_UNDEFINED;
+      s->definfo = stateInfo_copy (t->definfo);
     }
   else
     {
       s->defstate = t->defstate;
+      s->definfo = stateInfo_copy (t->definfo);
     }
   
   if (t->aliaskind == AK_LOCAL || t->aliaskind == AK_FRESH)
@@ -6832,7 +6963,9 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
       s->aliaskind = AK_UNKNOWN;
     }
 
-  sRef_setExKind (s, sRef_getExKind (t), fileloc_undefined);
+  s->expkind = sRef_getExKind (t);
+  s->expinfo = stateInfo_copy (t->expinfo);
+
   sRef_setTypeState (s);
 
   s->oaliaskind = s->aliaskind;
@@ -6840,22 +6973,24 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
 
   if (valueTable_isUndefined (s->state))
     {
-      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
     }
 
+  DPRINTF (("pointer: %s", sRef_unparseFull (s)));
   return s;
 }
 
 bool sRef_hasDerived (sRef s)
 {
-  return (sRef_isValid (s) && !sRefSet_isEmpty (s->deriv));
+  return (sRef_isReasonable (s) && !sRefSet_isEmpty (s->deriv));
 }
 
 void
 sRef_clearDerived (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
+      DPRINTF (("Clear derived: [%p] %s", s, sRef_unparseDebug (s)));
       sRefSet_clear (s->deriv); 
     }
 }
@@ -6863,17 +6998,18 @@ sRef_clearDerived (sRef s)
 void
 sRef_clearDerivedComplete (sRef s)
 {
-  
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sRef base = sRef_getBaseSafe (s);
-
-      while (sRef_isValid (base))
+      
+      while (sRef_isReasonable (base))
        {
+         DPRINTF (("Clear derived: [%p] %s", base, sRef_unparse (base)));
          sRefSet_clear (base->deriv); 
          base = sRef_getBaseSafe (base);
        }
 
+      DPRINTF (("Clear derived: [%p] %s", s, sRef_unparse (s)));
       sRefSet_clear (s->deriv); 
     }
 }
@@ -6883,7 +7019,7 @@ sRef_clearDerivedComplete (sRef s)
 {
   sRef res = sRef_buildPointer (s); 
 
-  DPRINTF (("Res: %s", sRef_unparse (res)));
+  DPRINTF (("Res: %s", sRef_unparseFull (res)));
   return res;
 }
 
@@ -6893,8 +7029,7 @@ sRef_clearDerivedComplete (sRef s)
 
 /*@exposed@*/ sRef
 sRef_makeAnyArrayFetch (/*@exposed@*/ sRef arr)
-{
-  
+{  
   if (sRef_isAddress (arr))
     {
       return (arr->info->ref);
@@ -7098,7 +7233,7 @@ sRef_unparseKindNamePlain (sRef s)
 void
 sRef_copyState (sRef s1, sRef s2)
 {
-  if (sRef_isValid (s1) && sRef_isValid (s2))
+  if (sRef_isReasonable (s1) && sRef_isReasonable (s2))
     {
       s1->defstate = s2->defstate;
       
@@ -7113,14 +7248,12 @@ sRef_copyState (sRef s1, sRef s2)
 
       s1->expkind = s2->expkind;
       s1->expinfo = stateInfo_update (s1->expinfo, s2->expinfo);
-      
+
       s1->nullstate = s2->nullstate;
       s1->nullinfo = stateInfo_update (s1->nullinfo, s2->nullinfo);
 
-      /*@-mustfree@*/
-      /*@i834 don't free it: valueTable_free (s1->state); */
-      /*@i32@*/ s1->state = valueTable_copy (s2->state);
-      /*@=mustfree@*/
+      valueTable_free (s1->state);  
+      s1->state = valueTable_copy (s2->state);
       s1->safe = s2->safe;
     }
 }
@@ -7133,7 +7266,7 @@ sRef_makeNew (ctype ct, sRef t, cstring name)
   s->kind = SK_NEW;
   s->type = ct;
 
-  llassert (sRef_isValid (t));
+  llassert (sRef_isReasonable (t));
   s->defstate = t->defstate;
 
   s->aliaskind = t->aliaskind;
@@ -7191,7 +7324,7 @@ sRef_makeType (ctype ct)
   s->oaliaskind = s->aliaskind;
   s->oexpkind = s->expkind;
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
 
   DPRINTF (("Create: %s", sRef_unparseFull (s)));
   return s;
@@ -7212,7 +7345,9 @@ sRef_makeConst (ctype ct)
   /* start modification */
   s->bufinfo.bufstate = BB_NULLTERMINATED;
   /* end modification */
-  if (ctype_isUA (ct))
+
+  /* evans 2002-04-22: added isManifestBool to avoid errors for -boolfalse initializations */
+  if (!ctype_isManifestBool (ct) && ctype_isUA (ct)) 
     {
       typeId uid = ctype_typeId (ct);
       uentry te = usymtab_getTypeEntrySafe (uid);
@@ -7223,12 +7358,11 @@ sRef_makeConst (ctype ct)
        }
     }
   
-  
   s->oaliaskind = s->aliaskind;
   s->oexpkind = s->expkind;
 
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc, SA_CREATED));
 
   return s;
 }
@@ -7643,10 +7777,14 @@ sRef_showRefLost (sRef s)
 void
 sRef_showRefKilled (sRef s)
 {
-  if (sRef_hasStateInfoLoc (s))
+  if (sRef_isValid (s)) 
     {
-      llgenindentmsg (message ("Storage %q released", 
-                              sRef_unparse (s)), sRef_getStateInfoLoc (s));
+      DPRINTF (("Killed: %s", sRef_unparseFull (s)));
+      if (context_getLocIndentSpaces () == 0) {
+       stateInfo_display (s->definfo, message ("  Storage %q", sRef_unparseOpt (s)));
+      } else {
+       stateInfo_display (s->definfo, message ("Storage %q", sRef_unparseOpt (s)));
+      }
     }
 }
 
@@ -7665,49 +7803,25 @@ sRef_showStateInconsistent (sRef s)
 void
 sRef_showStateInfo (sRef s)
 {
-  if (sRef_hasStateInfoLoc (s))
-    {
-      if (s->defstate == SS_DEAD)
-       {
-         llgenindentmsg 
-           (message ("Storage %qis released", sRef_unparseOpt (s)),
-            sRef_getStateInfoLoc (s));
-       }
-      else if (s->defstate == SS_ALLOCATED || s->defstate == SS_DEFINED)
-       {
-         llgenindentmsg 
-           (message ("Storage %qis %s", sRef_unparseOpt (s), 
-                     sstate_unparse (s->defstate)),
-            sRef_getStateInfoLoc (s));
-       }
-      else if (s->defstate == SS_UNUSEABLE)
-       {
-         llgenindentmsg 
-           (message ("Storage %qbecomes inconsistent (clauses merge with"
-                     "%qreleased on one branch)",
-                     sRef_unparseOpt (s), 
-                     sRef_unparseOpt (s)),
-            sRef_getStateInfoLoc (s));
-       }
-      else 
-       {
-         llgenindentmsg (message ("Storage %qbecomes %s", 
-                                  sRef_unparseOpt (s), 
-                                  sstate_unparse (s->defstate)),
-                         sRef_getStateInfoLoc (s));
-       }
+  if (sRef_isValid (s)) {
+    if (context_getLocIndentSpaces () == 0) {
+      stateInfo_display (s->definfo, message ("   Storage %q", sRef_unparseOpt (s)));
+    } else {
+      stateInfo_display (s->definfo, message ("Storage %q", sRef_unparseOpt (s)));
     }
+  }
 }
 
 void
 sRef_showExpInfo (sRef s)
 {
-  if (sRef_hasExpInfoLoc (s))
-    {
-      llgenindentmsg (message ("Storage %qbecomes %s", sRef_unparseOpt (s), 
-                              exkind_unparse (s->expkind)),
-                     sRef_getExpInfoLoc (s));
+  if (sRef_isValid (s)) {
+    if (context_getLocIndentSpaces () == 0) {
+      stateInfo_display (s->expinfo, message ("   Storage %q", sRef_unparseOpt (s)));
+    } else {
+      stateInfo_display (s->expinfo, message ("Storage %q", sRef_unparseOpt (s)));
     }
+  }
 }
 
 void
@@ -7716,7 +7830,7 @@ sRef_showMetaStateInfo (sRef s, cstring key)
   stateValue val;
   metaStateInfo minfo = context_lookupMetaStateInfo (key);
 
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
   llassert (valueTable_isDefined (s->state));
   llassert (metaStateInfo_isDefined (minfo));
 
@@ -7804,24 +7918,23 @@ sRef_showNullInfo (sRef s)
 void
 sRef_showAliasInfo (sRef s)
 {
-  if (sRef_hasAliasInfoLoc (s))
+  if (sRef_isValid (s)) 
     {
       if (sRef_isFresh (s))
        {
-         llgenindentmsg 
-           (message ("Fresh storage %qallocated", sRef_unparseOpt (s)),
-            sRef_getAliasInfoLoc (s));
+         if (context_getLocIndentSpaces () == 0) {
+           stateInfo_display (s->aliasinfo, message ("   Fresh storage %q", sRef_unparseOpt (s)));
+         } else {
+           stateInfo_display (s->aliasinfo, message ("Fresh storage %q", sRef_unparseOpt (s)));
+         }
        }
-      else 
+      else
        {
-         if (!sRef_isRefCounted (s))
-           {
-             llgenindentmsg 
-               (message ("Storage %qbecomes %s", 
-                         sRef_unparseOpt (s),
-                         alkind_unparse (sRef_getAliasKind (s))),
-                sRef_getAliasInfoLoc (s));
-           }
+         if (context_getLocIndentSpaces () == 0) {
+           stateInfo_display (s->aliasinfo, message ("   Storage %q", sRef_unparseOpt (s))); 
+         } else {
+           stateInfo_display (s->aliasinfo, message ("Storage %q", sRef_unparseOpt (s)));
+         }
        }
     }
 }
@@ -7829,7 +7942,7 @@ sRef_showAliasInfo (sRef s)
 void
 sRef_mergeNullState (sRef s, nstate n)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       nstate old;
       
@@ -7837,7 +7950,7 @@ sRef_mergeNullState (sRef s, nstate n)
       
       if (n != old && n != NS_UNKNOWN)
        {                 
-           sRef_setNullState (s, n, g_currentloc);
+         sRef_setNullState (s, n, g_currentloc);
        }
     }
   else
@@ -7849,12 +7962,12 @@ sRef_mergeNullState (sRef s, nstate n)
 bool
 sRef_possiblyNull (sRef s)
 {
-  if (sRef_isValid (s))
-      {
-       if (sRef_getNullState (s) == NS_ABSNULL)
+  if (sRef_isReasonable (s))
+    {
+      if (sRef_getNullState (s) == NS_ABSNULL)
        {
          ctype rct = ctype_realType (s->type);
-
+         
          if (ctype_isAbstract (rct))
            {
              return FALSE;
@@ -7879,7 +7992,7 @@ sRef_possiblyNull (sRef s)
          return nstate_possiblyNull (sRef_getNullState (s));
        }
     }
-
+  
   return FALSE;
 }
 
@@ -7924,7 +8037,7 @@ sRef_unparseScope (sRef s)
 int
 sRef_getScope (sRef s)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   if (sRef_isCvar (s))
     {
@@ -7943,13 +8056,13 @@ sRef_getScope (sRef s)
 bool
 sRef_isDead (sRef s)
 {
-  return (sRef_isValid (s) && (s)->defstate == SS_DEAD);
+  return (sRef_isReasonable (s) && (s)->defstate == SS_DEAD);
 }
 
 bool
 sRef_isDeadStorage (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (s->defstate == SS_DEAD
          || s->defstate == SS_UNUSEABLE
@@ -7972,12 +8085,12 @@ sRef_isDeadStorage (sRef s)
 bool
 sRef_isPossiblyDead (sRef s)
 {
-  return (sRef_isValid (s) && s->defstate == SS_HOFFA);
+  return (sRef_isReasonable (s) && s->defstate == SS_HOFFA);
 }
 
 bool sRef_isStateLive (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       sstate ds = s->defstate;
 
@@ -7995,7 +8108,7 @@ bool sRef_isStateLive (sRef s)
 
 bool sRef_isStateUndefined (sRef s)
 {
-  return ((sRef_isValid(s)) && ((s)->defstate == SS_UNDEFINED));
+  return ((sRef_isReasonable(s)) && ((s)->defstate == SS_UNDEFINED));
 }
 
 bool sRef_isJustAllocated (sRef s)
@@ -8019,7 +8132,7 @@ bool sRef_isJustAllocated (sRef s)
 static bool
 sRef_isAllocatedStorage (sRef s)
 {
-  if (sRef_isValid (s) && ynm_toBoolStrict (sRef_isValidLvalue (s)))
+  if (sRef_isReasonable (s) && ynm_toBoolStrict (sRef_isValidLvalue (s)))
     {
       return (ctype_isVisiblySharable (sRef_getType (s)));
     }
@@ -8038,7 +8151,7 @@ sRef_isUnuseable (sRef s)
 bool
 sRef_perhapsNull (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (sRef_getNullState (s) == NS_ABSNULL)
        {
@@ -8079,7 +8192,7 @@ sRef_perhapsNull (sRef s)
 bool 
 sRef_definitelyNull (sRef s)
 {
-  return (sRef_isValid (s)
+  return (sRef_isReasonable (s)
          && (sRef_getNullState (s) == NS_DEFNULL || sRef_getNullState (s) == NS_CONSTNULL));
 }
 
@@ -8090,11 +8203,11 @@ sRef_definitelyNull (sRef s)
 void
 sRef_setDerivNullState (sRef set, sRef guide, nstate ns)
 {
-  if (sRef_isValid (set))
+  if (sRef_isReasonable (set))
     {
       sRef deriv = sRef_getDeriv (set, guide);
       
-      if (sRef_isValid (deriv))
+      if (sRef_isReasonable (deriv))
        {
          sRef_setNullStateN (deriv, ns);
        }
@@ -8104,20 +8217,18 @@ sRef_setDerivNullState (sRef set, sRef guide, nstate ns)
 static /*@exposed@*/ sRef
 sRef_getDeriv (/*@returned@*/ /*@notnull@*/ sRef set, sRef guide)
 {
-  llassert (sRef_isValid (set));
-  llassert (sRef_isValid (guide));
+  llassert (sRef_isReasonable (set));
+  llassert (sRef_isReasonable (guide));
 
   switch (guide->kind)
     {
     case SK_CVAR:
-      llassert (set->kind == SK_CVAR);
-      
+      llassert (set->kind == SK_CVAR);      
       return set;
 
     case SK_PARAM:
       llassert (set->kind == guide->kind);
       llassert (set->info->paramno == guide->info->paramno);
-
       return set;
 
     case SK_ARRAYFETCH:
@@ -8219,14 +8330,21 @@ sRef_aliasCheckPred (bool (predf) (sRef, exprNode, sRef, exprNode),
       
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
-             if (!sRef_similar (current, s)
-                 || (error && sRef_sameName (current, s)))
+             if (sRef_isReasonable (current))
+               {
+                 if (!sRef_similar (current, s)
+                     || (error && sRef_sameName (current, s)))
+                   {
+                     (void) (*predf)(current, e, s, err);
+                   }
+               }
+             else
                {
-                 (void) (*predf)(current, e, s, err);
+                 llcontbug (message ("Invalid sRef as alias field of %s", sRef_unparse (s)));
                }
-             }
+           }
        } end_sRefSet_realElements;
 
       sRefSet_free (aliases);
@@ -8253,7 +8371,7 @@ sRef_aliasCheckSimplePred (sRefTest predf, sRef s)
       
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              sRef cref = sRef_updateSref (current);
              
@@ -8291,7 +8409,7 @@ sRef_aliasCompleteSimplePred (bool (predf) (sRef), sRef s)
   
   sRefSet_realElements (aliases, current)
     {
-      if (sRef_isValid (current))
+      if (sRef_isReasonable (current))
        {
          current = sRef_updateSref (current);
          if ((*predf)(current)) result = TRUE;
@@ -8315,10 +8433,11 @@ sRef_aliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
 
   sRefSet_realElements (aliases, current)
     {
-      if (sRef_isValid (current))
+      if (sRef_isReasonable (current))
        {
          current = sRef_updateSref (current);
          ((*predf)(current, loc));
+         DPRINTF (("Killed: %s", sRef_unparseFull (current)));
        }
     } end_sRefSet_realElements;
 
@@ -8344,7 +8463,7 @@ sRef_aliasSetCompleteParam (void (predf) (sRef, int, fileloc), sRef s,
 
   sRefSet_realElements (aliases, current)
     {
-      if (sRef_isValid (current))
+      if (sRef_isReasonable (current))
        {
          current = sRef_updateSref (current);
          ((*predf)(current, kind, loc));
@@ -8377,7 +8496,7 @@ sRef_aliasSetCompleteAlkParam (void (predf) (sRef, alkind, fileloc), sRef s,
 
   sRefSet_realElements (aliases, current)
     {
-      if (sRef_isValid (current))
+      if (sRef_isReasonable (current))
        {
          current = sRef_updateSref (current);
          ((*predf)(current, kind, loc));
@@ -8394,7 +8513,7 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
   sRefSet aliases;
   ctype ct;
 
-  if (!sRef_isValid (s)) return;
+  if (!sRef_isReasonable (s)) return;
 
   /*
   ** Type equivalence checking is necessary --- there might be casting.
@@ -8415,7 +8534,7 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
       
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              current = sRef_updateSref (current);
              
@@ -8438,7 +8557,7 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
 
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              current = sRef_updateSref (current);
              DPRINTF (("Current: %s", sRef_unparseFull (current)));
@@ -8484,7 +8603,7 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
       
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              current = sRef_updateSref (current);
              
@@ -8524,7 +8643,7 @@ sRef_innerAliasSetCompleteParam (void (predf) (sRef, sRef), sRef s, sRef t)
   sRefSet aliases;
   ctype ct;
 
-  if (!sRef_isValid (s)) return;
+  if (!sRef_isReasonable (s)) return;
 
   /*
   ** Type equivalence checking is necessary --- there might be casting.
@@ -8545,7 +8664,7 @@ sRef_innerAliasSetCompleteParam (void (predf) (sRef, sRef), sRef s, sRef t)
             
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              current = sRef_updateSref (current);
              
@@ -8567,7 +8686,7 @@ sRef_innerAliasSetCompleteParam (void (predf) (sRef, sRef), sRef s, sRef t)
 
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              current = sRef_updateSref (current);
              
@@ -8600,7 +8719,7 @@ sRef_innerAliasSetCompleteParam (void (predf) (sRef, sRef), sRef s, sRef t)
       
       sRefSet_realElements (aliases, current)
        {
-         if (sRef_isValid (current))
+         if (sRef_isReasonable (current))
            {
              current = sRef_updateSref (current);
              
@@ -8757,6 +8876,16 @@ static void
     {
       res->aliaskind = AK_KEPT;
     }
+  else if ((ares == AK_OWNED && aother == AK_ONLY)
+          || (aother == AK_OWNED && ares == AK_ONLY))
+    {
+      res->aliaskind = AK_OWNED;
+
+      if (aother == AK_OWNED)
+       {
+         res->aliasinfo = stateInfo_update (res->aliasinfo, other->aliasinfo);
+       }
+    }
   else
     {
       hasError = TRUE;
@@ -9073,13 +9202,13 @@ static /*@null@*/ sinfo sinfo_copy (/*@notnull@*/ sRef s)
       ret->arrayfetch = (ainfo) dmalloc (sizeof (*ret->arrayfetch));
       ret->arrayfetch->indknown = s->info->arrayfetch->indknown;
       ret->arrayfetch->ind = s->info->arrayfetch->ind;
-      ret->arrayfetch->arr = s->info->arrayfetch->arr; /* sRef_copy (s->info->arrayfetch->arr); */ /*@i32@*/
+      ret->arrayfetch->arr = s->info->arrayfetch->arr; 
       break;
 
     case SK_FIELD:
       ret = (sinfo) dmalloc (sizeof (*ret));
       ret->field = (fldinfo) dmalloc (sizeof (*ret->field));
-      ret->field->rec = s->info->field->rec; /* sRef_copy (s->info->field->rec); */ /*@i32@*/
+      ret->field->rec = s->info->field->rec; 
       ret->field->field = s->info->field->field; 
       break;
 
@@ -9106,11 +9235,13 @@ static /*@null@*/ sinfo sinfo_copy (/*@notnull@*/ sRef s)
       ret = (sinfo) dmalloc (sizeof (*ret));
       ret->spec = s->info->spec;
       break;
+
     case SK_UNCONSTRAINED:
     case SK_NEW:
       ret = (sinfo) dmalloc (sizeof (*ret));
       ret->fname = s->info->fname;
       break;
+
     case SK_RESULT:
     case SK_CONST:
     case SK_TYPE:
@@ -9297,7 +9428,7 @@ static void sinfo_free (/*@special@*/ /*@temp@*/ /*@notnull@*/ sRef s)
     case SK_PTR:
     case SK_ADR:
     case SK_DERIVED:
-    case SK_EXTERNAL: /*@i32 is copy now! */
+    case SK_EXTERNAL: /* is copy now! */
       break;
 
     case SK_CONJ:
@@ -9399,7 +9530,7 @@ static speckind speckind_fromInt (int i)
 }
 
 
-static void sRef_updateNullState (sRef res, sRef other)
+static void sRef_updateNullState (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other)
      /*@modifies res@*/
 {
   res->nullstate = other->nullstate;
@@ -9469,7 +9600,7 @@ void sRef_combineNullState (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other)
 
 cstring sRef_nullMessage (sRef s)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   switch (sRef_getNullState (s))
     {
@@ -9484,7 +9615,7 @@ cstring sRef_nullMessage (sRef s)
 
 /*@observer@*/ cstring sRef_ntMessage (sRef s)
 {
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   switch (s->nullstate)
     {
@@ -9504,7 +9635,7 @@ sRef sRef_fixResultType (/*@returned@*/ sRef s, ctype typ, uentry ue)
   sRef tmp = sRef_undefined;
   sRef ret;
 
-  llassert (sRef_isValid (s));
+  llassert (sRef_isReasonable (s));
 
   switch (s->kind)
     {
@@ -9640,63 +9771,63 @@ bool sRef_isDependent (sRef s)
 
 bool sRef_isOwned (sRef s)
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_OWNED));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_OWNED));
 }
 
 bool sRef_isKeep (sRef s) 
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_KEEP));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_KEEP));
 }
 
 bool sRef_isTemp (sRef s)
 {
-  return (sRef_isValid (s) && alkind_isTemp (s->aliaskind));
+  return (sRef_isReasonable (s) && alkind_isTemp (s->aliaskind));
 }
 
 bool sRef_isLocalState (sRef s) 
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_LOCAL));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_LOCAL));
 }
 
 bool sRef_isUnique (sRef s)
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_UNIQUE));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_UNIQUE));
 }
 
 bool sRef_isShared (sRef s) 
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_SHARED));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_SHARED));
 }
 
 bool sRef_isExposed (sRef s) 
 {
-  return (sRef_isValid (s) && (s->expkind == XO_EXPOSED));
+  return (sRef_isReasonable (s) && (s->expkind == XO_EXPOSED));
 }
 
 bool sRef_isObserver (sRef s) 
 {
-  return (sRef_isValid (s) && (s->expkind == XO_OBSERVER));
+  return (sRef_isReasonable (s) && (s->expkind == XO_OBSERVER));
 }
 
 bool sRef_isFresh (sRef s) 
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_FRESH));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_FRESH));
 }
 
 bool sRef_isDefinitelyNull (sRef s) 
 {
-  return (sRef_isValid (s) && (sRef_getNullState (s) == NS_DEFNULL 
+  return (sRef_isReasonable (s) && (sRef_getNullState (s) == NS_DEFNULL 
                               || sRef_getNullState (s) == NS_CONSTNULL));
 }
 
 bool sRef_isAllocated (sRef s)
 {
-  return (sRef_isValid (s) && (s->defstate == SS_ALLOCATED));
+  return (sRef_isReasonable (s) && (s->defstate == SS_ALLOCATED));
 }
 
 bool sRef_isStack (sRef s)
 {
-  return (sRef_isValid (s) && (s->aliaskind == AK_STACK));
+  return (sRef_isReasonable (s) && (s->aliaskind == AK_STACK));
 }
 
 bool sRef_isNotNull (sRef s)
@@ -9717,7 +9848,7 @@ alkind sRef_getAliasKind (sRef s)
 
 nstate sRef_getNullState (sRef s)
 {
-  if (sRef_isValid (s)) {
+  if (sRef_isReasonable (s)) {
     llassert (nstate_isValid (s->nullstate));
     return s->nullstate;
   }
@@ -9727,14 +9858,16 @@ nstate sRef_getNullState (sRef s)
 
 void sRef_reflectAnnotation (sRef s, annotationInfo a, fileloc loc)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (!valueTable_isDefined (s->state))
        {
          s->state = valueTable_create (1);
-         valueTable_insert (s->state, 
-                            cstring_copy (metaStateInfo_getName (annotationInfo_getState (a))),
-                            stateValue_create (annotationInfo_getValue (a), stateInfo_makeLoc (loc)));
+         valueTable_insert
+           (s->state, 
+            cstring_copy (metaStateInfo_getName (annotationInfo_getState (a))),
+            stateValue_create (annotationInfo_getValue (a), 
+                               stateInfo_makeLoc (loc, SA_DECLARED)));
        }
       else
        {
@@ -9742,8 +9875,9 @@ void sRef_reflectAnnotation (sRef s, annotationInfo a, fileloc loc)
          valueTable_update 
            (s->state,
             metaStateInfo_getName (annotationInfo_getState (a)),
-            stateValue_create (annotationInfo_getValue (a), stateInfo_makeLoc (loc)));
-         DPRINTF (("state info: %s", stateInfo_unparse (stateInfo_makeLoc (loc))));
+            stateValue_create (annotationInfo_getValue (a),
+                               stateInfo_makeLoc (loc, SA_DECLARED)));
+         
          DPRINTF (("sref: %s", sRef_unparse (s)));
          DPRINTF (("sref: %s", sRef_unparseFull (s)));
        }
@@ -9758,7 +9892,7 @@ void sRef_setMetaStateValueComplete (sRef s, cstring key, int value, fileloc loc
 
   sRefSet_realElements (aliases, current)
     {
-      if (sRef_isValid (current))
+      if (sRef_isReasonable (current))
        {
          current = sRef_updateSref (current);
          sRef_setMetaStateValue (current, key, value, loc);
@@ -9772,14 +9906,15 @@ void sRef_setMetaStateValue (sRef s, cstring key, int value, fileloc loc)
 {
   sRef_checkMutable (s);
 
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (!valueTable_isDefined (s->state))
        {
          DPRINTF (("inserting state: %s: %s %d", sRef_unparse (s), key, value));
          s->state = valueTable_create (1);
          valueTable_insert (s->state, cstring_copy (key),
-                            stateValue_create (value, stateInfo_makeLoc (loc)));
+                            stateValue_create (value, 
+                                               stateInfo_makeLoc (loc, SA_CHANGED)));
        }
       else
        {
@@ -9788,12 +9923,14 @@ void sRef_setMetaStateValue (sRef s, cstring key, int value, fileloc loc)
          if (valueTable_contains (s->state, key))
            {
              valueTable_update 
-               (s->state, key, stateValue_create (value, stateInfo_makeLoc (loc)));
+               (s->state, key, stateValue_create (value,
+                                                  stateInfo_makeLoc (loc, SA_CHANGED)));
            }
          else
            {
              valueTable_insert 
-               (s->state, cstring_copy (key), stateValue_create (value, stateInfo_makeLoc (loc)));
+               (s->state, cstring_copy (key),
+                stateValue_create (value, stateInfo_makeLoc (loc, SA_CHANGED)));
            }
 
          DPRINTF (("After: %s", sRef_unparseFull (s)));
@@ -9803,7 +9940,7 @@ void sRef_setMetaStateValue (sRef s, cstring key, int value, fileloc loc)
 
 bool sRef_checkMetaStateValue (sRef s, cstring key, int value)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (valueTable_isDefined (s->state))
        {
@@ -9829,7 +9966,7 @@ bool sRef_checkMetaStateValue (sRef s, cstring key, int value)
 
 /*@observer@*/ stateValue sRef_getMetaStateValue (sRef s, cstring key)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       if (valueTable_isDefined (s->state))
        {
@@ -9854,9 +9991,9 @@ bool sRef_checkMetaStateValue (sRef s, cstring key, int value)
 {
   DPRINTF (("Get value table: %s", sRef_unparse (s)));
 
-  if (sRef_isValid (s)) 
+  if (sRef_isReasonable (s)) 
     {
-      llassert (sRef_isValid (s));
+      llassert (sRef_isReasonable (s));
       DPRINTF (("Value table: %s", valueTable_unparse (s->state)));
       return s->state;
     }  
@@ -9873,7 +10010,7 @@ bool sRef_makeStateSpecial (sRef s)
   ** Default defined state can be made special.
   */
 
-  llassert (sRef_isValid (s)); /*@i523 why doesn't null-checking work!??? */
+  llassert (sRef_isReasonable (s));
 
   if (s->defstate == SS_UNKNOWN || s->defstate == SS_DEFINED || s->defstate == SS_SPECIAL)
     {
@@ -9892,7 +10029,7 @@ bool sRef_makeStateSpecial (sRef s)
 
 void sRef_markImmutable (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       DPRINTF (("Mark immutable: %s", sRef_unparseFull (s)));
       s->immut = TRUE;
@@ -9925,7 +10062,7 @@ struct s_bbufinfo sRef_getNullTerminatedState (sRef p_s) {
 }
 
 void sRef_setNullTerminatedState(sRef p_s) {
-   if(sRef_isValid (p_s)) {
+   if(sRef_isReasonable (p_s)) {
       p_s->bufinfo.bufstate = BB_NULLTERMINATED;
    } else {
       llfatalbug( message("sRef_setNT passed a invalid sRef\n"));
@@ -9934,7 +10071,7 @@ void sRef_setNullTerminatedState(sRef p_s) {
 
 
 void sRef_setPossiblyNullTerminatedState(sRef p_s) {
-   if( sRef_isValid (p_s)) {
+   if( sRef_isReasonable (p_s)) {
       p_s->bufinfo.bufstate = BB_POSSIBLYNULLTERMINATED;
    } else {
       llfatalbug( message("sRef_setPossNT passed a invalid sRef\n"));
@@ -9942,7 +10079,7 @@ void sRef_setPossiblyNullTerminatedState(sRef p_s) {
 }
 
 void sRef_setNotNullTerminatedState(sRef p_s) {
-   if( sRef_isValid (p_s)) {
+   if( sRef_isReasonable (p_s)) {
       p_s->bufinfo.bufstate = BB_NOTNULLTERMINATED;
    } else {
       llfatalbug( message("sRef_unsetNT passed a invalid sRef\n"));
@@ -9950,28 +10087,37 @@ void sRef_setNotNullTerminatedState(sRef p_s) {
 }
 
 void sRef_setLen(sRef p_s, int len) {
-   if( sRef_isValid (p_s) && sRef_isNullTerminated(p_s)) {
-      p_s->bufinfo.len = len;
-   } else {
-      llfatalbug( message("sRef_setLen passed a invalid sRef\n"));
-   }
+   if (sRef_isReasonable (p_s) && sRef_isNullTerminated(p_s)) 
+     {
+       p_s->bufinfo.len = len;
+     } 
+   else 
+     {
+       llfatalbug( message("sRef_setLen passed an invalid sRef\n"));
+     }
 }
     
 
 void sRef_setSize(sRef p_s, int size) {
-   if( sRef_isValid(p_s)) {
+   if( sRef_isValid(p_s)) 
+     {
        p_s->bufinfo.size = size;
-   } else {
-      llfatalbug( message("sRef_setSize passed a invalid sRef\n"));
-   }
+     } 
+   else
+     {
+       llfatalbug( message("sRef_setSize passed a invalid sRef\n"));
+     }
 }
 
 void sRef_resetLen(sRef p_s) {
-       if (sRef_isValid (p_s)) {
-               p_s->bufinfo.len = 0;
-       } else {
-               llfatalbug (message ("sRef_setLen passed an invalid sRef\n"));
-       }
+  if (sRef_isReasonable (p_s)) 
+    {
+      p_s->bufinfo.len = 0;
+    }
+  else
+    {
+      llfatalbug (message ("sRef_setLen passed an invalid sRef\n"));
+    }
 }
 
 /*drl7x 11/28/2000 */
@@ -9982,32 +10128,38 @@ bool sRef_isFixedArray (sRef p_s) /*@*/ {
   return ( ctype_isFixedArray (c) );
 }
 
-long int sRef_getArraySize (sRef p_s) /*@*/ {
+size_t sRef_getArraySize (sRef p_s) /*@*/ 
+{
   ctype c;
   llassert (sRef_isFixedArray(p_s) );
   DPRINTF (( message ("sRef_getArraySize getting array size for %s", sRef_unparse(p_s) )  ));
   
   c = sRef_getType (p_s);
-
-  return (ctype_getArraySize (c) );
+  return (ctype_getArraySize (c));
 }
 
 void sRef_setValue (sRef s, multiVal val)
 {
-  llassert (sRef_isValid (s));
+  if (!sRef_isReasonable (s))
+    {
+      llcontbuglit ("Unreasonable sRef");
+      llcontbug (message ("sRef: %s", sRef_unparse (s)));
+      return;
+    }
+
   multiVal_free (s->val);
   s->val = val;
 }
 
 bool sRef_hasValue (sRef s)
 {
-  return (sRef_isValid (s)
+  return (sRef_isReasonable (s)
          && multiVal_isDefined (s->val));
 }
 
 multiVal sRef_getValue (sRef s)
 {
-  if (sRef_isValid (s))
+  if (sRef_isReasonable (s))
     {
       return s->val;
     }
This page took 0.213943 seconds and 4 git commands to generate.