]> andersk Git - splint.git/blobdiff - src/uentry.c
Fixed bug which would cause splint to crash if it was started with the -i flags and...
[splint.git] / src / uentry.c
index 675df280ae3f062e8d51daeffb653fcef39bbb9c..2624510c9d2c4d3989dfbfdf5f97d841eae0e93d 100644 (file)
@@ -43,7 +43,7 @@ static bool uentry_isReallySpecified (uentry p_e) /*@*/ ;
 static void uentry_checkIterArgs (uentry p_ue);
 static cstring uentry_dumpAux (uentry p_v, bool p_isParam);
 
-static void uentry_showWhereLastKind (uentry p_spec) /*@modifies g_msgstream@*/ ; 
+static void uentry_showWhereLastKind (uentry p_spec) /*@modifies g_warningstream@*/ ; 
 
 static void uentry_combineModifies (uentry p_ue, /*@owned@*/ sRefSet p_sr) 
      /*@modifies p_ue@*/ ;
@@ -66,10 +66,8 @@ static void checkVarConformance (/*@notnull@*/ uentry p_old,
                                 bool p_mustConform, bool p_completeConform) 
    /*@modifies p_old, p_unew@*/;
 
-# ifndef NOLCL
 static void uentry_setHasMods (uentry p_ue) /*@modifies p_ue@*/;
 static void uentry_setHasGlobs (uentry p_ue) /*@modifies p_ue@*/;
-# endif
 
 static void uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry p_e);
 
@@ -86,7 +84,7 @@ static void
   paramTypeError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_oldCurrent,
                  ctype p_oldType, /*@notnull@*/ uentry p_unew,
                  /*@notnull@*/ uentry p_newCurrent, 
-                 ctype p_newType, int p_paramno) /*@modifies g_msgstream@*/ ;
+                 ctype p_newType, int p_paramno) /*@modifies g_warningstream@*/ ;
 
 static /*@only@*/ /*@notnull@*/ uentry 
   uentry_makeVariableAux (cstring p_n, ctype p_t, /*@keep@*/ fileloc p_f,
@@ -687,7 +685,6 @@ static void uentry_setConstantValue (uentry ue, /*@only@*/ multiVal val)
   return ue;
 }
 
-# ifndef NOLCL
 /*@notnull@*/ uentry uentry_makeSpecEnumConstant (cstring n, ctype t, fileloc loc)
 {
   uentry ue = uentry_makeConstant (n, t, loc);
@@ -695,19 +692,21 @@ static void uentry_setConstantValue (uentry ue, /*@only@*/ multiVal val)
   ue->ukind = KENUMCONST;
   return ue;
 }
-# endif
 
 /*@notnull@*/ uentry uentry_makeVariableLoc (cstring n, ctype t)
 {
   return uentry_makeVariable (n, t, setLocation (), FALSE);
 }
 
-# ifndef NOLCL
+bool uentry_isUnnamedVariable (uentry ue)
+{
+  return uentry_isVariable (ue) && cstring_isUndefined (ue->uname);
+}
+
 /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
 {
   return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
 }
