From 8ea5df88d4d589854cfd2cf734e203ce58da744d Mon Sep 17 00:00:00 2001 From: evans1629 Date: Thu, 10 Jul 2003 20:33:24 +0000 Subject: [PATCH] Fixed problem with global struct assignments. --- src/constraintExpr.c | 15 ++++++--- src/cpplib.c | 10 ++---- src/exprNode.c | 14 +++++++- src/flags.def | 2 +- src/transferChecks.c | 77 ++++++++++++++++++++++++-------------------- test/db1/Makefile | 2 +- 6 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/constraintExpr.c b/src/constraintExpr.c index e0ff371..fc0f221 100644 --- a/src/constraintExpr.c +++ b/src/constraintExpr.c @@ -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)); diff --git a/src/cpplib.c b/src/cpplib.c index fbbf3ad..100290d 100644 --- a/src/cpplib.c +++ b/src/cpplib.c @@ -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 diff --git a/src/exprNode.c b/src/exprNode.c index 62b44f8..7af8f10 100644 --- a/src/exprNode.c +++ b/src/exprNode.c @@ -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 { diff --git a/src/flags.def b/src/flags.def index fbce747..e210f93 100644 --- a/src/flags.def +++ b/src/flags.def @@ -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, diff --git a/src/transferChecks.c b/src/transferChecks.c index fe12682..0f27d78 100644 --- a/src/transferChecks.c +++ b/src/transferChecks.c @@ -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 diff --git a/test/db1/Makefile b/test/db1/Makefile index 8d5274c..050fc91 100644 --- a/test/db1/Makefile +++ b/test/db1/Makefile @@ -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 -- 2.45.0