2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include <ctype.h> /* for isdigit */
29 # include "splintMacros.nf"
31 # include "cgrammar.h"
32 # include "cscanner.h"
33 # include "cscannerHelp.h"
34 # include "cgrammar_tokens.h"
36 # include "exprChecks.h"
37 # include "transferChecks.h"
38 # include "exprNodeSList.h"
40 static bool exprNode_sameStorage (exprNode p_e1, exprNode p_e2) /*@*/ ;
41 static bool exprNode_isEmptyStatement (exprNode p_e);
42 static /*@exposed@*/ exprNode exprNode_firstStatement (/*@returned@*/ exprNode p_e);
43 static bool exprNode_isFalseConstant (exprNode p_e) /*@*/ ;
44 static bool exprNode_isStatement (exprNode p_e);
45 static void checkGlobUse (uentry p_glob, bool p_isCall, /*@notnull@*/ exprNode p_e);
46 static void exprNode_addUse (exprNode p_e, /*@exposed@*/ sRef p_s);
47 static bool exprNode_matchArgType (ctype p_ct, exprNode p_e);
48 static exprNode exprNode_fakeCopy (exprNode p_e) /*@*/ ;
49 static exprNode exprNode_statementError (/*@only@*/ exprNode p_e, /*@only@*/ lltok p_t);
50 static bool exprNode_matchTypes (exprNode p_e1, exprNode p_e2);
51 static void checkUniqueParams (exprNode p_fcn,
52 /*@notnull@*/ exprNode p_current, exprNodeList p_args,
53 int p_paramno, uentry p_ucurrent);
54 static void updateAliases (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2);
55 static bool abstractOpError (ctype p_tr1, ctype p_tr2, lltok p_op,
56 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2,
57 fileloc p_loc1, fileloc p_loc2)
58 /*@modifies g_warningstream@*/ ;
59 static ctype checkNumerics (ctype p_tr1, ctype p_tr2, ctype p_te1, ctype p_te2,
60 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, lltok p_op);
61 static void doAssign (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, bool p_isInit);
62 static void checkSafeUse (exprNode p_e, /*@exposed@*/ sRef p_s);
63 static void reflectNullTest (/*@notnull@*/ exprNode p_e, bool p_isnull);
64 static void checkMacroParen (exprNode p_e);
65 static exprNodeSList exprNode_flatten (/*@dependent@*/ exprNode p_e);
66 static void exprNode_checkSetAny (exprNode p_e, /*@dependent@*/ cstring p_name);
67 static void exprNode_checkUse (exprNode p_e, /*@exposed@*/ sRef p_s, fileloc p_loc);
68 static void exprNode_mergeUSs (exprNode p_res, exprNode p_other);
69 static void exprNode_mergeCondUSs (exprNode p_res, exprNode p_other1, exprNode p_other2);
70 static /*@only@*/ /*@notnull@*/ exprNode exprNode_fromIdentifierAux (/*@observer@*/ uentry p_c);
71 static void checkAnyCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn,
72 /*@dependent@*/ cstring p_fname,
73 uentryList p_pn, exprNodeList p_args,
74 bool p_hasMods, sRefSet p_mods, bool p_isSpec,
76 static void checkOneArg (uentry p_ucurrent, /*@notnull@*/ exprNode p_current,
77 /*@dependent@*/ exprNode p_fcn, bool p_isSpec, int p_argno, int p_totargs);
79 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn, uentryList p_params, exprNodeList p_args);
81 static /*@only@*/ exprNode exprNode_effect (exprNode p_e)
82 /*@globals internalState@*/ ;
83 static /*@only@*/ cstring exprNode_doUnparse (exprNode p_e);
84 static /*@observer@*/ cstring exprNode_rootVarName (exprNode p_e);
85 static /*@exposed@*/ exprNode
86 exprNode_lastStatement (/*@returned@*/ exprNode p_e);
88 static /*@only@*/ exprNode s_mustExitNode = exprNode_undefined;
90 static int checkArgsReal (uentry p_fcn, /*@dependent@*/ exprNode p_f,
92 exprNodeList p_args, bool p_isIter, exprNode p_ret);
94 static bool inEffect = FALSE;
95 static int nowalloc = 0;
96 static int totalloc = 0;
97 static int maxalloc = 0;
99 static /*@only@*/ uentry regArg;
100 static /*@only@*/ uentry outArg;
101 static /*@only@*/ uentry outStringArg;
102 static /*@exposed@*/ sRef stdinRef;
103 static /*@exposed@*/ sRef stdoutRef;
104 static /*@only@*/ uentry csArg;
105 static /*@only@*/ uentry csOnlyArg;
106 static ctype cstringType;
107 static ctype ctypeType;
108 static ctype filelocType;
109 static bool initMod = FALSE;
111 /*@function void exprNode_swap (sef exprNode, sef exprNode)@*/
113 # define exprNode_swap(e1,e2) do { exprNode m_tmp = (e1); (e1) = (e2); (e2) = m_tmp; } while (FALSE)
116 static void exprNode_defineConstraints(/*@sef@*/ /*@special@*/ /*@notnull@*/ exprNode e)
117 /*@defines e->requiresConstraints, e->ensuresConstraints,
118 e->trueEnsuresConstraints, e->falseEnsuresConstraints @*/
120 e->requiresConstraints = constraintList_makeNew ();
121 e->ensuresConstraints = constraintList_makeNew ();
122 e->trueEnsuresConstraints = constraintList_makeNew ();
123 e->falseEnsuresConstraints = constraintList_makeNew ();
127 ** must occur after library has been read
130 void exprNode_initMod (void)
131 /*@globals undef regArg, undef outArg, undef outStringArg,
132 undef csOnlyArg, undef csArg;
139 cstringType = ctype_unknown;
140 ctypeType = ctype_unknown;
141 filelocType = ctype_unknown;
143 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
145 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
148 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
150 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
153 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
155 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
158 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdin")))
160 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdin"));
162 else /* define stdin */
164 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdin"),
166 fileloc_getBuiltin (),
168 uentry_setHasNameError (ue);
169 ue = usymtab_supGlobalEntryReturn (ue);
172 stdinRef = sRef_makePointer (uentry_getSref (ue));
174 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdout")))
176 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdout"));
180 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdout"),
182 fileloc_getBuiltin (),
184 uentry_setHasNameError (ue);
185 ue = usymtab_supGlobalEntryReturn (ue);
188 stdoutRef = sRef_makePointer (uentry_getSref (ue));
190 tmp = idDecl_create (cstring_undefined, qtype_create (ctype_unknown));
192 regArg = uentry_makeParam (tmp, PARAMUNKNOWN);
195 qtype_addQual (qtype_create (ctype_makePointer (ctype_unknown)),
198 outArg = uentry_makeParam (tmp, PARAMUNKNOWN);
200 idDecl_setTyp (tmp, qtype_addQual (qtype_create (ctype_string),
203 outStringArg = uentry_makeParam (tmp, PARAMUNKNOWN);
205 idDecl_setTyp (tmp, qtype_addQual (qtype_addQual (qtype_create (cstringType),
207 qual_createNull ()));
209 csOnlyArg = uentry_makeParam (tmp, PARAMUNKNOWN);
211 idDecl_setTyp (tmp, qtype_addQual (qtype_create (cstringType), qual_createNull ()));
212 csArg = uentry_makeParam (tmp, PARAMUNKNOWN);
218 exprNode_destroyMod (void)
219 /*@globals killed regArg, killed outArg, killed outStringArg,
220 killed s_mustExitNode, initMod @*/
224 /* evans 2002-07-12: changed uentry_free to uentry_freeComplete */
225 uentry_freeComplete (regArg);
226 uentry_freeComplete (outArg);
227 uentry_freeComplete (outStringArg);
229 exprNode_free (s_mustExitNode);
236 static void exprNode_resetSref (/*@notnull@*/ exprNode e)
238 e->sref = sRef_undefined;
241 exprNode exprNode_fakeCopy (exprNode e)
243 /*@-temptrans@*/ /*@-retalias@*/
245 /*@=temptrans@*/ /*@=retalias@*/
248 static bool isFlagKey (char key)
250 return (key == '-' || key == '+' || key == ' ' || key == '#');
253 static void exprNode_combineControl (/*@notnull@*/ exprNode ret,
254 /*@notnull@*/ exprNode ifclause,
255 /*@notnull@*/ exprNode elseclause)
257 ret->canBreak = ifclause->canBreak || elseclause->canBreak;
260 (ifclause->mustBreak || exprNode_mustEscape (ifclause))
261 && (elseclause->mustBreak || exprNode_mustEscape (elseclause));
263 ret->exitCode = exitkind_combine (ifclause->exitCode,
264 elseclause->exitCode);
269 ** For exprNode's returned by exprNode_effect.
272 static bool shallowKind (exprKind kind)
274 return (kind == XPR_STRINGLITERAL
275 || kind == XPR_NUMLIT
278 || kind == XPR_NODE);
282 exprNode_freeIniter (/*@only@*/ exprNode e)
284 if (!exprNode_isError (e))
290 ** Its a fake copy, don't free the field->rec and field->field
295 sfree (e->edata->field);
301 exprNode_free (e->edata->op->b);
302 /*@-compdestroy@*/ sfree (e->edata->op); /*@=compdestroy@*/
306 llbug (message ("other: %s", exprNode_unparse (e)));
309 multiVal_free (e->val);
310 cstring_free (e->etext);
311 fileloc_free (e->loc);
312 sRefSet_free (e->uses);
313 sRefSet_free (e->sets);
314 sRefSet_free (e->msets);
315 guardSet_free (e->guards);
317 constraintList_free(e->requiresConstraints);
318 constraintList_free(e->ensuresConstraints);
319 constraintList_free(e->trueEnsuresConstraints);
320 constraintList_free(e->falseEnsuresConstraints);
322 e->requiresConstraints = NULL;
323 e->ensuresConstraints = NULL;
324 e->trueEnsuresConstraints = NULL;
325 e->falseEnsuresConstraints = NULL;
332 exprNode_freeShallow (/*@only@*/ exprNode e)
334 if (!exprNode_isError (e))
336 if (shallowKind (e->kind))
343 if (e->kind == XPR_EMPTY
344 || e->kind == XPR_BODY
345 || e->kind == XPR_STRINGLITERAL
346 || e->kind == XPR_NUMLIT
347 || e->kind == XPR_NODE
348 || e->kind == XPR_OFFSETOF
349 || e->kind == XPR_ALIGNOFT
350 || e->kind == XPR_ALIGNOF
351 || e->kind == XPR_SIZEOFT
352 || e->kind == XPR_SIZEOF)
354 /* don't free anything */
358 /* multiVal_free (e->val); */
359 cstring_free (e->etext);
360 fileloc_free (e->loc);
361 sRefSet_free (e->uses);
362 sRefSet_free (e->sets);
363 sRefSet_free (e->msets);
364 guardSet_free (e->guards);
365 exprData_freeShallow (e->edata, e->kind);
367 /*@-compdestroy@*/ sfree (e); /*@=compdestroy@*/
376 exprNode_free (exprNode e)
378 if (!exprNode_isError (e))
382 multiVal_free (e->val);
383 cstring_free (e->etext);
384 fileloc_free (e->loc);
385 sRefSet_free (e->uses);
386 sRefSet_free (e->sets);
387 sRefSet_free (e->msets);
388 guardSet_free (e->guards);
389 exprData_free (e->edata, e->kind);
391 constraintList_free(e->requiresConstraints);
392 constraintList_free(e->ensuresConstraints);
393 constraintList_free(e->trueEnsuresConstraints);
394 constraintList_free(e->falseEnsuresConstraints);
396 e->requiresConstraints = NULL;
397 e->ensuresConstraints = NULL;
398 e->trueEnsuresConstraints = NULL;
399 e->falseEnsuresConstraints = NULL;
409 exprNode_makeError ()
411 return exprNode_undefined;
414 static /*@out@*/ /*@only@*/ /*@notnull@*/ exprNode
417 exprNode ret = (exprNode) dmalloc (sizeof (*ret));
418 /* static int lastexpnodes = 0; */
423 if (nowalloc > maxalloc)
431 static /*@notnull@*/ /*@special@*/ exprNode
432 exprNode_createPlain (ctype c)
434 /*@ensures isnull result->edata, result->loc, result->val, result->guards,
435 result->uses, result->sets, result->msets, result->etext @*/
438 exprNode e = exprNode_new ();
442 e->val = multiVal_undefined;
443 e->sref = sRef_undefined;
444 e->etext = cstring_undefined;
445 e->loc = fileloc_undefined;
446 e->guards = guardSet_undefined;
447 e->uses = sRefSet_undefined;
448 e->sets = sRefSet_undefined;
449 e->msets = sRefSet_undefined;
450 e->edata = exprData_undefined;
451 e->exitCode = XK_NEVERESCAPE;
453 e->mustBreak = FALSE;
454 e->isJumpPoint = FALSE;
456 exprNode_defineConstraints(e);
461 /*@observer@*/ exprNode exprNode_makeMustExit (void)
463 if (exprNode_isUndefined (s_mustExitNode))
465 s_mustExitNode = exprNode_createPlain (ctype_unknown);
466 s_mustExitNode->exitCode = XK_MUSTEXIT;
469 return s_mustExitNode;
473 static /*@notnull@*/ /*@special@*/ exprNode exprNode_create (ctype c)
475 /*@post:isnull result->edata, result->guards, result->val,
476 result->uses, result->sets, result->msets@*/
479 exprNode e = exprNode_createPlain (c);
480 e->loc = fileloc_copy (g_currentloc);
484 static /*@notnull@*/ /*@special@*/ exprNode exprNode_createUnknown (void)
486 /*@post:isnull result->edata, result->guards,
487 result->uses, result->sets, result->msets@*/
490 return (exprNode_create (ctype_unknown));
493 static /*@notnull@*/ /*@special@*/ exprNode
494 exprNode_createLoc (ctype c, /*@keep@*/ fileloc loc)
496 /*@post:isnull result->edata, result->guards, result->val,
497 result->uses, result->sets, result->msets@*/
500 exprNode e = exprNode_createPlain (c);
506 exprNode_copySets (/*@special@*/ /*@notnull@*/ exprNode ret, exprNode e)
507 /*@defines ret->guards, ret->uses, ret->sets, ret->msets@*/
509 if (exprNode_isDefined (e))
511 ret->guards = guardSet_copy (e->guards);
512 ret->uses = sRefSet_newCopy (e->uses);
513 ret->sets = sRefSet_newCopy (e->sets);
514 ret->msets = sRefSet_newCopy (e->msets);
518 ret->guards = guardSet_undefined;
519 ret->uses = sRefSet_undefined;
520 ret->sets = sRefSet_undefined;
521 ret->msets = sRefSet_undefined;
525 static /*@notnull@*/ /*@special@*/ exprNode
526 exprNode_createPartialLocCopy (exprNode e, /*@only@*/ fileloc loc)
528 /*@post:isnull result->edata, result->etext@*/
531 exprNode ret = exprNode_new ();
533 if (exprNode_isError (e))
535 ret->typ = ctype_unknown;
536 ret->val = multiVal_undefined;
538 ret->guards = guardSet_undefined;
539 ret->uses = sRefSet_undefined;
540 ret->sets = sRefSet_undefined;
541 ret->msets = sRefSet_undefined;
546 ret->val = multiVal_copy (e->val);
548 ret->guards = guardSet_copy (e->guards);
549 ret->uses = sRefSet_newCopy (e->uses);
550 ret->sets = sRefSet_newCopy (e->sets);
551 ret->msets = sRefSet_newCopy (e->msets);
554 ret->kind = XPR_EMPTY;
555 ret->sref = sRef_undefined;
556 ret->etext = cstring_undefined;
557 ret->exitCode = XK_NEVERESCAPE;
558 ret->canBreak = FALSE;
559 ret->mustBreak = FALSE;
560 ret->isJumpPoint = FALSE;
561 ret->edata = exprData_undefined;
563 exprNode_defineConstraints(ret);
569 static /*@notnull@*/ /*@special@*/ exprNode
570 exprNode_createPartialCopy (exprNode e)
572 /*@post:isnull result->edata, result->etext@*/
575 return (exprNode_createPartialLocCopy (e, fileloc_copy (exprNode_loc (e))));
578 static /*@notnull@*/ /*@special@*/ exprNode
579 exprNode_createPartialNVCopy (exprNode e)
581 /*@post:isnull result->edata, result->etext, result->val @*/
584 exprNode ret = exprNode_new ();
586 if (exprNode_isError (e))
588 ret->typ = ctype_unknown;
589 ret->loc = fileloc_undefined;
590 ret->guards = guardSet_undefined;
591 ret->uses = sRefSet_undefined;
592 ret->sets = sRefSet_undefined;
593 ret->msets = sRefSet_undefined;
598 ret->loc = fileloc_copy (e->loc);
599 ret->guards = guardSet_copy (e->guards);
600 ret->uses = sRefSet_newCopy (e->uses);
601 ret->sets = sRefSet_newCopy (e->sets);
602 ret->msets = sRefSet_newCopy (e->msets);
605 ret->val = multiVal_undefined;
606 ret->kind = XPR_EMPTY;
607 ret->sref = sRef_undefined;
608 ret->etext = cstring_undefined;
609 ret->exitCode = XK_NEVERESCAPE;
610 ret->canBreak = FALSE;
611 ret->mustBreak = FALSE;
612 ret->isJumpPoint = FALSE;
613 ret->edata = exprData_undefined;
615 exprNode_defineConstraints(ret);
620 static /*@notnull@*/ /*@special@*/ exprNode
621 exprNode_createSemiCopy (exprNode e)
623 /*@post:isnull result->edata, result->etext, result->sets,
624 result->msets, result->uses, result->guards@*/
627 if (exprNode_isError (e))
629 return exprNode_createPlain (ctype_unknown);
633 exprNode ret = exprNode_new ();
636 ret->val = multiVal_copy (e->val);
637 ret->loc = fileloc_copy (e->loc);
638 ret->guards = guardSet_undefined;
639 ret->uses = sRefSet_undefined;
640 ret->sets = sRefSet_undefined;
641 ret->msets = sRefSet_undefined;
643 ret->kind = XPR_EMPTY;
644 ret->sref = sRef_undefined;
645 ret->etext = cstring_undefined;
646 ret->exitCode = XK_NEVERESCAPE;
647 ret->canBreak = FALSE;
648 ret->mustBreak = FALSE;
649 ret->isJumpPoint = FALSE;
650 ret->edata = exprData_undefined;
652 exprNode_defineConstraints(ret);
659 exprNode_isNullValue (exprNode e)
661 if (exprNode_isDefined (e))
663 multiVal m = exprNode_getValue (e);
665 if (multiVal_isInt (m))
667 return (multiVal_forceInt (m) == 0);
675 exprNode_isUnknownConstant (/*@notnull@*/ exprNode e)
677 while (e->kind == XPR_PARENS)
679 e = exprData_getUopNode (e->edata);
681 if (!exprNode_isDefined (e))
686 /* evans 2002-02-05: was llassert (exprNode_isDefined (e)); but this can fail */
689 if (e->kind == XPR_CONST)
691 multiVal m = exprNode_getValue (e);
693 if (multiVal_isUnknown (m))
703 exprNode_numLiteral (ctype c, /*@temp@*/ cstring t,
704 /*@only@*/ fileloc loc, long val)
706 exprNode e = exprNode_createLoc (c, loc);
708 e->kind = XPR_NUMLIT;
710 llassert (multiVal_isUndefined (e->val));
711 e->val = multiVal_makeInt (val);
712 e->edata = exprData_makeLiteral (cstring_copy (t));
716 e->sref = sRef_makeUnknown ();
717 sRef_setDefNull (e->sref, e->loc);
720 DPRINTF (("Num lit: %s / %s", exprNode_unparse (e), ctype_unparse (exprNode_getType (e))));
725 exprNode_charLiteral (char c, cstring text, /*@only@*/ fileloc loc)
727 exprNode e = exprNode_createLoc (ctype_char, loc);
729 if (context_getFlag (FLG_CHARINTLITERAL))
731 e->typ = ctype_makeConj (ctype_char, ctype_int);
734 e->kind = XPR_NUMLIT;
735 e->val = multiVal_makeChar (c);
737 e->edata = exprData_makeLiteral (cstring_copy (text));
742 exprNode_floatLiteral (double d, ctype ct, cstring text, /*@only@*/ fileloc loc)
744 exprNode e = exprNode_createLoc (ct, loc);
746 e->kind = XPR_NUMLIT;
747 e->val = multiVal_makeDouble (d);
748 e->edata = exprData_makeLiteral (cstring_copy (text));
752 multiVal exprNode_getValue (exprNode e)
754 while (exprNode_isInParens (e)) {
755 if (e->edata != NULL) {
756 e = exprData_getUopNode (e->edata);
762 if (exprNode_isDefined (e)) {
765 return multiVal_undefined;
770 exprNode_combineLiterals (exprNode e, exprNode rest)
774 /* Both must be string literals. */
776 if (exprNode_isUndefined (rest) || exprNode_isUndefined (e))
778 exprNode_free (rest);
782 if (!exprNode_isStringLiteral (e))
786 message ("Constant concatentation is ungrammatical: %s %s", exprNode_unparse (e),
787 exprNode_unparse (rest)),
789 exprNode_free (rest);
793 if (!exprNode_isStringLiteral (rest))
797 message ("Constant concatentation is ungrammatical: %s %s", exprNode_unparse (e), exprNode_unparse (rest)),
800 exprNode_free (rest);
804 ns = cstring_concat (multiVal_forceString (exprNode_getValue (e)),
805 multiVal_forceString (exprNode_getValue (rest)));
807 multiVal_free (e->val);
808 exprData_free (e->edata, e->kind);
809 e->edata = exprData_makeLiteral (cstring_copy (ns));
810 e->val = multiVal_makeString (ns);
811 exprNode_free (rest);
816 exprNode_rawStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
818 exprNode e = exprNode_createLoc (ctype_string, loc);
819 size_t len = cstring_length (t);
821 if (context_getFlag (FLG_STRINGLITERALLEN))
823 if (len > size_fromInt (context_getValue (FLG_STRINGLITERALLEN)))
825 voptgenerror (FLG_STRINGLITERALLEN,
827 ("String literal length (%d) exceeds maximum "
828 "length (%d): \"%s\"",
830 context_getValue (FLG_STRINGLITERALLEN),
836 e->kind = XPR_STRINGLITERAL;
837 e->val = multiVal_makeString (cstring_copy (t));
838 e->edata = exprData_makeLiteral (t);
839 e->sref = sRef_makeConst (ctype_string);
841 if (context_getFlag (FLG_READONLYSTRINGS))
843 sRef_setAliasKind (e->sref, AK_STATIC, fileloc_undefined);
844 sRef_setExKind (e->sref, XO_OBSERVER, loc);
848 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
851 return (e); /* s released */
855 exprNode_wideStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
857 exprNode res = exprNode_stringLiteral (t, loc);
858 res->typ = ctype_makeWideString ();
863 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
865 size_t len = size_fromInt (size_toInt (cstring_length (t)) - 2);
866 char *ts = cstring_toCharsSafe (t);
867 char *s = cstring_toCharsSafe (cstring_create (len + 1));
869 llassert (*ts == '\"' && *(ts + len + 1) == '\"');
870 strncpy (s, ts+1, len);
873 return exprNode_rawStringLiteral (cstring_fromCharsO (s), loc);
876 exprNode exprNode_fromUIO (cstring c)
878 fileloc loc = context_getSaveLocation ();
879 exprNode e = exprNode_createPlain (ctype_unknown);
883 if (fileloc_isUndefined (loc))
885 loc = fileloc_copy (g_currentloc);
888 e->loc = loc; /* save loc was mangled */
889 e->sref = sRef_undefined;
891 if (usymtab_exists (c))
893 uentry ue = usymtab_lookupEither (c);
895 if (uentry_isDatatype (ue)
896 && uentry_isSpecified (ue))
899 (message ("%q: Specified datatype %s used in code, but not defined. "
900 "(Cannot continue reasonably from this error.)",
901 fileloc_unparse (e->loc), c));
909 llassertprint (!usymtab_exists (c), ("Entry exists: %s", c));
912 ** was supercedeGlobalEntry...is this better?
915 if (!context_inIterEnd ())
917 if (context_inMacro ())
919 if (context_getFlag (FLG_UNRECOG))
923 message ("Unrecognized identifier in macro definition: %s", c), e->loc);
927 flagcode_recordSuppressed (FLG_UNRECOG);
933 (FLG_UNRECOG, message ("Unrecognized identifier: %s", c), e->loc);
937 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
939 /* No alias errors for unrecognized identifiers */
940 sRef_setAliasKind (e->sref, AK_ERROR, loc);
945 exprNode exprNode_makeConstantString (cstring c, /*@only@*/ fileloc loc)
947 exprNode e = exprNode_createPlain (ctype_unknown);
950 e->sref = sRef_makeConst (ctype_string);
951 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
952 e->typ = ctype_string;
954 /* No alias errors for unrecognized identifiers */
955 sRef_setAliasKind (e->sref, AK_STATIC, loc);
956 sRef_setExKind (e->sref, XO_OBSERVER, loc);
961 exprNode exprNode_createId (/*@observer@*/ uentry c)
963 if (uentry_isValid (c))
965 exprNode e = exprNode_new ();
967 DPRINTF (("create id: %s", uentry_unparse (c)));
969 e->typ = uentry_getType (c);
971 if (uentry_isFunction (c)
972 && !sRef_isLocalVar (uentry_getSref (c)))
974 e->sref = sRef_undefined;
978 e->sref = uentry_getSref (c);
981 if (sRef_isStateUnknown (e->sref) && uentry_isNonLocal (c))
983 sRef_setDefined (e->sref, fileloc_undefined);
987 ** yoikes! leaving this out was a heinous bug...that would have been
988 ** caught if i had splint working first. gag!
991 e->etext = cstring_undefined;
993 if (uentry_isEitherConstant (c))
996 e->val = multiVal_copy (uentry_getConstantValue (c));
1001 e->val = multiVal_unknown ();
1004 e->edata = exprData_makeId (c);
1005 e->loc = context_getSaveLocation ();
1007 if (fileloc_isUndefined (e->loc))
1009 fileloc_free (e->loc);
1010 e->loc = fileloc_copy (g_currentloc);
1013 e->guards = guardSet_new ();
1014 e->sets = sRefSet_new ();
1015 e->msets = sRefSet_new ();
1016 e->uses = sRefSet_new ();
1018 /*> missing fields, detected by splint <*/
1019 e->exitCode = XK_NEVERESCAPE;
1020 e->isJumpPoint = FALSE;
1021 e->canBreak = FALSE;
1022 e->mustBreak = FALSE;
1024 exprNode_defineConstraints (e);
1029 return exprNode_createUnknown ();
1033 /*@notnull@*/ exprNode
1034 exprNode_fromIdentifier (/*@observer@*/ uentry c)
1038 if (context_justPopped ()) /* watch out! c could be dead */
1040 uentry ce = usymtab_lookupSafe (cscannerHelp_observeLastIdentifier ());
1042 if (uentry_isValid (ce))
1048 llbuglit ("Looks like Aunt Millie forgot to walk to dog again.");
1052 ret = exprNode_fromIdentifierAux (c);
1056 static void exprNode_checkStringLiteralLength (ctype t1, exprNode e2)
1058 multiVal mval = exprNode_getValue (e2);
1062 if (ctype_isFixedArray (t1))
1064 size_t nelements = ctype_getArraySize (t1);
1066 llassert (multiVal_isString (mval));
1067 slit = multiVal_forceString (mval);
1069 len = cstring_lengthExpandEscapes (slit);
1071 llassert (exprNode_isDefined (e2));
1073 if (len == nelements)
1077 temp = cstring_expandEscapes (slit);
1079 if (temp[len-1] == '\0')
1082 (FLG_STRINGLITNOROOMFINALNULL,
1083 message ("String literal with %d character%& "
1084 "is assigned to %s (no room for final null terminator): %s",
1085 size_toInt (len + 1),
1087 exprNode_unparse (e2)),
1093 (FLG_STRINGLITNOROOM,
1094 message ("String literal with %d character%& "
1095 "is assigned to %s (no room for null terminator): %s",
1096 size_toInt (len + 1),
1098 exprNode_unparse (e2)),
1102 else if (len > nelements)
1105 (FLG_STRINGLITTOOLONG,
1106 message ("String literal with %d character%& (counting null terminator) "
1107 "is assigned to %s (insufficient storage available): %s",
1108 size_toInt (len + 1),
1110 exprNode_unparse (e2)),
1113 else if (len < nelements - 1)
1116 (FLG_STRINGLITSMALLER,
1117 message ("String literal with %d character%& is assigned to %s (possible waste of storage): %s",
1118 size_toInt (len + 1),
1120 exprNode_unparse (e2)),
1130 static /*@only@*/ /*@notnull@*/ exprNode
1131 exprNode_fromIdentifierAux (/*@observer@*/ uentry c)
1133 exprNode e = exprNode_createId (c);
1136 uentry_setUsed (c, e->loc);
1138 if (uentry_isVar (c) && sRef_isFileOrGlobalScope (sr))
1140 checkGlobUse (c, FALSE, e);
1147 exprNode_isZero (exprNode e)
1149 if (exprNode_isDefined (e))
1151 multiVal m = exprNode_getValue (e);
1153 if (multiVal_isInt (m))
1155 return (multiVal_forceInt (m) == 0);
1163 exprNode_isNonNegative (exprNode e)
1165 if (exprNode_isDefined (e))
1167 multiVal m = exprNode_getValue (e);
1169 if (multiVal_isInt (m))
1171 return (multiVal_forceInt (m) >= 0);
1175 ** This is not always true if programmer defines enum
1176 ** values, but then the constant should be known.
1179 if (ctype_isEnum (ctype_realType (e->typ)))
1189 ** a[x] - uses a but NOT a[]
1190 ** result sref = a[] (set/use in assignment)
1192 ** The syntax x[a] is also legal in C, and has the same
1193 ** semantics. If ind is an array, and arr is an int, flip
1198 exprNode_arrayFetch (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
1201 ** error in arr, error propagates (no new messages)
1202 ** error in ind, assume valid and continue
1205 DPRINTF (("Array fetch: %s / %s",
1206 exprNode_unparse (e1), exprNode_unparse (e2)));
1208 if (exprNode_isError (e1))
1211 return (exprNode_makeError ());
1217 ctype carr = exprNode_getType (e1);
1218 ctype crarr = ctype_realType (carr);
1221 ** this sets up funny aliasing, that leads to spurious
1222 ** splint errors. Hence, the i2 comments.
1225 /* evans 2001-09-09 added ctype_isKnown so there is no swap when e1 type is unknown */
1226 if (ctype_isKnown (crarr)
1227 && !ctype_isRealArray (crarr)
1228 && ctype_isRealNumeric (crarr)
1229 && !exprNode_isError (e2)
1230 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1235 carr = exprNode_getType (arr);
1236 crarr = ctype_realType (carr);
1244 DPRINTF (("arr: %s", exprNode_unparse (arr)));
1246 if (sRef_possiblyNull (arr->sref))
1248 if (!usymtab_isGuarded (arr->sref))
1250 if (!context_inSizeof() )
1252 if (optgenerror (FLG_NULLDEREF,
1253 message ("Index of %s pointer %q: %s",
1254 sRef_nullMessage (arr->sref),
1255 sRef_unparse (arr->sref),
1256 exprNode_unparse (arr)),
1259 DPRINTF (("ref: %s", sRef_unparseFull (arr->sref)));
1260 sRef_showNullInfo (arr->sref);
1262 /* suppress future messages */
1263 sRef_setNullError (arr->sref);
1269 if (exprNode_isError (ind))
1271 if ((ctype_isArrayPtr (crarr)
1272 && !ctype_isFunction (crarr))
1273 || ctype_isUnknown (carr))
1275 exprNode ret = exprNode_createPartialCopy (arr);
1277 if (ctype_isKnown (carr))
1279 ret->typ = ctype_baseArrayPtr (crarr);
1283 ret->typ = ctype_unknown;
1286 ret->sref = sRef_makeArrayFetch (arr->sref);
1288 ret->kind = XPR_FETCH;
1291 ** Because of funny aliasing (when arr and ind are
1292 ** flipped) spurious errors would be reported here.
1295 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1296 checkSafeUse (ret, arr->sref);
1301 voptgenerror (FLG_TYPE,
1302 message ("Array fetch from non-array (%t): %s[%s]", carr,
1303 exprNode_unparse (e1), exprNode_unparse (e2)),
1305 exprNode_free (arr);
1306 return (exprNode_makeError ());
1311 if (!ctype_isForceRealInt (&(ind->typ)))
1313 ctype rt = ctype_realType (ind->typ);
1315 if (ctype_isChar (rt))
1319 message ("Array fetch using non-integer, %t: %s[%s]",
1321 exprNode_unparse (e1), exprNode_unparse (e2)),
1324 else if (ctype_isEnum (rt))
1328 message ("Array fetch using non-integer, %t: %s[%s]",
1330 exprNode_unparse (e1), exprNode_unparse (e2)),
1337 message ("Array fetch using non-integer, %t: %s[%s]",
1339 exprNode_unparse (e1), exprNode_unparse (e2)),
1343 multiVal_free (ind->val);
1344 ind->val = multiVal_unknown ();
1347 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1349 exprNode ret = exprNode_createSemiCopy (arr);
1350 multiVal m = exprNode_getValue (ind);
1352 ret->typ = ctype_baseArrayPtr (crarr);
1353 ret->kind = XPR_FETCH;
1355 if (multiVal_isInt (m))
1357 int i = (int) multiVal_forceInt (m);
1359 if (sRef_isValid (arr->sref)) {
1360 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1362 ret->sref = sRef_undefined;
1367 ret->sref = sRef_makeArrayFetch (arr->sref);
1370 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1371 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1372 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1374 /* (see comment on spurious errors above) */
1375 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1377 exprNode_checkUse (ret, ind->sref, ind->loc);
1378 exprNode_checkUse (ret, arr->sref, arr->loc);
1384 if (ctype_isUnknown (carr))
1386 exprNode ret = exprNode_createPartialCopy (arr);
1388 ret->kind = XPR_FETCH;
1389 ret->typ = ctype_unknown;
1390 ret->sets = sRefSet_union (ret->sets, ind->sets);
1391 ret->msets = sRefSet_union (ret->msets, ind->msets);
1392 ret->uses = sRefSet_union (ret->uses, ind->uses);
1394 /* (see comment on spurious errors above) */
1395 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1397 exprNode_checkUse (ret, ind->sref, ind->loc);
1398 exprNode_checkUse (ret, arr->sref, arr->loc);
1405 message ("Array fetch from non-array (%t): %s[%s]", carr,
1406 exprNode_unparse (e1), exprNode_unparse (e2)),
1409 exprNode_free (arr);
1410 exprNode_free (ind);
1412 return (exprNode_makeError ());
1422 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1423 exprNodeList args, exprNode ret)
1425 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1429 ** checkPrintfArgs --- checks arguments for printf-like functions
1430 ** Arguments before ... have already been checked.
1431 ** The argument before the ... is a char *.
1432 ** argno is the format string argument.
1436 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1437 exprNodeList args, exprNode ret, int argno)
1440 ** the last argument before the elips is the format string
1445 int nargs = exprNodeList_size (args);
1446 uentryList params = uentry_getParams (fcn);
1450 ** These should be ensured by checkSpecialFunction
1453 llassert (uentryList_size (params) == argno + 1);
1454 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1456 a = exprNodeList_getN (args, argno - 1);
1457 formatloc = fileloc_copy (exprNode_loc (a));
1459 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1460 && exprNode_knownStringValue (a))
1462 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1463 char *code = format;
1466 nargs = exprNodeList_size (args);
1468 while ((code = strchr (code, '%')) != NULL)
1470 char *origcode = code;
1471 cstring codetext = cstring_newEmpty ();
1472 char key = *(++code);
1473 ctype modtype = ctype_int;
1474 bool modified = FALSE;
1476 fileloc_addColumn (formatloc, code - ocode);
1478 codetext = cstring_appendChar (codetext, key);
1481 while (isFlagKey (key))
1484 codetext = cstring_appendChar (codetext, key);
1485 fileloc_incColumn (formatloc);
1488 if (key == 'm') /* skipped in syslog */
1493 /* ignore field width */
1494 while (isdigit ((int) key) != 0)
1497 codetext = cstring_appendChar (codetext, key);
1498 fileloc_incColumn (formatloc);
1501 /* ignore precision */
1505 codetext = cstring_appendChar (codetext, key);
1506 fileloc_incColumn (formatloc);
1509 ** In printf, '*' means: read the next arg as an int for the
1510 ** field width. This seems to be missing from my copy of the
1511 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1512 ** later) but never does.
1517 ; /* don't do anything --- handle later */
1521 while (isdigit ((int) key) != 0)
1524 codetext = cstring_appendChar (codetext, key);
1525 fileloc_incColumn (formatloc);
1532 modtype = ctype_sint; /* short */
1534 codetext = cstring_appendChar (codetext, key);
1535 fileloc_incColumn (formatloc);
1537 else if (key == 'l' || key == 'L')
1539 modtype = ctype_lint; /* long */
1541 codetext = cstring_appendChar (codetext, key);
1542 fileloc_incColumn (formatloc);
1544 if (key == 'l' || key == 'L') {
1545 modtype = ctype_llint; /* long long */
1547 codetext = cstring_appendChar (codetext, key);
1548 fileloc_incColumn (formatloc);
1556 /* now, key = type of conversion to apply */
1558 fileloc_incColumn (formatloc);
1566 message ("No argument corresponding to %q format "
1567 "code %d (%%%s): \"%s\"",
1568 uentry_getName (fcn),
1570 cstring_fromChars (format)),
1573 if (fileloc_isDefined (formatloc)
1574 && context_getFlag (FLG_SHOWCOL))
1576 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1584 a = exprNodeList_getN (args, i);
1587 if (!exprNode_isError (a))
1593 case '*': /* int argument for fieldwidth */
1594 expecttype = ctype_int;
1595 *(--code) = '%'; /* convert it for next code */
1596 fileloc_subColumn (formatloc, 1);
1597 /*@switchbreak@*/ break;
1600 expecttype = ctype_combine (ctype_uint, modtype);
1601 /*@switchbreak@*/ break;
1603 case 'i': /* int argument */
1605 expecttype = ctype_combine (ctype_int, modtype);
1606 /*@switchbreak@*/ break;
1608 case 'x': /* unsigned int */
1610 expecttype = ctype_combine (ctype_uint, modtype);
1612 /*@switchbreak@*/ break;
1618 case 'f': /* double */
1619 expecttype = ctype_combine (ctype_double, modtype);
1620 /*@switchbreak@*/ break;
1622 case 'c': /* int converted to char (check its a char?) */
1623 expecttype = ctype_makeConj (ctype_int,
1624 ctype_makeConj (ctype_char,
1627 /* evans 2001-10-05 - changed to reflect correct ISO spec:
1628 int converted to char */
1630 /* expecttype = ctype_makeConj (ctype_char, ctype_uchar); */
1631 /*@switchbreak@*/ break;
1633 case 's': /* string */
1634 expecttype = ctype_string;
1635 /*@switchbreak@*/ break;
1638 while (((key = *(++code)) != ']')
1641 codetext = cstring_appendChar (codetext, key);
1642 fileloc_incColumn (formatloc);
1648 (message ("Bad character set format: %s",
1649 cstring_fromChars (origcode)));
1652 expecttype = ctype_string;
1653 /*@switchbreak@*/ break;
1655 case 'p': /* pointer */
1656 expecttype = ctype_makePointer (ctype_void);
1657 /* need not be defined */
1658 uentry_setDefState (regArg, SS_RELDEF);
1659 sRef_setPosNull (uentry_getSref (regArg),
1662 /*@switchbreak@*/ break;
1664 case 'n': /* pointer to int, modified by call! */
1665 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1667 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1668 /*@switchbreak@*/ break;
1670 case 'm': /* in a syslog, it doesn't consume an argument */
1671 /* should check we're really doing syslog */
1673 /*@switchbreak@*/ break;
1677 expecttype = ctype_unknown;
1681 message ("Unrecognized format code: %s",
1682 cstring_fromChars (origcode)),
1683 fileloc_isDefined (formatloc)
1684 ? formatloc : g_currentloc);
1686 /*@switchbreak@*/ break;
1689 if (!(exprNode_matchArgType (expecttype, a)))
1691 if (ctype_isVoidPointer (expecttype)
1692 && ctype_isRealAbstract (a->typ)
1693 && (context_getFlag (FLG_ABSTVOIDP)))
1699 if (llgenformattypeerror
1700 (expecttype, exprNode_undefined,
1702 message ("Format argument %d to %q (%%%s) expects "
1705 uentry_getName (fcn),
1708 a->typ, exprNode_unparse (a)),
1711 if (fileloc_isDefined (formatloc)
1712 && context_getFlag (FLG_SHOWCOL))
1715 (cstring_makeLiteral
1716 ("Corresponding format code"),
1723 uentry_setType (regArg, expecttype);
1724 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1726 if (ctype_equal (expecttype, ctype_string))
1728 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1731 uentry_setType (regArg, ctype_unknown);
1732 uentry_fixupSref (regArg);
1736 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1747 cstring_free (codetext);
1752 voptgenerror (FLG_TYPE,
1753 message ("Format string for %q has %d arg%&, given %d",
1754 uentry_getName (fcn), i - argno, nargs - argno),
1760 /* no checking possible for compile-time unknown format strings */
1761 if (exprNode_isDefined (a))
1765 message ("Format string parameter to %s is not a compile-time constant: %s",
1766 exprNode_unparse (f),
1767 exprNode_unparse (a)),
1772 fileloc_free (formatloc);
1776 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1777 exprNodeList args, exprNode ret, int argno)
1781 int nargs = exprNodeList_size (args);
1782 uentryList params = uentry_getParams (fcn);
1786 ** These should be ensured by checkSpecialFunction
1789 llassert (uentryList_size (params) == argno + 1);
1790 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1792 a = exprNodeList_getN (args, argno - 1);
1793 formatloc = fileloc_copy (exprNode_loc (a));
1795 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1796 && exprNode_knownStringValue (a))
1798 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1799 char *code = format;
1802 nargs = exprNodeList_size (args);
1804 while ((code = strchr (code, '%')) != NULL)
1806 char *origcode = code;
1807 char key = *(++code);
1808 cstring codetext = cstring_newEmpty ();
1809 ctype modtype = ctype_int;
1810 char modifier = '\0';
1811 bool modified = TRUE;
1812 bool ignore = FALSE;
1814 codetext = cstring_appendChar (codetext, key);
1815 fileloc_addColumn (formatloc, code - ocode);
1818 ** this is based on ANSI standard library description of fscanf
1819 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1822 /* '*' suppresses assignment (does not need match argument) */
1827 codetext = cstring_appendChar (codetext, key);
1830 fileloc_incColumn (formatloc);
1833 /* ignore field width */
1834 while (isdigit ((int) key) != 0)
1837 codetext = cstring_appendChar (codetext, key);
1838 fileloc_incColumn (formatloc);
1843 modtype = ctype_sint; /* short */
1845 codetext = cstring_appendChar (codetext, key);
1846 fileloc_incColumn (formatloc);
1848 else if (key == 'l' || key == 'L')
1850 modtype = ctype_lint; /* long */
1854 codetext = cstring_appendChar (codetext, key);
1856 fileloc_incColumn (formatloc);
1858 if (key == 'l' || key == 'L') {
1859 modtype = ctype_llint; /* long long */
1861 codetext = cstring_appendChar (codetext, key);
1862 fileloc_incColumn (formatloc);
1870 /* now, key = type of conversion to apply */
1872 fileloc_incColumn (formatloc);
1886 message ("No argument corresponding to %q format "
1887 "code %d (%%%s): \"%s\"",
1888 uentry_getName (fcn),
1890 cstring_fromChars (format)),
1893 if (fileloc_isDefined (formatloc)
1894 && context_getFlag (FLG_SHOWCOL))
1897 (cstring_makeLiteral ("Corresponding format code"),
1905 a = exprNodeList_getN (args, i);
1908 if (!exprNode_isError (a))
1914 case '*': /* int argument for fieldwidth */
1915 expecttype = ctype_makePointer (ctype_int);
1916 *(--code) = '%'; /* convert it for next code */
1917 fileloc_subColumn (formatloc, 1);
1918 /*@switchbreak@*/ break;
1921 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1922 /*@switchbreak@*/ break;
1927 case 'X': /* unsigned int */
1928 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1929 /*@switchbreak@*/ break;
1936 /* printf is double, scanf is float! */
1938 if (modifier == 'l')
1940 expecttype = ctype_makePointer (ctype_double);
1942 else if (modifier == 'L')
1944 expecttype = ctype_makePointer (ctype_ldouble);
1948 llassert (modifier == '\0');
1949 expecttype = ctype_makePointer (ctype_float);
1951 /*@switchbreak@*/ break;
1953 case 'c': /* int converted to char (check its a char?) */
1954 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1955 /*@switchbreak@*/ break;
1957 case 's': /* string */
1958 expecttype = ctype_string;
1959 /*@switchbreak@*/ break;
1963 while (((key = *(++code)) != ']')
1966 codetext = cstring_appendChar (codetext, key);
1967 fileloc_incColumn (formatloc);
1973 (message ("Bad character set format: %s",
1974 cstring_fromChars (origcode)));
1977 expecttype = ctype_string;
1978 /*@switchbreak@*/ break;
1981 case 'p': /* pointer */
1984 message ("Format code should not be used in scanf: %s",
1985 cstring_fromChars (origcode)),
1986 fileloc_isDefined (formatloc)
1987 ? formatloc : g_currentloc);
1989 expecttype = ctype_unknown;
1990 /*@switchbreak@*/ break;
1992 case 'n': /* pointer to int, modified by call! */
1993 expecttype = ctype_makePointer (ctype_int);
1994 /*@switchbreak@*/ break;
1997 expecttype = ctype_unknown;
2001 message ("Unrecognized format code: %s",
2002 cstring_fromChars (origcode)),
2003 fileloc_isDefined (formatloc)
2004 ? formatloc : g_currentloc);
2006 /*@switchbreak@*/ break;
2009 if (!(exprNode_matchArgType (expecttype, a)))
2011 if (ctype_isVoidPointer (expecttype)
2012 && ctype_isRealAbstract (a->typ)
2013 && (context_getFlag (FLG_ABSTVOIDP)))
2019 if (llgenformattypeerror
2020 (expecttype, exprNode_undefined,
2022 message ("Format argument %d to %q (%%%s) expects "
2025 uentry_getName (fcn),
2026 codetext, expecttype,
2027 a->typ, exprNode_unparse (a)),
2030 if (fileloc_isDefined (formatloc)
2031 && context_getFlag (FLG_SHOWCOL))
2034 (cstring_makeLiteral
2035 ("Corresponding format code"),
2042 uentry_setType (outArg, expecttype);
2043 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
2044 uentry_setType (outArg, ctype_unknown);
2045 uentry_fixupSref (outArg);
2049 exprNode_checkCallModifyVal (a->sref, args, f, ret);
2054 /* a->sref = sRef_undefined; */
2061 cstring_free (codetext);
2066 voptgenerror (FLG_TYPE,
2067 message ("Format string for %q has %d arg%&, given %d",
2068 uentry_getName (fcn), i - argno, nargs - argno),
2074 /* no checking possible for compile-time unknown format strings */
2077 fileloc_free (formatloc);
2081 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
2084 /*@unused@*/ int argno)
2087 ** the last argument before the elips is the format string
2090 int nargs = exprNodeList_size (args);
2095 a = exprNodeList_getN (args, argno - 1);
2096 formatloc = fileloc_copy (exprNode_loc (a));
2098 if (ctype_isUnknown (cstringType)) {
2099 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
2101 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
2105 if (ctype_isUnknown (ctypeType)) {
2106 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
2108 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
2112 if (ctype_isUnknown (filelocType)) {
2113 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
2115 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
2119 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
2120 && exprNode_knownStringValue (a))
2122 cstring format = multiVal_forceString (exprNode_getValue (a));
2123 char *code = cstring_toCharsSafe (format);
2126 nargs = exprNodeList_size (args);
2128 while ((code = strchr (code, '%')) != NULL)
2130 char *origcode = code;
2131 char key = *(++code);
2132 cstring codetext = cstring_newEmpty ();
2133 bool isOnly = FALSE;
2135 codetext = cstring_appendChar (codetext, key);
2137 fileloc_addColumn (formatloc, code - ocode);
2139 while (key >= '0' && key <= '9')
2142 codetext = cstring_appendChar (codetext, key);
2143 fileloc_incColumn (formatloc);
2147 fileloc_incColumn (formatloc);
2151 if (key == '&') /* plural marker */
2160 message ("Message missing format arg %d (%%%s): \"%s\"",
2161 i + 1, codetext, format),
2167 a = exprNodeList_getN (args, i);
2171 if (!exprNode_isError (a))
2175 /*@-loopswitchbreak@*/
2181 expecttype = ctype_char; break;
2183 expecttype = cstringType; break;
2185 expecttype = cstringType; isOnly = TRUE; break;
2187 expecttype = cstringType; isOnly = TRUE; break;
2188 case 'd': expecttype = ctype_int; break;
2189 case 'u': expecttype = ctype_uint; break;
2190 case 'w': expecttype = ctype_ulint; break;
2191 case 'f': expecttype = ctype_float; break;
2192 case 'b': expecttype = ctype_bool; break;
2193 case 't': expecttype = ctypeType; break;
2195 expecttype = ctype_makePointer (ctype_void);
2196 /* need not be defined */
2197 uentry_setDefState (regArg, SS_RELDEF);
2198 sRef_setPosNull (uentry_getSref (regArg),
2201 /*@switchbreak@*/ break;
2202 case 'l': expecttype = filelocType; break;
2203 case '&': /* a wee bit of a hack methinks */
2204 expecttype = ctype_int;
2206 case 'r': expecttype = ctype_bool; break;
2208 expecttype = ctype_unknown;
2211 message ("Unrecognized format code: %s",
2212 cstring_fromChars (origcode)),
2213 fileloc_isDefined (formatloc)
2214 ? formatloc : g_currentloc);
2217 /*@=loopswitchbreak@*/
2219 if (!(exprNode_matchArgType (expecttype, a)))
2221 if (ctype_isVoidPointer (expecttype)
2222 && ctype_isRealAbstract (a->typ)
2223 && (context_getFlag (FLG_ABSTVOIDP)))
2229 if (llgenformattypeerror
2230 (expecttype, exprNode_undefined,
2232 message ("Format argument %d to %q (%%%s) expects "
2235 uentry_getName (fcn),
2236 codetext, expecttype,
2237 a->typ, exprNode_unparse (a)),
2240 if (fileloc_isDefined (formatloc)
2241 && context_getFlag (FLG_SHOWCOL))
2244 (cstring_makeLiteral
2245 ("Corresponding format code"),
2252 if (ctype_equal (expecttype, cstringType))
2256 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
2257 uentry_fixupSref (csOnlyArg);
2261 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2262 uentry_fixupSref (csArg);
2267 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2268 uentry_fixupSref (regArg);
2274 cstring_free (codetext);
2279 voptgenerror (FLG_TYPE,
2280 message ("Format string for %q has %d arg%&, given %d",
2281 uentry_getName (fcn), i - argno, nargs -argno),
2287 /* no checking possible for compile-time unknown format strings */
2290 fileloc_free (formatloc);
2294 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2295 /*@notnull@*/ exprNode e2,
2301 bool hadUncon = FALSE;
2303 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e1->sref)) &&
2304 sRefSet_hasUnconstrained (sets2))
2307 (FLG_EVALORDERUNCON,
2309 ("Expression may have undefined behavior (%q used in right operand "
2310 "may set global variable %q used in left operand): %s %s %s",
2311 sRefSet_unparseUnconstrained (sets2),
2312 sRef_unparse (sRef_getRootBase (e1->sref)),
2313 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2317 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e2->sref)) &&
2318 sRefSet_hasUnconstrained (sets1))
2321 (FLG_EVALORDERUNCON,
2323 ("Expression has undefined behavior (%q used in left operand "
2324 "may set global variable %q used in right operand): %s %s %s",
2325 sRefSet_unparseUnconstrained (sets1),
2326 sRef_unparse (e2->sref),
2327 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2331 sRefSet_realElements (e1->uses, sr)
2333 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2338 ("Expression has undefined behavior (left operand uses %q, "
2339 "modified by right operand): %s %s %s",
2341 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2344 } end_sRefSet_realElements;
2346 sRefSet_realElements (sets1, sr)
2348 if (sRef_isMeaningful (sr))
2350 if (sRef_same (sr, e2->sref))
2355 ("Expression has undefined behavior (value of right operand "
2356 "modified by left operand): %s %s %s",
2357 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2360 else if (sRefSet_member (e2->uses, sr))
2365 ("Expression has undefined behavior (left operand modifies %q, "
2366 "used by right operand): %s %s %s",
2368 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2373 if (sRefSet_member (sets2, sr))
2375 if (sRef_isUnconstrained (sr))
2383 hadUncon = optgenerror
2384 (FLG_EVALORDERUNCON,
2386 ("Expression may have undefined behavior. Left operand "
2387 "calls %q; right operand calls %q. The unconstrained "
2388 "functions may modify global state used by "
2389 "the other operand): %s %s %s",
2390 sRefSet_unparseUnconstrained (sets1),
2391 sRefSet_unparseUnconstrained (sets2),
2392 exprNode_unparse (e1), lltok_unparse (op),
2393 exprNode_unparse (e2)),
2402 ("Expression has undefined behavior (both "
2403 "operands modify %q): %s %s %s",
2405 exprNode_unparse (e1),
2406 lltok_unparse (op), exprNode_unparse (e2)),
2412 } end_sRefSet_realElements;
2415 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2417 bool hasError = FALSE;
2419 if (exprNode_isError (e1) || exprNode_isError (e2))
2424 if (sRefSet_member (e2->sets, e1->sref))
2426 if (e2->kind == XPR_CALL)
2432 hasError = optgenerror
2434 message ("Expression has undefined behavior "
2435 "(value of left operand %s is modified "
2436 "by right operand %s): %s %s %s",
2437 exprNode_unparse (e1),
2438 exprNode_unparse (e2),
2439 exprNode_unparse (e1), lltok_unparse (op),
2440 exprNode_unparse (e2)),
2445 if (context_getFlag (FLG_EVALORDERUNCON))
2447 if (sRefSet_member (e2->msets, e1->sref))
2449 if (e2->kind == XPR_CALL)
2455 hasError = optgenerror
2458 ("Expression has undefined behavior (value of left "
2459 "operand may be modified by right operand): %s %s %s",
2460 exprNode_unparse (e1), lltok_unparse (op),
2461 exprNode_unparse (e2)),
2469 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2471 if (context_maybeSet (FLG_EVALORDERUNCON))
2473 checkExpressionDefinedAux (e1, e2, e1->msets,
2474 e2->msets, op, FLG_EVALORDERUNCON);
2479 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2482 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2483 exprNodeList args, bool isIter, exprNode ret)
2487 if (!exprNode_isError (f))
2489 if (!uentryList_isMissingParams (cl))
2491 int nargs = exprNodeList_size (args);
2492 int expectargs = uentryList_size (cl);
2496 if (expectargs == 0)
2504 message ("Iter %q invoked with %d args, "
2506 uentry_getName (fcn),
2514 message ("Function %s called with %d args, "
2516 exprNode_unparse (f), nargs),
2523 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2525 exprNodeList_reset (args);
2527 uentryList_elements (cl, current)
2529 ctype ct = uentry_getType (current);
2532 if (ctype_isElips (ct))
2535 ** do special checking for printf/scanf library functions
2537 ** this is kludgey code, just for handling the special case
2541 if (uentry_isPrintfLike (fcn))
2543 checkPrintfArgs (f, fcn, args, ret, i);
2546 else if (uentry_isScanfLike (fcn))
2548 checkScanfArgs (f, fcn, args, ret, i);
2551 else if (uentry_isMessageLike (fcn))
2553 checkMessageArgs (f, fcn, args, i);
2558 llassert (!uentry_isSpecialFunction (fcn));
2561 nargs = expectargs; /* avoid errors */
2566 if (i >= nargs) break;
2568 a = exprNodeList_current (args);
2569 exprNodeList_advance (args);
2573 if (exprNode_isError (a))
2580 probably necessary? I'm not sure about this one
2581 checkMacroParen (a);
2584 f->guards = guardSet_union (f->guards, a->guards);
2586 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2588 if (!(exprNode_matchArgType (ct, a)))
2590 DPRINTF (("Args mismatch!"));
2592 if (ctype_isVoidPointer (ct)
2593 && (ctype_isPointer (a->typ)
2594 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2599 ("Pointer to abstract type (%t) used "
2601 "(arg %d to %q): %s",
2603 uentry_getName (fcn),
2604 exprNode_unparse (a)),
2612 (ct, exprNode_undefined,
2615 ("Iter %q expects arg %d to "
2616 "be %t gets %t: %s",
2617 uentry_getName (fcn),
2618 i, ct, a->typ, exprNode_unparse (a)),
2629 ("Function %q expects arg %d to be %t gets %t: %s",
2630 uentry_getName (fcn),
2631 i, ct, a->typ, exprNode_unparse (a)),
2634 DPRINTF (("Types: %s / %s",
2636 ctype_unparse (a->typ)));
2640 ** Clear null marker for abstract types.
2641 ** (It is not revealed, so suppress future messages.)
2644 if (ctype_isAbstract (a->typ))
2646 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2653 } end_uentryList_elements ;
2656 if (expectargs != nargs) /* note: not != since we may have ... */
2658 if (ctype_isElips (last))
2662 message ("Function %s called with %d args, expects at least %d",
2663 exprNode_unparse (f),
2664 nargs, expectargs - 1),
2673 message ("Iter %q invoked with %d args, expects %d",
2674 uentry_getName (fcn), nargs, expectargs),
2681 message ("Function %s called with %d args, expects %d",
2682 exprNode_unparse (f),
2695 ** Check for undefined code sequences in function arguments:
2697 ** one parameter sets something used by another parameter
2698 ** one parameter sets something set by another parameter
2702 checkSequencingOne (exprNode f, exprNodeList args,
2703 /*@notnull@*/ exprNode el, int argno)
2706 ** Do second loop, iff +undefunspec
2710 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2712 for (checkloop = 0; checkloop < numloops; checkloop++)
2718 thissets = el->sets;
2722 llassert (checkloop == 1);
2723 thissets = el->msets;
2726 sRefSet_realElements (thissets, thisset)
2730 /*@access exprNodeList@*/
2731 for (j = 0; j < args->nelements; j++)
2733 exprNode jl = args->elements[j];
2734 int thisargno = j + 1;
2736 if (thisargno != argno && exprNode_isDefined (jl))
2738 sRefSet otheruses = jl->uses;
2740 if (sRef_isFileOrGlobalScope (sRef_getRootBase (jl->sref)) &&
2741 sRefSet_hasUnconstrained (thissets))
2744 (FLG_EVALORDERUNCON,
2747 ("%q used in argument %d may set "
2748 "global variable %q used by argument %d: %s(%q)",
2749 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2752 sRef_unparse (sRef_getRootBase (jl->sref)),
2754 exprNode_unparse (f), exprNodeList_unparse (args)),
2758 if (sRefSet_member (otheruses, thisset))
2760 if (sRef_isUnconstrained (thisset))
2763 (FLG_EVALORDERUNCON,
2765 ("Unconstrained functions used in arguments %d (%q) "
2766 "and %d (%s) may modify "
2767 "or use global state in undefined way: %s(%q)",
2769 sRefSet_unparseUnconstrainedPlain (otheruses),
2771 sRef_unconstrainedName (thisset),
2772 exprNode_unparse (f),
2773 exprNodeList_unparse (args)),
2781 ("Argument %d modifies %q, used by argument %d "
2782 "(order of evaluation of actual parameters is "
2783 "undefined): %s(%q)",
2784 argno, sRef_unparse (thisset), thisargno,
2785 exprNode_unparse (f), exprNodeList_unparse (args)),
2791 sRefSet othersets = jl->sets;
2793 if (sRefSet_member (othersets, thisset))
2795 if (sRef_isUnconstrained (thisset))
2798 (FLG_EVALORDERUNCON,
2800 ("Unconstrained functions used in "
2801 "arguments %d (%q) and %d (%s) may modify "
2802 "or use global state in undefined way: %s(%q)",
2804 sRefSet_unparseUnconstrainedPlain (othersets),
2806 sRef_unconstrainedName (thisset),
2807 exprNode_unparse (f), exprNodeList_unparse (args)),
2815 ("Argument %d modifies %q, set by argument %d (order of"
2816 " evaluation of actual parameters is undefined): %s(%q)",
2817 argno, sRef_unparse (thisset), thisargno,
2818 exprNode_unparse (f), exprNodeList_unparse (args)),
2825 /*@noaccess exprNodeList@*/
2826 } end_sRefSet_realElements;
2831 checkSequencing (exprNode f, exprNodeList args)
2833 if (exprNodeList_size (args) > 1)
2838 /*@access exprNodeList*/
2840 for (i = 0; i < args->nelements; i++)
2842 el = args->elements[i];
2844 if (!exprNode_isError (el))
2846 checkSequencingOne (f, args, el, i + 1);
2849 /*@noaccess exprNodeList*/
2854 ** requires le = exprNode_getUentry (f)
2858 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2859 uentry le, exprNodeList args,
2860 /*@notnull@*/ exprNode ret, int specialArgs)
2862 bool isSpec = FALSE;
2863 bool hasMods = FALSE;
2865 globSet usesGlobs = globSet_undefined;
2866 sRefSet mods = sRefSet_undefined;
2867 bool freshMods = FALSE;
2868 uentryList params = uentryList_undefined;
2870 DPRINTF (("Check glob mods: %s", exprNode_unparse (ret)));
2873 ** check globals and modifies
2878 if (!uentry_isValid (le))
2880 ctype fr = ctype_realType (f->typ);
2882 if (ctype_isFunction (fr))
2884 params = ctype_argsFunction (fr);
2888 params = uentryList_missingParams;
2891 if (!context_getFlag (FLG_MODNOMODS)
2892 && !context_getFlag (FLG_GLOBUNSPEC))
2894 checkUnspecCall (f, params, args);
2900 fname = uentry_rawName (le);
2904 if (uentry_isFunction (le))
2906 params = uentry_getParams (le);
2907 mods = uentry_getMods (le);
2908 hasMods = uentry_hasMods (le);
2909 usesGlobs = uentry_getGlobs (le);
2910 isSpec = uentry_isSpecified (le);
2912 else /* not a function */
2914 ctype ct = ctype_realType (uentry_getType (le));
2916 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2917 ("checkModGlobs: uentry not a function: %s",
2918 uentry_unparse (le)));
2920 params = ctype_argsFunction (ct);
2921 return; /*@32 ! remove this? */
2930 globSet_allElements (usesGlobs, el)
2932 if (sRef_isValid (el))
2934 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2936 context_usedGlobal (el);
2937 exprNode_checkUse (f, el, f->loc);
2939 if (context_checkInternalUse ())
2941 if (!context_globAccess (el))
2943 if (sRef_isSystemState (el)
2944 && !context_getFlag (FLG_MODFILESYSTEM))
2953 ("Called procedure %s may access %q, but "
2954 "globals list does not include globals %s",
2955 exprNode_unparse (f),
2957 cstring_makeLiteralTemp (sRef_isInternalState (el)
2965 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2971 uentry gle = sRef_getUentry (el);
2972 sRef sr = sRef_updateSref (el);
2974 if (sRef_isUndefGlob (el))
2976 sRef_setDefined (sr, f->loc);
2977 exprNode_checkSet (f, sr);
2985 if (sRef_isAllocated (el))
2987 exprNode_checkSet (f, sr);
2991 if (sRef_isStateUndefined (sr))
2996 ("%s %q used by function undefined before call: %s",
2997 sRef_getScopeName (sr),
2999 exprNode_unparse (f)),
3001 sRef_setDefined (sr, f->loc);
3003 exprNode_checkUse (f, sr, f->loc);
3006 checkGlobUse (gle, TRUE, f);
3009 if (sRef_isKilledGlob (el))
3011 sRef_kill (sr, f->loc);
3012 context_usedGlobal (sr);
3016 } end_globSet_allElements;
3022 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
3024 sRefSet smods = sRefSet_undefined;
3027 ** NEED to check for modifies anything
3031 ** check each sRef that called function modifies (ml), is
3037 sRefSet_allElements (mods, s) /* s is something which may be modified */
3039 DPRINTF (("Check modify: %s", sRef_unparse (s)));
3041 if (sRef_isKindSpecial (s))
3043 if (sRef_isSpecInternalState (s))
3045 if (context_getFlag (FLG_MODINTERNALSTRICT))
3047 exprNode_checkCallModifyVal (s, args, f, ret);
3051 sRefSet mmods = context_modList ();
3053 sRefSet_allElements (mmods, el)
3055 if (sRef_isInternalState (el))
3057 sRef_setModified (el);
3059 } end_sRefSet_allElements ;
3064 exprNode_checkCallModifyVal (s, args, f, ret);
3069 sRef rb = sRef_getRootBase (s);
3071 if (sRef_isFileOrGlobalScope (rb))
3073 context_usedGlobal (rb);
3076 if (sRef_isFileStatic (s)
3077 && !fileId_equal (fileloc_fileId (f->loc),
3078 fileloc_fileId (uentry_whereDefined (le))))
3080 smods = sRefSet_insert (smods, s);
3084 exprNode_checkCallModifyVal (s, args, f, ret);
3087 } end_sRefSet_allElements;
3092 ** Static elements in modifies set can have nasty consequences.
3093 ** (I think...have not been able to reproduce a possible bug.)
3096 if (!sRefSet_isDefined (smods))
3098 mods = sRefSet_newCopy (mods);
3101 sRefSet_allElements (smods, el)
3103 bool res = sRefSet_delete (mods, el);
3106 } end_sRefSet_allElements;
3108 sRefSet_free (smods);
3113 else if (sRefSet_isDefined (mods))
3114 { /* just check observers */
3117 sRefSet_allElements (mods, s) /* s is something which may be modified */
3119 sRef rb = sRef_getRootBase (s);
3123 if (sRef_isParam (rb))
3125 sRef b = sRef_fixBaseParam (s, args);
3127 if (sRef_isObserver (b))
3129 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
3133 message ("Function call may modify observer%q: %s",
3134 sRef_unparsePreOpt (b), exprNode_unparse (e)),
3137 sRef_showExpInfo (b);
3141 } end_sRefSet_allElements;
3145 if (!hasMods) /* no specified modifications */
3147 if (context_getFlag (FLG_MODOBSERVERUNCON))
3149 exprNodeList_elements (args, e)
3151 if (exprNode_isDefined (e))
3153 sRef s = exprNode_getSref (e);
3155 if (sRef_isObserver (s)
3156 && ctype_isMutable (sRef_getType (s)))
3159 (FLG_MODOBSERVERUNCON,
3161 ("Call to unconstrained function %s may modify observer%q: %s",
3162 exprNode_unparse (f),
3163 sRef_unparsePreOpt (s), exprNode_unparse (e)),
3166 sRef_showExpInfo (s);
3170 } end_exprNodeList_elements;
3175 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
3177 ret->uses = sRefSet_union (ret->uses, f->uses);
3178 ret->sets = sRefSet_union (ret->sets, f->sets);
3179 ret->msets = sRefSet_union (ret->msets, f->msets);
3184 ** Spurious errors reported, because splint can't tell
3185 ** mods must be fresh if freshMods is true.
3188 /*@i@*/ sRefSet_free (mods);
3194 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
3196 if (uentry_isVar (glob))
3198 if (context_inFunctionLike ())
3200 sRef sr = uentry_getSref (glob);
3202 context_usedGlobal (sr);
3204 if (context_checkGlobUse (glob))
3206 if (!context_globAccess (sr))
3212 message ("Called procedure %s may access %s %q",
3213 exprNode_unparse (e),
3214 sRef_unparseScope (sr),
3215 uentry_getName (glob)),
3222 message ("Undocumented use of %s %s",
3223 sRef_unparseScope (sr),
3224 exprNode_unparse (e)),
3233 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
3238 reflectEnsuresClause (exprNode ret, uentry le, exprNode f, exprNodeList args)
3240 DPRINTF (("Reflect ensures clause: %s(%s) / %s / %s",
3241 exprNode_unparse (f), exprNodeList_unparse (args),
3242 uentry_unparseFull (le),
3243 stateClauseList_unparse (uentry_getStateClauseList (le))));
3245 if (uentry_isValid (le) && uentry_isFunction (le))
3247 stateClauseList sclauses = uentry_getStateClauseList (le);
3249 if (stateClauseList_isDefined (sclauses))
3251 DPRINTF (("Reflect ensures: %s / %s / %s",
3252 uentry_unparse (le),
3253 exprNode_unparse (f), exprNodeList_unparse (args)));
3255 stateClauseList_elements (sclauses, cl)
3257 if (stateClause_hasEnsures (cl))
3259 /* Same in usymtab.c:1904 */
3260 if (stateClause_setsMetaState (cl))
3262 qual q = stateClause_getMetaQual (cl);
3263 annotationInfo ainfo = qual_getAnnotationInfo (q);
3264 metaStateInfo minfo = annotationInfo_getState (ainfo);
3265 cstring key = metaStateInfo_getName (minfo);
3266 int mvalue = annotationInfo_getValue (ainfo);
3268 sRefSet osrs = sRefSet_undefined;
3271 if (stateClause_isGlobal (cl))
3273 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3278 srs = stateClause_getRefs (cl);
3281 DPRINTF (("Reflect ensures clause: %s", stateClause_unparse (cl)));
3284 DPRINTF (("Sets meta state! %s", stateClause_unparse (cl)));
3286 sRefSet_elements (srs, sel)
3290 if (sRef_isResult (sRef_getRootBase (sel)))
3292 s = exprNode_getSref (ret);
3296 s = sRef_fixBaseParam (sel, args);
3299 DPRINTF (("Reflecting state clause on: %s / %s",
3300 sRef_unparse (sel), sRef_unparse (s)));
3302 sRef_setMetaStateValueComplete (s, key, mvalue, exprNode_loc (f));
3303 } end_sRefSet_elements;
3305 sRefSet_free (osrs);
3309 sRefSet srs = stateClause_getRefs (cl);
3310 sRefModVal modf = stateClause_getEnsuresFunction (cl);
3311 int eparam = stateClause_getStateParameter (cl);
3313 llassert (modf != NULL);
3315 DPRINTF (("Reflect after clause: %s / %s",
3316 stateClause_unparse (cl),
3317 sRefSet_unparse (srs)));
3319 sRefSet_elements (srs, sel)
3323 DPRINTF (("elements: %s", sRef_unparse (sel)));
3324 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3326 if (sRef_isResult (sRef_getRootBase (sel)))
3328 DPRINTF (("Fix base: %s / %s",
3329 sRef_unparse (sel), sRef_unparse (exprNode_getSref (ret))));
3330 s = sRef_fixBase (sel, exprNode_getSref (ret));
3331 DPRINTF (("==> %s", sRef_unparseFull (s)));
3335 s = sRef_fixBaseParam (sel, args);
3338 DPRINTF (("elements: %s", sRef_unparse (s)));
3339 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3341 DPRINTF (("Reflecting state clause on: %s / %s",
3342 sRef_unparseFull (sel), sRef_unparseFull (s)));
3344 /* evans 2001-08-24 - added aliasSetCompleteParam */
3345 sRef_aliasSetCompleteParam (modf, s, eparam, exprNode_loc (f));
3347 DPRINTF (("After reflecting state clause on: %s / %s",
3348 sRef_unparseFull (sel), sRef_unparseFull (s)));
3349 } end_sRefSet_elements;
3352 } end_stateClauseList_elements ;
3355 DPRINTF (("Here: %s / %s",
3356 uentry_unparseFull (le),
3357 bool_unparse (uentry_hasMetaStateEnsures (le))));
3359 if (uentry_hasMetaStateEnsures (le))
3361 fileloc loc = exprNode_loc (f);
3363 metaStateConstraintList mscl = uentry_getMetaStateEnsures (le);
3365 metaStateConstraintList_elements (mscl, msc)
3367 metaStateSpecifier msspec = metaStateConstraint_getSpecifier (msc);
3368 metaStateInfo msinfo = metaStateSpecifier_getMetaStateInfo (msspec);
3369 metaStateExpression msexpr = metaStateConstraint_getExpression (msc);
3370 cstring key = metaStateInfo_getName (msinfo);
3371 sRef mlsr = metaStateSpecifier_getSref (msspec);
3373 sRef lastref = sRef_undefined;
3374 stateValue sval = stateValue_undefined;
3376 DPRINTF (("Meta state constraint for %s: %s", uentry_unparse (le),
3377 metaStateConstraint_unparse (msc)));
3378 DPRINTF (("Matches left: %s", sRef_unparseDebug (mlsr)));
3380 if (sRef_isResult (sRef_getRootBase (mlsr)))
3382 s = exprNode_getSref (ret);
3386 s = sRef_fixBaseParam (mlsr, args);
3389 DPRINTF (("Setting state: %s", sRef_unparseFull (s)));
3391 while (metaStateExpression_isDefined (msexpr))
3393 metaStateSpecifier ms = metaStateExpression_getSpecifier (msexpr);
3394 metaStateInfo msi = metaStateSpecifier_getMetaStateInfo (ms);
3397 DPRINTF (("Check expression: %s", metaStateExpression_unparse (msexpr)));
3399 if (metaStateExpression_isMerge (msexpr))
3401 msexpr = metaStateExpression_getRest (msexpr);
3405 msexpr = metaStateExpression_undefined;
3408 if (metaStateInfo_isDefined (msi))
3410 /* Must match lhs state */
3411 llassert (metaStateInfo_equal (msinfo, msi));
3414 if (metaStateSpecifier_isElipsis (ms))
3417 ** For elipsis, we need to merge all the relevant elipsis parameters
3421 uentryList params = uentry_getParams (le);
3422 int paramno = uentryList_size (params) - 1;
3424 if (!uentry_isElipsisMarker (uentryList_getN (params, paramno)))
3428 message ("Ensures clauses uses ... for function without ... in parameter list: %q",
3429 uentry_getName (le)),
3430 uentry_whereLast (le));
3431 /*@innerbreak@*/ break;
3434 while (paramno < exprNodeList_size (args))
3436 exprNode arg = exprNodeList_getN (args, paramno);
3437 fs = exprNode_getSref (arg);
3438 DPRINTF (("Merge arg: %s", exprNode_unparse (arg)));
3440 /* cut and pasted... gack*/
3441 if (stateValue_isDefined (sval))
3443 /* Use combination table to merge old state value with new one: */
3444 stateValue tval = sRef_getMetaStateValue (fs, key);
3446 if (stateValue_isDefined (tval))
3448 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3449 cstring msg = cstring_undefined;
3450 int nval = stateCombinationTable_lookup (sctable,
3451 stateValue_getValue (sval),
3452 stateValue_getValue (tval),
3454 DPRINTF (("Combining: %s + %s -> %d",
3455 stateValue_unparseValue (sval, msinfo),
3456 stateValue_unparseValue (tval, msinfo),
3459 if (nval == stateValue_error)
3464 ("Attributes merged in ensures clause in states that "
3465 "cannot be combined (%q is %q, %q is %q)%q",
3466 sRef_unparse (lastref),
3467 stateValue_unparseValue (sval, msinfo),
3469 stateValue_unparseValue (tval, msinfo),
3470 cstring_isDefined (msg) ?
3471 message (": %s", msg) : cstring_undefined),
3474 sRef_showMetaStateInfo (fs, key);
3478 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3479 loc = exprNode_loc (arg);
3483 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3488 sval = sRef_getMetaStateValue (fs, key);
3493 if (stateValue_isError (sval))
3495 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3504 msr = metaStateSpecifier_getSref (ms);
3507 llassert (sRef_isParam (sRef_getRootBase (msr)));
3508 fs = sRef_fixBaseParam (msr, args);
3510 if (stateValue_isDefined (sval))
3512 /* Use combination table to merge old state value with new one: */
3513 stateValue tval = sRef_getMetaStateValue (fs, key);
3515 if (stateValue_isDefined (tval))
3517 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3518 cstring msg = cstring_undefined;
3519 int nval = stateCombinationTable_lookup (sctable,
3520 stateValue_getValue (sval),
3521 stateValue_getValue (tval),
3523 DPRINTF (("Combining: %s + %s -> %d",
3524 stateValue_unparseValue (sval, msinfo),
3525 stateValue_unparseValue (tval, msinfo),
3528 if (nval == stateValue_error)
3533 ("Attributes merged in ensures clause in states that "
3534 "cannot be combined (%q is %q, %q is %q)%q",
3535 sRef_unparse (lastref),
3536 stateValue_unparseValue (sval, msinfo),
3538 stateValue_unparseValue (tval, msinfo),
3539 cstring_isDefined (msg)
3540 ? message (": %s", msg) : cstring_undefined),
3543 sRef_showMetaStateInfo (fs, key);
3547 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3551 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3556 sval = sRef_getMetaStateValue (fs, key);
3561 if (stateValue_isError (sval))
3563 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3568 DPRINTF (("Setting: %s:%s <- %s", sRef_unparse (s), key, stateValue_unparse (sval)));
3570 if (stateValue_isDefined (sval))
3572 sRef_setMetaStateValueComplete (s, key, stateValue_getValue (sval), loc);
3576 DPRINTF (("Undefined state: %s", cstring_toCharsSafe (sRef_unparse (s))));
3578 } end_metaStateConstraintList_elements ;
3580 metaStateConstraintList_free (mscl);
3586 checkRequiresClause (uentry le, exprNode f, exprNodeList args)
3588 DPRINTF (("Check requires clause: %s(%s) / %s / %s",
3589 exprNode_unparse (f), exprNodeList_unparse (args),
3590 uentry_unparseFull (le),
3591 stateClauseList_unparse (uentry_getStateClauseList (le))));
3593 if (uentry_isValid (le) && uentry_isFunction (le))
3595 stateClauseList sclauses = uentry_getStateClauseList (le);
3597 if (stateClauseList_isDefined (sclauses))
3599 DPRINTF (("Check requires: %s / %s / %s",
3600 uentry_unparse (le),
3601 exprNode_unparse (f), exprNodeList_unparse (args)));
3603 stateClauseList_elements (sclauses, cl)
3605 DPRINTF (("Check clause: %s / %s",
3606 stateClause_unparse (cl),
3607 bool_unparse (stateClause_hasRequires (cl))));
3609 if (stateClause_hasRequires (cl))
3611 sRefSet osrs = sRefSet_undefined;
3614 if (stateClause_isGlobal (cl))
3616 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3621 srs = stateClause_getRefs (cl);
3624 DPRINTF (("Refs: %s", sRefSet_unparse (srs)));
3626 if (stateClause_setsMetaState (cl))
3628 qual q = stateClause_getMetaQual (cl);
3629 annotationInfo ainfo = qual_getAnnotationInfo (q);
3630 metaStateInfo minfo = annotationInfo_getState (ainfo);
3631 cstring key = metaStateInfo_getName (minfo);
3632 int mvalue = annotationInfo_getValue (ainfo);
3634 DPRINTF (("Requires meta state! %s = %d", key, mvalue));
3636 sRefSet_elements (srs, sel)
3638 sRef s = sRef_fixBaseParam (sel, args);
3640 if (sRef_isResult (sRef_getRootBase (sel)))
3646 DPRINTF (("Checking state clause on: %s / %s / %s = %d",
3647 sRef_unparseFull (sel), sRef_unparseFull (s),
3650 if (!sRef_checkMetaStateValue (s, key, mvalue))
3652 DPRINTF (("HERE: %s", sRef_unparse (s)));
3656 ("Requires clause of called function %q not satisfied%q (state is %q): %q",
3657 uentry_getName (le),
3658 sRef_isGlobalMarker (s)
3660 : message (" by %q", sRef_unparse (s)),
3661 stateValue_unparseValue (sRef_getMetaStateValue (s, key),
3663 stateClause_unparse (cl)),
3666 sRef_showAliasInfo (s);
3670 DPRINTF (("Error supressed!"));
3671 DPRINTF (("Loc: %s", fileloc_unparse (exprNode_loc (f))));
3672 DPRINTF (("Context supress: %s",
3673 bool_unparse (context_suppressFlagMsg (FLG_STATETRANSFER, exprNode_loc (f)))));
3677 } end_sRefSet_elements;
3681 sRefModVal modf = stateClause_getRequiresBodyFunction (cl);
3682 int eparam = stateClause_getStateParameter (cl);
3684 DPRINTF (("Reflect after clause: %s / %s",
3685 stateClause_unparse (cl),
3686 sRefSet_unparse (srs)));
3688 llassert (modf != NULL);
3690 sRefSet_elements (srs, sel)
3694 DPRINTF (("elements: %s", sRef_unparse (sel)));
3695 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3697 s = sRef_fixBaseParam (sel, args);
3699 DPRINTF (("elements: %s", sRef_unparse (s)));
3700 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3702 if (sRef_isResult (sRef_getRootBase (sel)))
3704 ; /*@i423 what do we do about results */
3708 DPRINTF (("Reflecting state clause on: %s / %s",
3709 sRef_unparse (sel), sRef_unparse (s)));
3711 modf (s, eparam, exprNode_loc (f));
3713 } end_sRefSet_elements;
3716 sRefSet_free (osrs);
3718 } end_stateClauseList_elements ;
3723 static /*@only@*/ exprNode
3724 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
3725 ctype t, /*@keep@*/ exprNodeList args)
3727 /* requires f is a non-error exprNode, with type function */
3728 cstring fname = exprNode_unparse (f);
3729 uentry le = exprNode_getUentry (f);
3730 exprNode ret = exprNode_createPartialCopy (f);
3735 DPRINTF (("Call: %s %s",exprNode_unparse (f), exprNodeList_unparse (args)));
3737 ret->typ = ctype_getReturnType (t);
3738 ret->kind = XPR_CALL;
3740 ret->edata = exprData_makeCall (f, args);
3743 ** Order of these steps is very important!
3745 ** Must check for argument dependencies before messing up uses and sets.
3748 if (context_getFlag (FLG_EVALORDER))
3750 exprNodeList_elements (args, current)
3752 if (exprNode_isDefined (current))
3754 exprNode_addUse (current, current->sref);
3756 } end_exprNodeList_elements;
3758 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3760 checkSequencing (f, args);
3763 exprNodeList_elements (args, current)
3765 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3767 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3769 } end_exprNodeList_elements ;
3772 special = checkArgs (le, f, t, args, ret);
3773 checkGlobMods (f, le, args, ret, special);
3774 checkRequiresClause (le, f, args);
3777 if (uentry_isValid (le)
3778 && (uentry_isFunction (le)
3779 || (uentry_isVariable (le)
3780 && ctype_isFunction (uentry_getType (le)))))
3782 exitkind exk = uentry_getExitCode (le);
3784 /* f->typ is already set to the return type */
3786 DPRINTF (("Function: %s", uentry_unparseFull (le)));
3787 ret->sref = uentry_returnedRef (le, args, exprNode_loc (f));
3788 DPRINTF (("Returned: %s / %s",
3789 uentry_unparseFull (le),
3790 sRef_unparseFull (ret->sref)));
3792 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3794 qual nullPred = uentry_nullPred (le);
3796 if (qual_isTrueNull (nullPred))
3798 exprNode arg = exprNodeList_head (args);
3800 if (exprNode_isDefined (arg))
3802 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3805 else if (qual_isFalseNull (nullPred))
3807 exprNode arg = exprNodeList_head (args);
3809 if (exprNode_isDefined (arg))
3811 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3816 llassert (qual_isUnknown (nullPred));
3820 if (exitkind_isConditionalExit (exk))
3824 ** if (arg0) then { exit! } else { ; }
3826 ** if (arg0) then { ; } else { exit! }
3831 llassert (!exprNodeList_isEmpty (args));
3832 firstArg = exprNodeList_head (args);
3834 if (exprNode_isDefined (firstArg)
3835 && !guardSet_isEmpty (firstArg->guards))
3837 usymtab_trueBranch (guardSet_undefined);
3838 usymtab_altBranch (guardSet_undefined);
3840 if (exitkind_isTrueExit (exk))
3842 usymtab_popBranches (firstArg,
3843 exprNode_makeMustExit (),
3845 TRUE, TRUEEXITCLAUSE);
3849 usymtab_popBranches (firstArg,
3851 exprNode_makeMustExit (),
3852 TRUE, FALSEEXITCLAUSE);
3856 ret->exitCode = XK_MAYEXIT;
3858 else if (exitkind_mustExit (exk))
3860 ret->exitCode = XK_MUSTEXIT;
3862 else if (exitkind_couldExit (exk))
3864 ret->exitCode = XK_MAYEXIT;
3871 if (cstring_equalLit (fname, "exit"))
3873 if (exprNodeList_size (args) == 1)
3875 exprNode arg = exprNodeList_head (args);
3877 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3879 long int val = multiVal_forceInt (exprNode_getValue (arg));
3886 ("Argument to exit has implementation defined behavior: %s",
3887 exprNode_unparse (arg)),
3888 exprNode_loc (arg));
3896 ret->sref = sRef_undefined;
3897 exprNode_checkSetAny (ret, uentry_rawName (le));
3900 DPRINTF (("Before reflect: %s", sRef_unparseFull (ret->sref)));
3901 DPRINTF (("Reflect: %s", uentry_unparseFull (le)));
3902 reflectEnsuresClause (ret, le, f, args);
3905 DPRINTF (("Here: %s", sRef_unparseFull (ret->sref)));
3910 ** this is yucky! should keep the uentry as part of exprNode!
3913 uentry exprNode_getUentry (exprNode e)
3915 if (exprNode_isError (e))
3917 return uentry_undefined;
3921 cstring s = exprNode_rootVarName (e);
3922 uentry ue = usymtab_lookupSafe (s);
3929 ** Returns true iff e1 and e2 are both exactly the same storage
3933 static bool exprNode_sameStorage (exprNode e1, exprNode e2)
3935 sRef s1 = exprNode_getSref (e1);
3936 sRef s2 = exprNode_getSref (e2);
3938 return (sRef_realSame (s1, s2));
3942 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3944 exprNode ret = exprNode_createPlain (ctype_unknown);
3946 ret->kind = XPR_INITBLOCK;
3947 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3948 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3954 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3959 usymtab_checkAllValid ();
3962 if (exprNode_isUndefined (f))
3965 exprNodeList_free (args);
3966 return exprNode_undefined;
3969 t = exprNode_getType (f);
3971 if (sRef_isLocalVar (f->sref))
3973 exprNode_checkUse (f, f->sref, f->loc);
3975 if (sRef_possiblyNull (f->sref))
3977 if (!usymtab_isGuarded (f->sref))
3979 if (optgenerror (FLG_NULLDEREF,
3980 message ("Function call using %s pointer %q",
3981 sRef_nullMessage (f->sref),
3982 sRef_unparse (f->sref)),
3985 sRef_showNullInfo (f->sref);
3986 sRef_setNullError (f->sref);
3994 if (ctype_isRealFunction (t))
3996 exprNode ret = functionCallSafe (f, t, args);
4000 else if (ctype_isUnknown (t))
4002 exprNode ret = exprNode_createPartialCopy (f);
4008 exprNodeList_elements (args, current)
4010 if (exprNode_isDefined (current))
4012 exprNode_checkUse (ret, current->sref, ret->loc);
4015 ** also, anything derivable from current->sref may be used
4018 exprNode_addUse (ret, sRef_makeDerived (current->sref));
4019 exprNode_mergeUSs (ret, current);
4021 } end_exprNodeList_elements;
4023 ret->edata = exprData_makeCall (f, args);
4024 ret->kind = XPR_CALL;
4026 tstring = cstring_copy (exprNode_unparse (f));
4028 cstring_markOwned (tstring);
4029 exprNode_checkSetAny (ret, tstring);
4035 voptgenerror (FLG_TYPE,
4036 message ("Call to non-function (type %t): %s", t,
4037 exprNode_unparse (f)),
4040 exprNodeList_free (args);
4042 return (exprNode_makeError ());
4047 exprNode_fieldAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
4048 /*@only@*/ cstring f)
4050 exprNode ret = exprNode_createPartialCopy (s);
4052 ret->kind = XPR_FACCESS;
4054 if (exprNode_isError (s))
4056 ret->edata = exprData_makeField (s, f);
4061 ctype t = exprNode_getType (s);
4062 ctype tr = ctype_realType (t);
4064 checkMacroParen (s);
4066 ret->edata = exprData_makeField (s, f);
4068 if (ctype_isStructorUnion (tr))
4070 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
4072 if (uentry_isUndefined (tf))
4074 voptgenerror (FLG_TYPE,
4075 message ("Access non-existent field %s of %t: %s", f, t,
4076 exprNode_unparse (ret)),
4078 /*! cstring_free (f); */ /* evans 2001-03-25 self-detect */
4083 uentry_setUsed (tf, exprNode_loc (ret));
4085 ret->typ = uentry_getType (tf);
4086 checkSafeUse (ret, s->sref);
4088 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
4089 /*!? exprNode_free (s); */ /* evans 2001-03-25 self-detect */
4093 else /* isStructorUnion */
4095 if (ctype_isRealAbstract (tr))
4099 message ("Access field of abstract type (%t): %s.%s",
4100 t, exprNode_unparse (s), f),
4102 ret->typ = ctype_unknown;
4106 if (ctype_isKnown (tr))
4111 ("Access field of non-struct or union (%t): %s.%s",
4112 t, exprNode_unparse (s), f),
4115 ret->typ = ctype_unknown;
4119 cstring sn = cstring_copy (f);
4121 checkSafeUse (ret, s->sref);
4122 cstring_markOwned (sn);
4123 ret->sref = sRef_makeField (s->sref, sn);
4135 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ lltok dot,
4136 /*@only@*/ cstring f)
4138 exprNode res = exprNode_fieldAccessAux (s, lltok_getLoc (dot), f);
4144 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
4146 exprNode ret = exprNode_createPartialCopy (e);
4148 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
4149 ret->kind = XPR_PARENS;
4150 ret->edata = exprData_makeUop (e, lpar);
4152 if (!exprNode_isError (e))
4154 ret->exitCode = e->exitCode;
4155 ret->canBreak = e->canBreak;
4156 ret->mustBreak = e->mustBreak;
4157 ret->isJumpPoint = e->isJumpPoint;
4158 ret->sref = e->sref;
4165 exprNode_arrowAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
4166 /*@only@*/ cstring f)
4168 exprNode ret = exprNode_createPartialCopy (s);
4170 ret->edata = exprData_makeField (s, f);
4171 ret->kind = XPR_ARROW;
4173 if (exprNode_isError (s))
4179 ctype t = exprNode_getType (s);
4180 ctype tr = ctype_realType (t);
4182 checkMacroParen (s);
4184 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
4186 if (ctype_isRealPointer (tr))
4188 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
4190 if (ctype_isStructorUnion (b))
4192 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4194 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
4196 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
4200 message ("Arrow access from %s pointer%q: %s",
4201 sRef_nullMessage (s->sref),
4202 sRef_unparsePreOpt (s->sref),
4203 exprNode_unparse (ret)),
4206 sRef_showNullInfo (s->sref);
4207 sRef_setNullError (s->sref);
4212 if (uentry_isUndefined (fentry))
4216 message ("Access non-existent field %s of %t: %s",
4217 f, t, exprNode_unparse (ret)),
4219 ret->typ = ctype_unknown;
4225 ** was safeUse: shouldn't be safe!
4228 ** rec must be defined,
4229 ** *rec must be allocated
4230 ** rec->field need only be defined it if is an rvalue
4233 uentry_setUsed (fentry, exprNode_loc (ret));
4234 ret->typ = uentry_getType (fentry);
4236 exprNode_checkUse (ret, s->sref, s->loc);
4238 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
4239 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4243 else /* Pointer to something that is not a struct or union*/
4245 if (ctype_isRealAbstract (tr))
4247 ctype xrt = ctype_forceRealType (tr);
4251 message ("Arrow access field of abstract type (%t): %s->%s",
4252 t, exprNode_unparse (s), f),
4256 ** Set the state correctly, as if the abstraction is broken.
4259 if (ctype_isRealPointer (xrt) &&
4260 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
4261 ctype_isStructorUnion (b)))
4263 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4264 ret->typ = uentry_getType (fentry);
4265 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4269 ret->typ = ctype_unknown;
4270 ret->sref = sRef_undefined;
4273 else /* not a struct, union or abstract */
4275 if (ctype_isUnknown (tr)) {
4276 cstring sn = cstring_copy (f);
4278 DPRINTF (("Here: %s", exprNode_unparse (s)));
4280 exprNode_checkUse (ret, s->sref, s->loc);
4281 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4283 cstring_markOwned (sn);
4284 ret->sref = sRef_makeArrow (s->sref, sn);
4286 ret->kind = XPR_ARROW;
4291 message ("Arrow access field of non-struct or union "
4292 "pointer (%t): %s->%s",
4293 t, exprNode_unparse (s), f),
4296 ret->typ = ctype_unknown;
4297 ret->sref = sRef_undefined;
4302 else /* its not a pointer */
4304 if (!ctype_isUnknown (tr))
4308 message ("Arrow access of non-pointer (%t): %s->%s",
4309 t, exprNode_unparse (s), f),
4312 ret->typ = ctype_unknown;
4313 ret->sref = sRef_undefined;
4317 cstring sn = cstring_copy (f);
4319 DPRINTF (("Here: %s", exprNode_unparse (s)));
4321 exprNode_checkUse (ret, s->sref, s->loc);
4322 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4324 cstring_markOwned (sn);
4325 ret->sref = sRef_makeArrow (s->sref, sn);
4327 ret->kind = XPR_ARROW;
4338 exprNode_arrowAccess (/*@only@*/ exprNode s,
4339 /*@only@*/ lltok arrow,
4340 /*@only@*/ cstring f)
4342 exprNode res = exprNode_arrowAccessAux (s, lltok_getLoc (arrow), f);
4348 ** only postOp's in C: i++ and i--
4352 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4354 /* check modification also */
4355 /* cstring opname = lltok_unparse (op);*/
4357 exprNode ret = exprNode_createPartialCopy (e);
4359 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4360 ret->kind = XPR_POSTOP;
4361 ret->edata = exprData_makeUop (e, op);
4363 if (!exprNode_isDefined (e))
4368 checkMacroParen (e);
4370 exprNode_checkUse (ret, e->sref, e->loc);
4371 exprNode_checkSet (ret, e->sref);
4373 t = exprNode_getType (e);
4375 if (sRef_isUnsafe (e->sref))
4377 voptgenerror (FLG_MACROPARAMS,
4378 message ("Operand of %s is macro parameter (non-functional): %s%s",
4379 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
4381 sRef_makeSafe (e->sref);
4382 sRef_makeSafe (ret->sref);
4385 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
4391 if (ctype_isRealAbstract (t))
4393 if (ctype_isRealNumAbstract (t)) {
4394 ; /* Allow operations on numabstract types */
4398 message ("Operand of %s is abstract type (%t): %s",
4399 lltok_unparse (op), t, exprNode_unparse (e)),
4407 message ("Operand of %s is non-numeric (%t): %s",
4408 lltok_unparse (op), t, exprNode_unparse (e)),
4411 ret->typ = ctype_unknown;
4414 /* if (ctype_isZero (t)) e->typ = ctype_int; */
4416 exprNode_checkModify (e, ret);
4418 /* added 7/11/2000 D.L */
4420 /* updateEnvironmentForPostOp (e); */
4422 /* start modifications */
4423 /* added by Seejo on 4/16/2000 */
4425 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4427 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4429 ret->sref = sRef_copy (e->sref);
4432 if (lltok_getTok (op) == INC_OP) {
4433 if (sRef_getSize(e->sref) > 0) {
4435 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4437 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4438 /* Assumption: there is only 1 \0 in the buffer */
4439 /* This will not be correct if there are 2 \0's in the buffer */
4440 sRef_setNotNullTerminatedState(ret->sref);
4441 sRef_resetLen(ret->sref);
4443 sRef_setNullTerminatedState(ret->sref);
4444 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4446 if (sRef_isNullTerminated (ret->sref))
4447 printf ("ret->sref is Null Terminated\n");
4448 else if (sRef_isPossiblyNullTerminated (ret->sref))
4449 printf ("ret->sref is Possibly Null Terminated\n");
4450 else if (sRef_isNotNullTerminated (ret->sref))
4451 printf ("ret->sref is Not Null Terminated\n");
4458 if (lltok_getTok (op) == DEC_OP) {
4459 if (sRef_getSize(e->sref) >= 0) {
4460 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4461 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4465 /* end modifications */
4471 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4473 bool checkMod = FALSE;
4475 int opid = lltok_getTok (op);
4476 exprNode ret = exprNode_createSemiCopy (e);
4478 exprNode_copySets (ret, e);
4480 multiVal_free (ret->val);
4481 ret->val = multiVal_undefined;
4482 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4483 ret->kind = XPR_PREOP;
4484 ret->edata = exprData_makeUop (e, op);
4486 if (exprNode_isError (e))
4491 checkMacroParen (e);
4493 te = exprNode_getType (e);
4494 tr = ctype_realType (te);
4496 if (opid != TAMPERSAND)
4498 exprNode_checkUse (ret, e->sref, e->loc);
4500 if (ctype_isRealAbstract (tr)
4501 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
4503 if (ctype_isRealNumAbstract (tr))
4505 ; /* no warning for numabstract types */
4509 if (optgenerror (FLG_ABSTRACT,
4510 message ("Operand of %s is abstract type (%t): %s",
4511 lltok_unparse (op), tr,
4512 exprNode_unparse (ret)),
4515 tr = te = ctype_unknown;
4516 ret->typ = ctype_unknown;
4517 sRef_setNullError (e->sref);
4526 case DEC_OP: /* should also check modification! */
4527 if (sRef_isMacroParamRef (e->sref))
4531 message ("Operand of %s is macro parameter (non-functional): %s",
4532 lltok_unparse (op), exprNode_unparse (ret)),
4537 exprNode_checkSet (ret, e->sref);
4540 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
4545 if (context_msgStrictOps ())
4549 message ("Operand of %s is non-numeric (%t): %s",
4550 lltok_unparse (op), te, exprNode_unparse (ret)),
4553 ret->typ = ctype_int;
4556 /* start modifications */
4557 /* added by Seejo on 4/16/2000 */
4559 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4561 if ((sRef_isPossiblyNullTerminated (e->sref))
4562 || (sRef_isNullTerminated(e->sref))) {
4563 ret->sref = sRef_copy (e->sref);
4566 if (lltok_getTok (op) == INC_OP) {
4567 if (sRef_getSize(e->sref) > 0) {
4569 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4571 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4572 /* Assumption: there is only 1 \0 in the buffer */
4573 /* This will not be correct if there are 2 \0's in the buffer */
4574 sRef_setNotNullTerminatedState(ret->sref);
4575 sRef_resetLen (ret->sref);
4577 sRef_setNullTerminatedState(ret->sref);
4578 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4584 if (lltok_getTok (op) == DEC_OP) {
4585 if (sRef_getSize(e->sref) >= 0) {
4586 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4587 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4592 /* end modifications */
4599 if (ctype_isForceRealNumeric (&tr))
4603 ret->val = multiVal_invert (exprNode_getValue (e));
4607 ret->val = multiVal_copy (exprNode_getValue (e));
4612 if (context_msgStrictOps ())
4616 message ("Operand of %s is non-numeric (%t): %s",
4617 lltok_unparse (op), te, exprNode_unparse (ret)),
4621 ret->typ = ctype_int;
4625 case TEXCL: /* maybe this should be restricted */
4626 guardSet_flip (ret->guards);
4628 if (ctype_isRealBool (te) || ctype_isUnknown (te))
4634 if (ctype_isRealPointer (tr))
4636 if (sRef_isKnown (e->sref))
4638 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
4642 (FLG_BOOLOPS, FLG_PTRNEGATE,
4643 message ("Operand of %s is non-boolean (%t): %s",
4644 lltok_unparse (op), te, exprNode_unparse (ret)),
4651 message ("Operand of %s is non-boolean (%t): %s",
4652 lltok_unparse (op), te, exprNode_unparse (ret)),
4656 ret->typ = ctype_bool;
4661 if (ctype_isForceRealInt (&tr))
4666 if (context_msgStrictOps ())
4670 message ("Operand of %s is non-integer (%t): %s",
4671 lltok_unparse (op), te, exprNode_unparse (ret)),
4675 if (ctype_isInt (e->typ))
4681 ret->typ = ctype_int;
4687 ret->typ = ctype_makePointer (e->typ);
4689 if (sRef_isKnown (e->sref))
4691 ret->sref = sRef_makeAddress (e->sref);
4698 if (ctype_isAP (tr))
4700 ret->typ = ctype_baseArrayPtr (e->typ);
4704 if (ctype_isKnown (te))
4706 if (ctype_isFunction (te))
4712 message ("Dereference of function type (%t): %s",
4713 te, exprNode_unparse (ret)),
4718 voptgenerror (FLG_TYPE,
4719 message ("Dereference of non-pointer (%t): %s",
4720 te, exprNode_unparse (ret)),
4722 ret->typ = ctype_unknown;
4727 ret->typ = ctype_unknown;
4732 if (sRef_isKnown (e->sref))
4734 DPRINTF (("Checking possibly null: %s", sRef_unparseFull (e->sref)));
4736 if (sRef_possiblyNull (e->sref))
4738 DPRINTF (("Checking possibly null: %s", sRef_unparse (e->sref)));
4739 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
4743 message ("Dereference of %s pointer %q: %s",
4744 sRef_nullMessage (e->sref),
4745 sRef_unparse (e->sref),
4746 exprNode_unparse (ret)),
4749 sRef_showNullInfo (e->sref);
4750 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
4755 ret->sref = sRef_makePointer (e->sref);
4760 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
4765 exprNode_checkModify (e, ret);
4772 ** any reason to disallow sizeof (abstract type) ?
4776 ** used by both sizeof
4780 ctype sizeof_resultType (void)
4782 static ctype sizet = ctype_unknown;
4784 if (ctype_isUnknown (sizet))
4786 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
4788 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
4792 sizet = ctype_ulint;
4799 exprNode_sizeofType (/*@only@*/ qtype qt)
4801 exprNode ret = exprNode_create (sizeof_resultType ());
4802 ctype ct = qtype_getType (qt);
4804 ret->kind = XPR_SIZEOFT;
4805 ret->edata = exprData_makeSizeofType (qt);
4807 voptgenerror (FLG_SIZEOFTYPE,
4808 message ("Parameter to sizeof is type %s: %s",
4810 exprNode_unparse (ret)),
4817 exprNode_alignofType (/*@only@*/ qtype qt)
4819 exprNode ret = exprNode_create (sizeof_resultType ());
4820 ctype ct = qtype_getType (qt);
4822 ret->kind = XPR_ALIGNOFT;
4823 ret->edata = exprData_makeSizeofType (qt);
4825 voptgenerror (FLG_SIZEOFTYPE,
4826 message ("Parameter to alignof is type %s: %s",
4828 exprNode_unparse (ret)),
4834 exprNode exprNode_offsetof (qtype qt, cstringList s)
4836 exprNode ret = exprNode_create (sizeof_resultType ());
4837 ctype ct = qtype_getType (qt);
4839 ret->kind = XPR_OFFSETOF;
4840 ret->edata = exprData_makeOffsetof (qt, s);
4842 if (!ctype_isRealSU (ct))
4844 voptgenerror (FLG_TYPE,
4845 message ("First parameter to offsetof is not a "
4846 "struct or union type (type %s): %s",
4848 exprNode_unparse (ret)),
4855 cstringList_elements (s, el) {
4859 if (ctype_isUndefined (lt))
4863 else if (!ctype_isRealSU (lt))
4865 voptgenerror (FLG_TYPE,
4866 message ("Inner offsetof type is not a "
4867 "struct or union type (type %s before field %s): %s",
4868 ctype_unparse (lt), el,
4869 exprNode_unparse (ret)),
4875 fields = ctype_getFields (ctype_realType (lt));
4876 fld = uentryList_lookupField (fields, el);
4877 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4879 if (uentry_isUndefined (fld))
4881 if (ctype_equal (lt, ct)) {
4882 voptgenerror (FLG_TYPE,
4883 message ("Field %s in offsetof is not the "
4884 "name of a field of %s: %s",
4887 exprNode_unparse (ret)),
4890 voptgenerror (FLG_TYPE,
4891 message ("Deep field %s in offsetof is not the "
4892 "name of a field of %s: %s",
4895 exprNode_unparse (ret)),
4901 lt = uentry_getType (fld);
4904 } end_cstringList_elements;
4906 /* Should report error if its a bit field - behavior is undefined! */
4913 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4917 if (exprNode_isUndefined (e))
4919 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4920 ret->edata = exprData_makeSingle (e);
4921 ret->typ = sizeof_resultType ();
4922 ret->kind = XPR_SIZEOF;
4926 uentry u = exprNode_getUentry (e);
4928 ret = exprNode_createPartialCopy (e);
4929 ret->edata = exprData_makeSingle (e);
4931 ret->typ = sizeof_resultType ();
4932 ret->kind = XPR_SIZEOF;
4934 if (uentry_isValid (u)
4935 && uentry_isRefParam (u)
4936 && ctype_isRealArray (uentry_getType (u)))
4939 (FLG_SIZEOFFORMALARRAY,
4940 message ("Parameter to sizeof is an array-type function parameter: %s",
4941 exprNode_unparse (ret)),
4947 ** sizeof (x) doesn't "really" use x
4954 exprNode_alignofExpr (/*@only@*/ exprNode e)
4958 if (exprNode_isUndefined (e))
4960 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4964 ret = exprNode_createPartialCopy (e);
4967 ret->edata = exprData_makeSingle (e);
4968 ret->typ = sizeof_resultType ();
4969 ret->kind = XPR_ALIGNOF;
4972 ** sizeof (x) doesn't "really" use x
4979 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4985 if (exprNode_isError (e))
4989 return exprNode_undefined;
4992 checkMacroParen (e);
4994 c = qtype_getType (q);
4995 t = exprNode_getType (e);
4997 ret = exprNode_createPartialCopy (e);
4999 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
5001 ret->kind = XPR_CAST;
5002 ret->edata = exprData_makeCast (tok, e, q);
5004 ret->sref = sRef_copy (e->sref);
5006 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
5008 if (!sRef_isConst (e->sref))
5010 usymtab_addForceMustAlias (ret->sref, e->sref);
5013 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
5014 sRef_setTypeFull (ret->sref, c);
5015 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
5021 ** void * <-> abstract * (if FLG_ABSTVOIDP)
5022 ** abstract * <-> void * (if FLG_ABSTVOIDP)
5025 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
5027 /* evans 2002-07-19: added this warning */
5028 DPRINTF (("Checking: %s / %s", exprNode_unparse (ret), sRef_unparseFull (ret->sref)));
5029 if (sRef_isFresh (ret->sref))
5033 message ("New fresh storage %q(type %s) cast to void (not released): %s",
5034 sRef_unparseOpt (ret->sref),
5035 ctype_unparse (exprNode_getType (ret)),
5036 exprNode_unparse (ret)),
5037 exprNode_loc (ret));
5040 else if (ctype_isRealAP (c)) /* casting to array or pointer */
5042 ctype bc = ctype_getBaseType (c);
5043 ctype bt = ctype_getBaseType (t);
5044 ctype rt = ctype_realType (t);
5046 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
5047 && (ctype_isArrayPtr (rt)
5048 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
5052 message ("Cast from function pointer type (%t) to "
5053 "non-function pointer (%t): %s",
5054 c, t, exprNode_unparse (ret)),
5058 if (!ctype_isFunction (ctype_baseArrayPtr (c))
5059 && (ctype_isArrayPtr (rt)
5060 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
5064 message ("Cast from non-function pointer type (%t) to "
5065 "function pointer (%t): %s",
5066 c, t, exprNode_unparse (ret)),
5070 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
5071 !(ctype_isRealAbstract (bc)
5072 && context_hasAccess (ctype_typeId (bc))))
5074 ; /* okay to cast zero */
5078 if (ctype_isRealAbstract (bc)
5079 && !context_hasAccess (ctype_typeId (bc)))
5081 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
5085 message ("Cast to underlying abstract type %t: %s",
5086 c, exprNode_unparse (ret)),
5093 message ("Cast to underlying abstract type %t: %s",
5094 c, exprNode_unparse (ret)),
5099 if (ctype_isRealAbstract (bt)
5100 && !context_hasAccess (ctype_typeId (bt)))
5102 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
5106 message ("Cast from underlying abstract type %t: %s",
5107 t, exprNode_unparse (ret)),
5114 message ("Cast from underlying abstract type %t: %s",
5115 t, exprNode_unparse (ret)),
5123 ctype bt = ctype_realType (ctype_getBaseType (t));
5124 ctype bc = ctype_realType (ctype_getBaseType (c));
5126 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
5128 if (ctype_match (c, t))
5130 if (ctype_equal (c, t))
5134 message ("Redundant cast involving abstract type %t: %s",
5135 bt, exprNode_unparse (ret)),
5143 message ("Cast from abstract type %t: %s",
5144 bt, exprNode_unparse (ret)),
5149 if (ctype_isAbstract (bc)
5150 && !context_hasAccess (ctype_typeId (bc)))
5152 if (ctype_match (c, t))
5158 if (ctype_isNumAbstract (bc))
5160 if (exprNode_isNumLiteral (e))
5163 (FLG_NUMABSTRACTCAST,
5164 message ("Cast from literal to numabstract type %t: %s", bc,
5165 exprNode_unparse (ret)),
5172 message ("Cast to numabstract type %t: %s", bc,
5173 exprNode_unparse (ret)),
5179 DPRINTF (("No access to: %s / %d",
5180 ctype_unparse (bc), ctype_typeId (bc)));
5181 DPRINTF (("Context %s %s",
5182 bool_unparse (context_inFunctionLike ()),
5183 context_unparse ()));
5186 message ("Cast to abstract type %t: %s", bc,
5187 exprNode_unparse (ret)),
5194 if (ctype_isAbstract (c))
5196 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
5198 /* okay, cast exposed to abstract */
5199 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
5203 if (ctype_isVisiblySharable (t)
5204 && sRef_isExternallyVisible (e->sref)
5205 && !(ctype_isAbstract (t)
5206 && context_hasAccess (ctype_typeId (t))))
5210 message ("Cast to abstract type from externally visible "
5211 "mutable storage exposes rep of %s: %s",
5213 exprNode_unparse (e)),
5223 evaluationOrderUndefined (lltok op)
5225 int opid = lltok_getTok (op);
5227 return (opid != AND_OP && opid != OR_OP);
5230 static bool checkIntegral (/*@notnull@*/ exprNode e1,
5231 /*@notnull@*/ exprNode e2,
5232 /*@notnull@*/ exprNode ret,
5237 ctype te1 = exprNode_getType (e1);
5238 ctype te2 = exprNode_getType (e2);
5240 ctype tr1 = ctype_realishType (te1);
5241 ctype tr2 = ctype_realishType (te2);
5243 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
5249 if (context_msgStrictOps ())
5251 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
5253 if (ctype_sameName (te1, te2))
5257 message ("Operands of %s are non-integer (%t): %s",
5258 lltok_unparse (op), te1,
5259 exprNode_unparse (ret)),
5266 message ("Operands of %s are non-integers (%t, %t): %s",
5267 lltok_unparse (op), te1, te2,
5268 exprNode_unparse (ret)),
5272 else if (!ctype_isInt (tr1))
5276 message ("Left operand of %s is non-integer (%t): %s",
5277 lltok_unparse (op), te1, exprNode_unparse (ret)),
5281 /* !ctype_isInt (te2) */
5285 message ("Right operand of %s is non-integer (%t): %s",
5286 lltok_unparse (op), te2, exprNode_unparse (ret)),
5296 ** returns exprNode representing e1 op e2
5298 ** uses msg if there are errors
5299 ** can be used for both assignment ops and regular ops
5304 static /*@only@*/ /*@notnull@*/ exprNode
5305 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
5306 /*@keep@*/ lltok op)
5308 ctype te1, te2, tr1, tr2, tret;
5309 int opid = lltok_getTok (op);
5310 bool hasError = FALSE;
5313 if (exprNode_isError (e1))
5315 ret = exprNode_createPartialNVCopy (e2);
5319 ret = exprNode_createPartialNVCopy (e1);
5322 ret->val = multiVal_undefined;
5325 ret->edata = exprData_makeOp (e1, e2, op);
5327 if (exprNode_isError (e1) || exprNode_isError (e2))
5329 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5330 || opid == EQ_OP || opid == NE_OP
5331 || opid == AND_OP || opid == OR_OP)
5333 ret->typ = ctype_bool;
5336 if (exprNode_isDefined (e1))
5338 exprNode_checkUse (ret, e1->sref, e1->loc);
5341 if (exprNode_isDefined (e2))
5343 exprNode_mergeUSs (ret, e2);
5344 exprNode_checkUse (ret, e2->sref, e2->loc);
5350 tret = ctype_unknown;
5351 te1 = exprNode_getType (e1);
5353 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
5355 te2 = exprNode_getType (e2);
5357 tr1 = ctype_realishType (te1);
5358 tr2 = ctype_realishType (te2);
5362 ret->guards = guardSet_or (ret->guards, e2->guards);
5364 else if (opid == AND_OP)
5366 ret->guards = guardSet_and (ret->guards, e2->guards);
5373 if (opid == EQ_OP || opid == NE_OP)
5375 exprNode temp1 = e1, temp2 = e2;
5377 /* could do NULL == x */
5379 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
5381 temp1 = e2; temp2 = e1;
5384 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
5386 reflectNullTest (temp1, (opid == NE_OP));
5387 guardSet_free (ret->guards);
5388 ret->guards = guardSet_copy (temp1->guards);
5392 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5393 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
5398 if (anyAbstract (tr1, tr2) &&
5399 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
5400 (opid == AND_OP || opid == OR_OP
5401 || opid == EQ_OP || opid == NE_OP))))
5403 if (abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc))
5405 tret = ctype_unknown;
5410 if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
5412 /* unknown types, no comparisons possible */
5418 case TMULT: /* multiplication and division: */
5420 case MUL_ASSIGN: /* numeric, numeric -> numeric */
5421 case DIV_ASSIGN: /* */
5422 if (opid == TMULT || opid == MUL_ASSIGN)
5424 ret->val = multiVal_multiply (exprNode_getValue (e1),
5425 exprNode_getValue (e2));
5429 ret->val = multiVal_divide (exprNode_getValue (e1),
5430 exprNode_getValue (e2));
5433 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5436 case TPLUS: /* addition and subtraction: */
5437 case TMINUS: /* pointer, int -> pointer */
5438 case SUB_ASSIGN: /* int, pointer -> pointer */
5439 case ADD_ASSIGN: /* numeric, numeric -> numeric */
5440 if (opid == TPLUS || opid == ADD_ASSIGN)
5442 ret->val = multiVal_add (exprNode_getValue (e1),
5443 exprNode_getValue (e2));
5447 ret->val = multiVal_subtract (exprNode_getValue (e1),
5448 exprNode_getValue (e2));
5451 tr1 = ctype_fixArrayPtr (tr1);
5453 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
5454 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
5458 if (context_msgPointerArith ())
5462 message ("Pointer arithmetic (%t, %t): %s",
5463 te1, te2, exprNode_unparse (ret)),
5468 ** Swap terms so e1 is always the pointer
5471 if (ctype_isRealPointer (tr1))
5477 exprNode_swap (e1, e2);
5480 if (sRef_possiblyNull (e1->sref)
5481 && !usymtab_isGuarded (e1->sref))
5484 (FLG_NULLPOINTERARITH,
5485 message ("Pointer arithmetic involving possibly "
5486 "null pointer %s: %s",
5487 exprNode_unparse (e1),
5488 exprNode_unparse (ret)),
5492 ret->sref = sRef_copy (e1->sref);
5494 /* start modifications */
5495 /* added by Seejo on 4/16/2000 */
5497 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5499 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
5502 added ugly fixed to stop
5503 program from crashing on point + int +int
5504 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
5506 if (!multiVal_isInt (e2->val) )
5510 val = (int) multiVal_forceInt (e2->val);
5512 /* Operator : + or += */
5513 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5514 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
5515 val should not result in a
5516 size < 0 (size = 0 is ok !) */
5518 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
5520 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
5521 sRef_setNotNullTerminatedState(ret->sref);
5522 sRef_resetLen (ret->sref);
5524 sRef_setNullTerminatedState(ret->sref);
5525 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
5530 /* Operator : - or -= */
5531 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5532 if (sRef_getSize(e1->sref) >= 0) {
5533 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
5534 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
5539 /* end modifications */
5541 sRef_setNullError (ret->sref);
5544 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5545 ** since is points to storage that should not be deallocated
5546 ** through this pointer.
5549 if (sRef_isOnly (ret->sref)
5550 || sRef_isFresh (ret->sref))
5552 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5557 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
5558 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
5560 if (context_msgPointerArith ())
5564 message ("Pointer arithmetic (%t, %t): %s",
5565 te1, te2, exprNode_unparse (ret)),
5569 if (sRef_possiblyNull (e1->sref)
5570 && !usymtab_isGuarded (e1->sref))
5573 (FLG_NULLPOINTERARITH,
5574 message ("Pointer arithmetic involving possibly "
5575 "null pointer %s: %s",
5576 exprNode_unparse (e2),
5577 exprNode_unparse (ret)),
5581 ret->sref = sRef_copy (e2->sref);
5583 /* start modifications */
5584 /* added by Seejo on 4/16/2000 */
5586 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5589 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
5590 int val = (int) multiVal_forceInt (e1->val);
5592 /* Operator : + or += */
5593 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5594 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
5595 val should not result in a
5596 size < 0 (size = 0 is ok !) */
5598 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
5600 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
5601 sRef_setNotNullTerminatedState(ret->sref);
5602 sRef_resetLen (ret->sref);
5604 sRef_setNullTerminatedState(ret->sref);
5605 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
5610 /* Operator : - or -= */
5611 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5612 if (sRef_getSize(e2->sref) >= 0) {
5613 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
5614 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
5618 /* end modifications */
5620 sRef_setNullError (ret->sref);
5623 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5624 ** since is points to storage that should not be deallocated
5625 ** through this pointer.
5628 if (sRef_isOnly (ret->sref)
5629 || sRef_isFresh (ret->sref)) {
5630 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5634 ret->sref = e2->sref;
5638 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5647 case TAMPERSAND: /* bitwise & */
5649 case TCIRC: /* ^ (XOR) */
5654 bool reported = FALSE;
5660 if (opid == LEFT_OP || opid == LEFT_ASSIGN
5661 || opid == RIGHT_OP || opid == RIGHT_ASSIGN)
5664 ** evans 2002-01-01: fixed this to follow ISO 6.5.7.
5667 if (!ctype_isUnsigned (tr2)
5668 && !exprNode_isNonNegative (e2))
5670 reported = optgenerror
5672 message ("Right operand of %s may be negative (%t): %s",
5673 lltok_unparse (op), te2,
5674 exprNode_unparse (ret)),
5678 if (!ctype_isUnsigned (tr1)
5679 && !exprNode_isNonNegative (e1))
5681 reported = optgenerror
5682 (FLG_SHIFTIMPLEMENTATION,
5683 message ("Left operand of %s may be negative (%t): %s",
5684 lltok_unparse (op), te1,
5685 exprNode_unparse (ret)),
5690 ** Should check size of right operand also...
5696 if (!ctype_isUnsigned (tr1))
5698 if (exprNode_isNonNegative (e1)) {
5701 reported = optgenerror
5703 message ("Left operand of %s is not unsigned value (%t): %s",
5704 lltok_unparse (op), te1,
5705 exprNode_unparse (ret)),
5715 if (!ctype_isUnsigned (tr2))
5717 if (!exprNode_isNonNegative (e2)) {
5718 reported = optgenerror
5720 message ("Right operand of %s is not unsigned value (%t): %s",
5721 lltok_unparse (op), te2,
5722 exprNode_unparse (ret)),
5731 if (!checkIntegral (e1, e2, ret, op)) {
5732 te1 = ctype_unknown;
5736 DPRINTF (("Set: %s", ctype_unparse (te1)));
5739 ** tret is the widest type of te1 and te2
5742 tret = ctype_widest (te1, te2);
5747 if (checkIntegral (e1, e2, ret, op)) {
5750 tret = ctype_unknown;
5755 case TLT: /* comparisons */
5756 case TGT: /* numeric, numeric -> bool */
5758 DPRINTF (("Here we go: %s / %s",
5759 ctype_unparse (tr1), ctype_unparse (tr2)));
5761 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
5762 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
5765 bool fepsilon = FALSE;
5767 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
5772 if (opid == TLT || opid == TGT)
5774 uentry ue1 = exprNode_getUentry (e1);
5775 uentry ue2 = exprNode_getUentry (e2);
5778 ** FLT_EPSILON, etc. really is a variable, not
5782 if (uentry_isVariable (ue1))
5784 cstring uname = uentry_rawName (ue1);
5786 if (cstring_equalLit (uname, "FLT_EPSILON")
5787 || cstring_equalLit (uname, "DBL_EPSILON")
5788 || cstring_equalLit (uname, "LDBL_EPSILON"))
5794 if (uentry_isVariable (ue2))
5796 cstring uname = uentry_rawName (ue2);
5798 if (cstring_equalLit (uname, "FLT_EPSILON")
5799 || cstring_equalLit (uname, "DBL_EPSILON")
5800 || cstring_equalLit (uname, "LDBL_EPSILON"))
5809 ; /* Don't complain. */
5815 message ("Dangerous comparison involving %s types: %s",
5816 ctype_unparse (rtype),
5817 exprNode_unparse (ret)),
5826 ** Types should match.
5829 DPRINTF (("Match types: %s / %s", exprNode_unparse (e1),
5830 exprNode_unparse (e2)));
5832 if (!exprNode_matchTypes (e1, e2))
5834 hasError = gentypeerror
5836 message ("Operands of %s have incompatible types (%t, %t): %s",
5837 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5843 || (ctype_isForceRealNumeric (&tr1)
5844 && ctype_isForceRealNumeric (&tr2)) ||
5845 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
5851 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
5852 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
5856 message ("Comparison of pointer and numeric (%t, %t): %s",
5857 te1, te2, exprNode_unparse (ret)),
5862 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5867 /* certain comparisons on unsigned's and zero look suspicious */
5869 if (opid == TLT || opid == LE_OP || opid == GE_OP)
5871 if ((ctype_isUnsigned (tr1) && exprNode_isZero (e2))
5872 || (ctype_isUnsigned (tr2) && exprNode_isZero (e1)))
5875 (FLG_UNSIGNEDCOMPARE,
5876 message ("Comparison of unsigned value involving zero: %s",
5877 exprNode_unparse (ret)),
5882 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
5884 if ((opid == EQ_OP || opid == NE_OP) &&
5885 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
5888 ** is one a variable?
5891 if (uentry_isVariable (exprNode_getUentry (e1))
5892 || uentry_isVariable (exprNode_getUentry (e2)))
5895 ** comparisons with FALSE are okay
5898 if (exprNode_isFalseConstant (e1)
5899 || exprNode_isFalseConstant (e2))
5908 ("Use of %q with %s variables (risks inconsistency because "
5909 "of multiple true values): %s",
5910 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
5911 context_printBoolName (), exprNode_unparse (ret)),
5918 case AND_OP: /* bool, bool -> bool */
5920 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
5926 if (context_maybeSet (FLG_BOOLOPS))
5928 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
5930 if (ctype_sameName (te1, te2))
5934 message ("Operands of %s are non-boolean (%t): %s",
5935 lltok_unparse (op), te1,
5936 exprNode_unparse (ret)),
5944 ("Operands of %s are non-booleans (%t, %t): %s",
5945 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5949 else if (!ctype_isRealBool (te1))
5953 message ("Left operand of %s is non-boolean (%t): %s",
5954 lltok_unparse (op), te1, exprNode_unparse (ret)),
5957 else if (!ctype_isRealBool (te2))
5961 message ("Right operand of %s is non-boolean (%t): %s",
5962 lltok_unparse (op), te2, exprNode_unparse (ret)),
5975 (cstring_makeLiteral
5976 ("There has been a problem in the parser. This is believed to result "
5977 "from a problem with bison v. 1.25. Please try rebuidling Splint "
5978 "using the pre-compiled grammar files by commenting out the "
5979 "BISON= line in the top-level Makefile."));
5984 DPRINTF (("Return type %s: %s", exprNode_unparse (ret), ctype_unparse (tret)));
5986 exprNode_checkUse (ret, e1->sref, e1->loc);
5987 exprNode_mergeUSs (ret, e2);
5988 exprNode_checkUse (ret, e2->sref, e2->loc);
5994 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5995 /*@only@*/ lltok op)
5999 checkMacroParen (e1);
6000 checkMacroParen (e2);
6002 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
6004 checkExpressionDefined (e1, e2, op);
6007 ret = exprNode_makeOp (e1, e2, op);
6012 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
6015 ** This is somewhat bogus!
6017 ** Assigning to a nested observer in a non-observer datatype
6018 ** should not produce an error.
6021 sRef ref = exprNode_getSref (e1);
6023 DPRINTF (("Check assign mod: %s",
6024 sRef_unparseFull (ref)));
6026 if (sRef_isObserver (ref)
6027 || ((sRef_isFileStatic (ref) || sRef_isFileOrGlobalScope (ref))
6028 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
6030 sRef base = sRef_getBase (ref);
6032 if (sRef_isValid (base) && sRef_isObserver (base))
6034 exprNode_checkModify (e1, ret);
6038 exprNode_checkModifyVal (e1, ret);
6043 exprNode_checkModify (e1, ret);
6048 exprNode_assign (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2, /*@only@*/ lltok op)
6050 bool isalloc = FALSE;
6051 bool isjustalloc = FALSE;
6052 bool noalias = FALSE;
6055 DPRINTF (("%s [%s] <- %s [%s]",
6056 exprNode_unparse (e1),
6057 ctype_unparse (e1->typ),
6058 exprNode_unparse (e2),
6059 ctype_unparse (e2->typ)));
6061 if (lltok_getTok (op) != TASSIGN)
6063 ret = exprNode_makeOp (e1, e2, op);
6065 DPRINTF (("Here goes: %s %s",
6066 ctype_unparse (e1->typ),
6067 ctype_unparse (e2->typ)));
6069 if (exprNode_isDefined (e1)
6070 && exprNode_isDefined (e2))
6072 if (ctype_isNumeric (e2->typ)
6073 || ctype_isNumeric (e1->typ))
6075 /* Its a pointer arithmetic expression like ptr += i */
6082 ret = exprNode_createPartialCopy (e1);
6083 ret->kind = XPR_ASSIGN;
6084 ret->edata = exprData_makeOp (e1, e2, op);
6086 if (!exprNode_isError (e2))
6088 ret->sets = sRefSet_union (ret->sets, e2->sets);
6089 ret->msets = sRefSet_union (ret->msets, e2->msets);
6090 ret->uses = sRefSet_union (ret->uses, e2->uses);
6094 checkExpressionDefined (e1, e2, op);
6096 if (exprNode_isError (e1))
6098 if (!exprNode_isError (e2))
6100 ret->loc = fileloc_update (ret->loc, e2->loc);
6104 ret->loc = fileloc_update (ret->loc, g_currentloc);
6108 if (!exprNode_isError (e2))
6110 checkMacroParen (e2);
6113 if (exprNode_isDefined (e1))
6115 if (sRef_isMacroParamRef (e1->sref))
6117 if (context_inIterDef ())
6119 uentry ue = sRef_getUentry (e1->sref);
6121 if (uentry_isYield (ue))
6127 if (fileloc_isDefined (e1->loc))
6131 message ("Assignment to non-yield iter parameter: %q",
6132 sRef_unparse (e1->sref)),
6139 message ("Assignment to non-yield iter parameter: %q",
6140 sRef_unparse (e1->sref)),
6147 if (fileloc_isDefined (e1->loc))
6151 message ("Assignment to macro parameter: %q",
6152 sRef_unparse (e1->sref)),
6159 message ("Assignment to macro parameter: %q",
6160 sRef_unparse (e1->sref)),
6164 exprNode_checkAssignMod (e1, ret); /* evans 2001-07-22 */
6169 exprNode_checkAssignMod (e1, ret);
6172 if (exprNode_isDefined (e2))
6174 if (lltok_getTok (op) == TASSIGN)
6176 ctype te1 = exprNode_getType (e1);
6177 ctype te2 = exprNode_getType (e2);
6179 if (ctype_isVoid (te2))
6183 message ("Assignment of void value to %t: %s %s %s",
6184 te1, exprNode_unparse (e1),
6186 exprNode_unparse (e2)),
6189 else if (!ctype_forceMatch (te1, te2))
6191 if (exprNode_matchLiteral (te1, e2))
6193 DPRINTF (("Literals match: %s / %s",
6194 ctype_unparse (te1), exprNode_unparse (e2)));
6195 if (ctype_isNumAbstract (te1)) {
6196 if (!context_flagOn (FLG_NUMABSTRACTLIT, e1->loc)) {
6197 (void) llgenhinterror
6200 ("Assignment of %t literal to numabstract type %t: %s %s %s",
6202 exprNode_unparse (e1),
6204 exprNode_unparse (e2)),
6206 ("Use +numabstractlit to allow numeric literals to be used as numabstract values"),
6215 message ("Assignment of %t to %t: %s %s %s",
6216 te2, te1, exprNode_unparse (e1),
6218 exprNode_unparse (e2)),
6224 /* Type checks okay */
6228 exprNode_mergeUSs (ret, e2);
6229 exprNode_checkUse (ret, e2->sref, e2->loc);
6231 DPRINTF (("Do assign! %s %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6238 doAssign (e1, e2, FALSE);
6241 ret->sref = e1->sref;
6245 if (exprNode_isDefined (e2))
6247 exprNode_mergeUSs (ret, e2);
6248 exprNode_checkUse (ret, e2->sref, e2->loc);
6252 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
6254 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
6257 isjustalloc = sRef_isJustAllocated (e1->sref);
6258 isalloc = sRef_isAllocated (e1->sref);
6260 if (sRef_isField (e1->sref))
6262 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
6264 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
6266 exprNode_checkUse (ret, root, e1->loc);
6272 ** be careful! this defines e1->sref.
6275 /* evans 2001-07-22: removed if (!sRef_isMacroParamRef (e1->sref)) */
6277 DPRINTF (("Setting: %s -> %s", exprNode_unparse (ret), sRef_unparse (e1->sref)));
6278 exprNode_checkSet (ret, e1->sref);
6282 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
6283 ? e2->loc : e1->loc);
6289 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
6298 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
6299 /*@keep@*/ exprNode elseclause)
6303 if (!exprNode_isError (pred))
6305 ret = exprNode_createPartialCopy (pred);
6306 checkMacroParen (pred);
6307 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
6309 if (!exprNode_isError (ifclause))
6311 checkMacroParen (ifclause); /* update macro counts! */
6313 if (!exprNode_isError (elseclause))
6315 checkMacroParen (elseclause);
6317 if (!exprNode_matchTypes (ifclause, elseclause))
6320 (exprNode_getType (ifclause),
6322 exprNode_getType (elseclause),
6324 message ("Conditional clauses are not of same type: "
6326 exprNode_unparse (ifclause),
6327 exprNode_getType (ifclause),
6328 exprNode_unparse (elseclause),
6329 exprNode_getType (elseclause)),
6332 ret->sref = sRef_undefined;
6333 ret->typ = ctype_unknown;
6338 /* for now...should merge the states */
6339 ret->sref = ifclause->sref;
6340 ret->typ = ifclause->typ;
6342 if (exprNode_isNullValue (ifclause))
6344 ret->typ = elseclause->typ;
6348 exprNode_checkUse (ret, pred->sref, pred->loc);
6349 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6350 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6352 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6357 ret->typ = ifclause->typ;
6359 exprNode_checkUse (pred, pred->sref, pred->loc);
6360 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6362 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
6367 if (!exprNode_isError (elseclause))
6369 ret->typ = elseclause->typ;
6371 exprNode_checkUse (pred, pred->sref, pred->loc);
6372 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6374 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6378 else /* pred is error */
6380 if (!exprNode_isError (ifclause))
6382 ret = exprNode_createSemiCopy (ifclause);
6384 checkMacroParen (ifclause); /* update macro counts! */
6386 if (!exprNode_isError (elseclause))
6388 checkMacroParen (elseclause);
6390 ret->typ = ifclause->typ;
6392 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
6395 (exprNode_getType (ifclause),
6397 exprNode_getType (elseclause),
6399 message ("Conditional clauses are not of same type: "
6401 exprNode_unparse (ifclause),
6402 exprNode_getType (ifclause),
6403 exprNode_unparse (elseclause),
6404 exprNode_getType (elseclause)),
6407 ret->typ = ctype_unknown;
6411 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6412 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6414 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6417 else if (!exprNode_isError (elseclause)) /* pred, if errors */
6419 ret = exprNode_createSemiCopy (ifclause);
6421 ret->typ = elseclause->typ;
6422 checkMacroParen (elseclause);
6424 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6425 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6427 else /* all errors! */
6429 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6433 ret->kind = XPR_COND;
6434 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
6436 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
6438 exprNode_combineControl (ret, ifclause, elseclause);
6445 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
6447 ctype totype = qtype_getType (qt);
6449 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
6453 ** check use of va_arg : <valist>, type -> type
6456 if (exprNode_isError (arg))
6461 targ = exprNode_getType (arg);
6464 ** arg should have be a pointer
6467 if (!ctype_isUA (targ) ||
6468 (!usymId_equal (ctype_typeId (targ),
6469 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
6473 message ("First argument to va_arg is not a va_list (type %t): %s",
6474 targ, exprNode_unparse (arg)),
6478 exprNode_checkSet (ret, arg->sref);
6482 ** return type is totype
6486 ret->kind = XPR_VAARG;
6487 ret->edata = exprData_makeCast (tok, arg, qt);
6492 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
6494 exprNode ret = exprNode_createPlain (ctype_undefined);
6495 ret->kind = XPR_LABEL;
6496 ret->edata = exprData_makeLiteral (label);
6497 ret->isJumpPoint = TRUE;
6499 return (ret); /* for now, ignore label */
6502 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
6504 if (exprNode_isDefined (stmt))
6506 stmt->isJumpPoint = TRUE;
6508 /* This prevent stray no return path errors, etc. */
6509 stmt->exitCode = XK_MUSTEXIT;
6515 bool exprNode_isDefaultMarker (exprNode e)
6517 if (exprNode_isDefined (e))
6519 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
6525 bool exprNode_isCaseMarker (exprNode e)
6527 if (exprNode_isDefined (e))
6529 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
6535 bool exprNode_isLabelMarker (exprNode e)
6537 if (exprNode_isDefined (e))
6539 return (e->kind == XPR_LABEL);
6545 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
6547 exprNode ret = exprNode_createPartialCopy (test);
6549 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6551 if (exprNode_isError (test)) {
6555 exprNode_checkUse (ret, test->sref, test->loc);
6557 usymtab_setExitCode (ret->exitCode);
6561 usymtab_setMustBreak ();
6564 ret->edata = exprData_makeSingle (test);
6565 ret->isJumpPoint = TRUE;
6571 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
6573 exprNode ret = exprNode_createPartialCopy (test);
6575 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6576 ret->edata = exprData_makePair (test, stmt);
6577 ret->isJumpPoint = TRUE;
6579 if (exprNode_isError (test))
6584 exprNode_checkUse (ret, test->sref, test->loc);
6586 if (exprNode_isError (stmt))
6591 exprNode_mergeUSs (ret, stmt);
6593 ret->exitCode = stmt->exitCode;
6594 ret->mustBreak = stmt->mustBreak;
6595 ret->canBreak = stmt->canBreak;
6597 usymtab_setExitCode (ret->exitCode);
6601 usymtab_setMustBreak ();
6608 /*@notnull@*/ /*@only@*/ exprNode
6609 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
6611 exprNode ret = exprNode_createTok (def);
6613 ret->isJumpPoint = TRUE;
6614 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
6619 exprNode_mayEscape (exprNode e)
6621 if (exprNode_isDefined (e))
6623 return exitkind_couldEscape (e->exitCode);
6629 exprNode_mustBreak (exprNode e)
6631 if (exprNode_isDefined (e))
6633 return e->mustBreak;
6640 exprNode_mustEscape (exprNode e)
6642 if (exprNode_isDefined (e))
6644 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
6651 exprNode_errorEscape (exprNode e)
6653 if (exprNode_isDefined (e))
6655 return exitkind_isError (e->exitCode);
6661 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
6663 exprNode ret = exprNode_createPartialCopy (e1);
6665 DPRINTF (("Concat: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6667 ret->edata = exprData_makePair (e1, e2);
6668 ret->kind = XPR_STMTLIST;
6670 if (exprNode_isDefined (e1))
6672 ret->isJumpPoint = e1->isJumpPoint;
6673 ret->canBreak = e1->canBreak;
6677 if (exprNode_isDefined (e2))
6679 ret->loc = fileloc_update (ret->loc, e2->loc);
6683 if (exprNode_isDefined (e2))
6685 ret->exitCode = e2->exitCode;
6686 ret->mustBreak = e2->mustBreak;
6687 if (e2->canBreak) ret->canBreak = TRUE;
6691 ** if e1 must return, then e2 is unreachable!
6694 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
6696 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
6697 && !(e2->isJumpPoint))
6699 if (context_getFlag (FLG_UNREACHABLE))
6703 if (e2->kind == XPR_STMT)
6705 nr = exprData_getUopNode (e2->edata);
6708 if ((nr->kind == XPR_TOK
6709 && lltok_isSemi (exprData_getTok (nr->edata))))
6711 /* okay to have unreachable ";" */
6712 ret->exitCode = XK_MUSTEXIT;
6713 ret->canBreak = TRUE;
6717 if (optgenerror (FLG_UNREACHABLE,
6718 message ("Unreachable code: %s",
6719 exprNode_unparseFirst (nr)),
6722 ret->isJumpPoint = TRUE;
6723 ret->mustBreak = FALSE;
6724 ret->exitCode = XK_ERROR;
6725 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
6729 ret->exitCode = XK_MUSTEXIT;
6730 ret->canBreak = TRUE;
6738 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
6741 ** We want a warning anytime we have:
6743 ** yyy; <<<- no break or return
6747 exprNode lastStmt = exprNode_lastStatement (e1);
6749 if (exprNode_isDefined (lastStmt)
6750 && !exprNode_mustEscape (lastStmt)
6751 && !exprNode_mustBreak (lastStmt)
6752 && !exprNode_isCaseMarker (lastStmt)
6753 && !exprNode_isDefaultMarker (lastStmt)
6754 && !exprNode_isLabelMarker (lastStmt))
6756 voptgenerror (FLG_CASEBREAK,
6758 ("Fall through case (no preceding break)"),
6765 exprNode_mergeUSs (ret, e2);
6767 usymtab_setExitCode (ret->exitCode);
6771 usymtab_setMustBreak ();
6774 DPRINTF (("==> %s", exprNode_unparse (ret)));
6778 exprNode exprNode_createTok (/*@only@*/ lltok t)
6780 exprNode ret; /*@i23 if on same line, bad things happen...!@*/
6781 ret = exprNode_create (ctype_unknown);
6782 ret->kind = XPR_TOK;
6783 ret->edata = exprData_makeTok (t);
6787 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6789 if (!exprNode_isError (e))
6791 exprChecks_checkStatementEffect(e);
6794 return (exprNode_statementError (e, t));
6797 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6799 exprNode ret = exprNode_createPartialCopy (e);
6801 if (!exprNode_isError (e))
6803 if (e->kind != XPR_ASSIGN)
6805 exprNode_checkUse (ret, e->sref, e->loc);
6808 ret->exitCode = e->exitCode;
6809 ret->canBreak = e->canBreak;
6810 ret->mustBreak = e->mustBreak;
6813 ret->edata = exprData_makeUop (e, t);
6814 ret->kind = XPR_STMT;
6819 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
6821 if (!exprNode_isError (e))
6823 if (e->kind != XPR_ASSIGN)
6825 exprNode_checkUse (e, e->sref, e->loc);
6832 void exprNode_produceGuards (exprNode pred)
6834 if (!exprNode_isError (pred))
6836 if (ctype_isRealPointer (pred->typ))
6838 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
6841 exprNode_checkUse (pred, pred->sref, pred->loc);
6842 exprNode_resetSref (pred);
6846 exprNode exprNode_compoundStatementExpression (/*@only@*/ lltok tlparen, /*@only@*/ exprNode e)
6850 DPRINTF (("Compound: %s", exprNode_unparse (e)));
6852 if (!context_flagOn (FLG_GNUEXTENSIONS, exprNode_loc (e)))
6854 (void) llgenhinterror
6856 message ("Compound statement expressions is not supported by ISO C99"),
6857 message ("Use +gnuextensions to allow compound statement expressions (and other GNU language extensions) "
6858 "without this warning"),
6863 ** The type of a compoundStatementExpression is the type of the last statement
6866 llassert (exprNode_isBlock (e));
6867 laststmt = exprNode_lastStatement (e);
6869 DPRINTF (("Last statement: %s / %s", exprNode_unparse (laststmt), ctype_unparse (exprNode_getType (laststmt))));
6870 DPRINTF (("e: %s", exprNode_unparse (e)));
6871 e->typ = exprNode_getType (laststmt);
6872 return exprNode_addParens (tlparen, e);
6876 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
6878 exprNode ret = exprNode_createPartialCopy (e);
6880 if (!exprNode_isError (e))
6882 ret->exitCode = e->exitCode;
6883 ret->canBreak = e->canBreak;
6884 ret->mustBreak = e->mustBreak;
6887 DPRINTF (("Block e: %s", exprNode_unparse (e)));
6888 ret->edata = exprData_makeSingle (e);
6889 ret->kind = XPR_BLOCK;
6890 DPRINTF (("Block: %s", exprNode_unparse (ret)));
6894 bool exprNode_isBlock (exprNode e)
6896 return (exprNode_isDefined (e)
6897 && ((e)->kind == XPR_BLOCK));
6900 bool exprNode_isStatement (exprNode e)
6902 return (exprNode_isDefined (e)
6903 && ((e)->kind == XPR_STMT));
6906 bool exprNode_isAssign (exprNode e)
6908 if (exprNode_isDefined (e))
6910 return (e->kind == XPR_ASSIGN);
6916 bool exprNode_isEmptyStatement (exprNode e)
6918 return (exprNode_isDefined (e)
6919 && (e->kind == XPR_TOK)
6920 && (lltok_isSemi (exprData_getTok (e->edata))));
6923 bool exprNode_isMultiStatement (exprNode e)
6925 return (exprNode_isDefined (e)
6926 && ((e->kind == XPR_FOR)
6927 || (e->kind == XPR_FORPRED)
6928 || (e->kind == XPR_IF)
6929 || (e->kind == XPR_IFELSE)
6930 || (e->kind == XPR_WHILE)
6931 || (e->kind == XPR_WHILEPRED)
6932 || (e->kind == XPR_DOWHILE)
6933 || (e->kind == XPR_BLOCK)
6934 || (e->kind == XPR_STMT)
6935 || (e->kind == XPR_STMTLIST)
6936 || (e->kind == XPR_SWITCH)));
6939 void exprNode_checkIfPred (exprNode pred)
6941 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6944 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
6947 bool emptyErr = FALSE;
6949 if (context_maybeSet (FLG_IFEMPTY))
6951 if (exprNode_isEmptyStatement (tclause))
6953 emptyErr = optgenerror (FLG_IFEMPTY,
6955 ("Body of if statement is empty"),
6956 exprNode_loc (tclause));
6960 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
6962 if (exprNode_isDefined (tclause)
6963 && !exprNode_isBlock (tclause))
6965 voptgenerror (FLG_IFBLOCK,
6967 ("Body of if statement is not a block: %s",
6968 exprNode_unparse (tclause)),
6969 exprNode_loc (tclause));
6973 if (exprNode_isError (pred))
6975 if (exprNode_isError (tclause))
6977 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6981 ret = exprNode_createPartialCopy (tclause);
6986 if (exprNode_mustEscape (pred))
6990 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6991 exprNode_loc (pred));
6994 /*! exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred); */ /*@i523@*/
6995 exprNode_checkUse (pred, pred->sref, pred->loc);
6997 if (!exprNode_isError (tclause))
6999 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
7002 ret = exprNode_createPartialCopy (pred);
7006 ret->edata = exprData_makePair (pred, tclause);
7008 ret->exitCode = XK_UNKNOWN;
7010 if (exprNode_isDefined (tclause))
7012 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
7013 ret->canBreak = tclause->canBreak;
7014 ret->sets = sRefSet_union (ret->sets, tclause->sets);
7015 ret->msets = sRefSet_union (ret->msets, tclause->msets);
7016 ret->uses = sRefSet_union (ret->uses, tclause->uses);
7019 ret->mustBreak = FALSE;
7024 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
7025 /*@only@*/ exprNode tclause,
7026 /*@only@*/ exprNode eclause)
7029 bool tEmptyErr = FALSE;
7030 bool eEmptyErr = FALSE;
7032 if (context_maybeSet (FLG_IFEMPTY))
7034 if (exprNode_isEmptyStatement (tclause))
7036 tEmptyErr = optgenerror
7039 ("Body of if clause of if statement is empty"),
7040 exprNode_loc (tclause));
7043 if (exprNode_isEmptyStatement (eclause))
7045 eEmptyErr = optgenerror
7048 ("Body of else clause of if statement is empty"),
7049 exprNode_loc (eclause));
7053 if (context_maybeSet (FLG_IFBLOCK))
7056 && exprNode_isDefined (tclause)
7057 && !exprNode_isBlock (tclause))
7059 voptgenerror (FLG_IFBLOCK,
7061 ("Body of if clause of if statement is not a block: %s",
7062 exprNode_unparse (tclause)),
7063 exprNode_loc (tclause));
7067 && exprNode_isDefined (eclause)
7068 && !exprNode_isBlock (eclause)
7069 && !(eclause->kind == XPR_IF)
7070 && !(eclause->kind == XPR_IFELSE))
7075 ("Body of else clause of if statement is not a block: %s",
7076 exprNode_unparse (eclause)),
7077 exprNode_loc (eclause));
7081 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
7083 if (exprNode_isDefined (eclause)
7084 && (eclause->kind == XPR_IF))
7086 voptgenerror (FLG_ELSEIFCOMPLETE,
7087 message ("Incomplete else if logic (no final else): %s",
7088 exprNode_unparse (eclause)),
7089 exprNode_loc (eclause));
7093 if (exprNode_isError (pred))
7095 if (exprNode_isError (tclause))
7097 if (exprNode_isError (eclause))
7099 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7103 ret = exprNode_createPartialCopy (eclause);
7108 ret = exprNode_createPartialCopy (tclause);
7111 else /* pred is okay */
7113 ret = exprNode_createPartialCopy (pred);
7115 if (exprNode_mustEscape (pred))
7119 message ("Predicate always exits: %s", exprNode_unparse (pred)),
7120 exprNode_loc (pred));
7123 /*@i3423 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);*/
7124 exprNode_checkUse (ret, pred->sref, pred->loc);
7126 exprNode_mergeCondUSs (ret, tclause, eclause);
7129 ret->kind = XPR_IFELSE;
7130 ret->edata = exprData_makeCond (pred, tclause, eclause);
7132 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
7134 exprNode_combineControl (ret, tclause, eclause);
7135 ret->loc = fileloc_update (ret->loc, eclause->loc);
7142 ** *allpaths <- TRUE iff all executions paths must go through the switch
7146 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
7148 exprNodeSList el = exprNode_flatten (e);
7149 bool mustReturn = TRUE; /* find a branch that doesn't */
7150 bool thisReturn = FALSE;
7151 bool hasDefault = FALSE;
7152 bool hasAllMembers = FALSE;
7153 bool inSwitch = FALSE;
7154 bool isEnumSwitch = FALSE;
7155 bool canBreak = FALSE;
7156 bool fallThrough = FALSE;
7157 ctype ct = ctype_unknown;
7158 enumNameSList usedEnums;
7161 if (exprNode_isDefined (test))
7166 ttype = ctype_realType (ct);
7168 if (ctype_isEnum (ttype))
7170 isEnumSwitch = TRUE;
7171 enums = ctype_elist (ttype);
7172 usedEnums = enumNameSList_new ();
7176 exprNodeSList_elements (el, current)
7179 DPRINTF ((message("checkSwitchExpr current = %s ", exprNode_unparse(current) ) ));
7181 if (exprNode_isDefined (current))
7183 switch (current->kind)
7190 (FLG_DUPLICATECASES,
7191 message ("Duplicate default cases in switch"),
7192 exprNode_loc (current));
7197 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
7205 exprNode st = exprData_getSingle (current->edata);
7206 uentry ue = exprNode_getUentry (st);
7208 if (uentry_isValid (ue))
7210 cstring cname = uentry_rawName (ue);
7212 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
7214 if (enumNameSList_member
7215 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
7218 (FLG_DUPLICATECASES,
7219 message ("Duplicate case in switch: %s",
7225 enumNameSList_addh (usedEnums, cname);
7232 message ("Case in switch not %s member: %s",
7233 ctype_unparse (ct), cname),
7240 if (inSwitch && !fallThrough)
7242 if (!thisReturn || canBreak)
7252 /*@switchbreak@*/ break;
7254 thisReturn = thisReturn || exprNode_mustEscape (current);
7255 canBreak = canBreak || current->canBreak;
7256 if (canBreak) fallThrough = FALSE;
7259 } end_exprNodeSList_elements;
7261 if (inSwitch) /* check the last one! */
7263 if (!thisReturn || canBreak)
7272 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
7273 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
7275 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
7277 voptgenerror (FLG_MISSCASE,
7278 message ("Missing case%s in switch: %q",
7279 cstring_makeLiteralTemp
7280 ((enumNameSList_size (unused) > 1) ? "s" : ""),
7281 enumNameSList_unparse (unused)),
7284 enumNameSList_free (unused);
7285 *allpaths = FALSE; /* evans 2002-01-01 */
7289 hasAllMembers = TRUE;
7293 enumNameSList_free (usedEnums);
7297 *allpaths = hasDefault;
7300 exprNodeSList_free (el);
7301 return ((hasDefault || hasAllMembers) && mustReturn);
7304 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
7306 exprNode ret = exprNode_createPartialCopy (e);
7309 DPRINTF (("Switch: %s", exprNode_unparse (s)));
7311 ret->kind = XPR_SWITCH;
7312 ret->edata = exprData_makePair (e, s);
7314 if (!exprNode_isError (s))
7316 exprNode fs = exprNode_firstStatement (s);
7317 ret->loc = fileloc_update (ret->loc, s->loc);
7319 if (exprNode_isUndefined (fs)
7320 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
7321 || exprNode_isDefaultMarker (fs)) {
7324 voptgenerror (FLG_FIRSTCASE,
7326 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
7331 if (!exprNode_isError (e))
7333 if (checkSwitchExpr (e, s, &allpaths))
7335 ret->exitCode = XK_MUSTRETURN;
7339 ret->exitCode = e->exitCode;
7342 ret->canBreak = e->canBreak;
7343 ret->mustBreak = e->mustBreak;
7347 ** exprNode.c:3883,32: Variable allpaths used before definition
7354 DPRINTF (("Context exit switch!"));
7355 context_exitSwitch (ret, allpaths);
7356 DPRINTF (("Context exit switch done!"));
7361 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
7362 /*@notnull@*/ exprNode body)
7364 sRefSet tuses = test->uses;
7366 if (!sRefSet_isEmpty (test->uses))
7368 sRefSet sets = sRefSet_newCopy (body->sets);
7369 bool hasError = TRUE;
7370 bool innerState = FALSE;
7371 sRefSet tuncon = sRefSet_undefined;
7373 sets = sRefSet_union (sets, test->sets);
7374 sets = sRefSet_union (sets, body->msets);
7375 sets = sRefSet_union (sets, test->msets);
7377 sRefSet_allElements (tuses, el)
7379 if (sRef_isUnconstrained (el))
7381 tuncon = sRefSet_insert (tuncon, el);
7385 if (sRefSet_member (sets, el))
7392 if (sRef_isInternalState (el)
7393 || sRef_isFileStatic (sRef_getRootBase (el)))
7397 } end_sRefSet_allElements ;
7401 sRefSet suncon = sRefSet_undefined;
7402 bool sinner = FALSE;
7404 sRefSet_allElements (sets, el)
7406 if (sRef_isUnconstrained (el))
7408 suncon = sRefSet_insert (suncon, el);
7410 else if (sRef_isInternalState (el))
7418 } end_sRefSet_allElements ;
7420 if (sinner && innerState)
7424 else if (sRefSet_isEmpty (tuncon)
7425 && sRefSet_isEmpty (suncon))
7430 ("Suspected infinite loop. No value used in loop test (%q) "
7431 "is modified by test or loop body.",
7432 sRefSet_unparsePlain (tuses)),
7437 if (sRefSet_isEmpty (tuncon))
7441 message ("Suspected infinite loop. No condition values "
7442 "modified. Modification possible through "
7443 "unconstrained calls: %q",
7444 sRefSet_unparsePlain (suncon)),
7451 message ("Suspected infinite loop. No condition values "
7452 "modified. Possible undetected dependency through "
7453 "unconstrained calls in loop test: %q",
7454 sRefSet_unparsePlain (tuncon)),
7460 sRefSet_free (sets);
7464 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
7467 bool emptyErr = FALSE;
7469 if (context_maybeSet (FLG_WHILEEMPTY))
7471 if (exprNode_isEmptyStatement (b))
7473 emptyErr = optgenerror
7476 ("Body of while statement is empty"),
7481 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
7483 if (exprNode_isDefined (b)
7484 && !exprNode_isBlock (b))
7486 if (context_inIterDef ()
7487 && (b->kind == XPR_STMTLIST
7488 || b->kind == XPR_TOK))
7494 voptgenerror (FLG_WHILEBLOCK,
7496 ("Body of while statement is not a block: %s",
7497 exprNode_unparse (b)),
7503 if (exprNode_isError (t))
7505 if (exprNode_isError (b))
7507 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7511 ret = exprNode_createPartialCopy (b);
7518 ret = exprNode_createPartialCopy (t);
7520 llassert (t->kind == XPR_WHILEPRED);
7522 test = exprData_getSingle (t->edata);
7524 if (!exprNode_isError (b) && exprNode_isDefined (test))
7526 if (context_maybeSet (FLG_INFLOOPS)
7527 || context_maybeSet (FLG_INFLOOPSUNCON))
7530 ** check that some variable in the predicate is set by the body
7531 ** if the predicate uses any variables
7534 checkInfiniteLoop (test, b);
7537 exprNode_mergeUSs (ret, b);
7539 if (exprNode_isDefined (b))
7541 ret->exitCode = exitkind_makeConditional (b->exitCode);
7546 ret->edata = exprData_makePair (t, b);
7547 ret->kind = XPR_WHILE;
7549 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
7553 message ("Predicate always exits: %s", exprNode_unparse (t)),
7557 ret->exitCode = XK_NEVERESCAPE;
7560 ** If loop is infinite, and there is no break inside,
7561 ** exit code is never reach.
7564 if (exprNode_knownIntValue (t))
7566 if (!exprNode_isZero (t))
7568 if (exprNode_isDefined (b))
7572 /* Really, it means never reached. */
7573 ret->exitCode = XK_MUSTEXIT;
7583 ret->canBreak = FALSE;
7584 ret->mustBreak = FALSE;
7590 ** do { b } while (t);
7592 ** note: body passed as first argument
7595 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
7599 DPRINTF (("Do while: %s / %s",
7600 exprNode_unparse (b), exprNode_unparse (t)));
7602 if (exprNode_isError (t))
7604 if (exprNode_isError (b))
7606 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7610 ret = exprNode_createPartialCopy (b);
7612 ret->exitCode = exitkind_makeConditional (b->exitCode);
7613 exprNode_checkUse (ret, b->sref, b->loc);
7614 ret->exitCode = b->exitCode;
7615 ret->canBreak = b->canBreak;
7616 ret->mustBreak = FALSE;
7621 DPRINTF (("Do while: %s / %s",
7622 exitkind_unparse (t->exitCode),
7623 exitkind_unparse (b->exitCode)));
7625 ret = exprNode_createPartialCopy (t);
7626 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
7628 if (!exprNode_isError (b))
7631 ** forgot the copy's --- why wasn't this detected??
7634 ret->sets = sRefSet_copyInto (ret->sets, b->sets);
7635 ret->msets = sRefSet_copyInto (ret->msets, b->msets);
7636 ret->uses = sRefSet_copyInto (ret->uses, b->uses);
7638 /* left this out --- causes and aliasing bug (infinite loop)
7639 should be detected?? */
7641 exprNode_checkUse (ret, b->sref, b->loc);
7642 exprNode_mergeUSs (ret, t);
7643 exprNode_checkUse (ret, t->sref, t->loc);
7645 /* evans 2001-10-05: while loop can break */
7646 ret->exitCode = exitkind_makeConditional (b->exitCode);
7648 DPRINTF (("Do while: %s",
7649 exitkind_unparse (ret->exitCode)));
7651 ret->canBreak = b->canBreak;
7653 /* Always FALSE for doWhile loops - break's when test is false */
7654 ret->mustBreak = FALSE; /* b->mustBreak; */
7658 context_exitDoWhileClause (t);
7660 ret->kind = XPR_DOWHILE;
7661 ret->edata = exprData_makePair (t, b);
7665 bool exprNode_loopMustExec (exprNode forPred)
7668 ** Returns true if it is obvious that the loop always executes at least once
7670 ** For now, we only identify the most obvious cases. Should be true anytime
7671 ** we can prove init => !test.
7674 if (exprNode_isDefined (forPred))
7676 exprNode init, test, inc;
7679 llassert (forPred->kind == XPR_FORPRED);
7681 edata = forPred->edata;
7682 init = exprData_getTripleInit (edata);
7683 test = exprData_getTripleTest (edata);
7684 inc = exprData_getTripleInc (edata);
7686 if (exprNode_isAssign (init))
7688 exprNode loopVar = exprData_getOpA (init->edata);
7689 exprNode loopInit = exprData_getOpB (init->edata);
7691 if (exprNode_isDefined (test) && test->kind == XPR_OP)
7693 exprNode testVar = exprData_getOpA (test->edata);
7694 exprNode testVal = exprData_getOpB (test->edata);
7695 lltok comp = exprData_getOpTok (test->edata);
7696 int opid = lltok_getTok (comp);
7698 DPRINTF (("Same storage: %s / %s", exprNode_unparse (loopVar),
7699 exprNode_unparse (testVar)));
7701 if (exprNode_sameStorage (loopVar, testVar))
7703 multiVal valinit = exprNode_getValue (loopInit);
7704 multiVal valtest = exprNode_getValue (testVal);
7706 DPRINTF (("Values: %s / %s", multiVal_unparse (valinit),
7707 multiVal_unparse (valtest)));
7709 if (multiVal_isInt (valinit) && multiVal_isInt (valtest))
7711 long v1 = multiVal_forceInt (valinit);
7712 long v2 = multiVal_forceInt (valtest);
7714 DPRINTF (("Here: %ld %ld", v1, v2));
7716 if ((opid == EQ_OP && v1 < v2)
7717 || (opid == NE_OP && v1 != v2)
7718 || (opid == TLT && v1 <= v2)
7719 || (opid == TGT && v1 >= v2)
7720 || (opid == LE_OP && v1 < v2)
7721 || (opid == GE_OP && v1 > v2))
7723 DPRINTF (("mustexec if inc"));
7732 DPRINTF (("loop must exec: FALSE"));
7736 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
7739 bool emptyErr = FALSE;
7741 if (context_maybeSet (FLG_FOREMPTY))
7743 if (exprNode_isEmptyStatement (body))
7745 emptyErr = optgenerror
7748 ("Body of for statement is empty"),
7749 exprNode_loc (body));
7753 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
7755 if (exprNode_isDefined (body)
7756 && !exprNode_isBlock (body))
7758 if (context_inIterDef ()
7759 && (body->kind == XPR_STMTLIST
7760 || body->kind == XPR_TOK))
7766 voptgenerror (FLG_FORBLOCK,
7768 ("Body of for statement is not a block: %s",
7769 exprNode_unparse (body)),
7770 exprNode_loc (body));
7776 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
7779 if (exprNode_isError (body))
7781 ret = exprNode_createPartialCopy (inc);
7785 ret = exprNode_createPartialCopy (body);
7787 ret->exitCode = exitkind_makeConditional (body->exitCode);
7789 exprNode_mergeUSs (inc, body);
7791 if (exprNode_isDefined (inc))
7795 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
7797 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
7798 exprNode_freeShallow (tmp);
7800 context_clearMessageAnnote ();
7801 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
7803 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
7804 exprNode_freeShallow (tmp);
7806 context_clearMessageAnnote ();
7808 ret->uses = sRefSet_copyInto (ret->uses, inc->uses);
7809 ret->sets = sRefSet_copyInto (ret->sets, inc->sets);
7810 ret->msets = sRefSet_copyInto (ret->msets, inc->msets);
7814 ret->kind = XPR_FOR;
7815 ret->edata = exprData_makePair (inc, body);
7817 if (exprNode_isDefined (inc)) {
7818 exprNode test = exprData_getTripleTest (inc->edata);
7820 if (exprNode_isUndefined (test)) {
7821 if (exprNode_isDefined (body)) {
7822 if (!body->canBreak) {
7823 /* Really, it means never reached. */
7824 ret->exitCode = XK_MUSTEXIT;
7834 ** for (init; test; inc)
7837 ** while (test) { body; inc; }
7839 ** Now: check use of init (may set vars for test)
7840 ** check use of test
7844 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
7848 if (exprNode_isError (pred)) return guardSet_undefined;
7850 llassert (pred->kind == XPR_FORPRED);
7852 test = exprData_getTripleTest (pred->edata);
7854 if (!exprNode_isError (test))
7856 return (test->guards);
7859 return guardSet_undefined;
7862 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
7864 exprNode ret = exprNode_createSemiCopy (test);
7866 if (exprNode_isDefined (test))
7868 exprNode_copySets (ret, test);
7869 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
7870 exprNode_checkUse (ret, test->sref, test->loc);
7872 exprNode_produceGuards (test);
7874 ret->guards = guardSet_copy (test->guards);
7877 ret->edata = exprData_makeSingle (test);
7878 ret->kind = XPR_WHILEPRED;
7882 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
7883 /*@only@*/ exprNode inc)
7888 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
7891 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
7893 if (!exprNode_isError (inc))
7895 ret = exprNode_createPartialCopy (inc);
7899 if (!exprNode_isError (init))
7901 ret = exprNode_createPartialCopy (init);
7903 else if (!exprNode_isError (test))
7905 ret = exprNode_createPartialCopy (test);
7909 ret = exprNode_createUnknown ();
7913 exprNode_mergeUSs (ret, init);
7915 if (exprNode_isDefined (init))
7917 exprNode_checkUse (ret, init->sref, init->loc);
7920 exprNode_mergeUSs (ret, test);
7922 if (exprNode_isDefined (test))
7924 exprNode_checkUse (ret, test->sref, test->loc);
7927 ret->kind = XPR_FORPRED;
7928 ret->edata = exprData_makeFor (init, test, inc);
7932 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
7934 exprNode ret = exprNode_createUnknown ();
7936 if (context_inMacro ())
7938 voptgenerror (FLG_MACROSTMT,
7939 message ("Macro %s uses goto (not functional)",
7940 context_inFunctionName ()),
7944 ret->kind = XPR_GOTO;
7945 ret->edata = exprData_makeLiteral (label);
7946 ret->mustBreak = TRUE;
7947 ret->exitCode = XK_GOTO;
7948 ret->canBreak = TRUE;
7952 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
7954 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7956 ret->kind = XPR_CONTINUE;
7957 ret->edata = exprData_makeTok (l);
7958 ret->canBreak = TRUE;
7959 ret->mustBreak = TRUE;
7961 if (qcontinue == QSAFEBREAK)
7965 else if (qcontinue == QINNERCONTINUE)
7967 if (!context_inDeepLoop ())
7970 (FLG_LOOPLOOPCONTINUE,
7971 cstring_makeLiteral ("Continue statement marked with innercontinue "
7972 "is not inside a nested loop"),
7973 exprNode_loc (ret));
7976 else if (qcontinue == BADTOK)
7978 if (context_inDeepLoop ())
7981 (FLG_LOOPLOOPCONTINUE,
7982 cstring_makeLiteral ("Continue statement in nested loop"),
7983 exprNode_loc (ret));
7988 llbuglit ("exprNode_continue: bad qcontinue");
7994 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
7996 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7997 clause breakClause = context_breakClause ();
7999 ret->kind = XPR_BREAK;
8000 ret->edata = exprData_makeTok (l);
8001 ret->canBreak = TRUE;
8002 ret->mustBreak = TRUE;
8004 if (breakClause == NOCLAUSE)
8008 cstring_makeLiteral ("Break not inside while, for or switch statement"),
8009 exprNode_loc (ret));
8013 if (bqual != BADTOK)
8020 if (breakClause == SWITCHCLAUSE)
8022 if (!context_inDeepSwitch ())
8024 voptgenerror (FLG_SYNTAX,
8026 ("Break preceded by innerbreak is not in a deep switch"),
8027 exprNode_loc (ret));
8032 if (!context_inDeepLoop ())
8034 voptgenerror (FLG_SYNTAX,
8036 ("Break preceded by innerbreak is not in a deep loop"),
8037 exprNode_loc (ret));
8042 if (breakClause == SWITCHCLAUSE)
8044 voptgenerror (FLG_SYNTAX,
8046 ("Break preceded by loopbreak is breaking a switch"),
8047 exprNode_loc (ret));
8051 if (breakClause != SWITCHCLAUSE)
8055 message ("Break preceded by switchbreak is breaking %s",
8056 cstring_makeLiteralTemp
8057 ((breakClause == WHILECLAUSE
8058 || breakClause == DOWHILECLAUSE) ? "a while loop"
8059 : (breakClause == FORCLAUSE) ? "a for loop"
8060 : (breakClause == ITERCLAUSE) ? "an iterator"
8062 exprNode_loc (ret));
8070 if (breakClause == SWITCHCLAUSE)
8072 clause nextBreakClause = context_nextBreakClause ();
8074 switch (nextBreakClause)
8076 case NOCLAUSE: break;
8082 (FLG_LOOPSWITCHBREAK,
8083 cstring_makeLiteral ("Break statement in switch inside loop"),
8084 exprNode_loc (ret));
8088 (FLG_SWITCHSWITCHBREAK,
8089 cstring_makeLiteral ("Break statement in switch inside switch"),
8090 exprNode_loc (ret));
8097 if (context_inDeepLoop ())
8101 cstring_makeLiteral ("Break statement in nested loop"),
8102 exprNode_loc (ret));
8106 if (context_inDeepLoopSwitch ())
8109 (FLG_SWITCHLOOPBREAK,
8110 cstring_makeLiteral ("Break statement in loop inside switch"),
8111 exprNode_loc (ret));
8121 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
8123 fileloc loc = lltok_getLoc (t);
8124 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
8126 context_returnFunction ();
8127 exprChecks_checkNullReturn (loc);
8129 ret->kind = XPR_NULLRETURN;
8130 ret->edata = exprData_makeTok (t);
8131 ret->exitCode = XK_MUSTRETURN;
8135 exprNode exprNode_return (/*@only@*/ exprNode e)
8139 if (exprNode_isError (e))
8141 ret = exprNode_createUnknown ();
8145 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
8147 exprNode_checkUse (ret, e->sref, e->loc);
8148 exprNode_checkReturn (e);
8151 context_returnFunction ();
8152 ret->kind = XPR_RETURN;
8153 ret->edata = exprData_makeSingle (e);
8154 ret->exitCode = XK_MUSTRETURN;
8159 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
8163 if (exprNode_isError (e1))
8165 if (exprNode_isError (e2))
8167 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
8171 ret = exprNode_createPartialCopy (e2);
8172 exprNode_checkUse (ret, e2->sref, e2->loc);
8173 ret->sref = e2->sref;
8178 ret = exprNode_createPartialCopy (e1);
8180 exprNode_checkUse (ret, e1->sref, e1->loc);
8182 if (!exprNode_isError (e2))
8184 exprNode_mergeUSs (ret, e2);
8185 exprNode_checkUse (ret, e2->sref, e2->loc);
8186 ret->sref = e2->sref;
8190 ret->kind = XPR_COMMA;
8191 ret->edata = exprData_makePair (e1, e2);
8193 if (exprNode_isDefined (e1))
8195 if (exprNode_isDefined (e2))
8199 if (exprNode_mustEscape (e1) || e1->mustBreak)
8203 message ("Second clause of comma expression is unreachable: %s",
8204 exprNode_unparse (e2)),
8208 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
8209 ret->mustBreak = e1->mustBreak || e2->mustBreak;
8210 ret->canBreak = e1->canBreak || e2->canBreak;
8214 if (exprNode_mustEscape (e1) || e1->mustBreak)
8218 message ("Second clause of comma expression is unreachable: %s",
8219 exprNode_unparse (e2)),
8223 ret->exitCode = e1->exitCode;
8224 ret->canBreak = e1->canBreak;
8229 if (exprNode_isDefined (e2))
8231 ret->exitCode = e2->exitCode;
8232 ret->mustBreak = e2->mustBreak;
8233 ret->canBreak = e2->canBreak;
8240 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
8242 ctype t1 = exprNode_getType (el);
8243 ctype t2 = exprNode_getType (val);
8244 bool hasError = FALSE;
8246 DPRINTF (("Check one init: %s / %s",
8247 exprNode_unparse (el),
8248 exprNode_unparse (val)));
8250 if (ctype_isUnknown (t1))
8252 voptgenerror (FLG_IMPTYPE,
8253 message ("Variable has unknown (implicitly int) type: %s",
8254 exprNode_unparse (el)),
8258 el->typ = ctype_int;
8261 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
8263 exprNodeList vals = exprData_getArgs (val->edata);
8265 DPRINTF (("Check one init: %s", exprNodeList_unparse (vals)));
8266 DPRINTF (("Type: %s", ctype_unparse (t1)));
8268 if (ctype_isRealAP (t1))
8273 if (ctype_isFixedArray (t1))
8275 size_t nelements = ctype_getArraySize (t1);
8277 DPRINTF (("Checked array: %s / %d",
8278 ctype_unparse (t1), nelements));
8280 if (exprNode_isStringLiteral (val))
8282 exprNode_checkStringLiteralLength (t1, val);
8286 if (exprNodeList_size (vals) != size_toInt (nelements))
8288 hasError = optgenerror
8289 (exprNodeList_size (vals) > size_toInt (nelements)
8290 ? FLG_INITSIZE : FLG_INITALLELEMENTS,
8291 message ("Initializer block for "
8292 "%s has %d element%&, but declared as %s: %q",
8293 exprNode_unparse (el),
8294 exprNodeList_size (vals),
8296 exprNodeList_unparse (vals)),
8302 exprNodeList_elements (vals, oneval)
8304 cstring istring = message ("%d", i);
8307 (exprNode_fakeCopy (el),
8308 exprNode_numLiteral (ctype_int, istring,
8309 fileloc_copy (el->loc), i));
8311 if (exprNode_isDefined (newel))
8313 if (exprNodeList_size (vals) == 1
8314 && ctype_isString (exprNode_getType (oneval))
8315 && ctype_isChar (exprNode_getType (newel)))
8317 exprNode_freeIniter (newel);
8321 if (exprNode_checkOneInit (newel, oneval))
8326 if (nerrors > 3 && exprNodeList_size (vals) > 6)
8329 (message ("Additional initialization errors "
8330 "for %s not reported",
8331 exprNode_unparse (el)),
8333 exprNode_freeIniter (newel);
8338 exprNode_freeIniter (newel);
8343 exprNode_freeIniter (newel);
8348 cstring_free (istring);
8351 } end_exprNodeList_elements;
8354 else if (ctype_isStruct (ctype_realType (t1)))
8356 uentryList fields = ctype_getFields (t1);
8359 if (uentryList_size (fields) != exprNodeList_size (vals))
8361 if (uentryList_size (fields) > exprNodeList_size (vals))
8363 hasError = optgenerror
8365 message ("Initializer block for "
8366 "%s has %d field%&, but %s has %d field%&: %q",
8367 exprNode_unparse (el),
8368 exprNodeList_size (vals),
8370 uentryList_size (fields),
8371 exprNodeList_unparse (vals)),
8376 hasError = optgenerror
8378 message ("Initializer block for "
8379 "%s has %d field%&, but %s has %d field%&: %q",
8380 exprNode_unparse (el),
8381 exprNodeList_size (vals),
8383 uentryList_size (fields),
8384 exprNodeList_unparse (vals)),
8390 exprNodeList_elements (vals, oneval)
8392 uentry thisfield = uentryList_getN (fields, i);
8394 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
8396 uentry_getName (thisfield));
8398 if (exprNode_isDefined (newel))
8400 if (exprNode_checkOneInit (newel, oneval))
8405 exprNode_freeIniter (newel);
8409 } end_exprNodeList_elements;
8412 /* evans 2001-12-30: added to fix bug reported by Jim Zelenka */
8413 else if (ctype_isUnion (ctype_realType (t1)))
8415 uentryList fields = ctype_getFields (t1);
8419 ** Union initializers set the first member always.
8422 DPRINTF (("Union initializer: %s / %s",
8423 exprNode_unparse (el), ctype_unparse (ctype_realType (t1))));
8425 if (exprNodeList_size (vals) != 1)
8427 hasError = optgenerror
8429 message ("Initializer block for union "
8430 "%s has %d elements, union initializers should have one element: %q",
8431 exprNode_unparse (el),
8432 exprNodeList_size (vals),
8433 exprNodeList_unparse (vals)),
8438 exprNode oneval = exprNodeList_head (vals);
8439 uentry thisfield = uentryList_getN (fields, i);
8441 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
8443 uentry_getName (thisfield));
8445 if (exprNode_isDefined (newel))
8447 if (exprNode_checkOneInit (newel, oneval))
8452 exprNode_freeIniter (newel);
8458 hasError = optgenerror
8460 message ("Initializer block used for "
8461 "%s where %t is expected: %s",
8462 exprNode_unparse (el), t1, exprNode_unparse (val)),
8468 if (exprNode_isDefined (val))
8470 doAssign (el, val, TRUE);
8472 if (!exprNode_matchType (t1, val))
8474 hasError = gentypeerror
8476 message ("Initial value of %s is type %t, "
8478 exprNode_unparse (el),
8479 t2, t1, exprNode_unparse (val)),
8488 static /*@notnull@*/ exprNode
8489 exprNode_makeInitializationAux (/*@temp@*/ idDecl t)
8493 DPRINTF (("Initialization: %s", idDecl_unparse (t)));
8495 if (usymtab_exists (idDecl_observeId (t)))
8497 uentry ue = usymtab_lookup (idDecl_observeId (t));
8498 ret = exprNode_createId (ue);
8500 /*@i723 don't do this...but why? */
8502 ct = ctype_realishType (ret->typ);
8504 DPRINTF (("Type: %s", ctype_unparse (ret->typ)));
8506 if (ctype_isUnknown (ct))
8508 if (uentry_isAnyTag (ue))
8512 message ("%s used but not previously declared: %s",
8513 uentry_ekindName (ue),
8514 idDecl_getName (t)),
8522 message ("Variable has unknown (implicitly int) type: %s",
8523 idDecl_getName (t)),
8535 DPRINTF (("Unrecognized: %s", idDecl_unparse (t)));
8537 ue = uentry_makeUnrecognized (idDecl_observeId (t), fileloc_copy (g_currentloc));
8538 /*!! fileloc_copy (g_currentloc)); */
8539 /*@i32!!! should get error without this */
8541 ret = exprNode_fromIdentifierAux (ue);
8544 ** No error - this happens in old style declarations:
8548 message ("Unrecognized identifier in intializer: %s", idDecl_observeId (t)),
8555 exprData_free (ret->edata, ret->kind);
8556 ret->edata = exprData_undefined;
8557 ret->exitCode = XK_NEVERESCAPE;
8558 ret->mustBreak = FALSE;
8559 ret->kind = XPR_INIT;
8563 exprNode exprNode_makeEmptyInitialization (/*@only@*/ idDecl t)
8565 exprNode ret = exprNode_makeInitializationAux (t);
8566 llassert (ret->edata == exprData_undefined);
8567 ret->edata = exprData_makeInit (t, exprNode_undefined);
8571 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
8572 /*@only@*/ exprNode e)
8574 uentry ue = usymtab_lookup (idDecl_observeId (t));
8575 exprNode ret = exprNode_makeInitializationAux (t);
8576 fileloc loc = exprNode_loc (e);
8578 DPRINTF (("initialization: %s = %s", idDecl_unparse (t), exprNode_unparse (e)));
8580 if (exprNode_isError (e))
8582 e = exprNode_createUnknown ();
8583 /* error: assume initializer is defined */
8584 sRef_setDefined (ret->sref, g_currentloc);
8585 ret->edata = exprData_makeInit (t, e);
8589 ctype ct = ctype_realishType (ret->typ);
8594 ** was addSafeUse --- what's the problem?
8596 ** int x = 3, y = x ?
8599 exprData_free (ret->edata, ret->kind);
8600 ret->edata = exprData_makeInit (t, e);
8601 DPRINTF (("ret: %s", exprNode_unparse (ret)));
8603 exprNode_checkUse (ret, e->sref, e->loc);
8605 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
8607 exprNode lhs = exprNode_createId (ue);
8610 ** static storage should be undefined before initializing
8613 if (uentry_isStatic (ue))
8615 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
8618 (void) exprNode_checkOneInit (lhs, e);
8620 if (uentry_isStatic (ue))
8622 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
8625 exprNode_free (lhs);
8629 if (!exprNode_matchType (ct, e))
8631 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
8638 (exprNode_getType (e), e, exprNode_getType (ret), ret,
8640 ("Variable %q initialized to type %t, expects %t: %s",
8641 uentry_getName (ue), exprNode_getType (e),
8642 exprNode_getType (ret),
8643 exprNode_unparse (e)),
8649 if (uentry_isStatic (ue))
8651 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
8654 if (exprNode_isStringLiteral (e)
8655 && (ctype_isArray (ct))
8656 && (ctype_isChar (ctype_realType (ctype_baseArrayPtr (ct)))))
8659 ** If t is a char [], the literal is copied.
8662 exprNode_checkStringLiteralLength (ct, e);
8663 sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
8664 ret->val = multiVal_copy (e->val);
8666 sRef_setNullTerminatedState (ret->sref);
8668 if (multiVal_isDefined (e->val))
8670 cstring slit = multiVal_forceString (e->val);
8671 sRef_setLen (ret->sref, size_toInt (cstring_length (slit) + 1));
8674 if (ctype_isFixedArray (ct))
8676 sRef_setSize (ret->sref, size_toInt (ctype_getArraySize (ct)));
8681 doAssign (ret, e, TRUE);
8684 if (uentry_isStatic (ue))
8686 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
8690 if (context_inIterDef ())
8692 /* should check if it is yield */
8693 uentry_setUsed (ue, loc);
8700 exprNode_mergeUSs (ret, e);
8701 DPRINTF (("Ret: %s %p %p",
8702 exprNode_unparse (ret),
8703 ret->requiresConstraints,
8704 ret->ensuresConstraints));
8706 DPRINTF (("Ret: %s %s %s",
8707 exprNode_unparse (ret),
8708 constraintList_unparse (ret->requiresConstraints),
8709 constraintList_unparse (ret->ensuresConstraints)));
8713 exprNode exprNode_iter (/*@observer@*/ uentry name,
8714 /*@only@*/ exprNodeList alist,
8715 /*@only@*/ exprNode body,
8716 /*@observer@*/ uentry end)
8721 llassert (uentry_isValid (name));
8723 uentry_setUsed (name, exprNode_loc (body));
8725 ret = exprNode_createPartialCopy (body);
8726 iname = uentry_getName (name);
8728 if (uentry_isInvalid (end))
8730 llerror (FLG_ITERBALANCE,
8731 message ("Iter %s not balanced with end_%s", iname, iname));
8735 cstring ename = uentry_getName (end);
8737 if (!cstring_equalPrefixLit (ename, "end_"))
8739 llerror (FLG_ITERBALANCE, message ("Iter %s not balanced with end_%s: %s",
8740 iname, iname, ename));
8744 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
8746 llerror (FLG_ITERBALANCE,
8747 message ("Iter %s not balanced with end_%s: %s",
8748 iname, iname, ename));
8752 cstring_free (ename);
8755 context_exitIterClause (body);
8757 ret->kind = XPR_ITER;
8758 ret->edata = exprData_makeIter (name, alist, body, end);
8760 if (uentry_isIter (name))
8762 (void) checkArgsReal (name, body,
8763 uentry_getParams (name), alist, TRUE, ret);
8766 cstring_free (iname);
8772 exprNode_iterNewId (/*@only@*/ cstring s)
8774 exprNode e = exprNode_new ();
8775 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
8777 llassert (processingIterVars ());
8779 e->loc = context_getSaveLocation ();
8781 if (fileloc_isUndefined (e->loc))
8783 fileloc_free (e->loc);
8784 e->loc = fileloc_copy (g_currentloc);
8787 e->uses = sRefSet_new ();
8788 e->sets = sRefSet_new ();
8789 e->msets = sRefSet_new ();
8791 e->val = multiVal_unknown ();
8792 e->guards = guardSet_new ();
8793 e->sref = sRef_undefined;
8794 e->isJumpPoint = FALSE;
8795 e->exitCode = XK_NEVERESCAPE;
8797 /*> missing fields, detected by splint <*/
8798 e->canBreak = FALSE;
8799 e->mustBreak = FALSE;
8800 e->etext = cstring_undefined;
8802 if (uentry_isYield (ue))
8804 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
8805 fileloc_copy (e->loc),
8809 uue = usymtab_supEntrySrefReturn (uue);
8811 sr = uentry_getSref (uue);
8812 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
8813 sr = uentry_getSref (uue);
8814 sRef_setDefined (sr, e->loc);
8816 e->typ = uentry_getType (uue);
8818 e->edata = exprData_makeId (uue);
8819 uentry_setUsed (uue, g_currentloc);
8825 sRef_setGlobalScope ();
8826 uue = uentry_makeVariableLoc (s, ctype_unknown);
8828 e->typ = ctype_unknown;
8829 e->edata = exprData_makeId (uue);
8831 uentry_setUsed (uue, e->loc);
8832 uentry_setHasNameError (uue);
8834 if (context_getFlag (FLG_REPEATUNRECOG))
8836 uentry_markOwned (uue);
8840 usymtab_supGlobalEntry (uue);
8843 sRef_clearGlobalScope ();
8845 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
8852 exprNode_defineConstraints(e);
8857 exprNode_iterExpr (/*@returned@*/ exprNode e)
8859 if (!processingIterVars ())
8861 llcontbuglit ("checkIterParam: not in iter");
8865 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
8868 if (exprNode_isDefined (e))
8870 if (fileloc_isDefined (e->loc))
8874 message ("Yield parameter is not simple identifier: %s",
8875 exprNode_unparse (e)),
8882 message ("Yield parameter is not simple identifier: %s",
8883 exprNode_unparse (e)),
8893 exprNode_iterId (/*@observer@*/ uentry c)
8897 llassert (processingIterVars ());
8899 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
8902 if (uentry_isYield (ue))
8904 ctype ct = uentry_getType (ue);
8905 exprNode e = exprNode_createPlain (ct);
8906 cstring name = uentry_getName (c);
8907 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
8909 uentry_setUsed (ue, g_currentloc);
8910 uentry_setHasNameError (ue);
8912 cstring_free (name);
8915 e->edata = exprData_makeId (le);
8916 e->loc = context_getSaveLocation ();
8917 e->sref = uentry_getSref (le);
8919 usymtab_supEntrySref (le);
8921 if (!context_inHeader ())
8925 message ("Yield parameter shadows local declaration: %q",
8926 uentry_getName (c)),
8927 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
8929 uentry_showWhereDeclared (c);
8936 return (exprNode_fromIdentifierAux (c));
8939 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
8941 exprNode ret = exprNode_create (ctype_unknown);
8943 ret->kind = XPR_ITERCALL;
8944 ret->edata = exprData_makeIterCall (name, alist);
8946 if (uentry_isIter (name))
8948 uentryList params = uentry_getParams (name);
8950 if (context_inIterDef ()
8951 && uentryList_size (params) == exprNodeList_size (alist))
8955 exprNodeList_elements (alist, arg)
8957 uentry parg = uentryList_getN (params, i);
8959 if (uentry_isYield (parg))
8961 uentry ue = exprNode_getUentry (arg);
8963 if (uentry_isValid (ue))
8970 } end_exprNodeList_elements;
8973 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
8974 checkUnspecCall (ret, params, alist);
8980 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
8982 if (exprNode_isDefined (e))
8984 if (sRef_isInvalid (e->sref))
8987 e->sref = sRef_makeUnknown ();
8988 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
8999 return sRef_undefined;
9003 /*@observer@*/ cstring
9004 exprNode_unparseFirst (exprNode e)
9006 if (exprNode_isDefined (e))
9010 if (e->kind == XPR_STMTLIST
9011 || e->kind == XPR_COMMA || e->kind == XPR_COND)
9013 exprNode first = exprData_getPairA (e->edata);
9015 if (exprNode_isDefined (first))
9017 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
9021 return (cstring_makeLiteralTemp ("..."));
9025 ret = cstring_elide (exprNode_unparse (e), 20);
9026 cstring_markOwned (ret);
9032 return cstring_makeLiteralTemp ("<error>");
9036 /*@observer@*/ cstring
9037 exprNode_unparse (/*@temp@*/ exprNode e)
9039 if (exprNode_isError (e))
9041 return cstring_makeLiteralTemp ("<error>");
9044 if (cstring_isDefined (e->etext))
9050 cstring ret = exprNode_doUnparse (e);
9052 /*@-modifies@*/ /* benevolent */
9059 /*@observer@*/ fileloc
9060 exprNode_loc (exprNode e)
9062 if (exprNode_isError (e))
9064 return (g_currentloc);
9073 ** executes exprNode e
9074 ** recursively rexecutes as though in original parse using
9075 ** information in e->edata
9078 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
9080 exprNodeList ret = exprNodeList_new ();
9082 exprNodeList_elements (e, current)
9084 exprNodeList_addh (ret, exprNode_effect (current));
9085 } end_exprNodeList_elements;
9090 static /*@only@*/ exprNode exprNode_effect (exprNode e)
9091 /*@globals internalState@*/
9093 bool innerEffect = inEffect;
9099 context_clearJustPopped ();
9101 if (exprNode_isError (e))
9103 ret = exprNode_undefined;
9108 ** Turn off expose and dependent transfer checking.
9109 ** Need to pass exposed internal nodes,
9110 ** [ copying would be a waste! ]
9111 ** [ Actually, I think I wasted a lot more time than its worth ]
9112 ** [ trying to do this. ]
9116 /*@-observertrans@*/
9117 /*@-dependenttrans@*/
9124 ret = exprNode_addParens (exprData_getUopTok (data),
9125 exprNode_effect (exprData_getUopNode (data)));
9128 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
9129 exprNode_effect (exprData_getOpB (data)),
9130 exprData_getOpTok (data));
9133 ret = exprNode_undefined;
9136 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
9137 exprNodeList_effect (exprData_getArgs (data)));
9150 cstring id = exprData_getId (data);
9151 uentry ue = usymtab_lookupSafe (id);
9153 ret = exprNode_fromIdentifierAux (ue);
9154 ret->loc = fileloc_update (ret->loc, e->loc);
9161 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
9162 exprNode_effect (exprData_getPairB (data)));
9166 ** evans 2002-03-15: for && and ||, need to do the guards also
9167 ** this is what cgrammar.y does - should be
9168 ** able to avoid duplication, but need to
9169 ** time with grammar productions.
9172 DPRINTF (("Effect: %s", exprNode_unparse (e)));
9174 if (lltok_getTok (exprData_getOpTok (data)) == AND_OP)
9176 exprNode e1 = exprNode_effect (exprData_getOpA (data));
9178 exprNode_produceGuards (e1);
9179 context_enterAndClause (e1);
9180 e2 = exprNode_effect (exprData_getOpB (data));
9182 ret = exprNode_op (e1, e2,
9183 exprData_getOpTok (data));
9185 context_exitAndClause (ret, e2);
9187 else if (lltok_getTok (exprData_getOpTok (data)) == OR_OP)
9189 exprNode e1 = exprNode_effect (exprData_getOpA (data));
9191 exprNode_produceGuards (e1);
9192 context_enterOrClause (e1);
9193 e2 = exprNode_effect (exprData_getOpB (data));
9195 ret = exprNode_op (e1, e2,
9196 exprData_getOpTok (data));
9198 context_exitOrClause (ret, e2);
9202 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
9203 exprNode_effect (exprData_getOpB (data)),
9204 exprData_getOpTok (data));
9209 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
9210 exprData_getUopTok (data));
9213 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
9214 exprData_getUopTok (data));
9226 ret = exprNode_vaArg (exprData_getCastTok (data),
9227 exprNode_effect (exprData_getCastNode (data)),
9228 exprData_getCastType (data));
9232 ret = exprNode_cast (exprData_getCastTok (data),
9233 exprNode_effect (exprData_getCastNode (data)),
9234 exprData_getCastType (data));
9237 ret = exprNode_iterStart (exprData_getIterCallIter (data),
9239 (exprData_getIterCallArgs (data)));
9243 ret = exprNode_iter (exprData_getIterSname (data),
9244 exprNodeList_effect (exprData_getIterAlist (data)),
9245 exprNode_effect (exprData_getIterBody (data)),
9246 exprData_getIterEname (data));
9250 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
9251 exprNode_effect (exprData_getPairB (data)));
9255 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
9256 exprNode_effect (exprData_getTripleTest (data)),
9257 exprNode_effect (exprData_getTripleInc (data)));
9261 ret = exprNode_createTok (exprData_getTok (data));
9265 ret = exprNode_goto (exprData_getLiteral (data));
9266 ret->loc = fileloc_update (ret->loc, e->loc);
9270 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
9274 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
9278 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
9281 case XPR_NULLRETURN:
9282 ret = exprNode_nullReturn (exprData_getTok (data));
9286 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
9287 exprNode_effect (exprData_getPairB (data)));
9291 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
9292 exprNode_effect (exprData_getTripleTrue (data)),
9293 exprNode_effect (exprData_getTripleFalse (data)));
9296 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
9297 exprNode_effect (exprData_getPairB (data)));
9301 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
9302 exprNode_effect (exprData_getTripleTrue (data)),
9303 exprNode_effect (exprData_getTripleFalse (data)));
9306 ret = exprNode_whilePred (exprData_getSingle (data));
9310 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
9311 exprNode_effect (exprData_getPairB (data)));
9315 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
9316 exprNode_effect (exprData_getPairB (data)));
9320 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
9324 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
9325 exprData_getUopTok (data));
9329 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
9330 exprNode_effect (exprData_getPairB (data)));
9335 ret = exprNode_caseMarker
9336 (exprNode_effect (exprData_getSingle (data)),
9342 ret = exprNode_createTok (exprData_getTok (data));
9346 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
9347 exprNode_effect (exprData_getPairB (data)));
9351 ret = exprNode_makeInitialization
9352 (exprData_getInitId (data),
9353 exprNode_effect (exprData_getInitNode (data)));
9357 ret = exprNode_fieldAccessAux
9358 (exprNode_effect (exprData_getFieldNode (data)),
9359 exprNode_loc (exprData_getFieldNode (data)),
9360 cstring_copy (exprData_getFieldName (data)));
9364 ret = exprNode_arrowAccessAux
9365 (exprNode_effect (exprData_getFieldNode (data)),
9366 exprNode_loc (exprData_getFieldNode (data)),
9367 cstring_copy (exprData_getFieldName (data)));
9370 case XPR_STRINGLITERAL:
9384 /*@=observertrans@*/
9386 /*@=dependenttrans@*/
9397 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
9402 if (exprNode_isError (e))
9404 return cstring_undefined;
9412 ret = exprNode_rootVarName (exprData_getUopNode (data));
9415 ret = exprNode_rootVarName (exprData_getOpA (data));
9419 ret = exprData_getId (data);
9422 ret = idDecl_getName (exprData_getInitId (data));
9447 case XPR_NULLRETURN:
9469 case XPR_STRINGLITERAL:
9470 ret = cstring_undefined;
9477 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
9482 if (exprNode_isError (e))
9484 static /*@only@*/ cstring error = cstring_undefined;
9486 if (!cstring_isDefined (error))
9488 error = cstring_makeLiteral ("<error>");
9499 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
9502 ret = message ("%s %s %s",
9503 exprNode_unparse (exprData_getOpA (data)),
9504 lltok_unparse (exprData_getOpTok (data)),
9505 exprNode_unparse (exprData_getOpB (data)));
9508 ret = message ("%s(%q)",
9509 exprNode_unparse (exprData_getFcn (data)),
9510 exprNodeList_unparse (exprData_getArgs (data)));
9513 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
9516 ret = cstring_undefined;
9519 ret = message ("%s:", exprData_getId (data));
9523 ret = cstring_copy (exprData_getId (data));
9526 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
9527 exprNode_unparse (exprData_getPairB (data)));
9530 ret = message ("<body>");
9533 ret = message ("%s %s %s",
9534 exprNode_unparse (exprData_getOpA (data)),
9535 lltok_unparse (exprData_getOpTok (data)),
9536 exprNode_unparse (exprData_getOpB (data)));
9540 ret = message ("%s%s",
9541 lltok_unparse (exprData_getUopTok (data)),
9542 exprNode_unparse (exprData_getUopNode (data)));
9546 ret = message ("%s%s",
9547 exprNode_unparse (exprData_getUopNode (data)),
9548 lltok_unparse (exprData_getUopTok (data)));
9552 ret = message ("offsetof(%s,%q)",
9553 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
9554 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
9558 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
9562 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
9566 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
9570 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
9574 ret = message ("va_arg(%s, %q)",
9575 exprNode_unparse (exprData_getCastNode (data)),
9576 qtype_unparse (exprData_getCastType (data)));
9580 ret = message ("%q(%q)",
9581 uentry_getName (exprData_getIterCallIter (data)),
9582 exprNodeList_unparse (exprData_getIterCallArgs (data)));
9585 ret = message ("%q(%q) %s %q",
9586 uentry_getName (exprData_getIterSname (data)),
9587 exprNodeList_unparse (exprData_getIterAlist (data)),
9588 exprNode_unparse (exprData_getIterBody (data)),
9589 uentry_getName (exprData_getIterEname (data)));
9592 ret = message ("(%q)%s",
9593 qtype_unparse (exprData_getCastType (data)),
9594 exprNode_unparse (exprData_getCastNode (data)));
9598 ret = message ("%s %s",
9599 exprNode_unparse (exprData_getPairA (data)),
9600 exprNode_unparse (exprData_getPairB (data)));
9604 ret = message ("for (%s; %s; %s)",
9605 exprNode_unparse (exprData_getTripleInit (data)),
9606 exprNode_unparse (exprData_getTripleTest (data)),
9607 exprNode_unparse (exprData_getTripleInc (data)));
9611 ret = message ("goto %s", exprData_getLiteral (data));
9615 ret = cstring_makeLiteral ("continue");
9619 ret = cstring_makeLiteral ("break");
9623 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
9626 case XPR_NULLRETURN:
9627 ret = cstring_makeLiteral ("return");
9631 ret = message ("%s, %s",
9632 exprNode_unparse (exprData_getPairA (data)),
9633 exprNode_unparse (exprData_getPairB (data)));
9637 ret = message ("%s ? %s : %s",
9638 exprNode_unparse (exprData_getTriplePred (data)),
9639 exprNode_unparse (exprData_getTripleTrue (data)),
9640 exprNode_unparse (exprData_getTripleFalse (data)));
9643 ret = message ("if (%s) %s",
9644 exprNode_unparse (exprData_getPairA (data)),
9645 exprNode_unparse (exprData_getPairB (data)));
9649 ret = message ("if (%s) %s else %s",
9650 exprNode_unparse (exprData_getTriplePred (data)),
9651 exprNode_unparse (exprData_getTripleTrue (data)),
9652 exprNode_unparse (exprData_getTripleFalse (data)));
9655 ret = message ("while (%s) %s",
9656 exprNode_unparse (exprData_getPairA (data)),
9657 exprNode_unparse (exprData_getPairB (data)));
9661 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
9665 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
9669 ret = message ("do { %s } while (%s)",
9670 exprNode_unparse (exprData_getPairB (data)),
9671 exprNode_unparse (exprData_getPairA (data)));
9675 ret = message ("{ %s }", exprNode_unparse (exprData_getSingle (data)));
9676 /* evans 2002-02-20 was unparseFirst! */
9680 ret = message ("%s;", exprNode_unparse (exprData_getUopNode (data)));
9684 if (exprNode_isStatement (exprData_getPairA (data)))
9687 ** statement expressions already print the ;
9690 ret = message ("%s %s",
9691 exprNode_unparse (exprData_getPairA (data)),
9692 exprNode_unparse (exprData_getPairB (data)));
9696 ret = message ("%s; %s",
9697 exprNode_unparse (exprData_getPairA (data)),
9698 exprNode_unparse (exprData_getPairB (data)));
9704 ret = cstring_makeLiteral ("default:");
9708 ret = message ("switch (%s) %s",
9709 exprNode_unparse (exprData_getPairA (data)),
9710 exprNode_unparse (exprData_getPairB (data)));
9715 ret = message ("case %s:",
9716 exprNode_unparse (exprData_getSingle (data)));
9720 if (exprNode_isError (exprData_getInitNode (data)))
9722 ret = message ("%q", idDecl_unparseC (exprData_getInitId (data)));
9726 ret = message ("%q = %s",
9727 idDecl_unparseC (exprData_getInitId (data)),
9728 exprNode_unparse (exprData_getInitNode (data)));
9733 ret = message ("%s.%s",
9734 exprNode_unparse (exprData_getFieldNode (data)),
9735 exprData_getFieldName (data));
9739 ret = message ("%s->%s",
9740 exprNode_unparse (exprData_getFieldNode (data)),
9741 exprData_getFieldName (data));
9744 case XPR_STRINGLITERAL:
9745 if (ctype_isWideString (e->typ))
9747 ret = message ("L\"%s\"", exprData_getLiteral (data));
9751 ret = message ("\"%s\"", exprData_getLiteral (data));
9756 ret = cstring_copy (exprData_getLiteral (data));
9760 ret = cstring_makeLiteral ("<node>");
9768 exprNode_isInitializer (exprNode e)
9770 return (exprNode_isDefined (e)
9771 && e->kind == XPR_INIT);
9775 exprNode_isCharLiteral (exprNode e)
9777 if (exprNode_isDefined (e))
9779 return (multiVal_isChar (exprNode_getValue (e)));
9788 exprNode_isNumLiteral (exprNode e)
9790 if (exprNode_isDefined (e))
9792 return (multiVal_isInt (exprNode_getValue (e)));
9801 exprNode_isFalseConstant (exprNode e)
9803 if (exprNode_isDefined (e))
9805 cstring s = exprNode_rootVarName (e);
9807 if (cstring_equal (s, context_getFalseName ()))
9817 exprNode_matchLiteral (ctype expected, exprNode e)
9819 if (exprNode_isDefined (e))
9821 multiVal m = exprNode_getValue (e);
9823 if (multiVal_isDefined (m))
9825 if (multiVal_isInt (m))
9827 long int val = multiVal_forceInt (m);
9829 if (ctype_isNumAbstract (expected)
9830 && context_flagOn (FLG_NUMABSTRACTLIT, exprNode_loc (e)))
9835 if (ctype_isDirectBool (ctype_realishType (expected)))
9839 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
9847 if (ctype_isRealInt (expected))
9850 ** unsigned <- [ constant >= 0 is okay ]
9853 if (ctype_isUnsigned (expected))
9862 ** No checks on sizes of integers...maybe add
9866 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
9867 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
9868 bool_unparse (ctype_isInt (exprNode_getType (e)))));
9870 if (context_getFlag (FLG_NUMLITERAL)
9871 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
9877 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
9881 else if (ctype_isChar (expected))
9885 else if (ctype_isArrayPtr (expected))
9888 ** evans 2001-10-14: We allow 0 to match any pointer, but only if the type matches or is void *.
9893 if (ctype_match (exprNode_getType (e), expected)
9894 || ctype_isVoidPointer (exprNode_getType (e)))
9904 else if (ctype_isAnyFloat (expected))
9906 return (context_getFlag (FLG_NUMLITERAL));
9913 else if (multiVal_isDouble (m))
9915 if (ctype_isAnyFloat (expected))
9920 else if (multiVal_isChar (m))
9922 char val = multiVal_forceChar (m);
9924 if (ctype_isChar (expected))
9926 if (ctype_isUnsigned (expected) && ((int)val) < 0)
9947 exprNode_matchType (ctype expected, exprNode e)
9951 if (!exprNode_isDefined (e)) return TRUE;
9953 actual = ctype_realishType (exprNode_getType (e));
9955 if (ctype_match (ctype_realishType (expected), actual))
9960 llassert (!exprNode_isError (e));
9961 return (exprNode_matchLiteral (expected, e));
9965 exprNode_matchTypes (exprNode e1, exprNode e2)
9970 if (!exprNode_isDefined (e1)) return TRUE;
9971 if (!exprNode_isDefined (e2)) return TRUE;
9974 ** realish type --- keep bools, bools
9977 t1 = ctype_realishType (exprNode_getType (e1));
9978 t2 = ctype_realishType (exprNode_getType (e2));
9980 if (ctype_match (t1, t2))
9985 DPRINTF (("Matching literal! %s %s %s %s",
9986 ctype_unparse (t1), exprNode_unparse (e2),
9987 ctype_unparse (t2), exprNode_unparse (e1)));
9989 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
9997 exprNode_matchArgType (ctype ct, exprNode e)
10001 if (!exprNode_isDefined (e))
10006 et = ctype_realType (exprNode_getType (e));
10008 if (ctype_matchArg (ct, et)) return TRUE;
10010 llassert (!exprNode_isError (e));
10011 return (exprNode_matchLiteral (ct, e));
10014 static /*@only@*/ exprNodeSList
10015 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
10017 if (exprNode_isDefined (e))
10019 if (e->kind == XPR_STMTLIST)
10021 return (exprNodeSList_append
10022 (exprNode_flatten (exprData_getPairA (e->edata)),
10023 exprNode_flatten (exprData_getPairB (e->edata))));
10025 else if (e->kind == XPR_BLOCK)
10027 return (exprNode_flatten (exprData_getSingle (e->edata)));
10031 return (exprNodeSList_singleton (e));
10035 return exprNodeSList_new ();
10038 static /*@exposed@*/ exprNode
10039 exprNode_lastStatement (/*@returned@*/ exprNode e)
10041 if (exprNode_isDefined (e))
10043 if (e->kind == XPR_STMTLIST)
10045 exprNode b = exprData_getPairB (e->edata);
10047 if (exprNode_isDefined (b))
10049 return exprNode_lastStatement (b);
10053 return exprNode_lastStatement (exprData_getPairA (e->edata));
10056 else if (e->kind == XPR_BLOCK)
10058 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
10066 return exprNode_undefined;
10069 static /*@exposed@*/ exprNode
10070 exprNode_firstStatement (/*@returned@*/ exprNode e)
10072 if (exprNode_isDefined (e))
10074 if (e->kind == XPR_STMTLIST)
10076 exprNode b = exprData_getPairA (e->edata);
10078 if (exprNode_isDefined (b))
10080 return exprNode_firstStatement (b);
10084 return exprNode_firstStatement (exprData_getPairB (e->edata));
10087 else if (e->kind == XPR_BLOCK)
10089 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
10097 return exprNode_undefined;
10101 exprNode_mergeUSs (exprNode res, exprNode other)
10103 if (exprNode_isDefined (res) && exprNode_isDefined (other))
10105 res->msets = sRefSet_union (res->msets, other->msets);
10106 res->sets = sRefSet_union (res->sets, other->sets);
10107 res->uses = sRefSet_union (res->uses, other->uses);
10112 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
10114 if (exprNode_isDefined (res))
10116 if (exprNode_isDefined (other1))
10118 res->sets = sRefSet_union (res->sets, other1->sets);
10119 res->msets = sRefSet_union (res->msets, other1->msets);
10120 res->uses = sRefSet_union (res->uses, other1->uses);
10122 if (exprNode_isDefined (other2))
10124 res->sets = sRefSet_union (res->sets, other2->sets);
10125 res->msets = sRefSet_union (res->msets, other2->msets);
10126 res->uses = sRefSet_union (res->uses, other2->uses);
10132 ** modifies e->uses
10134 ** Reports errors is s is not defined.
10138 exprNode_addUse (exprNode e, /*@exposed@*/ sRef s)
10140 if (exprNode_isDefined (e))
10142 e->uses = sRefSet_insert (e->uses, s);
10147 exprNode_checkUse (exprNode e, /*@exposed@*/ sRef s, fileloc loc)
10149 if (sRef_isKnown (s) && !sRef_isConst (s))
10152 ** need to check all outer types are useable
10155 DPRINTF (("Check use: %s / %s",
10156 exprNode_unparse (e), sRef_unparse (s)));
10158 exprNode_addUse (e, s);
10160 if (!context_inProtectVars ())
10163 ** only report the deepest error
10166 sRef errorRef = sRef_undefined;
10167 sRef lastRef = sRef_undefined;
10168 bool deadRef = FALSE;
10169 bool unuseable = FALSE;
10170 bool errorMaybe = FALSE;
10172 while (sRef_isValid (s) && sRef_isKnown (s))
10174 ynm readable = sRef_isValidLvalue (s);
10176 DPRINTF (("Readable: %s / %s",
10177 sRef_unparseFull (s), ynm_unparse (readable)));
10179 if (!(ynm_toBoolStrict (readable)))
10181 if (ynm_isMaybe (readable))
10183 lastRef = errorRef;
10185 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
10186 deadRef = sRef_isPossiblyDead (errorRef);
10187 unuseable = sRef_isUnuseable (errorRef);
10192 lastRef = errorRef;
10194 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
10195 deadRef = sRef_isDead (errorRef);
10196 unuseable = sRef_isUnuseable (errorRef);
10197 errorMaybe = FALSE;
10201 if (!sRef_isPartial (s))
10203 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
10204 sRef_setDefined (s, loc);
10205 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
10210 s = sRef_getBaseSafe (s);
10213 if (sRef_isValid (errorRef))
10215 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
10216 && sRef_isPointer (errorRef))
10218 errorRef = lastRef;
10219 DPRINTF (("errorRef: %s", sRef_unparseFull (errorRef)));
10224 if (sRef_isThroughArrayFetch (errorRef))
10227 (FLG_STRICTUSERELEASED,
10228 message ("%q %q may be used after being released",
10229 sRef_unparseKindNamePlain (errorRef),
10230 sRef_unparse (errorRef)),
10233 sRef_showRefKilled (errorRef);
10235 if (sRef_isKept (errorRef))
10237 sRef_clearAliasState (errorRef, loc);
10243 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
10247 message ("%q %q %qused after being released",
10248 sRef_unparseKindNamePlain (errorRef),
10249 sRef_unparse (errorRef),
10250 cstring_makeLiteral (errorMaybe
10251 ? "may be " : "")),
10254 sRef_showRefKilled (errorRef);
10256 if (sRef_isKept (errorRef))
10258 sRef_clearAliasState (errorRef, loc);
10263 else if (unuseable)
10267 message ("%q %q%qused in inconsistent state",
10268 sRef_unparseKindName (errorRef),
10269 sRef_unparseOpt (errorRef),
10270 cstring_makeLiteral (errorMaybe ? "may be " : "")),
10273 sRef_showStateInconsistent (errorRef);
10278 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
10282 message ("%q %q%qused before definition",
10283 sRef_unparseKindName (errorRef),
10284 sRef_unparseOpt (errorRef),
10285 cstring_makeLiteral (errorMaybe ? "may be " : "")),
10291 DPRINTF (("Error: %s", sRef_unparseFull (errorRef)));
10294 sRef_setDefined (errorRef, loc);
10296 if (sRef_isAddress (errorRef))
10298 sRef_setDefined (sRef_getRootBase (errorRef), loc);
10300 } /* end is error */
10308 checkSafeUse (exprNode e, /*@exposed@*/ sRef s)
10310 if (exprNode_isDefined (e) && sRef_isKnown (s))
10312 e->uses = sRefSet_insert (e->uses, s);
10317 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
10319 if (exprNode_isDefined (e))
10321 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
10326 exprNode_checkSet (exprNode e, /*@exposed@*/ sRef s)
10328 sRef defines = sRef_undefined;
10330 if (sRef_isValid (s) && !sRef_isNothing (s))
10332 uentry ue = sRef_getBaseUentry (s);
10334 if (uentry_isValid (ue))
10336 uentry_setLset (ue);
10339 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
10341 voptgenerror (FLG_USEDEF,
10342 message ("Attempt to set unuseable storage: %q",
10347 if (sRef_isMeaningful (s))
10349 if (sRef_isDead (s))
10351 sRef base = sRef_getBaseSafe (s);
10353 if (sRef_isValid (base)
10354 && sRef_isDead (base))
10356 sRef_setPartial (s, exprNode_loc (e));
10359 defines = s; /* okay - modifies for only param */
10361 else if (sRef_isPartial (s))
10363 sRef eref = exprNode_getSref (e);
10365 if (!sRef_isPartial (eref))
10368 ** should do something different here???
10371 sRef_setDefinedComplete (eref, exprNode_loc (e));
10375 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
10378 if (sRef_isMeaningful (eref))
10387 else if (sRef_isAllocated (s))
10389 sRef eref = exprNode_getSref (e);
10392 if (!sRef_isAllocated (eref))
10394 sRef_setDefinedComplete (eref, exprNode_loc (e));
10398 sRef base = sRef_getBaseSafe (eref);
10400 if (sRef_isValid (base))
10402 sRef_setPdefined (base, exprNode_loc (e));
10410 sRef_setDefinedNCComplete (s, exprNode_loc (e));
10415 else /* not meaningful...but still need to insert it */
10421 if (exprNode_isDefined (e) && sRef_isValid (defines))
10423 e->sets = sRefSet_insert (e->sets, defines);
10428 exprNode_checkMSet (exprNode e, /*@exposed@*/ sRef s)
10430 if (sRef_isValid (s) && !sRef_isNothing (s))
10432 uentry ue = sRef_getBaseUentry (s);
10434 if (uentry_isValid (ue))
10436 uentry_setLset (ue);
10439 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
10441 voptgenerror (FLG_USEDEF,
10442 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
10446 if (sRef_isMeaningful (s))
10448 sRef_setDefinedComplete (s, exprNode_loc (e));
10451 if (exprNode_isDefined (e))
10453 e->msets = sRefSet_insert (e->msets, s);
10459 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
10461 checkAnyCall (fcn, cstring_undefined, params, args,
10462 FALSE, sRefSet_undefined, FALSE, 0);
10466 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
10467 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
10471 if (uentry_isYield (ucurrent))
10473 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
10474 exprNode_checkSet (current, current->sref);
10478 if (uentry_isSefParam (ucurrent))
10480 sRefSet sets = current->sets;
10481 sRef ref = exprNode_getSref (current);
10483 if (sRef_isMacroParamRef (ref))
10485 uentry ue = sRef_getUentry (ref);
10487 if (!uentry_isSefParam (ue))
10492 ("Parameter %d to %s is declared sef, but "
10493 "the argument is a macro parameter declared "
10495 argno, exprNode_unparse (fcn),
10496 exprNode_unparse (current)),
10497 exprNode_loc (current));
10501 if (!sRefSet_isEmpty (sets))
10503 sRefSet reported = sRefSet_undefined;
10505 sRefSet_realElements (current->sets, el)
10507 if (sRefSet_isSameNameMember (reported, el))
10509 ; /* don't report again */
10513 if (sRef_isUnconstrained (el))
10518 ("Parameter %d to %s is declared sef, but "
10519 "the argument calls unconstrained function %s "
10520 "(no guarantee it will not modify something): %s",
10521 argno, exprNode_unparse (fcn),
10522 sRef_unconstrainedName (el),
10523 exprNode_unparse (current)),
10524 exprNode_loc (current));
10531 ("Parameter %d to %s is declared sef, but "
10532 "the argument may modify %q: %s",
10533 argno, exprNode_unparse (fcn),
10535 exprNode_unparse (current)),
10536 exprNode_loc (current));
10539 } end_sRefSet_realElements;
10543 transferChecks_passParam (current, ucurrent, isSpec, fcn, argno, totargs);
10544 exprNode_mergeUSs (fcn, current);
10549 checkAnyCall (/*@dependent@*/ exprNode fcn,
10550 /*@dependent@*/ cstring fname,
10553 bool hasMods, sRefSet mods,
10558 int nargs = exprNodeList_size (args);
10563 ** concat all args ud's to f, add each arg sref as a use unless
10564 ** it was specified as "out", in which case it is a def.
10567 uentryList_reset (pn);
10570 ** aliasing checks:
10572 ** if paramn is only or unique, no other arg may alias argn
10575 exprNodeList_elements (args, current)
10579 if (exprNode_isDefined (current))
10581 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
10583 uentry ucurrent = uentryList_current (pn);
10585 if (specialArgs == 0
10586 || (paramno < specialArgs))
10588 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
10590 if (context_maybeSet (FLG_ALIASUNIQUE))
10592 if (uentry_isOnly (ucurrent)
10593 || uentry_isUnique (ucurrent))
10595 checkUniqueParams (fcn, current, args,
10596 paramno, ucurrent);
10601 else /* uentry is undefined */
10603 if (specialArgs == 0)
10605 exprNode_checkUseParam (current);
10608 exprNode_mergeUSs (fcn, current);
10611 uentryList_advanceSafe (pn);
10612 } end_exprNodeList_elements;
10618 sRefSet_allElements (mods, s)
10621 sRef rb = sRef_getRootBase (s);
10623 if (sRef_isFileOrGlobalScope (rb))
10625 context_usedGlobal (rb);
10628 fb = sRef_fixBaseParam (s, args);
10630 if (!sRef_isMacroParamRef (fb))
10632 if (sRef_isNothing (fb))
10638 if (sRef_isValid (fb))
10640 uentry ue = sRef_getBaseUentry (s);
10642 if (uentry_isValid (ue))
10644 uentry_setLset (ue);
10648 fcn->sets = sRefSet_insert (fcn->sets, fb);
10651 sRef_clearDerivedComplete (s);
10652 } end_sRefSet_allElements;
10658 if (context_hasMods ())
10660 if (context_maybeSet (FLG_MODUNCON))
10664 message ("Undetected modification possible "
10665 "from call to unconstrained function %s: %s",
10667 exprNode_unparse (fcn)),
10668 exprNode_loc (fcn));
10673 if (context_maybeSet (FLG_MODUNCONNOMODS)
10674 && !(context_inIterDef () || context_inIterEnd ()))
10677 (FLG_MODUNCONNOMODS,
10678 message ("Undetected modification possible "
10679 "from call to unconstrained function %s: %s",
10681 exprNode_unparse (fcn)),
10682 exprNode_loc (fcn));
10686 exprNode_checkSetAny (fcn, fname);
10690 void exprNode_checkUseParam (exprNode current)
10692 if (exprNode_isDefined (current))
10694 exprNode_checkUse (current, current->sref, current->loc);
10699 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
10700 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10705 if (!ctype_match (tr1, tr2))
10707 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
10708 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
10710 DPRINTF (("No error: [%s] %s / [%s] %s",
10711 exprNode_unparse (e1), ctype_unparse (tr1),
10712 exprNode_unparse (e2), ctype_unparse (tr2)));
10714 ret = ctype_biggerType (tr1, tr2);
10718 if (ctype_isNumAbstract (tr1)
10719 && exprNode_isNumLiteral (e2)
10720 && context_flagOn (FLG_NUMABSTRACTLIT, e1->loc))
10722 ret = tr1; /* No error */
10724 else if (ctype_isNumAbstract (tr2)
10725 && exprNode_isNumLiteral (e1)
10726 && context_flagOn (FLG_NUMABSTRACTLIT, e1->loc))
10734 message ("Incompatible types for %s (%s, %s): %s %s %s",
10735 lltok_unparse (op),
10736 ctype_unparse (te1),
10737 ctype_unparse (te2),
10738 exprNode_unparse (e1), lltok_unparse (op),
10739 exprNode_unparse (e2)),
10742 ret = ctype_unknown;
10746 ret = ctype_biggerType (tr1, tr2);
10753 if (ctype_isNumAbstract (tr1))
10757 else if (ctype_isForceRealNumeric (&tr1)
10758 && ctype_isForceRealNumeric (&tr2))
10760 ret = ctype_resolveNumerics (tr1, tr2);
10762 else if (!context_msgStrictOps ())
10764 if (ctype_isPointer (tr1))
10766 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
10770 else if (ctype_isInt (tr2))
10776 ret = ctype_unknown;
10779 else if (ctype_isPointer (tr2))
10781 if (ctype_isPointer (tr1))
10785 else if (ctype_isInt (tr1))
10791 ret = ctype_unknown;
10796 ret = ctype_resolveNumerics (tr1, tr2);
10801 int opid = lltok_getTok (op);
10802 bool comparop = (opid == EQ_OP || opid == NE_OP
10803 || opid == TLT || opid == TGT
10804 || opid == LE_OP || opid == GE_OP);
10806 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
10809 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
10810 || (ctype_isBool (tr1) && ctype_isBool (tr2))
10811 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
10817 if (ctype_sameName (te1, te2))
10821 message ("Operands of %s are non-numeric (%t): %s %s %s",
10822 lltok_unparse (op), te1,
10823 exprNode_unparse (e1), lltok_unparse (op),
10824 exprNode_unparse (e2)),
10831 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
10832 lltok_unparse (op), te1, te2,
10833 exprNode_unparse (e1), lltok_unparse (op),
10834 exprNode_unparse (e2)),
10839 else if (!ctype_isNumeric (tr1))
10843 message ("Right operand of %s is non-numeric (%t): %s %s %s",
10844 lltok_unparse (op), te1,
10845 exprNode_unparse (e1), lltok_unparse (op),
10846 exprNode_unparse (e2)),
10851 if (!ctype_isNumeric (tr2))
10855 message ("Left operand of %s is non-numeric (%t): %s %s %s",
10856 lltok_unparse (op), te2,
10857 exprNode_unparse (e1), lltok_unparse (op),
10858 exprNode_unparse (e2)),
10863 ret = ctype_unknown;
10871 abstractOpError (ctype tr1, ctype tr2, lltok op,
10872 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10873 fileloc loc1, fileloc loc2)
10875 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
10877 if (ctype_match (tr1, tr2))
10879 if (ctype_isRealNumAbstract (tr1))
10881 ; /* No warning for numabstract types */
10885 if (lltok_isEqOp (op) || lltok_isNotEqOp (op))
10888 (FLG_ABSTRACTCOMPARE,
10889 message ("Object equality comparison (%s) on objects of abstract type (%t): %s %s %s",
10890 lltok_unparse (op), tr1,
10891 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10898 message ("Operands of %s are abstract type (%t): %s %s %s",
10899 lltok_unparse (op), tr1,
10900 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10907 if (ctype_isRealNumAbstract (tr1) && ctype_isRealNumAbstract (tr2))
10912 ("Operands of %s are different numabstract types (%t, %t): %s %s %s",
10913 lltok_unparse (op), tr1, tr2,
10914 exprNode_unparse (e1),
10915 lltok_unparse (op), exprNode_unparse (e2)),
10922 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
10923 lltok_unparse (op), tr1, tr2,
10924 exprNode_unparse (e1), lltok_unparse (op),
10925 exprNode_unparse (e2)),
10930 else if (ctype_isRealAbstract (tr1) && !ctype_isRealNumAbstract (tr1))
10934 message ("Left operand of %s is abstract type (%t): %s %s %s",
10935 lltok_unparse (op), tr1,
10936 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10941 if (ctype_isRealAbstract (tr2) && !ctype_isRealNumAbstract (tr2))
10945 message ("Right operand of %s is abstract type (%t): %s %s %s",
10946 lltok_unparse (op), tr2,
10947 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10958 ** requies e1 and e2 and not error exprNode's.
10962 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
10963 ** the rep of the abstract type is exposed.
10965 ** The order is very important:
10967 ** check rep expose (move into check transfer)
10973 ** This isn't really a sensible procedure, but the indententation
10974 ** was getting too deep.
10978 checkOneRepExpose (sRef ysr, sRef base,
10979 /*@notnull@*/ exprNode e1,
10980 /*@notnull@*/ exprNode e2, ctype ct,
10983 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
10984 || sRef_isOwned (ysr)
10985 || sRef_isExposed (ysr)))
10987 if (sRef_isAnyParam (base) && !sRef_isExposed (base)
10988 && !sRef_isObserver (base)) /* evans 2001-07-11: added isObserver */
10991 if (sRef_isIReference (ysr))
10993 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10998 ("Assignment of mutable component of parameter %q "
10999 "to component of abstract "
11000 "type %s exposes rep: %s = %s",
11001 sRef_unparse (base),
11002 ctype_unparse (ct),
11003 exprNode_unparse (e1), exprNode_unparse (e2)),
11011 ("Assignment of mutable component of parameter %q "
11012 "(through alias %q) to component of abstract "
11013 "type %s exposes rep: %s = %s",
11014 sRef_unparse (base),
11015 sRef_unparse (e2->sref),
11016 ctype_unparse (ct),
11017 exprNode_unparse (e1), exprNode_unparse (e2)),
11023 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
11027 message ("Assignment of mutable parameter %q "
11028 "to component of abstract type %s "
11029 "exposes rep: %s = %s",
11030 sRef_unparse (base),
11031 ctype_unparse (ct),
11032 exprNode_unparse (e1),
11033 exprNode_unparse (e2)),
11040 message ("Assignment of mutable parameter %q "
11041 "(through alias %q) to "
11042 "component of abstract type %s exposes "
11044 sRef_unparse (base),
11045 sRef_unparse (e2->sref),
11046 ctype_unparse (ct),
11047 exprNode_unparse (e1),
11048 exprNode_unparse (e2)),
11054 if (sRef_isFileOrGlobalScope (s2b))
11056 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
11060 message ("Assignment of global %q "
11062 "abstract type %s exposes rep: %s = %s",
11063 sRef_unparse (base),
11064 ctype_unparse (ct),
11065 exprNode_unparse (e1), exprNode_unparse (e2)),
11072 message ("Assignment of global %q (through alias %q) "
11074 "abstract type %s exposes rep: %s = %s",
11075 sRef_unparse (base),
11076 sRef_unparse (e2->sref),
11077 ctype_unparse (ct),
11078 exprNode_unparse (e1), exprNode_unparse (e2)),
11086 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
11088 DPRINTF (("Do assign: %s <- %s",
11089 exprNode_unparse (e1), exprNode_unparse (e2)));
11090 DPRINTF (("Ctype: %s", ctype_unparse (exprNode_getType (e1))));
11092 if (ctype_isRealFunction (exprNode_getType (e1))
11093 && !ctype_isRealPointer (exprNode_getType (e1)))
11097 message ("Invalid left-hand side of assignment (function type %s): %s",
11098 ctype_unparse (exprNode_getType (e1)),
11099 exprNode_unparse (e1)),
11103 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
11105 ctype t2 = exprNode_getType (e2);
11106 sRef sr = sRef_getRootBase (e1->sref);
11107 ctype ct = sRef_getType (sr);
11109 if (ctype_isAbstract (t2)
11110 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
11112 /* it is immutable, okay to reference */
11113 goto donerepexpose;
11116 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
11118 sRef s2b = sRef_getRootBase (e2->sref);
11119 sRef s1 = e1->sref;
11120 sRef s1b = sRef_getRootBase (s1);
11123 aliases = usymtab_canAlias (e2->sref);
11125 if (!sRef_similar (s2b, s1b)
11126 && !sRef_isExposed (s1)
11127 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
11129 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
11130 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
11131 && !sRef_isExposed (s2b))
11133 if (sRef_isIReference (e2->sref))
11138 ("Assignment of mutable component of parameter %q "
11139 "to component of abstract type %s exposes rep: %s = %s",
11140 sRef_unparse (s2b),
11141 ctype_unparse (ct),
11142 exprNode_unparse (e1), exprNode_unparse (e2)),
11149 message ("Assignment of mutable parameter %q to "
11150 "component of abstract type %s exposes rep: %s = %s",
11151 sRef_unparse (s2b),
11152 ctype_unparse (ct),
11153 exprNode_unparse (e1), exprNode_unparse (e2)),
11158 if (sRef_isFileOrGlobalScope (s2b))
11162 message ("Assignment of global %q to component of "
11163 "abstract type %s exposes rep: %s = %s",
11164 sRef_unparse (s2b),
11165 ctype_unparse (ct),
11166 exprNode_unparse (e1), exprNode_unparse (e2)),
11170 sRefSet_realElements (aliases, ysr)
11172 sRef base = sRef_getRootBase (ysr);
11174 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
11175 || sRef_sameName (base, s1b))
11177 ; /* error already reported or same sref */
11181 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
11183 } end_sRefSet_realElements;
11185 sRefSet_free (aliases);
11192 ** function variables don't really work...
11195 if (!ctype_isFunction (ctype_realType (e2->typ)))
11199 DPRINTF (("Check init: %s / %s",
11200 exprNode_unparse (e1), exprNode_unparse (e2)));
11201 transferChecks_initialization (e1, e2);
11205 transferChecks_assign (e1, e2);
11210 sRef fref = e2->sref;
11212 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
11213 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
11215 /* Need to typecheck the annotation on the parameters */
11217 if (ctype_isRealFunction (e1->typ)) {
11218 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
11219 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
11221 if (!uentryList_isMissingParams (e1p)
11222 && !uentryList_isMissingParams (e2p)
11223 && uentryList_size (e1p) > 0) {
11224 if (uentryList_size (e1p) == uentryList_size (e2p)) {
11227 uentryList_elements (e1p, el1) {
11230 el2 = uentryList_getN (e2p, n);
11232 uentry_checkMatchParam (el1, el2, n, e2);
11233 } end_uentryList_elements;
11239 if (exprNode_isStringLiteral (e2))
11241 exprNode_checkStringLiteralLength (exprNode_getType (e1), e2);
11244 if (isInit && sRef_isFileOrGlobalScope (e1->sref))
11250 DPRINTF (("Update aliases: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
11251 updateAliases (e1, e2);
11256 checkMacroParen (exprNode e)
11258 if (exprNode_isError (e) || e->kind == XPR_CAST)
11264 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
11268 message ("Macro parameter used without parentheses: %s",
11269 exprNode_unparse (e)),
11276 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
11280 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
11284 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
11291 ** if e2 is a parameter or global derived location which
11292 ** can be modified (that is, e2 is a mutable abstract type,
11293 ** or a derived pointer), then e1 can alias e2.
11295 ** e1 can alias everything which e2 can alias.
11297 ** Also, if e1 is guarded, remove from guard sets!
11300 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
11302 if (!context_inProtectVars ())
11305 ** depends on types of e1 and e2
11308 sRef s1 = e1->sref;
11309 sRef s2 = e2->sref;
11310 ctype t1 = exprNode_getType (e1);
11312 /* handle pointer sRefs, record fields, arrays, etc... */
11314 if (!ctype_isRealSU (t1))
11316 DPRINTF (("Copying real! %s", ctype_unparse (t1)));
11317 sRef_copyRealDerivedComplete (s1, s2);
11322 ** Fields should alias
11325 DPRINTF (("Not COPYING!: %s", ctype_unparse (t1)));
11328 if (ctype_isMutable (t1) && sRef_isKnown (s1))
11330 usymtab_clearAlias (s1);
11331 usymtab_addMustAlias (s1, s2);
11332 DPRINTF (("Add must alias: %s / %s", sRef_unparse (s1), sRef_unparse (s2)));
11336 DPRINTF (("Not mutable: %s", ctype_unparse (t1)));
11339 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
11341 usymtab_unguard (s1);
11346 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
11348 if (exprNode_isDefined (e))
11350 e->loc = fileloc_update (e->loc, loc);
11354 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
11360 static void checkUniqueParams (exprNode fcn,
11361 /*@notnull@*/ exprNode current,
11363 int paramno, uentry ucurrent)
11366 sRef thisref = exprNode_getSref (current);
11369 ** Check if any argument could match this argument.
11372 exprNodeList_elements (args, icurrent)
11376 if (iparamno != paramno)
11378 sRef sr = exprNode_getSref (icurrent);
11380 if (sRef_similarRelaxed (thisref, sr))
11382 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
11387 ("Parameter %d (%s) to function %s is declared %s but "
11388 "is aliased by parameter %d (%s)",
11390 exprNode_unparse (current),
11391 exprNode_unparse (fcn),
11392 alkind_unparse (uentry_getAliasKind (ucurrent)),
11393 iparamno, exprNode_unparse (icurrent)),
11399 sRefSet aliases = usymtab_canAlias (sr);
11401 sRefSet_allElements (aliases, asr)
11403 if (ctype_isUnknown (sRef_getType (thisref)))
11405 sRef_setType (thisref, uentry_getType (ucurrent));
11408 if (sRef_similarRelaxed (thisref, asr))
11410 if (sRef_isExternal (asr))
11412 if (sRef_isLocalState (thisref))
11418 sRef base = sRef_getRootBase (asr);
11420 if (!sRef_similar (sRef_getBase (asr), thisref))
11422 if (sRef_isUnique (base) || sRef_isOnly (base)
11423 || sRef_isKept (base)
11424 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
11425 || (sRef_isAddress (thisref)
11426 && sRef_isLocalVar (sRef_getRootBase (thisref))))
11428 ; /* okay, no error */
11433 (FLG_MAYALIASUNIQUE,
11435 ("Parameter %d (%s) to function %s is declared %s but "
11436 "may be aliased externally by parameter %d (%s)",
11438 exprNode_unparse (current),
11439 exprNode_unparse (fcn),
11440 alkind_unparse (uentry_getAliasKind (ucurrent)),
11441 iparamno, exprNode_unparse (icurrent)),
11452 ("Parameter %d (%s) to function %s is declared %s but "
11453 "is aliased externally by parameter %d (%s) through "
11456 exprNode_unparse (current),
11457 exprNode_unparse (fcn),
11458 alkind_unparse (uentry_getAliasKind (ucurrent)),
11459 iparamno, exprNode_unparse (icurrent),
11460 sRef_unparse (asr)),
11464 } end_sRefSet_allElements;
11465 sRefSet_free (aliases);
11468 } end_exprNodeList_elements;
11471 long exprNode_getLongValue (exprNode e) {
11474 if (exprNode_hasValue (e)
11475 && multiVal_isInt (exprNode_getValue (e)))
11477 value = multiVal_forceInt (exprNode_getValue (e));
11488 /*@observer@*/ fileloc exprNode_getfileloc (exprNode p_e)
11490 if (exprNode_isDefined (p_e) )
11491 return ( p_e->loc );
11493 return fileloc_undefined;
11496 /*@only@*/ fileloc exprNode_getNextSequencePoint (exprNode e)
11499 ** Returns the location of the sequence point following e.
11501 ** Only works for statements (for now).
11504 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
11505 lltok t = exprData_getUopTok (e->edata);
11506 return fileloc_copy(lltok_getLoc (t));
11508 /* drl possible problem : warning fix
11509 llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
11511 return fileloc_undefined;
11515 exprNode exprNode_createNew(ctype c)
11519 ret = exprNode_createPlain (c);
11524 bool exprNode_isInitBlock (exprNode e)
11526 return (exprNode_isDefined(e) && e->kind == XPR_INITBLOCK);
11529 /*drl 3/2/2003 moved this function out of constraint.c */
11530 exprNode exprNode_copyConstraints (/*@returned@*/ exprNode dst, exprNode src)
11533 llassert (exprNode_isDefined (dst) );
11534 llassert (exprNode_isDefined (src) );
11536 constraintList_free (dst->ensuresConstraints);
11537 constraintList_free (dst->requiresConstraints);
11538 constraintList_free (dst->trueEnsuresConstraints);
11539 constraintList_free (dst->falseEnsuresConstraints);
11541 dst->ensuresConstraints = constraintList_copy (src->ensuresConstraints);
11542 dst->requiresConstraints = constraintList_copy (src->requiresConstraints);
11543 dst->trueEnsuresConstraints = constraintList_copy (src->trueEnsuresConstraints);
11544 dst->falseEnsuresConstraints = constraintList_copy (src->falseEnsuresConstraints);