]> andersk Git - splint.git/commitdiff
Fixed problem with global struct assignments.
authorevans1629 <evans1629>
Thu, 10 Jul 2003 20:33:24 +0000 (20:33 +0000)
committerevans1629 <evans1629>
Thu, 10 Jul 2003 20:33:24 +0000 (20:33 +0000)
src/constraintExpr.c
src/cpplib.c
src/exprNode.c
src/flags.def
src/transferChecks.c
test/db1/Makefile

index e0ff371cea48520ac7d7b846f93b7bbf12b305d7..fc0f2214d5f0cb14ff9e0f81d526b41e8268a0ba 100644 (file)
@@ -1955,8 +1955,7 @@ doFixResultTerm (/*@only@*/ constraintExpr e, /*@exposed@*/ exprNode fcnCall)
 /*to be used for structure checking */
 
 / *@only@* / static constraintExpr
-doSRefFixInvarConstraintTerm (/ *@only@* / constraintExpr e,
- sRef s, ctype ct)
+doSRefFixInvarConstraintTerm (/ *@only@* / constraintExpr e, sRef s, ctype ct)
 {
   constraintTerm t;
 
@@ -2457,7 +2456,8 @@ static ctype constraintExpr_getOrigType (constraintExpr e)
 
 /*drl added these around 10/18/001*/
 
-static /*@only@*/ constraintExpr constraintExpr_div (/*@only@*/ constraintExpr e, ctype tfrom, ctype tto, fileloc loc)
+static /*@only@*/ constraintExpr 
+constraintExpr_div (/*@only@*/ constraintExpr e, ctype tfrom, ctype tto, fileloc loc)
 {
   int sizefrom = ctype_getSize (tfrom);
   int sizeto = ctype_getSize (tto);
@@ -2477,6 +2477,7 @@ static /*@only@*/ constraintExpr constraintExpr_div (/*@only@*/ constraintExpr e
 
   if (sizeto == sizefrom) 
     {
+      DPRINTF (("Sizes match: %d / %d", sizeto, sizefrom));
       ; /* Sizes match, a-ok */
     }
   else
@@ -2490,6 +2491,7 @@ static /*@only@*/ constraintExpr constraintExpr_div (/*@only@*/ constraintExpr e
       llassert (e != NULL);
       llassert (e->kind == term);
       ct = constraintExprData_termGetTerm (e->data);
+      DPRINTF (("constraint: %s / %s", constraintExpr_unparse (e), constraintTerm_unparse (ct)));
       llassert (constraintTerm_canGetValue (ct));
       val = constraintTerm_getValue (ct);
 
@@ -2520,7 +2522,8 @@ static /*@only@*/ constraintExpr constraintExpr_div (/*@only@*/ constraintExpr e
 
 
 /*@access exprNode@*/ 
-static /*@only@*/ constraintExpr constraintTerm_simpleDivTypeExprNode (/*@only@*/ constraintExpr e, ctype tfrom, ctype tto, fileloc loc)
+static /*@only@*/ constraintExpr 
+constraintTerm_simpleDivTypeExprNode (/*@only@*/ constraintExpr e, ctype tfrom, ctype tto, fileloc loc)
 {
   exprData data;
   exprNode t1, t2, expr;
@@ -2624,6 +2627,10 @@ static /*@only@*/ constraintExpr constraintTerm_simpleDivTypeExprNode (/*@only@*
              /* empty */
            }
        }
+      else 
+       {
+         DPRINTF (("Not a mult: %s", constraintExpr_unparse (e)));
+       }
     }
 
   return (constraintExpr_div (e, tfrom, tto, loc));
index fbbf3ad09cda75d9fda403d031fd49520e7e2b58..100290d1ea40c176cea3fdff609fe0fb1adbea16 100644 (file)
@@ -963,6 +963,9 @@ cppOptions_init (cppOptions *opts)
   opts->warn_comments = 0;
   opts->warnings_are_errors = 0;
 
+  /* Added 2003-07-10: */
+  opts->traditional = FALSE;
+  opts->c89 = TRUE;
   initialize_char_syntax (opts);
 }
 
@@ -3726,18 +3729,11 @@ initialize_builtins (cppReader *pfile)
   cpplib_installBuiltin ("__REGISTER_PREFIX__", ctype_string, -1, T_REGISTER_PREFIX_TYPE, 0, NULL, -1);
   cpplib_installBuiltin ("__TIME__", ctype_string, -1, T_TIME, 0, NULL, -1);
 
-  /*
-  ** No, don't define __STDC__
-  **
-
   if (!cppReader_isTraditional (pfile))
     {
       cpplib_installBuiltin ("__STDC__", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
     }
 
-  **
-  */
-
 # ifdef WIN32
     cpplib_installBuiltin ("_WIN32", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
 # endif
index 62b44f8b35e815adfa9f26800c499059d84eaf8b..7af8f10720673667cff5194eda0aaf1dec27b751 100644 (file)
@@ -10679,8 +10679,20 @@ static ctype
          DPRINTF (("No error: [%s] %s / [%s]  %s",
                    exprNode_unparse (e1), ctype_unparse (tr1),
                    exprNode_unparse (e2), ctype_unparse (tr2)));
+         
+         /*
+         ** evans 2003-06-15: changed this so if either type is a literal,
+         **    the other type is used.
+         **    (Need to look at the ISO C99 rules on this...)
+         */
 
-         ret = ctype_biggerType (tr1, tr2);
+         if (exprNode_isNumLiteral (e1)) {
+           ret = tr2;
+         } else if (exprNode_isNumLiteral (e2)) {
+           ret = tr1;
+         } else {
+           ret = ctype_biggerType (tr1, tr2);
+         }
        }
       else
        {
index fbce747f257fb0273568ed21ead25688471073fa..e210f93ac3000b26b4a68d6ea9afe5f0a7d683f1 100644 (file)
@@ -1641,7 +1641,7 @@ static flaglist flags =
     "casebreak",
     FLG_CASEBREAK,
     "non-empty case in a switch without preceding break",
-    "Execution falls through from the previous case.", 0, 0
+    "Execution falls through from the previous case (use /*@fallthrough@*/ to mark fallthrough cases).", 0, 0
   },
   {
     FK_CONTROL, FK_NONE, modeFlag,
index fe12682be7a5c64cbce70f74842edde0cffc77e1..0f27d78fced9cf3dc4f2ab6fab29970099d84cbb 100644 (file)
@@ -2346,7 +2346,7 @@ static void checkStructTransfer (exprNode lhs, sRef slhs, exprNode rhs, sRef srh
   if (ctype_isSU (st) && ctype_isRealSU (sRef_getType (slhs))
       && ctype_match (sRef_getType (slhs), st))
     {
-      if (tt == TT_DOASSIGN && sRef_isStateDefined (srhs))
+      if ((tt == TT_DOASSIGN || tt == TT_FIELDASSIGN) && sRef_isStateDefined (srhs))
        {
          sRef_setDefinedComplete (slhs, loc);
        }
@@ -2362,47 +2362,52 @@ static void checkStructTransfer (exprNode lhs, sRef slhs, exprNode rhs, sRef srh
          if (sRef_isLocalVar (slhs)
              && sRef_isFileOrGlobalScope (sRef_getRootBase (srhs)))
            {
+             DPRINTF (("Global scope!"));
              sRef_setDependent (slhs, exprNode_loc (lhs));
            }
-         else
-           {
-             if (ctype_isUnion (st))
-               {
-                 sRef_setDefState (slhs, sRef_getDefState (srhs), 
-                                   exprNode_loc (lhs));
+       }
 
-                 sRefSet_realElements (sRef_derivedFields (srhs), sr)
-                   {
-                     if (sRef_isField (sr))
-                       {
-                         cstring fieldname = sRef_getField (sr);
-                         sRef lfld = sRef_makeField (slhs, fieldname);
+      /*
+      ** evans 2003-07-10: should always copy the fields!
+      */
 
-                         (void) checkTransfer (rhs, sr, lhs, lfld, 
-                                               exprNode_undefined,
-                                               exprNode_loc (lhs), tt);
-                       }
-                   } end_sRefSet_realElements ;
-               }
-             else
+      if (ctype_isUnion (st))
+       {
+         sRef_setDefState (slhs, sRef_getDefState (srhs), 
+                           exprNode_loc (lhs));
+         
+         sRefSet_realElements (sRef_derivedFields (srhs), sr)
+           {
+             if (sRef_isField (sr))
                {
-                 uentryList fields = ctype_getFields (st);
+                 cstring fieldname = sRef_getField (sr);
+                 sRef lfld = sRef_makeField (slhs, fieldname);
                  
-                 uentryList_elements (fields, field)
-                   {
-                     sRef rfld = sRef_makeField (srhs, uentry_rawName (field));
-                     sRef lfld = sRef_makeField (slhs, uentry_rawName (field));
-                     (void) checkTransfer (rhs, rfld, lhs, lfld, 
-                                           exprNode_undefined,
-                                           exprNode_loc (lhs), tt);
-                   } end_uentryList_elements ;
-               }
-
-             if (sRef_isOnly (srhs))
-               {
-                 sRef_setKeptComplete (srhs, loc);
+                 (void) checkTransfer (rhs, sr, lhs, lfld, 
+                                       exprNode_undefined,
+                                       exprNode_loc (lhs), tt);
                }
-           }
+           } end_sRefSet_realElements ;
+       }
+      else
+       {
+         uentryList fields = ctype_getFields (st);
+         
+         uentryList_elements (fields, field)
+           {
+             sRef rfld = sRef_makeField (srhs, uentry_rawName (field));
+             sRef lfld = sRef_makeField (slhs, uentry_rawName (field));
+             DPRINTF (("Transfer field: %s := %s", 
+                       sRef_unparse (lfld), sRef_unparse (rfld)));
+             (void) checkTransfer (rhs, rfld, lhs, lfld, 
+                                   exprNode_undefined,
+                                   exprNode_loc (lhs), tt);
+           } end_uentryList_elements ;
+       }
+      
+      if (sRef_isOnly (srhs))
+       {
+         sRef_setKeptComplete (srhs, loc);
        }
     }
 }
@@ -2440,6 +2445,8 @@ transferChecks_assign (exprNode lhs, exprNode rhs)
 
   if (ctype_isRealSU (sRef_getType (srhs)))
     {
+      DPRINTF (("Check struct transfer: %s := %s", exprNode_unparse (lhs),
+               exprNode_unparse (rhs)));
       checkStructTransfer (lhs, slhs, rhs, srhs, exprNode_loc (lhs), TT_FIELDASSIGN);
     }
   else
index 8d5274c437290dcb7a6acbde47f6f6f93dc5d3ce..050fc91e2d95cdfd5a1eacac5fdb7a2dc0b0261b 100644 (file)
@@ -29,7 +29,7 @@ test:
 
 check: $(LCSFILES)
        -$(SPLINT) -showcol -weak $(MODULES) -expect 19
-       -$(SPLINT) -showcol +strict -modfilesystem +showsummary $(MODULES) -expect 338
+       -$(SPLINT) -showcol +strict -bounds -modfilesystem +showsummary $(MODULES) -expect 338
 
 # evans 2002-07-09: 5 bufferoverflowhigh warnings for using sprintf
 
This page took 0.06556 seconds and 5 git commands to generate.