]> andersk Git - splint.git/blobdiff - src/clabstract.c
Added checking for union initializers.
[splint.git] / src / clabstract.c
index 88b17d20d0f5248d27d6f4049dcd841492b5b276..e17b25f7b3b83e3f8c7ecf635f5a4fbd2420ef10 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** LCLint - annotation-assisted static program checker
+** Splint - annotation-assisted static program checker
 ** Copyright (C) 1994-2001 University of Virginia,
 **         Massachusetts Institute of Technology
 **
@@ -19,7 +19,7 @@
 **
 ** 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 more information: http://www.splint.org
 */
 /*
 ** clabstract.c
 ** right values are available in the right place.
 */
 
-/*drl */
-static /*@only@*/   constraintList implicitFcnConstraints = NULL;
-
-
-//static  constraintList fcnPreConditions = NULL;
+/*drl*/
+static /*@only@*/ constraintList implicitFcnConstraints = NULL;
 
 static void clabstract_prepareFunction (uentry p_e) /*@modifies p_e@*/ ;
 static bool fcnNoGlobals = FALSE;
@@ -531,7 +528,7 @@ void  setImplictfcnConstraints (void)
        chagned this is MaxSet(s) == 0 to MaxSet(s) >= 0 */
       
       c = constraint_makeSRefWriteSafeInt (s, 0);
-       // constraint_makeSRefSetBufferSize (s, 0);
+      /* constraint_makeSRefSetBufferSize (s, 0); */
       implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c);
     }
   end_uentryList_elements;
@@ -631,6 +628,7 @@ static /*@exposed@*/ uentry clabstract_globalDeclareFunction (idDecl tid)
   ue = usymtab_supGlobalEntryReturn (ue);
   DPRINTF (("After supercede function: %s", uentry_unparseFull (ue)));
 
+  DPRINTF (("Enter function: %s", uentry_unparseFull (ue)));
   context_enterFunction (ue);
   enterFunctionParams (uentry_getParams (ue));
 
@@ -664,6 +662,9 @@ static /*@only@*/ uentry globalDeclareOldStyleFunction (idDecl tid)
   uentry_setDefined (ue, g_currentloc);
   uentry_checkParams (ue);
   resetStorageClass ();
+
+  /* context_enterOldStyleScope (); */
+
   return (ue);
 }
 
@@ -674,6 +675,13 @@ static void oldStyleDeclareFunction (/*@only@*/ uentry e)
 
   llassert (ctype_isFunction (rt));
 
+  if (uentry_hasStateClauseList (e) 
+      || uentry_hasConditions (e))
+    {
+      llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
+                            fileloc_unparse (g_currentloc), uentry_unparse (e)));
+    }
+
   e = usymtab_supGlobalEntryReturn (e);
 
   context_enterFunction (e);
@@ -682,6 +690,28 @@ static void oldStyleDeclareFunction (/*@only@*/ uentry e)
   resetStorageClass ();
 }
 
+static void oldStyleCompleteFunction (/*@only@*/ uentry e)
+{
+  uentryList params = saveParamList;
+  ctype rt = uentry_getType (e);
+
+  llassert (ctype_isFunction (rt));
+
+  if (uentry_hasStateClauseList (e) 
+      || uentry_hasConditions (e))
+    {
+      llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
+                            fileloc_unparse (g_currentloc), uentry_unparse (e)));
+    }
+
+  e = usymtab_supGlobalEntryReturn (e);
+
+  context_completeOldStyleFunction (e);
+  enterFunctionParams (params);
+  saveParamList = uentryList_undefined;
+  resetStorageClass ();
+}
+
 void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
 {
   uentry ue;
@@ -692,6 +722,7 @@ void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
     {
       ue = globalDeclareOldStyleFunction (tid);
       saveFunction = ue;
+      DPRINTF (("Set save function: %s", uentry_unparseFull (ue)));
     }
   else
     {
@@ -881,7 +912,7 @@ checkTypeDecl (uentry e, ctype rep)
       uentry le  = usymtab_getTypeEntry (llm);
 
       uentry_setDeclared (e, g_currentloc); 
-      uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le)));
+      uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le), stateInfo_currentLoc ()));
 
       DPRINTF (("Here we are: %s / %s",
                n, context_getBoolName ()));
@@ -1137,7 +1168,7 @@ setGenericParamList (/*@dependent@*/ uentryList pm)
 }
 
 void
-setProcessingTypedef (/*@only@*/ qtype q)
+setProcessingTypedef (qtype q)
 {
   ProcessingTypedef = TRUE;
 
@@ -1153,7 +1184,7 @@ unsetProcessingVars ()
 }
 
 void 
-doneParams ()
+oldStyleDoneParams ()
 {  
   if (ProcessingParams)
     {
@@ -1170,7 +1201,7 @@ doneParams ()
          uentry_setType (saveFunction, ct2);
          ProcessingParams = FALSE;
 
-         oldStyleDeclareFunction (saveFunction);
+         oldStyleCompleteFunction (saveFunction);
          saveFunction = uentry_undefined;
          resetGlobals ();
        }
@@ -1198,6 +1229,8 @@ checkDoneParams ()
       ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
       ctype ct2;
 
+      DPRINTF (("save function: %s", uentry_unparseFull (saveFunction)));
+
       uentryList_elements (saveParamList, current)
        {
          uentry_setType (current, ctype_int); /* all params are ints */
@@ -1213,6 +1246,41 @@ checkDoneParams ()
     }
 }
 
