X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/990ec8680b4718e26f8774a8f2ccff44fb97b3c5..495af944dbec7ce9480ebe3d955aed7aff85a754:/src/sRef.c diff --git a/src/sRef.c b/src/sRef.c index 080cb90..f6ad605 100644 --- a/src/sRef.c +++ b/src/sRef.c @@ -1,6 +1,6 @@ /* -** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2001 University of Virginia, +** Splint - annotation-assisted static program checker +** Copyright (C) 1994-2002 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -17,9 +17,9 @@ ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ** MA 02111-1307, USA. ** -** For information on lclint: lclint-request@cs.virginia.edu -** To report a bug: lclint-bug@cs.virginia.edu -** For more information: http://lclint.cs.virginia.edu +** For information on splint: info@splint.org +** To report a bug: splint-bug@splint.org +** For more information: http://www.splint.org */ /* ** storeRef.c @@ -34,7 +34,7 @@ ** */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "basic.h" # include "exprChecks.h" # include "transferChecks.h" @@ -62,10 +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_aliasSetComplete (void (p_predf) (sRef, fileloc), sRef p_s, fileloc p_loc) - /*@modifies p_s@*/ ; +static void sRef_setNullStateN (sRef p_s, nstate p_n) /*@modifies p_s@*/ ; static int sRef_depth (sRef p_s) /*@*/ ; @@ -78,22 +75,95 @@ static void sRef_innerAliasSetCompleteParam (void (p_predf) (sRef, sRef), sRef p_s, sRef p_t) /*@modifies p_s@*/ ; -static void - sRef_aliasSetCompleteParam (void (p_predf) (sRef, alkind, fileloc), sRef p_s, - alkind p_kind, fileloc p_loc) - /*@modifies p_s@*/ ; - static speckind speckind_fromInt (int p_i); static bool sRef_equivalent (sRef p_s1, sRef p_s2); static bool sRef_isDeepUnionField (sRef p_s); static void sRef_addDeriv (/*@notnull@*/ sRef p_s, /*@notnull@*/ /*@exposed@*/ sRef p_t); -static /*@dependent@*/ sRef sRef_makeResultType (ctype p_ct) /*@*/ ; static bool sRef_checkModify (sRef p_s, sRefSet p_sl) /*@*/ ; +/* +** If s is definitely null, it has no memory state. +*/ + +static void sRef_resetAliasKind (/*@notnull@*/ sRef s) /*@modifies s->aliaskind@*/ +{ + if (s->nullstate == NS_DEFNULL) + { + /* s->aliaskind = AK_ERROR; */ + } +} + +# 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))); @@ -183,6 +253,7 @@ static /*@only@*/ cstring sRef_unparseWithArgs (sRef p_s, uentryList p_args); static /*@only@*/ cstring sRef_unparseNoArgs (sRef p_s); static /*@exposed@*/ sRef sRef_findDerivedPointer (sRef p_s); +static /*@exposed@*/ sRef sRef_findDerivedArrayFetch (/*@notnull@*/ sRef, bool, int, bool) ; static /*@exposed@*/ sRef sRef_findDerivedField (/*@notnull@*/ sRef p_rec, cstring p_f); static /*@exposed@*/ sRef sRef_getDeriv (/*@notnull@*/ /*@returned@*/ sRef p_set, sRef p_guide); @@ -247,7 +318,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)) { @@ -359,12 +430,15 @@ static /*@dependent@*/ /*@notnull@*/ /*@special@*/ sRef s->safe = TRUE; s->modified = FALSE; s->immut = FALSE; + s->val = multiVal_undefined; s->type = ctype_unknown; s->defstate = SS_UNKNOWN; /* start modifications */ s->bufinfo.bufstate = BB_NOTNULLTERMINATED; + s->bufinfo.size = -1; /*@i24 unknown@*/ + s->bufinfo.len = -1; /*@i24 unknown@*/ /* end modifications */ s->aliaskind = AK_UNKNOWN; @@ -431,7 +505,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)) { @@ -454,8 +528,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); @@ -466,6 +540,16 @@ sRef_addDeriv (/*@notnull@*/ sRef s, /*@notnull@*/ /*@exposed@*/ sRef t) return; } + /* This sometimes fails: (evans 2001-07-12) + if (sRef_isArrayFetch (t)) + { + DPRINTF (("Derived fetch: %s / %s / %s", + sRef_unparseFull (s), sRef_unparseFull (t), + sRef_unparseFull (t->info->arrayfetch->arr))); + llassert (t->info->arrayfetch->arr == s); + } + */ + if (sRef_isFileOrGlobalScope (s)) { if (context_inFunctionLike () @@ -490,6 +574,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); } } @@ -508,7 +596,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; @@ -538,7 +626,7 @@ bool sRef_modInFunction (void) void sRef_setStateFromType (sRef s, ctype ct) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { if (ctype_isUser (ct)) { @@ -561,7 +649,7 @@ 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); } @@ -570,29 +658,30 @@ static void sRef_setTypeState (sRef s) static 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 /*@falsenull@*/ bool +static /*@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 /*@falsenull@*/ bool +static /*@falsewhennull@*/ bool sRef_hasExpInfoLoc (sRef s) { - return (sRef_isValid (s) + return (sRef_isReasonable (s) && (s->expinfo != NULL) && (fileloc_isDefined (s->expinfo->loc))); } +# if 0 static /*@observer@*/ /*@unused@*/ stateInfo sRef_getInfo (sRef s, cstring key) { stateValue sv; - if (!sRef_isValid (s)) { + if (!sRef_isReasonable (s)) { return stateInfo_undefined; } @@ -605,26 +694,26 @@ static /*@observer@*/ /*@unused@*/ stateInfo sRef_getInfo (sRef s, cstring key) return stateInfo_undefined; } - +# endif 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); } @@ -632,7 +721,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); } @@ -640,7 +729,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); } @@ -648,7 +737,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); } @@ -656,7 +745,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); } @@ -686,22 +775,43 @@ void sRef_clearGlobalScope () } static bool oldInFunction = FALSE; +static int nestedScope = 0; void sRef_setGlobalScopeSafe () { - oldInFunction = inFunction; - DPRINTF (("leave function")); + if (nestedScope == 0) + { + oldInFunction = inFunction; + } + + nestedScope++; + DPRINTF (("leave function safe")); inFunction = FALSE; } void sRef_clearGlobalScopeSafe () { - inFunction = oldInFunction; - DPRINTF (("clear function: %s", bool_unparse (inFunction))); + nestedScope--; + llassert (nestedScope >= 0); + + if (nestedScope == 0) + { + inFunction = oldInFunction; + } + + DPRINTF (("clear function: %s", bool_unparse (inFunction))); } void sRef_enterFunctionScope () { + /* evans 2001-09-09 - cleanup if we are in a macro! */ + if (context_inMacro ()) + { + if (inFunction) { + sRef_exitFunctionScope (); + } + } + llassert (!inFunction); llassert (sRefTable_isEmpty (allRefs)); inFunction = TRUE; @@ -709,12 +819,12 @@ void sRef_enterFunctionScope () } void sRef_exitFunctionScope () -{ - +{ if (inFunction) { DPRINTF (("Exit function scope.")); sRefTable_clear (allRefs); + DPRINTF (("Exit function scope done.")); inFunction = FALSE; } else @@ -742,7 +852,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 @@ -757,7 +867,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); } @@ -777,7 +887,7 @@ sRef_getBaseUentry (sRef s) sRef base = sRef_getRootBase (s); uentry res = uentry_undefined; - if (sRef_isValid (base)) + if (sRef_isReasonable (base)) { switch (base->kind) { @@ -810,7 +920,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) { @@ -940,7 +1050,7 @@ sRef_updateSref (sRef s) uentry sRef_getUentry (sRef s) { - llassert (sRef_isValid (s)); + llassert (sRef_isReasonable (s)); switch (s->kind) { @@ -970,7 +1080,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; @@ -979,12 +1089,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; @@ -993,10 +1103,8 @@ void sRef_setModified (sRef s) { sRef base = sRef_getBase (s); - llassert (s->kind == SK_FIELD); - if (sRef_isPointer (base)) { base = sRef_getBase (base); @@ -1031,7 +1139,6 @@ sRef_canModifyVal (sRef s, sRefSet sl) bool sRef_canModify (sRef s, sRefSet sl) { - if (context_getFlag (FLG_MUSTMOD)) { return (sRef_doModify (s, sl)); @@ -1133,7 +1240,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) { @@ -1258,7 +1365,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) @@ -1347,7 +1454,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) { @@ -1429,8 +1536,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); @@ -1925,8 +2032,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) { @@ -2133,6 +2245,7 @@ sRef_closeEnough (sRef s1, sRef s2) s is an sRef of a formal paramenter in a function call constraint we trys to return a constraint expression derived from the actual parementer of a function call. */ + /*@only@*/ constraintExpr sRef_fixConstraintParam (/*@observer@*/ sRef s, /*@observer@*/ /*@temp@*/ exprNodeList args) { constraintExpr ce; @@ -2144,7 +2257,7 @@ sRef_closeEnough (sRef s1, sRef s2) { case SK_RESULT: { - // s = sRef_saveCopy(s); + /* s = sRef_saveCopy(s); */ /*@i523@*/ ce = constraintExpr_makeTermsRef (s); return ce; } @@ -2161,7 +2274,7 @@ sRef_closeEnough (sRef s1, sRef s2) { sRef temp; temp = (sRef_makePointer (sRef_fixBaseParam (s->info->ref, args))); - //temp = sRef_saveCopy(temp); + /* temp = sRef_saveCopy(temp); */ /*@i523@*/ ce = constraintExpr_makeTermsRef (temp); return ce; } @@ -2197,7 +2310,8 @@ sRef_closeEnough (sRef s1, sRef s2) default: { sRef temp; - llcontbug ((message("Trying to do fixConstraintParam on nonparam, nonglobal: %q for function with arguments %q", sRef_unparse (s), exprNodeList_unparse(args) ) )); + llcontbug (message ("Trying to do fixConstraintParam on nonparam, nonglobal: %q for function with arguments %q", + sRef_unparse (s), exprNodeList_unparse(args))); temp = sRef_saveCopy(s); ce = constraintExpr_makeTermsRef (temp); @@ -2205,9 +2319,6 @@ sRef_closeEnough (sRef s1, sRef s2) return ce; } } - - - } /*@exposed@*/ sRef @@ -2252,9 +2363,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))); @@ -2300,7 +2416,7 @@ sRef_undumpGlobal (char **c) reader_checkChar (c, '@'); nullstate = nstate_fromInt (reader_getInt (c)); - ret = sRef_makeGlobal (uid, ctype_unknown); + ret = sRef_makeGlobal (uid, ctype_unknown, stateInfo_currentLoc ()); sRef_setNullStateN (ret, nullstate); ret->defstate = defstate; return ret; @@ -2333,8 +2449,7 @@ sRef_undumpGlobal (char **c) BADEXIT; } -/*@exposed@*/ sRef -sRef_undump (char **c) +static /*@exposed@*/ sRef sRef_undumpBody (char **c) { char p = **c; @@ -2343,11 +2458,11 @@ sRef_undump (char **c) switch (p) { case 'g': - return (sRef_makeGlobal (usymId_fromInt (reader_getInt (c)), ctype_unknown)); + return (sRef_makeGlobal (usymId_fromInt (reader_getInt (c)), ctype_unknown, stateInfo_currentLoc ())); case 'p': - return (sRef_makeParam (reader_getInt (c), ctype_unknown)); + return (sRef_makeParam (reader_getInt (c), ctype_unknown, stateInfo_makeLoc (g_currentloc))); case 'r': - return (sRef_makeResultType (ctype_undump (c))); + return (sRef_makeResult (ctype_undump (c))); case 'a': { if ((**c >= '0' && **c <= '9') || **c == '-') @@ -2435,8 +2550,21 @@ sRef_undump (char **c) BADEXIT; } -/*@only@*/ cstring -sRef_dump (sRef s) +/*@exposed@*/ sRef sRef_undump (char **c) +{ + sRef res = sRef_undumpBody (c); + + if (reader_optCheckChar (c, '=')) + { + multiVal mv = multiVal_undump (c); + sRef_setValue (res, mv); + reader_checkChar (c, '='); + } + + return res; +} + +static /*@only@*/ cstring sRef_dumpBody (sRef s) { if (sRef_isInvalid (s)) { @@ -2504,8 +2632,22 @@ sRef_dump (sRef s) BADEXIT; } +/*@only@*/ cstring sRef_dump (sRef s) +{ + cstring res = sRef_dumpBody (s); + + if (sRef_hasValue (s)) + { + res = message ("%q=%q=", res, multiVal_dump (sRef_getValue (s))); + } + + return res; +} + cstring sRef_dumpGlobal (sRef s) { + llassert (!sRef_hasValue (s)); + if (sRef_isInvalid (s)) { return (cstring_makeLiteral ("-")); @@ -2747,9 +2889,7 @@ sRef_unparseWithArgs (sRef s, uentryList args) return uentry_getName (ue); } - return (message ("info->paramno + 1)); } case SK_ARRAYFETCH: if (s->info->arrayfetch->indknown) @@ -2919,7 +3059,14 @@ sRef_unparseDebug (sRef s) case SK_TYPE: return (message ("", ctype_unparse (s->type))); case SK_CONST: - return (message ("", ctype_unparse (s->type))); + if (sRef_hasValue (s)) + { + return (message ("", ctype_unparse (s->type), multiVal_unparse (sRef_getValue (s)))); + } + else + { + return (message ("", ctype_unparse (s->type))); + } case SK_RESULT: return (message ("", ctype_unparse (s->type))); case SK_SPECIAL: @@ -3044,11 +3191,11 @@ 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 - sRef_makeCvarAux (int level, usymId index, ctype ct) + sRef_makeCvarAux (int level, usymId index, ctype ct, /*@only@*/ stateInfo stinfo) { sRef s = sRef_newRef (); @@ -3089,25 +3236,25 @@ static /*@dependent@*/ /*@notnull@*/ sRef DPRINTF (("Made cvar: [%p] %s", s, sRef_unparseDebug (s))); llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stinfo); return s; } -/*@dependent@*/ sRef sRef_makeCvar (int level, usymId index, ctype ct) +/*@dependent@*/ sRef sRef_makeCvar (int level, usymId index, ctype ct, /*@only@*/ stateInfo stinfo) { - return (sRef_makeCvarAux (level, index, ct)); + return (sRef_makeCvarAux (level, index, ct, stinfo)); } 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); } @@ -3117,21 +3264,21 @@ int sRef_lexLevel (sRef s) } sRef -sRef_makeGlobal (usymId l, ctype ct) +sRef_makeGlobal (usymId l, ctype ct, /*@only@*/ stateInfo stinfo) { - return (sRef_makeCvar (globScope, l, ct)); + return (sRef_makeCvar (globScope, l, ct, 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); } /*@dependent@*/ sRef -sRef_makeParam (int l, ctype ct) +sRef_makeParam (int l, ctype ct, stateInfo stinfo) { sRef s = sRef_new (); @@ -3145,7 +3292,7 @@ sRef_makeParam (int l, ctype ct) /* (probably defined, unless its an out parameter) */ llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stinfo); return s; } @@ -3154,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); @@ -3167,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); @@ -3233,7 +3380,7 @@ static bool sRef_isZerothArrayFetch (/*@notnull@*/ sRef s) } llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return s; } } @@ -3242,10 +3389,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; @@ -3328,7 +3475,7 @@ sRef_getRootBaseAux (sRef s, int depth) ("Warning: reference base limit exceeded for %q. " "This either means there is a variable with at least " "%d indirections from this reference, or " - "there is a bug in LCLint.", + "there is a bug in Splint.", sRef_unparse (s), MAXBASEDEPTH), g_currentloc); @@ -3406,7 +3553,7 @@ sRef_makeObject (ctype o) s->info = (sinfo) dmalloc (sizeof (*s->info)); s->info->object = o; llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return s; } @@ -3418,20 +3565,20 @@ 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@*/ llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return s; } /*@dependent@*/ sRef sRef_makeDerived (/*@exposed@*/ sRef t) { - if (sRef_isValid (t)) + if (sRef_isReasonable (t)) { sRef s = sRef_newRef (); @@ -3441,7 +3588,7 @@ sRef sRef_makeExternal (sRef t) s->type = t->type; llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return s; } else @@ -3459,8 +3606,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; @@ -3519,8 +3666,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) @@ -3608,7 +3755,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); } @@ -3630,7 +3777,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); } @@ -3655,9 +3802,13 @@ 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", + sRef_unparseFull (res), + sRef_unparseFull (other))); + sRef_checkMutable (res); sRef_checkMutable (other); @@ -3870,7 +4021,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); @@ -3888,6 +4039,13 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other, ** Merge value table states */ + + /*@i3245@*/ +# if 0 + /* + ** This doesn't do anything. And its broken too... + */ + valueTable_elements (res->state, key, sv) { stateValue os = valueTable_lookup (other->state, key); @@ -3907,6 +4065,11 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other, DPRINTF (("Val: %d / %s", val, msg)); */ } end_valueTable_elements ; +# endif + + DPRINTF (("Merge aux: %s / %s", + sRef_unparseFull (res), + sRef_unparseFull (other))); } static sRefSet @@ -3922,11 +4085,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); } @@ -3949,11 +4112,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) @@ -4027,7 +4190,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); } @@ -4048,7 +4211,7 @@ sRef_mergeDerivs (/*@only@*/ sRefSet res, sRefSet other, sRefSet_allElements (other, el) { - if (sRef_isValid (el)) + if (sRef_isReasonable (el)) { (void) checkDeadState (el, FALSE, loc); } @@ -4105,7 +4268,6 @@ static bool checkDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc) ? "kept" : "released")), loc)) { - if (sRef_isKept (el)) { sRef_showAliasInfo (el); @@ -4134,7 +4296,7 @@ checkDerivDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc) { sRefSet_allElements (el->deriv, t) { - if (sRef_isValid (t)) + if (sRef_isReasonable (t)) { checkDerivDeadState (t, tbranch, loc); } @@ -4150,11 +4312,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)) { @@ -4189,7 +4351,7 @@ static sRefSet sRefSet_allElements (other, el) { - if (sRef_isValid (el)) + if (sRef_isReasonable (el)) { if (!sRefSet_member (ret, el)) { @@ -4212,8 +4374,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)) { @@ -4243,7 +4405,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); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return s; } else @@ -4261,7 +4423,7 @@ sRef_makeUnknown () return s; } -static /*@owned@*/ sRef +static /*@owned@*/ /*@notnull@*/ sRef sRef_makeSpecial (speckind sk) /*@*/ { sRef s = sRef_new (); @@ -4328,31 +4490,22 @@ sRef_makeGlobalMarker (void) { sRef s = sRef_makeSpecial (SR_GLOBALMARKER); llassert (valueTable_isUndefined (s->state)); - s->state = context_createGlobalMarkerValueTable (); + s->state = context_createGlobalMarkerValueTable (stateInfo_undefined); return s; } -static sRef -sRef_makeResultType (ctype ct) -{ - sRef res = sRef_makeResult (); - - res->type = ct; - return res; -} - sRef -sRef_makeResult () +sRef_makeResult (ctype c) { sRef s = sRef_newRef (); s->kind = SK_RESULT; - s->type = ctype_unknown; + s->type = c; s->defstate = SS_UNKNOWN; s->aliaskind = AK_UNKNOWN; sRef_setNullStateN (s, NS_UNKNOWN); llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); DPRINTF (("Result: [%p] %s", s, sRef_unparseFull (s))); return s; @@ -4387,7 +4540,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 @@ -4405,7 +4558,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); @@ -4414,7 +4567,7 @@ sRef_getScopeIndex (sRef s) void sRef_makeSafe (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { s->safe = TRUE; } @@ -4423,7 +4576,7 @@ sRef_makeSafe (sRef s) void sRef_makeUnsafe (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { s->safe = FALSE; } @@ -4437,8 +4590,8 @@ 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 [%s] { %q } < %q >", + s, sRef_unparseDebug (s), sRef_unparseState (s), exkind_unparse (s->oexpkind), @@ -4452,7 +4605,7 @@ sRef_makeUnsafe (sRef s) st = message ("%q:", sRef_unparseFull (s)); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { sRefSet_allElements (s->deriv, el) { @@ -4526,10 +4679,17 @@ bool sRef_hasNoStorage (sRef s) bool sRef_isStrictReadable (sRef s) { - return (ynm_toBoolStrict (sRef_isReadable (s))); + return (ynm_toBoolStrict (sRef_isValidLvalue (s))); } -ynm sRef_isReadable (sRef s) +/* +** Is this what is does? +** Returns YES if s can be used as an rvalue, +** MAYBE if its not clear +** NO if s cannot be safely used as an rvalue. +*/ + +ynm sRef_isValidLvalue (sRef s) { sstate ss; @@ -4539,9 +4699,9 @@ ynm sRef_isReadable (sRef s) if (sRef_isConj (s) && s->defstate == SS_UNKNOWN) { - if (ynm_toBoolStrict (sRef_isReadable (sRef_getConjA (s)))) + if (ynm_toBoolStrict (sRef_isValidLvalue (sRef_getConjA (s)))) { - if (ynm_toBoolStrict (sRef_isReadable (sRef_getConjB (s)))) + if (ynm_toBoolStrict (sRef_isValidLvalue (sRef_getConjB (s)))) { return YES; } @@ -4549,7 +4709,7 @@ ynm sRef_isReadable (sRef s) } else { - if (ynm_toBoolStrict (sRef_isReadable (sRef_getConjB (s)))) + if (ynm_toBoolStrict (sRef_isValidLvalue (sRef_getConjB (s)))) { return MAYBE; } @@ -4573,9 +4733,9 @@ ynm sRef_isReadable (sRef s) || ss == SS_FIXED || ss == SS_RELDEF || ss == SS_PDEFINED - || ss == SS_PARTIAL + || ss == SS_PARTIAL || ss == SS_SPECIAL - || ss == SS_ALLOCATED + || ss == SS_ALLOCATED || ss == SS_KILLED /* evans 2001-05-26: added this for killed globals */ || ss == SS_UNKNOWN)); } @@ -4592,7 +4752,7 @@ static /*@exposed@*/ sRef whatUndefined (/*@exposed@*/ sRef fref, int depth) ("Warning: check definition limit exceeded, checking %q. " "This either means there is a variable with at least " "%d indirections apparent in the program text, or " - "there is a bug in LCLint.", + "there is a bug in Splint.", sRef_unparse (fref), MAXDEPTH), g_currentloc); @@ -4654,7 +4814,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; } @@ -4720,7 +4880,7 @@ static bool checkDefined (/*@temp@*/ sRef sr) bool sRef_isReallyDefined (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { if (sRef_isAnyDefined (s)) { @@ -4746,7 +4906,7 @@ bool sRef_isReallyDefined (sRef s) void sRef_showNotReallyDefined (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { if (sRef_isAnyDefined (s)) { @@ -4759,7 +4919,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) { @@ -4808,14 +4968,14 @@ void sRef_clearAliasState (sRef s, fileloc loc) void sRef_setAliasKindComplete (sRef s, alkind kind, fileloc loc) { sRef_checkMutable (s); - sRef_aliasSetCompleteParam (sRef_setAliasKind, s, kind, loc); + sRef_aliasSetCompleteAlkParam (sRef_setAliasKind, s, kind, loc); } void sRef_setAliasKind (sRef s, alkind kind, fileloc loc) { sRef_checkMutable (s); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { sRef_clearDerived (s); @@ -4833,7 +4993,7 @@ void sRef_setOrigAliasKind (sRef s, alkind kind) { sRef_checkMutable (s); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { s->oaliaskind = kind; } @@ -4841,7 +5001,7 @@ void sRef_setOrigAliasKind (sRef s, alkind kind) exkind sRef_getExKind (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { return (s->expkind); } @@ -4853,7 +5013,7 @@ exkind sRef_getExKind (sRef s) exkind sRef_getOrigExKind (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { return (s->oexpkind); } @@ -4890,7 +5050,7 @@ void sRef_setExKind (sRef s, exkind exp, fileloc loc) { sRef_checkMutable (s); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { if (s->expkind != exp) { @@ -4910,7 +5070,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); @@ -4918,7 +5078,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); @@ -4926,7 +5086,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); @@ -4951,7 +5111,7 @@ void sRef_setUndefined (sRef s, fileloc loc) { sRef_checkMutable (s); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { s->defstate = SS_UNDEFINED; @@ -4969,6 +5129,8 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear) sRef_checkMutable (s); if (sRef_isInvalid (s)) return; + DPRINTF (("Set defined: %s", sRef_unparseFull (s))); + if (s->defstate != SS_DEFINED && fileloc_isDefined (loc)) { s->definfo = stateInfo_updateLoc (s->definfo, loc); @@ -4976,16 +5138,31 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear) s->defstate = SS_DEFINED; + DPRINTF (("Set defined: %s", sRef_unparseFull (s))); + /* e.g., if x is allocated, *x = 3 defines x */ if (s->kind == SK_PTR) { sRef p = s->info->ref; - - if (p->defstate == SS_ALLOCATED) + sRef arr; + + if (p->defstate == SS_ALLOCATED + || p->defstate == SS_SPECIAL) /* evans 2001-07-12: shouldn't need this */ { sRef_setDefinedAux (p, loc, clear); } + + /* + ** Defines a[0] also: + */ + + arr = sRef_findDerivedArrayFetch (p, FALSE, 0, FALSE); + + if (sRef_isReasonable (arr)) + { + sRef_setDefinedAux (arr, loc, clear); + } } else if (s->kind == SK_ARRAYFETCH) { @@ -4994,11 +5171,12 @@ 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) + || ptr->defstate == SS_UNDEFINED + || ptr->defstate == SS_SPECIAL) /* evans 2001-07-12: shouldn't need this */ { sRef_setDefinedAux (ptr, loc, clear); } @@ -5008,7 +5186,8 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear) { ; } - else if (p->defstate == SS_ALLOCATED || p->defstate == SS_PDEFINED) + else if (p->defstate == SS_ALLOCATED || p->defstate == SS_PDEFINED + || p->defstate == SS_SPECIAL) /* evans 2001-07-12: shouldn't need this */ { p->defstate = SS_DEFINED; } @@ -5021,7 +5200,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))) { @@ -5046,7 +5225,18 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear) if (clear) { sRef_clearDerived (s); - } + } + else + { + /* 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))); } static void sRef_setPartialDefined (sRef s, fileloc loc) @@ -5069,6 +5259,29 @@ void sRef_setDefinedComplete (sRef s, fileloc loc) sRef_innerAliasSetComplete (sRef_setDefined, s, loc); } +void sRef_setDefinedCompleteDirect (sRef s, fileloc loc) +{ + sRefSet aliases; + + aliases = usymtab_allAliases (s); + DPRINTF (("Set defined complete: %s", sRef_unparseFull (s))); + DPRINTF (("All aliases: %s", sRefSet_unparseFull (aliases))); + + sRef_setDefined (s, loc); + + sRefSet_realElements (aliases, current) + { + if (sRef_isReasonable (current)) + { + current = sRef_updateSref (current); + sRef_setDefined (current, loc); + } + } end_sRefSet_realElements; + + sRefSet_free (aliases); + sRef_innerAliasSetComplete (sRef_setDefined, s, loc); +} + void sRef_setDefined (sRef s, fileloc loc) { sRef_checkMutable (s); @@ -5098,7 +5311,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 @@ -5106,7 +5319,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))); } @@ -5118,7 +5331,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); @@ -5137,12 +5350,13 @@ void sRef_setPdefined (sRef s, fileloc loc) /* 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) { sRef nb; + DPRINTF (("set pdefined: %s", sRef_unparseFull (base))); base->defstate = SS_PDEFINED; nb = sRef_getBaseSafe (base); base = nb; @@ -5159,7 +5373,7 @@ static void sRef_setStateAux (sRef s, sstate ss, fileloc loc) { sRef_checkMutable (s); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { /* if (s->defstate == SS_RELDEF) return; */ @@ -5175,14 +5389,14 @@ 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) { sRef nb; - + + DPRINTF (("set pdefined: %s", sRef_unparseFull (s))); base->defstate = SS_PDEFINED; - nb = sRef_getBaseSafe (base); base = nb; } @@ -5192,8 +5406,7 @@ static void sRef_setStateAux (sRef s, sstate ss, fileloc loc) } } } - - } + } } void sRef_setAllocatedComplete (sRef s, fileloc loc) @@ -5205,7 +5418,7 @@ 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) { @@ -5240,7 +5453,7 @@ 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)) { @@ -5256,7 +5469,7 @@ 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); @@ -5266,10 +5479,10 @@ void sRef_setLastReference (sRef s, /*@exposed@*/ sRef ref, fileloc 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); @@ -5278,7 +5491,7 @@ void sRef_setNullStateAux (/*@notnull@*/ sRef s, nstate ns, fileloc loc) void sRef_setNotNull (sRef s, fileloc loc) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { sRef_setNullStateAux (s, NS_NOTNULL, loc); } @@ -5286,34 +5499,39 @@ void sRef_setNotNull (sRef s, fileloc loc) void sRef_setNullStateN (sRef s, nstate n) { - sRef_checkMutable (s); - s->nullstate = n; + 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); } } -void sRef_setNullTerminatedStateInnerComplete (sRef s, struct s_bbufinfo b, /*@unused@*/ 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. */ @@ -5359,7 +5577,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); } @@ -5367,7 +5585,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); } @@ -5375,7 +5593,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); } @@ -5383,34 +5601,35 @@ 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); - } + } } 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); @@ -5419,10 +5638,9 @@ void sRef_setDependent (sRef s, fileloc 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); } @@ -5430,26 +5648,25 @@ void sRef_setOwned (sRef s, fileloc 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); + base = sRef_getBaseSafe (base); } else { break; } - } + sRef_checkMutable (s); s->aliaskind = AK_KEPT; s->aliasinfo = stateInfo_updateLoc (s->aliasinfo, loc); } @@ -5483,10 +5700,9 @@ 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); } @@ -5495,16 +5711,17 @@ void sRef_setFresh (sRef s, fileloc loc) 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); } @@ -5524,17 +5741,16 @@ void sRef_kill (sRef s, fileloc loc) 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); } @@ -5559,7 +5775,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)) { @@ -5595,7 +5811,7 @@ static bool sRef_equivalent (sRef s1, sRef s2) { sRef ret; - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { bool old = inFunction; @@ -5629,7 +5845,7 @@ sRef sRef_copy (sRef s) /*@=retalias@*/ } - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { sRef t = sRef_alloc (); @@ -5641,6 +5857,7 @@ sRef sRef_copy (sRef s) t->modified = s->modified; t->immut = FALSE; /* Note mutability is not copied. */ t->type = s->type; + t->val = multiVal_copy (s->val); t->info = sinfo_copy (s); t->defstate = s->defstate; @@ -5666,7 +5883,7 @@ 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 @@ -5694,7 +5911,7 @@ bool sRef_isAddress (sRef s) bool sRef_isThroughArrayFetch (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { sRef tref = s; @@ -5709,7 +5926,7 @@ bool sRef_isThroughArrayFetch (sRef s) lt = sRef_getBase (tref); tref = lt; - } while (sRef_isValid (tref)); + } while (sRef_isReasonable (tref)); } return FALSE; @@ -5885,20 +6102,18 @@ void sRef_free (/*@only@*/ sRef 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) @@ -5917,17 +6132,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; @@ -5936,7 +6158,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; @@ -5951,11 +6173,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; } @@ -5968,7 +6190,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); } @@ -5981,7 +6203,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)) @@ -5994,7 +6216,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 && @@ -6037,14 +6259,14 @@ sRef_buildNCField (/*@exposed@*/ sRef rec, /*@exposed@*/ cstring f) s = sRef_findDerivedField (rec, f); - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { return s; } else { ctype ct = ctype_realType (rec->type); - + DPRINTF (("Field of: %s", sRef_unparse (rec))); s = sRef_newRef (); @@ -6088,7 +6310,7 @@ sRef_buildNCField (/*@exposed@*/ sRef rec, /*@exposed@*/ cstring f) s->oaliaskind = s->aliaskind; s->oexpkind = s->expkind; - + DPRINTF (("sref: %s", sRef_unparseFull (s))); } else @@ -6164,7 +6386,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)); } @@ -6180,6 +6402,10 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s, } /* a hack, methinks... makeArrayFetch (&a[0]) ==> a[] */ + /* evans - 2001-08-27: not sure where this was necessary - it + ** causes an assertion in in aliasCheckPred to fail. + */ + if (sRef_isAddress (arr)) { sRef t = arr->info->ref; @@ -6193,7 +6419,7 @@ 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)) @@ -6213,6 +6439,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 @@ -6295,32 +6522,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) + if (sRef_isReasonable (sr)) { - s->defstate = SS_ALLOCATED; - } - else - { - 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; @@ -6362,7 +6595,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s, { sRef s; - if (!sRef_isValid (arr)) { + if (!sRef_isReasonable (arr)) { /*@-nullret@*/ return arr /*@=nullret@*/; } @@ -6373,8 +6606,19 @@ 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) + { + sRef res; + check (sRefSet_delete (arr->deriv, s)); + res = sRef_buildArrayFetch (arr); + sRef_copyState (res, s); + llassert (res->info->arrayfetch->arr == arr); + return res; + } + sRef_setExKind (s, sRef_getExKind (arr), g_currentloc); return s; } @@ -6388,7 +6632,9 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s, s->info->arrayfetch->indknown = FALSE; s->info->arrayfetch->ind = 0; s->info->arrayfetch->arr = arr; /* sRef_copy (arr); */ /*@i32@*/ + sRef_setArrayFetchState (s, arr); + s->oaliaskind = s->aliaskind; s->oexpkind = s->expkind; @@ -6397,9 +6643,11 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s, sRef_addDeriv (arr, s); } - llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); - + if (valueTable_isUndefined (s->state)) + { + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); + } + return (s); } } @@ -6409,20 +6657,35 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s, { sRef s; - if (!sRef_isValid (arr)) { + if (!sRef_isReasonable (arr)) { /*@-nullret@*/ return arr /*@=nullret@*/; } if (ctype_isRealPointer (arr->type)) { - (void) sRef_buildPointer (arr); /* do this to define arr! */ + (void) sRef_buildPointer (arr); /* do this to define arr! */ } 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) + { + sRef res; + + check (sRefSet_delete (arr->deriv, s)); + res = sRef_buildArrayFetchKnown (arr, i); + + llassert (res->info->arrayfetch->arr == arr); + sRef_copyState (res, s); + llassert (res->info->arrayfetch->arr == arr); + return res; + } + sRef_setExKind (s, sRef_getExKind (arr), g_currentloc); + llassert (s->info->arrayfetch->arr == arr); return s; } else @@ -6435,16 +6698,16 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s, s->info->arrayfetch->arr = arr; /* sRef_copy (arr); */ /*@i32@*/ s->info->arrayfetch->indknown = TRUE; s->info->arrayfetch->ind = i; - + sRef_setArrayFetchState (s, arr); - + /* evans 2001-08-27 no: can change this - llassert (s->info->arrayfetch->arr == arr); */ + s->oaliaskind = s->aliaskind; s->oexpkind = s->expkind; sRef_addDeriv (arr, s); llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); - + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return (s); } } @@ -6458,7 +6721,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; @@ -6472,7 +6735,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 @@ -6485,7 +6748,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); @@ -6496,7 +6759,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); @@ -6518,7 +6781,7 @@ sRef_setStateFromUentry (sRef s, uentry ue) sstate defstate; sRef_checkMutable (s); - llassert (sRef_isValid (s)); + llassert (sRef_isReasonable (s)); sRef_setPartsFromUentry (s, ue); @@ -6552,7 +6815,7 @@ 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); @@ -6567,7 +6830,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); @@ -6589,7 +6852,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; @@ -6599,28 +6862,18 @@ 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; } else { sRef ret = sRef_constructPointer (t); - /* - ** This is necessary to prevent infinite depth - ** in checking complete destruction. - */ + DPRINTF (("Constructed pointer: %s", sRef_unparseFull (ret))); - if (isdead) - { - /* ret->defstate = SS_UNKNOWN; */ - return ret; - } - else - { - return ret; - } + return ret; } } else @@ -6646,6 +6899,8 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t) ctype rt = t->type; ctype st; + llassert (valueTable_isUndefined (s->state)); + s->kind = SK_PTR; s->info = (sinfo) dmalloc (sizeof (*s->info)); s->info->ref = t; /* sRef_copy (t); */ /*@i32*/ @@ -6656,7 +6911,7 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t) } st = ctype_realType (s->type); - + if (t->defstate == SS_UNDEFINED) { s->defstate = SS_UNUSEABLE; @@ -6678,28 +6933,32 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t) { s->aliaskind = AK_UNKNOWN; } - + sRef_setExKind (s, sRef_getExKind (t), fileloc_undefined); sRef_setTypeState (s); - + s->oaliaskind = s->aliaskind; s->oexpkind = s->expkind; - llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + if (valueTable_isUndefined (s->state)) + { + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); + } + 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); } } @@ -6707,17 +6966,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); } } @@ -6737,8 +6997,7 @@ sRef_clearDerivedComplete (sRef s) /*@exposed@*/ sRef sRef_makeAnyArrayFetch (/*@exposed@*/ sRef arr) -{ - +{ if (sRef_isAddress (arr)) { return (arr->info->ref); @@ -6942,7 +7201,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; @@ -6957,7 +7216,7 @@ 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); @@ -6977,7 +7236,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; @@ -7035,7 +7294,7 @@ sRef_makeType (ctype ct) s->oaliaskind = s->aliaskind; s->oexpkind = s->expkind; llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); DPRINTF (("Create: %s", sRef_unparseFull (s))); return s; @@ -7056,8 +7315,6 @@ sRef_makeConst (ctype ct) /* start modification */ s->bufinfo.bufstate = BB_NULLTERMINATED; /* end modification */ - - if (ctype_isUA (ct)) { typeId uid = ctype_typeId (ct); @@ -7074,7 +7331,7 @@ sRef_makeConst (ctype ct) s->oexpkind = s->expkind; llassert (valueTable_isUndefined (s->state)); - s->state = context_createValueTable (s); + s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc)); return s; } @@ -7562,7 +7819,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)); @@ -7571,7 +7828,7 @@ sRef_showMetaStateInfo (sRef s, cstring key) if (stateValue_hasLoc (val)) { llgenindentmsg - (message ("Meta state %qbecomes %q", sRef_unparseOpt (s), + (message ("%qbecomes %q", sRef_unparseOpt (s), stateValue_unparseValue (val, minfo)), stateValue_getLoc (val)); } @@ -7675,7 +7932,7 @@ sRef_showAliasInfo (sRef s) void sRef_mergeNullState (sRef s, nstate n) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { nstate old; @@ -7683,7 +7940,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 @@ -7695,12 +7952,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; @@ -7725,7 +7982,7 @@ sRef_possiblyNull (sRef s) return nstate_possiblyNull (sRef_getNullState (s)); } } - + return FALSE; } @@ -7770,7 +8027,7 @@ sRef_unparseScope (sRef s) int sRef_getScope (sRef s) { - llassert (sRef_isValid (s)); + llassert (sRef_isReasonable (s)); if (sRef_isCvar (s)) { @@ -7789,13 +8046,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 @@ -7818,12 +8075,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; @@ -7841,7 +8098,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) @@ -7865,7 +8122,7 @@ bool sRef_isJustAllocated (sRef s) static bool sRef_isAllocatedStorage (sRef s) { - if (sRef_isValid (s) && ynm_toBoolStrict (sRef_isReadable (s))) + if (sRef_isReasonable (s) && ynm_toBoolStrict (sRef_isValidLvalue (s))) { return (ctype_isVisiblySharable (sRef_getType (s))); } @@ -7884,7 +8141,7 @@ sRef_isUnuseable (sRef s) bool sRef_perhapsNull (sRef s) { - if (sRef_isValid (s)) + if (sRef_isReasonable (s)) { if (sRef_getNullState (s) == NS_ABSNULL) { @@ -7925,7 +8182,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)); } @@ -7936,11 +8193,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); } @@ -7950,20 +8207,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: @@ -8062,18 +8317,24 @@ sRef_aliasCheckPred (bool (predf) (sRef, exprNode, sRef, exprNode), else { sRefSet aliases = usymtab_allAliases (s); - 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)) { - (void) (*predf)(current, e, s, err); + if (!sRef_similar (current, s) + || (error && sRef_sameName (current, s))) + { + (void) (*predf)(current, e, s, err); + } } - } + else + { + llcontbug (message ("Invalid sRef as alias field of %s", sRef_unparse (s))); + } + } } end_sRefSet_realElements; sRefSet_free (aliases); @@ -8100,7 +8361,7 @@ sRef_aliasCheckSimplePred (sRefTest predf, sRef s) sRefSet_realElements (aliases, current) { - if (sRef_isValid (current)) + if (sRef_isReasonable (current)) { sRef cref = sRef_updateSref (current); @@ -8138,7 +8399,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; @@ -8149,7 +8410,7 @@ sRef_aliasCompleteSimplePred (bool (predf) (sRef), sRef s) return result; } -static void +void sRef_aliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc) { sRefSet aliases; @@ -8162,22 +8423,55 @@ 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; sRefSet_free (aliases); } -static void -sRef_aliasSetCompleteParam (void (predf) (sRef, alkind, fileloc), sRef s, - alkind kind, fileloc loc) +void +sRef_aliasSetCompleteParam (void (predf) (sRef, int, fileloc), sRef s, + int kind, fileloc loc) { sRefSet aliases; + + if (sRef_isDeep (s)) + { + aliases = usymtab_allAliases (s); + } + else + { + aliases = usymtab_aliasedBy (s); + } + + (*predf)(s, kind, loc); + + sRefSet_realElements (aliases, current) + { + if (sRef_isReasonable (current)) + { + current = sRef_updateSref (current); + ((*predf)(current, kind, loc)); + } + } end_sRefSet_realElements; + + sRefSet_free (aliases); +} + +/* +** Version of aliasSetCompleteParam for alkind parameters +*/ +void +sRef_aliasSetCompleteAlkParam (void (predf) (sRef, alkind, fileloc), sRef s, + alkind kind, fileloc loc) +{ + sRefSet aliases; if (sRef_isDeep (s)) { @@ -8192,7 +8486,7 @@ sRef_aliasSetCompleteParam (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)); @@ -8209,9 +8503,8 @@ 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. */ @@ -8228,11 +8521,10 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc) inner = s->info->ref; aliases = usymtab_allAliases (inner); ct = sRef_getType (inner); - sRefSet_realElements (aliases, current) { - if (sRef_isValid (current)) + if (sRef_isReasonable (current)) { current = sRef_updateSref (current); @@ -8251,28 +8543,44 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc) aliases = usymtab_allAliases (inner); ct = sRef_getType (inner); + DPRINTF (("Array fetch: %s", sRefSet_unparse (aliases))); + sRefSet_realElements (aliases, current) { - if (sRef_isValid (current)) + if (sRef_isReasonable (current)) { current = sRef_updateSref (current); - + DPRINTF (("Current: %s", sRef_unparseFull (current))); + if (ctype_equal (ct, sRef_getType (current))) { - if (s->info->arrayfetch->indknown) { sRef af = sRef_makeArrayFetchKnown (current, s->info->arrayfetch->ind); - + DPRINTF (("Defining: %s", sRef_unparseFull (af))); + /* evans 2001-08-27 This isn't true: + llassert (af->info->arrayfetch->arr == current); + see comments in buildArrayFetchKnown + */ ((*predf)(af, loc)); } else { sRef af = sRef_makeArrayFetch (current); - + /* evans 2001-08-27 This isn't true: + llassert (af->info->arrayfetch->arr == current); + see comments in buildArrayFetch + */ + DPRINTF (("Defining: %s", sRef_unparseFull (af))); ((*predf)(af, loc)); } } + else + { + DPRINTF (("Type mismatch: %s / %s", + ctype_unparse (ct), + ctype_unparse (sRef_getType (current)))); + } } } end_sRefSet_realElements; @@ -8282,11 +8590,10 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc) inner = s->info->field->rec; aliases = usymtab_allAliases (inner); ct = sRef_getType (inner); - sRefSet_realElements (aliases, current) { - if (sRef_isValid (current)) + if (sRef_isReasonable (current)) { current = sRef_updateSref (current); @@ -8326,9 +8633,8 @@ 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. */ @@ -8345,11 +8651,10 @@ sRef_innerAliasSetCompleteParam (void (predf) (sRef, sRef), sRef s, sRef t) inner = s->info->ref; aliases = usymtab_allAliases (inner); ct = sRef_getType (inner); - - + sRefSet_realElements (aliases, current) { - if (sRef_isValid (current)) + if (sRef_isReasonable (current)) { current = sRef_updateSref (current); @@ -8371,7 +8676,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); @@ -8404,7 +8709,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); @@ -8627,6 +8932,8 @@ static void sRef_checkMutable (res); + DPRINTF (("Combine alias kinds: \n\t%s / \n\t%s", + sRef_unparseFull (res), sRef_unparseFull (other))); if (alkind_equal (ares, aother) || aother == AK_UNKNOWN || aother == AK_ERROR) @@ -8639,12 +8946,14 @@ static void res ->aliaskind = AK_ERROR; } else if (ares == AK_UNKNOWN || ares == AK_ERROR - || sRef_isStateUndefined (res)) + || sRef_isStateUndefined (res) + || sRef_isDefinitelyNull (res)) { res->aliasinfo = stateInfo_update (res->aliasinfo, other->aliasinfo); res->aliaskind = aother; } - else if (sRef_isStateUndefined (other)) + else if (sRef_isStateUndefined (other) + || sRef_isDefinitelyNull (other)) { ; } @@ -8833,6 +9142,8 @@ extern /*@exposed@*/ sRef sRef_makeArrow (sRef s, /*@dependent@*/ cstring f) p = sRef_makePointer (s); ret = sRef_makeField (p, f); + DPRINTF (("Arrow: %s => %s", + sRef_unparseFull (s), sRef_unparseFull (ret))); return ret; } @@ -9197,11 +9508,12 @@ 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; res->nullinfo = stateInfo_update (res->nullinfo, other->nullinfo); + sRef_resetAliasKind (res); } void sRef_combineNullState (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other) @@ -9261,11 +9573,12 @@ void sRef_combineNullState (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other) } res->nullstate = nn; + sRef_resetAliasKind (res); } cstring sRef_nullMessage (sRef s) { - llassert (sRef_isValid (s)); + llassert (sRef_isReasonable (s)); switch (sRef_getNullState (s)) { @@ -9280,7 +9593,7 @@ cstring sRef_nullMessage (sRef s) /*@observer@*/ cstring sRef_ntMessage (sRef s) { - llassert (sRef_isValid (s)); + llassert (sRef_isReasonable (s)); switch (s->nullstate) { @@ -9300,7 +9613,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) { @@ -9436,63 +9749,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) @@ -9513,7 +9826,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; } @@ -9523,7 +9836,7 @@ 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)) { @@ -9554,7 +9867,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); @@ -9568,7 +9881,7 @@ 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)) { @@ -9599,7 +9912,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)) { @@ -9625,7 +9938,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)) { @@ -9650,9 +9963,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; } @@ -9669,18 +9982,18 @@ 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)); /*@i523 why doesn't null-checking work!??? */ if (s->defstate == SS_UNKNOWN || s->defstate == SS_DEFINED || s->defstate == SS_SPECIAL) { - s->aliaskind = AK_IMPTEMP; + /* s->aliaskind = AK_IMPTEMP; */ /* evans 2001-07-23 shouldn't effect alias state */ s->defstate = SS_SPECIAL; DPRINTF (("Made special: %s", sRef_unparseFull (s))); return TRUE; } else { - s->aliaskind = AK_IMPTEMP; + /* s->aliaskind = AK_IMPTEMP; */ s->defstate = SS_SPECIAL; return FALSE; } @@ -9688,7 +10001,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; @@ -9721,7 +10034,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")); @@ -9730,7 +10043,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")); @@ -9738,36 +10051,48 @@ 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")); } } +/* these next three function are used by the nullterminated checking only. + They are not directly realted to the buffer bounds checking +*/ 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 */ @@ -9778,13 +10103,41 @@ 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) +{ + 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_isReasonable (s) + && multiVal_isDefined (s->val)); +} + +multiVal sRef_getValue (sRef s) +{ + if (sRef_isReasonable (s)) + { + return s->val; + } + + return multiVal_undefined; +}