]> andersk Git - splint.git/blobdiff - src/usymtab.c
Fixed problem with loop guards in loop test effects. New test case
[splint.git] / src / usymtab.c
index bb2c40c31f4a07c1f7e34b77fdec4c1617e4b72b..179723c65f9d324a66d8750c3a5a945a2f1b2963 100644 (file)
@@ -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
 **                      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)));
     }
 }
 
@@ -746,8 +758,6 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st,
     }
   }
 
-  DPRINTF (("Using symtab: %s", usymtab_unparseLocalAux (st)));
-
   eindex = usymtab_getIndex (st, ename);
       
   if (eindex != NOT_FOUND)
@@ -853,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)));
@@ -942,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
       */
@@ -1049,7 +1070,6 @@ static /*@exposed@*/ uentry
   bool stat = (tab == globtab) && uentry_isStatic (e);
   uentry ret;
 
-    
   (void) usymtab_supEntryAux (tab, e, isref);
 
   if (stat)
@@ -1095,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);
@@ -1287,7 +1313,6 @@ void
   /*@modifies utab, globtab, e@*/
 {
   sRef old = uentry_getSref (e);
-
   
   if (sRef_isType (old))
     {
@@ -1558,6 +1583,7 @@ usymtab_getTypeEntryName (usymId uid)
   return (uentry_getName (ue));
 }
 
+# if 0
 /*@unused@*/ static void
 usymtab_rehash (/*@notnull@*/ usymtab s)
 {
@@ -1575,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
@@ -1813,11 +1840,9 @@ void usymtab_dump (FILE *fout)
                  
        }
     }
-    
-
-  
 }
 
+
 void usymtab_load (FILE *f)
   /*@globals utab, globtab@*/
   /*@modifies utab, *f@*/
@@ -1869,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."));
        }
 
@@ -1891,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)));
@@ -2018,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 ;
 
@@ -2110,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
                    {
@@ -2274,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)
            {
@@ -2371,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
@@ -2531,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)
   */
@@ -2540,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;
@@ -2852,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);
       
@@ -2866,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);
@@ -2878,7 +2938,7 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab,
                  && !sRef_isNotNull (sr))
                {
                  sRef_setDerivNullState (sr, el, NS_DEFNULL);
-                               }
+               }
            }
        }
       else
@@ -3617,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)));
@@ -3640,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))
                {
@@ -3657,7 +3719,7 @@ checkGlobalReturn (uentry glob, sRef orig)
              else
                {
                  sRef_protectDerivs ();
-                 (void) checkGlobalDestroyed (sr, g_currentloc);
+                 (void) transferChecks_globalDestroyed (sr, g_currentloc);
                  sRef_clearProtectDerivs ();
                }
            }
@@ -3677,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);
                    }
                }
@@ -3707,7 +3778,8 @@ checkGlobalReturn (uentry glob, sRef orig)
                }
              else
                {
-                 checkGlobReturn (glob);
+                 DPRINTF (("Check transfer: %s", uentry_unparseFull (glob)));
+                 transferChecks_globalReturn (glob);
                }
            }
        }
@@ -3721,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 ();
@@ -3757,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)))
@@ -3770,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))
@@ -3777,6 +3850,8 @@ void usymtab_checkFinalScope (bool isReturn)
              /*
              ** No state reference errors for definitely null references.
              */
+
+             DPRINTF (("Skipping check 2"));
            }
          else
            {
@@ -3793,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 
                  {
@@ -3838,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))
                {
@@ -3855,7 +3933,7 @@ void usymtab_checkFinalScope (bool isReturn)
                      
                      if (sRefSet_isEmpty (als))
                        {
-                         checkLocalDestroyed (sr, g_currentloc);
+                         transferChecks_localDestroyed (sr, g_currentloc);
                        }
                      else
                        {
@@ -3884,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;
@@ -3898,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),
@@ -3916,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 
@@ -3934,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)),
@@ -3964,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));
@@ -4160,7 +4236,7 @@ void usymtab_checkFinalScope (bool isReturn)
                                        {
                                          ss (sr);
                                        }
-
+                                     
                                      DPRINTF (("Storage: %s", sRef_unparseFull (sr)));
                                    }  
                                }
@@ -4192,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;
@@ -4266,6 +4342,10 @@ usymtab_quietExitScope (fileloc loc)
   usymtab_freeLevel (utab);
 
   utab = t;
+
+# ifdef DEBUGSPLINT
+  usymtab_checkAllValid ();
+# endif
 }
 
 /*
@@ -4312,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
   */
@@ -4363,7 +4445,7 @@ void usymtab_exitScope (exprNode expr)
   ** NOTE: note for exiting paramsScope, since checkReturn should be
   ** called first.
   */
-
+  
   if (!mustReturn && (usymtab_lexicalLevel () > functionScope))
     {
       /*
@@ -4382,7 +4464,6 @@ void usymtab_exitScope (exprNode expr)
       uentryList params = context_getParams ();
       globSet    globs = context_getUsedGlobs ();
 
-                  
       uentryList_elements (params, ue)
        {
          uentry_fixupSref (ue);
@@ -4390,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;
@@ -4410,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;
     }
   
@@ -4427,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@*/
 
 /*
@@ -4444,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 ()))
            {
@@ -4881,6 +4968,7 @@ usymtab_lookupQuietAux (usymtab s, cstring k, bool noalt)
        }
       else
        {
+         llassert (s != NULL); /*@i523 should not need this? */
          s = s->env;
        }
     }
@@ -4943,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;
 }
 
@@ -4951,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;
 }
 
@@ -4963,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;
 }
 
@@ -5362,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))
        {
          /*
@@ -5405,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));
 }
 
@@ -5581,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))
@@ -5600,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@*/
 {
@@ -5614,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;
             
@@ -5632,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;
@@ -5669,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)
     {
@@ -5680,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);
@@ -5688,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);
            }
@@ -5708,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;
 }
@@ -5729,7 +5831,7 @@ usymtab_printAll (void)
 
 static void
 usymtab_printAllAux (usymtab s)
-   /*@modifies g_msgstream@*/
+   /*@modifies g_warningstream@*/
 {
   int i;
   int depth = 0;
@@ -5827,6 +5929,7 @@ usymtab_printComplete ()
   mstring_free (ind);
 }
 
+# ifdef S_SPLINT_S
 static /*@only@*/ cstring /*@unused@*/ 
 usymtab_unparseLocalAux (/*@notnull@*/ usymtab s)
 {
@@ -5869,6 +5972,7 @@ usymtab_unparseLocalList (/*@notnull@*/ usymtab s)
 
   return (c);
 }
+# endif
 
 void
 usymtab_printLocal (void)
@@ -5903,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;
@@ -5980,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)))
@@ -6006,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);
@@ -6032,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)))
@@ -6064,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);
 
@@ -6108,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)))
@@ -6121,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,
@@ -6147,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);
@@ -6184,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);
@@ -6239,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
+
+
+
+
+
+
This page took 0.09496 seconds and 4 git commands to generate.