-# endif
 
 /*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
 {
@@ -741,9 +740,12 @@ void uentry_checkParams (uentry ue)
       if (uentry_isRealFunction (ue))
        {
          uentryList params = uentry_getParams (ue);
+         int paramno = 0;
 
          uentryList_elements (params, current)
            {
+             paramno++;
+
              if (uentry_isValid (current))
                {
                  ctype ct = current->utype;                  
@@ -757,24 +759,48 @@ void uentry_checkParams (uentry ue)
                        }
                      else
                        {
-                         voptgenerror 
-                           (FLG_FIXEDFORMALARRAY,
-                            message ("Function parameter %q declared as "
-                                     "manifest array (size constant is meaningless)",
-                                     uentry_getName (current)),
-                            uentry_whereDeclared (current));
+                         if (uentry_hasName (current))
+                           {
+                             voptgenerror 
+                               (FLG_FIXEDFORMALARRAY,
+                                message ("Function parameter %q declared as "
+                                         "manifest array (size constant is meaningless)",
+                                         uentry_getName (current)),
+                                uentry_whereDeclared (current));
+                           }
+                         else
+                           {
+                             voptgenerror 
+                               (FLG_FIXEDFORMALARRAY,
+                                message ("Unnamed function parameter %d declared as "
+                                         "manifest array (size constant is meaningless)",
+                                         paramno),
+                                uentry_whereDeclared (current));
+                           }
                        }
                    }
                  else 
                    {
                      if (ctype_isArray (ct))
                        {
-                         voptgenerror 
-                           (FLG_FORMALARRAY,
-                            message ("Function parameter %q declared as "
-                                     "array (treated as pointer)", 
-                                     uentry_getName (current)),
-                            uentry_whereDeclared (current));
+                         if (uentry_hasName (current))
+                           {
+                             voptgenerror 
+                               (FLG_FORMALARRAY,
+                                message ("Function parameter %q declared as "
+                                         "array (treated as pointer)", 
+                                         uentry_getName (current)),
+                                uentry_whereDeclared (current));
+                           }
+                         else
+                           {
+                             voptgenerror 
+                               (FLG_FORMALARRAY,
+                                message ("Unnamed function parameter %d declared as "
+                                         "array (treated as pointer)", 
+                                         paramno),
+                                uentry_whereDeclared (current));
+                           }
                        }
                    }
 
@@ -1306,7 +1332,6 @@ uentry_makeVariableParamAux (cstring n, ctype t, /*@dependent@*/ sRef s,
   return (e);
 }
 
-# ifndef NOLCL
 void
 uentry_setRefCounted (uentry e)
 {
@@ -1316,7 +1341,6 @@ uentry_setRefCounted (uentry e)
       sRef_storeState (e->sref);
     }
 }
-# endif
 
 void
 uentry_setStatic (uentry c)
@@ -2502,6 +2526,7 @@ uentry_reflectQualifiers (uentry ue, qualList q)
       else if (qual_isUnused (qel))
        {
          uentry_setUsed (ue, fileloc_undefined);         
+         DPRINTF (("Used: %s", uentry_unparseFull (ue)));
        }
       else if (qual_isExternal (qel))
        {
@@ -3087,7 +3112,7 @@ uentry_isSpecialFunction (uentry ue)
     {
       fileloc loc = setLocation ();
       uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
-      
+
       uentry_reflectQualifiers (ue, idDecl_getQuals (t));
 
       if (!uentry_isExtern (ue))
@@ -3099,12 +3124,10 @@ uentry_isSpecialFunction (uentry ue)
     }
 }
 
-# ifndef NOLCL
 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t, fileloc loc)
 {
   return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), fileloc_copy (loc), SS_DEFINED));
 }
-# endif
 
 /*
 ** constants
@@ -3152,17 +3175,20 @@ uentry uentry_makeConstantAux (cstring n, ctype t,
 
 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
 {
-  return (uentry_makeConstantAux (n, t, f, FALSE, FALSE, multiVal_unknown ()));
+  uentry ue = uentry_makeConstantAux (n, t, f, FALSE, FALSE, multiVal_unknown ());
+  return ue;
 }
 
 /*@notnull@*/ uentry uentry_makeConstantValue (cstring n, ctype t, fileloc f, bool priv, multiVal val)
 {
-  return (uentry_makeConstantAux (n, t, f, priv, FALSE, val));
+  uentry ue = uentry_makeConstantAux (n, t, f, priv, FALSE, val);
+  return ue;
 }
 
 /*@notnull@*/ uentry uentry_makeMacroConstant (cstring n, ctype t, fileloc f)
 {
-  return (uentry_makeConstantAux (n, t, f, FALSE, TRUE, multiVal_unknown ()));
+  uentry ue = uentry_makeConstantAux (n, t, f, FALSE, TRUE, multiVal_unknown ());
+  return ue;
 }
 
 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
@@ -3585,36 +3611,24 @@ void uentry_makeConstantFunction (uentry ue)
 }
 
 void
