X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/3814599dbdafeaf8cb335d07f1d1bf1729a98417..52e90c0f77bb0e3edb043873b71a73459d4ae8ab:/src/usymtab.c diff --git a/src/usymtab.c b/src/usymtab.c index 10722ba..179723c 100644 --- a/src/usymtab.c +++ b/src/usymtab.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 */ /* ** usymtab @@ -46,12 +46,18 @@ ** weird C syntax. */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "basic.h" # include "structNames.h" # include "exprChecks.h" # include "transferChecks.h" +/* Needed to install macros when loading libraries */ + +# include "cpplib.h" +# include "cpperror.h" +# include "cpphash.h" + /* ** Keep track of type definitions inside a function. */ @@ -112,10 +118,15 @@ static bool usymtab_isDefinitelyNullAux (sRef p_s) /*@globals utab@*/ ; static /*@only@*/ cstring usymtab_unparseStackTab (usymtab p_t); static /*@exposed@*/ /*@dependent@*/ uentry usymtab_getRefTab (/*@notnull@*/ usymtab p_u, int p_level, usymId p_index); + +# ifdef S_SPLINT_S +/* These are not used anymore... */ static /*@unused@*/ /*@only@*/ cstring usymtab_unparseLocalAux (/*@notnull@*/ usymtab p_s); static /*@unused@*/ /*@only@*/ cstring usymtab_unparseLocalList (/*@notnull@*/ usymtab p_s); +# endif + static /*@only@*/ cstring usymtab_typeName (/*@notnull@*/ usymtab p_t); static void usymtab_handleParams (void) /*@globals utab, globtab, filetab@*/ @@ -137,7 +148,7 @@ static /*@exposed@*/ /*@dependent@*/ uentry static /*@exposed@*/ /*@dependent@*/ uentry usymtab_lookupQuietNoAlt (usymtab p_s, cstring p_k); -static void usymtab_printAllAux (usymtab p_s) /*@modifies g_msgstream@*/ ; +static void usymtab_printAllAux (usymtab p_s) /*@modifies g_warningstream@*/ ; static int usymtab_getIndex (/*@notnull@*/ usymtab p_s, cstring p_k); static /*@exposed@*/ uentry usymtab_fetchIndex (/*@notnull@*/ usymtab p_s, int p_i); static /*@exposed@*/ uentry @@ -150,9 +161,9 @@ static bool usymtab_mustEscape (usymtab p_s); static void recordFunctionType (uentry ue) { - llassert (uentry_isDatatype (ue) || uentry_isAnyTag (ue) + llassert (uentry_isDatatype (ue) || uentry_isAnyTag (ue) || uentry_isEnumConstant (ue)); - + DPRINTF (("Function type: %s", uentry_unparseFull (ue))); /*@-temptrans@*/ functypes = uentryList_add (functypes, ue); /*@=temptrans@*/ @@ -182,7 +193,7 @@ static void clearFunctionTypes (void) uentryList_clear (functypes); } -static /*@falsenull@*/ bool usymtab_isBranch (usymtab u) +static /*@falsewhennull@*/ bool usymtab_isBranch (usymtab u) { return (usymtab_isDefined (u) && (u->kind == US_TBRANCH || u->kind == US_FBRANCH @@ -367,13 +378,14 @@ usymtab_initBool () */ usymtab_supGlobalEntry - (uentry_makeConstantAux (context_getFalseName (), boolt, - fileloc_getBuiltin (), FALSE, - multiVal_makeInt (0))); + (uentry_makeConstantValue (context_getFalseName (), boolt, + fileloc_getBuiltin (), FALSE, + multiVal_makeInt (0))); + usymtab_supGlobalEntry - (uentry_makeConstantAux (context_getTrueName (), boolt, - fileloc_getBuiltin (), FALSE, - multiVal_makeInt (1))); + (uentry_makeConstantValue (context_getTrueName (), boolt, + fileloc_getBuiltin (), FALSE, + multiVal_makeInt (1))); } } @@ -503,7 +515,8 @@ usymtab_addEntryBase (/*@notnull@*/ usymtab s, /*@only@*/ uentry e) if (uentry_isVar (e)) { uentry_setSref (e, sRef_makeCvar (globScope, thisentry, - uentry_getType (e))); + uentry_getType (e), + stateInfo_makeLoc (uentry_whereLast (e)))); } usymtab_addEntryQuiet (s, e); @@ -542,7 +555,8 @@ usymtab_addEntryAlways (/*@notnull@*/ usymtab s, /*@only@*/ uentry e) if (uentry_isVar (e) && !uentry_isGlobalMarker (e)) { uentry_setSref (e, sRef_makeCvar (globScope, thisentry, - uentry_getType (e))); + uentry_getType (e), + stateInfo_makeLoc (uentry_whereLast (e)))); } usymtab_addEntryQuiet (s, e); @@ -583,7 +597,7 @@ usymtab_addEntryAux (/*@notnull@*/ usymtab st, /*@keep@*/ uentry e, bool isSref) if (uentry_isStatic (e)) { - sRef sr = sRef_makeCvar (st->lexlevel, thisentry, ct); + sRef sr = sRef_makeCvar (st->lexlevel, thisentry, ct, stateInfo_makeLoc (uentry_whereLast (e))); if (sRef_isStack (sr) || sRef_isLocalState (sr)) { @@ -595,10 +609,9 @@ usymtab_addEntryAux (/*@notnull@*/ usymtab st, /*@keep@*/ uentry e, bool isSref) } else { - uentry_setSref (e, sRef_makeCvar (st->lexlevel, thisentry, ct)); + uentry_setSref (e, sRef_makeCvar (st->lexlevel, thisentry, ct, stateInfo_makeLoc (uentry_whereLast (e)))); } - - } + } if (uentry_isDatatype (e)) { @@ -745,8 +758,6 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st, } } - DPRINTF (("Using symtab: %s", usymtab_unparseLocalAux (st))); - eindex = usymtab_getIndex (st, ename); if (eindex != NOT_FOUND) @@ -852,13 +863,21 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st, if (uentry_isDeclared (ce)) { - llassert ((st->lexlevel > fileScope || !sRef_modInFunction ())); + /* evans 2001-08-26 + No - this can happen for internal typedefs + llassert ((st->lexlevel > fileScope || !sRef_modInFunction ())); + */ + DPRINTF (("Merge defn")); uentry_mergeDefinition (ce, e); } else { - llassert ((st->lexlevel > fileScope || !sRef_modInFunction ())); + /* evans 2001-08-26 + No - this can happen for internal typedefs + llassert ((st->lexlevel > fileScope || !sRef_modInFunction ())); + */ + DPRINTF (("Merge entries...")); uentry_mergeEntries (ce, e); DPRINTF (("After: %s", uentry_unparseFull (ce))); @@ -906,8 +925,8 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st, ct = ctype_getReturnType (ct); } - uentry_setSref (ce, sRef_makeCvar (st->lexlevel, eindex, ct)); - } + uentry_setSref (ce, sRef_makeCvar (st->lexlevel, eindex, ct, stateInfo_makeLoc (uentry_whereLast (ce)))); + } } else /* no previous entry */ { @@ -941,6 +960,9 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st, outer = usymtab_lookupQuiet (st->env, ename); + DPRINTF (("New : [%p] %s", e, uentry_unparseFull (e))); + DPRINTF (("Outer: [%p] %s", outer, uentry_unparseFull (outer))); + /* ** no previous definition, add the new one */ @@ -949,7 +971,9 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st, && uentry_isValid (outer) && !(uentry_isYield (e) || uentry_isYield (outer)) && fileloc_isDefined (uentry_whereLast (e)) - && fileloc_isDefined (uentry_whereLast (outer))) + && !fileloc_isXHFile (uentry_whereLast (e)) + && fileloc_isDefined (uentry_whereLast (outer)) + && !fileloc_isXHFile (uentry_whereLast (outer))) { if (!uentry_sameKind (outer, e)) { @@ -1046,7 +1070,6 @@ static /*@exposed@*/ uentry bool stat = (tab == globtab) && uentry_isStatic (e); uentry ret; - (void) usymtab_supEntryAux (tab, e, isref); if (stat) @@ -1092,6 +1115,12 @@ static /*@exposed@*/ uentry ret = usymtab_supEntryReturnAux (globtab, e, FALSE); + /* + ** We need to keep track of internal function declarations, so + ** we can remove them from the symbol table after exiting this + ** function. This is a bit bogus, of course. + */ + if (sRef_modInFunction ()) { recordFunctionType (ret); @@ -1284,7 +1313,6 @@ void /*@modifies utab, globtab, e@*/ { sRef old = uentry_getSref (e); - if (sRef_isType (old)) { @@ -1555,6 +1583,7 @@ usymtab_getTypeEntryName (usymId uid) return (uentry_getName (ue)); } +# if 0 /*@unused@*/ static void usymtab_rehash (/*@notnull@*/ usymtab s) { @@ -1572,6 +1601,7 @@ usymtab_rehash (/*@notnull@*/ usymtab s) cstringTable_insert (s->htable, cstring_copy (uentry_rawName (s->entries[i])), i); } } +# endif /* ** superficial copy of usymtab @@ -1810,11 +1840,9 @@ void usymtab_dump (FILE *fout) } } - - - } + void usymtab_load (FILE *f) /*@globals utab, globtab@*/ /*@modifies utab, *f@*/ @@ -1866,7 +1894,7 @@ void usymtab_load (FILE *f) { llfatalerror (cstring_makeLiteral - ("Library is in obsolete format. Use lclint +whichlib " + ("Library is in obsolete format. Use splint +whichlib " "to see which library is being loaded.")); } @@ -1888,6 +1916,30 @@ void usymtab_load (FILE *f) { int lastindex = utab->nentries; ue = usymtab_addEntryAlways (utab, ue); + + +# if 0 + if (uentry_isConstant (ue)) /*@i23! isPreProcessorMacro */ + { + cstring uname = uentry_getName (ue); + + /* Also check its a macro... */ + DPRINTF (("Installing: %s", uname)); + + cpphash_installMacro + (mstring_copy (cstring_toCharsSafe (uname)), + cstring_length (uname), + cpplib_createDefinition (message ("%s 255", uname), + loc, + FALSE, FALSE).defn, + cpphash_hashCode (cstring_toCharsSafe (uname), + cstring_length (uname), + CPP_HASHSIZE)); + + DPRINTF (("After install: %s", uname)); + } +# endif + if (utab->nentries != lastindex + 1) { DPRINTF (("No add: %s", uentry_unparseFull (ue))); @@ -1958,7 +2010,7 @@ void usymtab_load (FILE *f) } s = fgets (os, MAX_DUMP_LINE_LENGTH, f); - temp = cstring_fromChars(reader_getWord(&s) ); + temp = cstring_fromChars (reader_getWord(&s) ); if (cstring_compareLit (temp,"pre:") == 0 ) { @@ -1975,17 +2027,17 @@ void usymtab_load (FILE *f) s = fgets (os, MAX_DUMP_LINE_LENGTH, f); temp = cstring_fromChars(reader_getWord(&s) ); - if (cstring_compareLit (temp,"post:") == 0 ) + if (cstring_compareLit (temp, "post:") == 0 ) { postconditions = constraintList_undump (f); } else { - if (cstring_compareLit (temp,"post:EMPTY") != 0 ) + if (cstring_compareLit (temp, "post:EMPTY") != 0 ) llfatalbug ((message("Error reading library file post:EMPTY expected but got %s", temp ) )); } - cstring_free(temp); + cstring_free (temp); uentry_setPreconditions (ue, functionConstraint_createBufferConstraint (preconditions)); uentry_setPostconditions (ue, functionConstraint_createBufferConstraint (postconditions)); @@ -2015,8 +2067,8 @@ usymtab_enterFile () { if (sRef_hasDerived (uentry_getSref (ue))) { - fprintf (g_msgstream, "Derived Global: %s\n", uentry_unparse (ue)); - fprintf (g_msgstream, "sRef: %s\n", sRef_unparseFull (ue->sref)); + fprintf (g_warningstream, "Derived Global: %s\n", uentry_unparse (ue)); + fprintf (g_warningstream, "sRef: %s\n", sRef_unparseFull (ue->sref)); } } end_usymtab_entries ; @@ -2107,7 +2159,10 @@ usymtab_handleParams (void) { if (sRef_isStateSpecial (pref)) { - uentry_setDefState (ue, SS_ALLOCATED); + uentry_setDefState (ue, SS_SPECIAL); /* ALLOCATED); */ + /* evans 2002-01-01: should be unnecessary, the pre clauses + ** set the state if necessary. + */ } else { @@ -2271,11 +2326,13 @@ usymtab_enterFunctionScope (uentry fcn) { usymtab t = usymtab_create (US_NORMAL, utab, TRUE); + DPRINTF (("Enter function: %s", uentry_unparse (fcn))); + if (utab->lexlevel != fileScope) { if (utab->lexlevel > fileScope) { - llparseerror (cstring_makeLiteral ("New function scope inside function.")); + llparseerror (cstring_makeLiteral ("New function scope inside function")); while (utab->lexlevel > fileScope) { @@ -2368,6 +2425,9 @@ usymtab_enterFunctionScope (uentry fcn) } end_globSet_allElements; DPRINTF (("Globs after: %s", globSet_unparse (uentry_getGlobs (fcn)))); +# ifdef DEBUGSPLINT + usymtab_checkAllValid (); +# endif } static void @@ -2528,6 +2588,8 @@ usymtab_newCase (/*@unused@*/ exprNode pred, exprNode last) bool mustReturn = usymtab_mustEscape (utab); usymtab stab = utab; + DPRINTF (("New case!")); + /* ** Find last case (or outer switch) */ @@ -2537,9 +2599,7 @@ usymtab_newCase (/*@unused@*/ exprNode pred, exprNode last) stab = stab->env; llassert (stab != GLOBAL_ENV); } - - /* ??? */ - + while (stab->kind == US_CBRANCH) { stab = stab->env; @@ -2849,13 +2909,17 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab, if (!guardSet_isGuarded (ttab->guards, el) && !sRef_isNotNull (sr)) { + DPRINTF (("Here! %s / %s", + sRef_unparseFull (sr), + sRef_unparseFull (el))); sRef_setDerivNullState (sr, el, NS_DEFNULL); - } + } } } else { - } + ; + } ue = usymtab_getRefTab (ftab, level, index); @@ -2863,7 +2927,6 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab, { sRef sr = uentry_getSref (ue); - if (!trueGuard) /* yikes! forgot the ! */ { sRef_setDerivNullState (sr, el, NS_NOTNULL); @@ -2875,7 +2938,7 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab, && !sRef_isNotNull (sr)) { sRef_setDerivNullState (sr, el, NS_DEFNULL); - } + } } } else @@ -3185,6 +3248,7 @@ usymtab_allDefined (void) ekind_capName (uentry_getKind (e)), uentry_getName (e)), dloc); + DPRINTF (("decl: %s", uentry_unparseFull (e))); } } } @@ -3613,7 +3677,7 @@ checkGlobalReturn (uentry glob, sRef orig) { sRef sr = uentry_getSref (glob); - DPRINTF (("Check global return: %s // orig: %s // sr: %s", + DPRINTF (("Check global return: %s / orig: %s / sr: %s", uentry_unparseFull (glob), sRef_unparseFull (orig), sRef_unparseFull (sr))); @@ -3636,6 +3700,8 @@ checkGlobalReturn (uentry glob, sRef orig) else { ctype ct = ctype_realType (uentry_getType (glob)); + + DPRINTF (("Check global destroyed: %s", uentry_unparseFull (glob))); if (ctype_isVisiblySharable (ct)) { @@ -3653,7 +3719,7 @@ checkGlobalReturn (uentry glob, sRef orig) else { sRef_protectDerivs (); - (void) checkGlobalDestroyed (sr, g_currentloc); + (void) transferChecks_globalDestroyed (sr, g_currentloc); sRef_clearProtectDerivs (); } } @@ -3673,16 +3739,25 @@ checkGlobalReturn (uentry glob, sRef orig) } else { - if (sRef_isDead (sr)) + if (sRef_isDead (sr) || sRef_isKept (sr)) { if (optgenerror (FLG_GLOBSTATE, message ("Function returns with global %q " - "referencing released storage", - uentry_getName (glob)), + "referencing %s storage", + uentry_getName (glob), + cstring_makeLiteralTemp (sRef_isDead (sr) ? "released" : "kept")), g_currentloc)) { - sRef_showStateInfo (sr); + if (sRef_isKept (sr)) + { + sRef_showAliasInfo (sr); + } + else + { + sRef_showStateInfo (sr); + } + sRef_setDefState (sr, SS_UNKNOWN, fileloc_undefined); } } @@ -3703,7 +3778,8 @@ checkGlobalReturn (uentry glob, sRef orig) } else { - checkGlobReturn (glob); + DPRINTF (("Check transfer: %s", uentry_unparseFull (glob))); + transferChecks_globalReturn (glob); } } } @@ -3717,7 +3793,7 @@ checkGlobalReturn (uentry glob, sRef orig) void usymtab_checkFinalScope (bool isReturn) /*@globals utab@*/ { - bool mustFree = context_getFlag (FLG_MUSTFREE); + bool mustFree = context_getFlag (FLG_MUSTFREEONLY) || context_getFlag (FLG_MUSTFREEFRESH); /*@i423 remove this mustFree */ bool mustDefine = context_getFlag (FLG_MUSTDEFINE); /* bool mustNotAlias = context_getFlag (FLG_MUSTNOTALIAS); */ sRefSet checked = sRefSet_new (); @@ -3753,7 +3829,7 @@ void usymtab_checkFinalScope (bool isReturn) /*@innercontinue@*/ continue; } } - + DPRINTF (("Here check final scope: %s", uentry_unparseFull (ce))); if (ctype_isFunction (uentry_getType (ce))) @@ -3766,6 +3842,7 @@ void usymtab_checkFinalScope (bool isReturn) || sRef_isFileOrGlobalScope (rb)) { /* Don't do the loseref check...but should check state! */ + DPRINTF (("Skipping check 1")); } else if (sRef_isDefinitelyNull (sr) || usymtab_isDefinitelyNull (sr)) @@ -3773,6 +3850,8 @@ void usymtab_checkFinalScope (bool isReturn) /* ** No state reference errors for definitely null references. */ + + DPRINTF (("Skipping check 2")); } else { @@ -3789,9 +3868,10 @@ void usymtab_checkFinalScope (bool isReturn) minfo = context_lookupMetaStateInfo (fkey); llassert (metaStateInfo_isDefined (minfo)); - if (stateValue_isError (fval)) + if (stateValue_isError (fval) + || sRef_isStateUndefined (sr)) /* No errors for undefined state */ { - ; + DPRINTF (("Skipping check 3")); } else { @@ -3834,9 +3914,11 @@ void usymtab_checkFinalScope (bool isReturn) } end_valueTable_elements; } + DPRINTF (("Here 1")); + if (mustFree) { - DPRINTF (("Check entry: %s", uentry_unparseFull (ce))); + DPRINTF (("Check mustfree entry: %s", uentry_unparseFull (ce))); if (!sRefSet_member (checked, sr) && !sRef_isFileOrGlobalScope (rb)) { @@ -3851,7 +3933,7 @@ void usymtab_checkFinalScope (bool isReturn) if (sRefSet_isEmpty (als)) { - checkLocalDestroyed (sr, g_currentloc); + transferChecks_localDestroyed (sr, g_currentloc); } else { @@ -3880,7 +3962,7 @@ void usymtab_checkFinalScope (bool isReturn) if (!isReturn) { - if (canLoseReference (sr, g_currentloc)) + if (transferChecks_canLoseReference (sr, g_currentloc)) { DPRINTF (("Can lose!")); hasError = FALSE; @@ -3894,7 +3976,7 @@ void usymtab_checkFinalScope (bool isReturn) sRef ar = sRef_getAliasInfoRef (sr); if (optgenerror - (FLG_MUSTFREE, + (sRef_isFresh (ar) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY, message ("Last reference %q to %s storage %qnot %q before %q", sRef_unparse (sr), @@ -3912,7 +3994,7 @@ void usymtab_checkFinalScope (bool isReturn) else if (sRef_isNewRef (sr)) { if (optgenerror - (FLG_MUSTFREE, + (sRef_isFresh (sr) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY, message ("%q %q not released before %q", cstring_makeLiteral @@ -3930,14 +4012,14 @@ void usymtab_checkFinalScope (bool isReturn) { if (ctype_isRealSU (sRef_getType (sr))) { - checkStructDestroyed (sr, g_currentloc); + transferChecks_structDestroyed (sr, g_currentloc); } else { DPRINTF (("Here we are: %s", sRef_unparseFull (sr))); if (optgenerror - (FLG_MUSTFREE, + (sRef_isFresh (sr) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY, message ("%s storage %q not %q before %q", alkind_capName (sRef_getAliasKind (sr)), @@ -3960,59 +4042,57 @@ void usymtab_checkFinalScope (bool isReturn) ; } } - else if (mustDefine && uentry_isOut (ce)) - { - if (!ynm_toBoolStrict (sRef_isReadable (sr))) - { - voptgenerror - (FLG_MUSTDEFINE, - message ("Out storage %q not defined before %q", - uentry_getName (ce), - cstring_makeLiteral - (isReturn ? "return" : "scope exit")), - g_currentloc); - - /* uentry_showWhereDeclared (ce); */ - } - } - else + } + + if (mustDefine && uentry_isOut (ce)) + { + /* No error if its dead (either only or error already reported */ + if (!sRef_isReallyDefined (sr) && !sRef_isDead (sr)) { - ; + voptgenerror + (FLG_MUSTDEFINE, + message ("Out storage %q not defined before %q", + uentry_getName (ce), + cstring_makeLiteral + (isReturn ? "return" : "scope exit")), + g_currentloc); + + DPRINTF (("sr: %s", sRef_unparseFull (sr))); } + } + + /* + ** also check state is okay + */ + + if (usymtab_lexicalLevel () > functionScope + && uentry_isVariable (ce) + && (sRef_isLocalVar (sr) + && (sRef_isDependent (sr) || sRef_isLocalState (sr)))) + { + sRefSet ab = usymtab_aliasedBy (sr); - /* - ** also check state is okay - */ + /* should do something more efficient here */ - if (usymtab_lexicalLevel () > functionScope - && uentry_isVariable (ce) - && (sRef_isLocalVar (sr) - && (sRef_isDependent (sr) || sRef_isLocalState (sr)))) + if (sRefSet_isEmpty (ab)) { - sRefSet ab = usymtab_aliasedBy (sr); - - /* should do something more efficient here */ - - if (sRefSet_isEmpty (ab)) - { - /* and no local ref */ - DPRINTF (("Check lose ref: %s", uentry_unparseFull (ce))); - checkLoseRef (ce); - } - else - { - ; - } - - sRefSet_free (ab); + /* and no local ref */ + DPRINTF (("Check lose ref: %s", uentry_unparseFull (ce))); + transferChecks_loseReference (ce); } - else + else { ; } - checked = sRefSet_insert (checked, sr); + sRefSet_free (ab); + } + else + { + ; } + + checked = sRefSet_insert (checked, sr); } llassert (usymtab_isDefined (stab->env)); @@ -4156,6 +4236,8 @@ void usymtab_checkFinalScope (bool isReturn) { ss (sr); } + + DPRINTF (("Storage: %s", sRef_unparseFull (sr))); } } } @@ -4186,7 +4268,7 @@ void usymtab_checkFinalScope (bool isReturn) { uentry param = usymtab_lookupQuiet (utab, uentry_rawName (arg)); DPRINTF (("Check param return: %s", uentry_unparseFull (param))); - checkParamReturn (param); + transferChecks_paramReturn (param); } } } end_uentryList_elements; @@ -4260,6 +4342,10 @@ usymtab_quietExitScope (fileloc loc) usymtab_freeLevel (utab); utab = t; + +# ifdef DEBUGSPLINT + usymtab_checkAllValid (); +# endif } /* @@ -4306,32 +4392,34 @@ void usymtab_exitScope (exprNode expr) } if (utab->kind == US_TBRANCH || utab->kind == US_FBRANCH - || utab->kind == US_CBRANCH || utab->kind == US_SWITCH) { - - if (context_inMacro ()) { - /* evs 2000-07-25 */ - /* Unparseable macro may end inside nested scope. Deal with it. */ - - llerror (FLG_SYNTAX, - message ("Problem parsing macro body of %s (unbalanced scopes). " - "Attempting to recover, recommend /*@notfunction@*/ before " - "macro definition.", - context_inFunctionName ())); - - while (utab->kind == US_TBRANCH - || utab->kind == US_FBRANCH - || utab->kind == US_CBRANCH - || utab->kind == US_SWITCH) + || utab->kind == US_CBRANCH || utab->kind == US_SWITCH) + { + if (context_inMacro ()) { - utab = utab->env; - llassert (utab != GLOBAL_ENV); - } - } else { - llcontbug (message ("exitScope: in branch: %q", usymtab_unparseStack ())); - /*@-branchstate@*/ - } /*@=branchstate@*/ - } - + /* evs 2000-07-25 */ + /* Unparseable macro may end inside nested scope. Deal with it. */ + + llerror (FLG_SYNTAX, + message ("Problem parsing macro body of %s (unbalanced scopes). " + "Attempting to recover, recommend /*@notfunction@*/ before " + "macro definition.", + context_inFunctionName ())); + + while (utab->kind == US_TBRANCH + || utab->kind == US_FBRANCH + || utab->kind == US_CBRANCH + || utab->kind == US_SWITCH) + { + utab = utab->env; + llassert (utab != GLOBAL_ENV); + } + } else + { + llcontbug (message ("exitScope: in branch: %q", usymtab_unparseStack ())); + /*@-branchstate@*/ + } /*@=branchstate@*/ + } + /* ** check all variables in scope were used */ @@ -4357,7 +4445,7 @@ void usymtab_exitScope (exprNode expr) ** NOTE: note for exiting paramsScope, since checkReturn should be ** called first. */ - + if (!mustReturn && (usymtab_lexicalLevel () > functionScope)) { /* @@ -4376,7 +4464,6 @@ void usymtab_exitScope (exprNode expr) uentryList params = context_getParams (); globSet globs = context_getUsedGlobs (); - uentryList_elements (params, ue) { uentry_fixupSref (ue); @@ -4384,9 +4471,12 @@ void usymtab_exitScope (exprNode expr) clearFunctionTypes (); - + DPRINTF (("Fixing up globals: %s", globSet_unparse (globs))); + globSet_allElements (globs, el) { + DPRINTF (("Fix: %s", sRef_unparseDebug (el))); + if (sRef_isCvar (el)) { uentry current; @@ -4404,13 +4494,17 @@ void usymtab_exitScope (exprNode expr) if (uentry_isVariable (current)) { + DPRINTF (("Fixup: %s", uentry_unparse (current))); uentry_fixupSref (current); } else { + DPRINTF (("Clear: %s", uentry_getSref (current))); sRef_clearDerived (uentry_getSref (current)); } } + + sRef_clearDerived (el); /* evans 2002-03-14 - this is the likely source of many crashes! */ } end_globSet_allElements; } @@ -4421,8 +4515,13 @@ void usymtab_exitScope (exprNode expr) /*@i@*/ lctab->env = utab; /*@i@*/ utab = ctab; /*@-branchstate@*/ } /*@=branchstate@*/ -/*@-globstate@*/ -} + /*@-globstate@*/ + + +# ifdef DEBUGSPLINT + usymtab_checkAllValid (); +# endif +/*@i523@*/ } /*@=globstate@*/ /* @@ -4438,13 +4537,7 @@ uentry_directParamNo (uentry ue) if (sRef_lexLevel (sr) == functionScope) { - int index; - - /*@access sRef@*/ - llassert (sr->info != NULL); - llassert (sr->info->cvar != NULL); - index = sr->info->cvar->index; - /*@noaccess sRef@*/ + int index = sRef_getScopeIndex (sr); if (index < uentryList_size (context_getParams ())) { @@ -4875,6 +4968,7 @@ usymtab_lookupQuietAux (usymtab s, cstring k, bool noalt) } else { + llassert (s != NULL); /*@i523 should not need this? */ s = s->env; } } @@ -4937,6 +5031,7 @@ uentry usymtab_lookupGlob (cstring k) if (uentry_isPriv (ce)) llfatalbug (message ("usymtab_lookup: private: %s", k)); + DPRINTF (("Lookup global: %s", uentry_unparseFull (ce))); return ce; } @@ -4945,7 +5040,7 @@ uentry usymtab_lookupGlob (cstring k) /*@globals globtab@*/ { uentry ce = usymtab_lookupAux (globtab, k); - + DPRINTF (("Lookup global: %s", uentry_unparseFull (ce))); return ce; } @@ -4957,6 +5052,7 @@ uentry usymtab_lookupEither (cstring k) if (uentry_isUndefined (ce)) llfatalerror (message ("usymtab_lookup: not found: %s", k)); + DPRINTF (("Lookup either: %s", uentry_unparseFull (ce))); return ce; } @@ -5356,6 +5452,10 @@ static bool usymtab_isGuardedAux (sRef s) while (tab->lexlevel >= lowlevel) { + DPRINTF (("Is guarded? [%s] %s", + guardSet_unparse (tab->guards), + sRef_unparseFull (s))); + if (guardSet_isGuarded (tab->guards, s)) { /* @@ -5399,7 +5499,7 @@ void usymtab_unguard (sRef s) /*@modifies utab@*/ bool usymtab_isGuarded (sRef s) { - + DPRINTF (("Is guarded? %s", sRef_unparseFull (s))); return (sRef_aliasCompleteSimplePred (usymtab_isGuardedAux, s)); } @@ -5575,6 +5675,7 @@ void usymtab_addMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) void usymtab_addForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) /*@modifies utab@*/ { + /* evans 2002-03-3: was sRef_isMeaningful -- but we need to keep aliases for new storage also! */ if (sRef_isMeaningful (s) && sRef_isMeaningful (al) && !(sRef_isConst (s) || sRef_isConst (al)) @@ -5594,10 +5695,17 @@ void usymtab_addForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) } else { - ; + DPRINTF (("Not aliasing! %s / %s", sRef_unparseFull (s), sRef_unparseFull (al))); + DPRINTF (("meaningful: %d %d", sRef_isMeaningful (s), sRef_isMeaningful (al))); } } +void usymtab_addReallyForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) + /*@modifies utab@*/ +{ + utab->aliases = aliasTable_addMustAlias (utab->aliases, s, al); +} + void usymtab_clearAlias (sRef s) /*@modifies utab, s@*/ { @@ -5608,7 +5716,7 @@ void usymtab_clearAlias (sRef s) sRefSet usymtab_allAliases (sRef s) /*@globals utab@*/ { - if (sRef_isMeaningful (s)) + if (sRef_isSomewhatMeaningful (s)) { sRefSet ret; @@ -5626,7 +5734,7 @@ sRefSet usymtab_allAliases (sRef s) /*@only@*/ sRefSet usymtab_canAlias (sRef s) /*@globals utab@*/ { - if (sRef_isMeaningful (s)) + if (sRef_isSomewhatMeaningful (s)) { sRefSet res = aliasTable_canAlias (utab->aliases, s); return res; @@ -5663,7 +5771,7 @@ usymtab_printOut (void) int depth = 0; char *ind = mstring_copy (" "); - fprintf (g_msgstream, "<<< [symbol table] >>>\n"); + fprintf (g_warningstream, "<<< [symbol table] >>>\n"); while (s != GLOBAL_ENV && s->env != GLOBAL_ENV) { @@ -5674,7 +5782,7 @@ usymtab_printOut (void) ind[depth * 3 + 1] = '\0'; } - fprintf (g_msgstream, "level: %d (%s)\n", s->lexlevel, + fprintf (g_warningstream, "level: %d (%s)\n", s->lexlevel, cstring_toCharsSafe (tname)); cstring_free (tname); @@ -5682,17 +5790,17 @@ usymtab_printOut (void) for (i = 0; i < s->nentries; i++) { cstring us = uentry_unparseFull (s->entries[i]); - fprintf (g_msgstream, "%s\n", cstring_toCharsSafe (us)); + fprintf (g_warningstream, "%s\n", cstring_toCharsSafe (us)); cstring_free (us); } if (s->reftable != NULL && s->nentries > 0) { - fprintf (g_msgstream, "\t<< Ref table >>\n"); + fprintf (g_warningstream, "\t<< Ref table >>\n"); for (i = 0; i < s->nentries; i++) { - fprintf (g_msgstream, "\t%s %3d: %d, %d\n", ind, i, + fprintf (g_warningstream, "\t%s %3d: %d, %d\n", ind, i, s->reftable[i]->level, s->reftable[i]->index); } @@ -5702,7 +5810,7 @@ usymtab_printOut (void) depth++; s = s->env; } - fprintf (g_msgstream, "<<< end usymtab >>>\n"); + fprintf (g_warningstream, "<<< end usymtab >>>\n"); mstring_free (ind); return; } @@ -5723,7 +5831,7 @@ usymtab_printAll (void) static void usymtab_printAllAux (usymtab s) - /*@modifies g_msgstream@*/ + /*@modifies g_warningstream@*/ { int i; int depth = 0; @@ -5821,6 +5929,7 @@ usymtab_printComplete () mstring_free (ind); } +# ifdef S_SPLINT_S static /*@only@*/ cstring /*@unused@*/ usymtab_unparseLocalAux (/*@notnull@*/ usymtab s) { @@ -5863,6 +5972,7 @@ usymtab_unparseLocalList (/*@notnull@*/ usymtab s) return (c); } +# endif void usymtab_printLocal (void) @@ -5897,9 +6007,9 @@ usymtab_printLocal (void) static bool checkDistinctExternalName (uentry e) /*@globals globtab@*/ - /*@modifies *g_msgstream@*/ + /*@modifies *g_warningstream@*/ { - int checklen = context_getValue (FLG_EXTERNALNAMELEN); + size_t checklen = size_fromInt (context_getValue (FLG_EXTERNALNAMELEN)); bool ignorecase = context_getFlag (FLG_EXTERNALNAMECASEINSENSITIVE); bool gotone = FALSE; bool extras = FALSE; @@ -5974,7 +6084,7 @@ static bool checkDistinctExternalName (uentry e) "in the first %d characters (%q)", uentry_getName (e), uentry_getName (oe), - checklen, + size_toInt (checklen), cstring_clip (uentry_getName (e), checklen)), /*@=sefparams@*/ uentry_whereLast (e))) @@ -6000,7 +6110,7 @@ static bool checkDistinctExternalName (uentry e) "is ignored", uentry_getName (e), uentry_getName (oe), - checklen), + size_toInt (checklen)), uentry_whereLast (e))) { uentry_showWhereAny (oe); @@ -6026,7 +6136,7 @@ static bool checkDistinctExternalName (uentry e) "in the first %d characters (%q)", uentry_getName (e), uentry_getName (oe), - checklen, + size_toInt (checklen), cstring_clip (uentry_getName (e), checklen)), /*@=sefparams@*/ uentry_whereLast (e))) @@ -6058,11 +6168,11 @@ static bool checkDistinctExternalName (uentry e) static bool checkDistinctInternalName (uentry e) /*@globals utab@*/ - /*@modifies *g_msgstream@*/ + /*@modifies *g_warningstream@*/ { usymtab ttab = utab; cstring name = uentry_rawName (e); - int numchars = context_getValue (FLG_INTERNALNAMELEN); + size_t numchars = size_fromInt (context_getValue (FLG_INTERNALNAMELEN)); bool caseinsensitive = context_getFlag (FLG_INTERNALNAMECASEINSENSITIVE); bool lookalike = context_getFlag (FLG_INTERNALNAMELOOKALIKE); @@ -6102,7 +6212,7 @@ static bool checkDistinctInternalName (uentry e) "in the first %d characters (%q)", uentry_getName (e), uentry_getName (oe), - numchars, + size_toInt (numchars), cstring_clip (uentry_getName (e), numchars)), /*@=sefparams@*/ uentry_whereLast (e))) @@ -6115,8 +6225,7 @@ static bool checkDistinctInternalName (uentry e) /*@switchbreak@*/ break; case CGE_CASE: - if (numchars == 0 - || (cstring_length (name) <= numchars)) + if (numchars == 0 || (cstring_length (name) <= numchars)) { if (optgenerror (FLG_DISTINCTINTERNALNAMES, @@ -6141,7 +6250,7 @@ static bool checkDistinctInternalName (uentry e) "in the first %d characters without case sensitivity", uentry_getName (e), uentry_getName (oe), - numchars), + size_toInt (numchars)), uentry_whereLast (e))) { uentry_showWhereAny (oe); @@ -6178,7 +6287,7 @@ static bool checkDistinctInternalName (uentry e) "in the first %d characters except by lookalike characters", uentry_getName (e), uentry_getName (oe), - numchars), + size_toInt (numchars)), uentry_whereLast (e))) { uentry_showWhereAny (oe); @@ -6233,3 +6342,36 @@ void usymtab_checkDistinctName (uentry e, int scope) return uentry_getSref (ue); } + +# ifdef DEBUGSPLINT +/* +** For debugging only +*/ + +void +usymtab_checkAllValid () /*@globals utab@*/ +{ + usymtab tab = utab; + + while (tab != GLOBAL_ENV) + { + int i; + + for (i = 0; i < utab->nentries; i++) + { + uentry e = utab->entries[i]; + + uentry_checkValid (e); + } + + aliasTable_checkValid (tab->aliases); + tab = tab->env; + } +} +# endif + + + + + +