+void clabstract_declareType (/*@only@*/ exprNodeList decls, /*@only@*/ warnClause warn)
+{
+  llassert (ProcessingTypedef);
+
+  if (warnClause_isDefined (warn))
+    {
+      exprNodeList_elements (decls, el)
+       {
+         uentry ue = exprNode_getUentry (el);
+         cstring uname = uentry_getName (ue);
+
+         DPRINTF (("Entry: %s", exprNode_unparse (el)));
+
+         /*
+         ** Need to lookup again to make sure we have the right one...
+         */
+
+         ue = usymtab_lookupExposeGlob (uname);
+
+         llassert (uentry_isValid (ue));
+         llassert (uentry_isDatatype (ue));
+
+         DPRINTF (("Warning for %s: %s",
+                   uentry_unparse (ue), warnClause_unparse (warn)));
+
+         uentry_addWarning (ue, warnClause_copy (warn));
+         cstring_free (uname);
+       } end_exprNodeList_elements;
+    }
+
+  warnClause_free (warn);
+  exprNodeList_free (decls);
+  unsetProcessingTypedef ();
+}
+
 void
 unsetProcessingTypedef ()
 {
@@ -1222,13 +1290,14 @@ unsetProcessingTypedef ()
 void checkConstant (qtype t, idDecl id) 
 {
   uentry e;
-
+  
   id = idDecl_fixBase (id, t);
   e = uentry_makeIdConstant (id);
-
+  
   reflectStorageClass (e);
   resetStorageClass ();
 
+  DPRINTF (("Constant: %s", uentry_unparseFull (e)));
   usymtab_supGlobalEntry (e);
 }
 
@@ -1261,9 +1330,14 @@ void checkValueConstant (qtype t, idDecl id, exprNode e)
            {
              uentry_mergeConstantValue (ue, multiVal_copy (exprNode_getValue (e)));
            }
+         else
+           {
+             DPRINTF (("No value: %s", exprNode_unparse (e)));
+           }
        }
     }
 
+  DPRINTF (("Constant value: %s", uentry_unparseFull (ue)));
   usymtab_supGlobalEntry (ue);
 }
 
@@ -1279,7 +1353,7 @@ void processNamedDecl (idDecl t)
   t = idDecl_fixBase (t, processingType);
 
   DPRINTF (("Declare: %s", idDecl_unparse (t)));
-
+  
   if (ProcessingGlobals)
     {
       cstring id = idDecl_getName (t);
@@ -1325,9 +1399,11 @@ void processNamedDecl (idDecl t)
            {
              uentry cparam = uentryList_getN (saveParamList, paramno);
 
+             DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
              uentry_setType (cparam, idDecl_getCtype (t));
              uentry_reflectQualifiers (cparam, idDecl_getQuals (t));
              uentry_setDeclaredOnly (cparam, context_getSaveLocation ());
+             DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
            }
          else
            {
@@ -1715,10 +1791,12 @@ void setNewStyle ()              { flipNewStyle = TRUE; }
                cstring_makeLiteral ("Old style function declaration"),
                g_currentloc); 
 
+  DPRINTF (("Handle old style params: %s", uentryList_unparseFull (params)));
+
   uentryList_elements (params, current)
     {
       uentry_setParam (current);
-      uentry_setSref (current, sRef_makeParam (paramno, ctype_unknown));
+      uentry_setSref (current, sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (uentry_whereLast (current))));
       paramno++;
     } end_uentryList_elements;
 
@@ -1759,7 +1837,8 @@ doVaDcl ()
       
       if (i >= 0)
        {
-         e = uentry_makeVariableSrefParam (id, c, sRef_makeParam (i, c));
+         fileloc loc = context_getSaveLocation ();
+         e = uentry_makeVariableSrefParam (id, c, loc, sRef_makeParam (i, c, stateInfo_makeLoc (loc)));
        }
       else
        {
@@ -1939,15 +2018,15 @@ doVaDcl ()
                }
              else 
                {
-                 if (ctype_isAbstract (ct))
+                 if (ctype_isAbstract (rt))
                    {
                      voptgenerror 
                        (FLG_ABSTRACT,
                         message
-                        ("Modifies clause in header file arrow accesses abstract "
+                        ("Modifies clause arrow accesses inaccessible abstract "
                          "type %s (interface modifies clause should not depend "
                          "on or expose type representation): %q",
-                         ctype_unparse (ct),
+                         ctype_unparse (rt),
                          sRef_unparse (s)),
                         g_currentloc);
                    }
@@ -2046,6 +2125,7 @@ sRef checkbufferConstraintClausesId (uentry ue)
        }
     }
   
+  DPRINTF (("constrant id: %s", uentry_unparseFull (ue)));
   return sRef_saveCopy (uentry_getSref (ue)); /*@i523 why the saveCopy? */
 }
 
@@ -2139,7 +2219,7 @@ sRef fixStateClausesId (cstring s)
 
   if (cstring_equalLit (s, "result"))
     {
-      ret = sRef_makeResult ();
+      ret = sRef_makeResult (ctype_unknown);
     }
   else
     {
@@ -2246,11 +2326,3 @@ sRef clabstract_checkGlobal (exprNode e)
   exprNode_free (e);
   return sRef_copy (s);
 }
-
-
-
-
-
-
-
-
This page took 0.515909 seconds and 4 git commands to generate.