-uentry_setGlobals (uentry ue, /*@owned@*/ globSet globs)
+uentry_setGlobals (uentry ue, /*@only@*/ globSet globs)
 {
   llassert (uentry_isValid (ue));
 
+  globSet_markImmutable (globs);
+
   if (uentry_isIter (ue))
     {
-      llassert (globSet_isUndefined (ue->info->iter->globs));
-      ue->info->iter->globs = globs;
+      ue->info->iter->globs = globSet_unionFree (ue->info->iter->globs, globs);
     }
   else
     {
       uentry_convertVarFunction (ue);
-      
       llassert (uentry_isFunction (ue));
-      llassert (!ue->info->fcn->hasGlobs 
-               && globSet_isUndefined (ue->info->fcn->globs));
-      
-      ue->info->fcn->hasGlobs = TRUE;
-      globSet_markImmutable (globs);
-      /*@-mustfree@*/ ue->info->fcn->globs = globs;
-      /*@=mustfree@*/
-    }
 
-  /*@i23*/
-  /* ???  - evans 2001-09-09 not sure what's going on here...?
-  if (globSet_hasStatic (globs))
-    {
-      context_recordFileGlobals (globs);
+      ue->info->fcn->hasGlobs = TRUE;
+      ue->info->fcn->globs = globSet_unionFree (ue->info->fcn->globs, globs);
     }
-  */
 
   if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
     {
@@ -3662,7 +3676,6 @@ void uentry_addAccessType (uentry ue, typeId tid)
                                  FALSE, FALSE));
 }
 
-# ifndef NOLCL
 /*@notnull@*/ uentry 
   uentry_makePrivFunction2 (cstring n, ctype t, 
                            typeIdSet access, 
@@ -3691,7 +3704,6 @@ void uentry_addAccessType (uentry ue, typeId tid)
   reflectImplicitFunctionQualifiers (ue, TRUE);
   return (ue);
 }
-# endif
 
 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
 {
@@ -3730,7 +3742,6 @@ bool uentry_isForward (uentry e)
   return FALSE;
 }
 
-# ifndef NOLCL
 /*@notnull@*/ uentry 
 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
 {
@@ -3751,7 +3762,6 @@ uentry_makeUnspecFunction (cstring n, ctype t,
   reflectImplicitFunctionQualifiers (ue, TRUE);
   return ue;
 }
-# endif
 
 /*
 ** datatypes
@@ -3978,7 +3988,6 @@ uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
   return (ret);
 }
 
-# ifndef NOLCL
 uentry
 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
 {
@@ -3988,7 +3997,6 @@ uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
   cstring_free (ename);
   return ret;
 }
-# endif
 
 uentry
 uentry_makeUnionTagLoc (cstring n, ctype t)
@@ -4448,7 +4456,6 @@ uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abstract,
   return (e);
 }
 
-# ifndef NOLCL
 static void uentry_setHasGlobs (uentry ue)
 {
   llassert (uentry_isFunction (ue));
@@ -4462,7 +4469,6 @@ static void uentry_setHasMods (uentry ue)
 
   ue->info->fcn->hasMods = TRUE;
 }
-# endif
 
 bool uentry_hasGlobs (uentry ue)
 {
@@ -5373,8 +5379,9 @@ uentry_unparseFull (uentry v)
        }
       else if (uentry_isConstant (v))
        {
-         res = message ("%q = %q",
-                        res, multiVal_unparse (uentry_getConstantValue (v)));
+         res = message ("%q = %q / %q",
+                        res, multiVal_unparse (uentry_getConstantValue (v)),
+                        sRef_unparseFull (v->sref));
        }
       else
        {
@@ -5719,27 +5726,35 @@ uentry_getGlobs (uentry l)
       return globSet_undefined;
     }
 
-  if (l->ukind != KFCN)
+  if (uentry_isFunction (l))
+    {
+      return l->info->fcn->globs;
+    }
+  else if (uentry_isIter (l))
+    {
+      return l->info->iter->globs;
+    }
+  else if (uentry_isEndIter (l))
+    {
+      return globSet_undefined;
+    }
+  else
     {
-      if (l->ukind != KITER && l->ukind != KENDITER)
+      if (l->ukind == KVAR)
        {
-         if (l->ukind == KVAR)
-           {
-             llbug (message ("Bad call to uentry_getGlobs (var): %q (%s)", 
+         llcontbug (message ("Bad call to uentry_getGlobs (var): %q (%s)", 
                              uentry_unparse (l), 
                              ekind_unparse (l->ukind)));
-           }
-         else
-           {
-             llbug (message ("Bad call to uentry_getGlobs: %q (%s)", 
+       }
+      else
+       {
+         llcontbug (message ("Bad call to uentry_getGlobs: %q (%s)", 
                              uentry_unparse (l), 
                              ekind_unparse (l->ukind)));
-           }
        }
+
       return globSet_undefined;
     }
-
-  return l->info->fcn->globs;
 }
 
 /*@observer@*/ sRefSet
@@ -5753,7 +5768,22 @@ uentry_getMods (uentry l)
       return sRefSet_undefined; 
     }
 
-  return l->info->fcn->mods;
+  if (uentry_isFunction (l))
+    {
+      return l->info->fcn->mods;
+    }
+  else if (uentry_isIter (l))
+    {
+      return l->info->iter->mods;
+    }
+  else if (uentry_isEndIter (l))
+    {
+      return sRefSet_undefined;
+    }
+  else
+    {
+      BADBRANCH;
+    }
 }
 
 ekind
@@ -6774,7 +6804,7 @@ uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
 
   nuentries--;
   sfree (e);
-  }
+}
 
 extern void uentry_markOwned (/*@owned@*/ uentry u)
 {
@@ -6816,7 +6846,7 @@ KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
   llassert (uentry_isValid (old));
   llassert (uentry_isValid (unew));
 
-  if (uentry_isEitherConstant (unew)
+  if ((uentry_isEitherConstant (unew) || uentry_isDatatype (unew))
       && (fileloc_isPreproc (uentry_whereDeclared (old))
          || ctype_isUnknown (old->utype))
       && !uentry_isSpecified (old))
@@ -7288,9 +7318,10 @@ checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
       if (optgenerror 
          (FLG_MATCHFIELDS,
           message ("Enum %q declared with members { %q } but "
-                   "specified with members { %q }",
+                   "%s with members { %q }",
                    uentry_getName (old), 
                    enumNameList_unparse (enew),
+                   uentry_specOrDefName (old),
                    enumNameList_unparse (eold)),
           uentry_whereDeclared (unew)))
        {
@@ -9876,10 +9907,10 @@ static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
   unew->info = uinfo_copy (old->info, old->ukind);
 }
 
-
-uentry
-uentry_copy (uentry e)
+static uentry
+uentry_copyAux (uentry e, bool saveCopy)
 {
+  
   if (uentry_isValid (e))
     {
       uentry enew = uentry_alloc ();
@@ -9892,7 +9923,15 @@ uentry_copy (uentry e)
       enew->whereDefined = fileloc_copy (e->whereDefined);
       enew->whereDeclared = fileloc_copy (e->whereDeclared);
       
-      enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
+      if (saveCopy)
+       {
+         enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
+       }
+      else
+       {
+         enew->sref = sRef_copy (e->sref);
+       }
+      
       enew->used = e->used;
       enew->lset = FALSE;
       enew->isPrivate = e->isPrivate;
@@ -9915,6 +9954,18 @@ uentry_copy (uentry e)
     }
 }
 
+uentry
+uentry_copy (uentry e)
+{
+  return uentry_copyAux (e, TRUE);
+}
+
+uentry
+uentry_copyNoSave (uentry e)
+{
+  return uentry_copyAux (e, FALSE);
+}
+
 void
 uentry_setState (uentry res, uentry other)
 {
@@ -9966,8 +10017,8 @@ uentry_mergeUses (uentry res, uentry other)
 */
 
 static void
-  branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other, 
-                   bool flip, clause cl, fileloc loc)
+branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other, 
+                 bool flip, clause cl, fileloc loc)
 {
   if (optgenerror 
       (FLG_BRANCHSTATE,
@@ -9980,10 +10031,12 @@ static void
       if (sRef_isDead (res->sref))
        {
          sRef_showStateInfo (res->sref);
+         sRef_showStateInfo (other->sref);
        }
       else if (sRef_isKept (res->sref))
        {
          sRef_showAliasInfo (res->sref);
+         sRef_showAliasInfo (other->sref);
        }
       else /* dependent */
        {
@@ -10814,7 +10867,7 @@ bool uentry_isReturned (uentry u)
 }
 # endif
 
-/*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
+/*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args, fileloc loc)
 {
   llassert (uentry_isRealFunction (u));
 
@@ -10824,7 +10877,7 @@ bool uentry_isReturned (uentry u)
       sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
 
       DPRINTF (("Returned: %s", sRef_unparseFull (res)));
-      sRef_setAllocated (res, g_currentloc);
+      sRef_setAllocated (res, loc);
 
       DPRINTF (("ensures clause: %s / %s", uentry_unparse (u), 
                stateClauseList_unparse (clauses)));
@@ -10849,7 +10902,7 @@ bool uentry_isReturned (uentry u)
                      if (modf != NULL)
                        {
                          sRef sr = sRef_fixBase (el, res);
-                         modf (sr, g_currentloc);
+                         modf (sr, loc);
                        }
                    }
                  else
@@ -10889,19 +10942,25 @@ bool uentry_isReturned (uentry u)
                      
                      usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
 
+                     if (sRef_isNew (tcref))
+                       {
+                         /* tcref->kind = SK_OBJECT; */ /*!! Not new anymore */
+                       }
+
                      if (sRef_isDead (tcref))
                        {
-                         sRef_setDefined (tcref, g_currentloc);
-                         sRef_setOnly (tcref, g_currentloc);
+                         sRef_setDefined (tcref, loc);
+                         sRef_setOnly (tcref, loc);
                        }
                      
                      if (sRef_isRefCounted (tcref))
                        {
                          /* could be a new ref now (but only if its returned) */
-                         sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
+                         sRef_setAliasKindComplete (tcref, AK_ERROR, loc);
                        }
                      
                      sRef_makeSafe (tcref);
+                     DPRINTF (("Returns tcref / %s", sRef_unparseFull (tcref)));
                      prefs = sRefSet_insert (prefs, tcref);
                    }
                }
@@ -10926,7 +10985,7 @@ bool uentry_isReturned (uentry u)
          
          if (nstate_isKnown (n))
            {
-             sRef_setNullState (res, n, g_currentloc);
+             sRef_setNullState (res, n, loc);
            }
        }
       else
@@ -10943,7 +11002,7 @@ bool uentry_isReturned (uentry u)
          
          if (sRef_isRefCounted (res))
            {
-             sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
+             sRef_setAliasKind (res, AK_NEWREF, loc);
            }
        }
       
@@ -10954,7 +11013,7 @@ bool uentry_isReturned (uentry u)
          
          if (ctype_isAbstract (ct))
            {
-             sRef_setNotNull (res, g_currentloc);
+             sRef_setNotNull (res, loc);
            }
          else
            {
@@ -10964,18 +11023,18 @@ bool uentry_isReturned (uentry u)
                }
              else
                {
-                 sRef_setNotNull (res, g_currentloc);
+                 sRef_setNotNull (res, loc);
                }
            }
        }
       
       if (sRef_isRefCounted (res))
        {
-         sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
+         sRef_setAliasKind (res, AK_NEWREF, loc);
        }
       else if (sRef_isKillRef (res))
        {
-         sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
+         sRef_setAliasKind (res, AK_REFCOUNTED, loc);
        }
       else
        {
@@ -10988,11 +11047,18 @@ bool uentry_isReturned (uentry u)
        {
          sRef_setAliasKind (res, 
                             alkind_fixImplicit (ak),
-                            g_currentloc);
+                            loc);
        }
       
       sRefSet_free (prefs);
-      
+
+      /*
+      if (sRef_isOnly (res))
+       {
+         sRef_setFresh (res, loc);
+       }
+      */
+
       DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
       return res;
     }
@@ -11415,3 +11481,19 @@ metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
   llassert (uentry_isValid (e) && uentry_isFunction (e));
   return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);
 }
+
+# ifdef DEBUGSPLINT
+
+/*
+** For debugging only
+*/
+
+void uentry_checkValid (uentry ue)
+{
+  if (uentry_isValid (ue))
+    {
+      sRef_checkCompletelyReasonable (ue->sref);
+    }
+}
+
+# endif
This page took 0.326731 seconds and 4 git commands to generate.