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)),
1333 else if (ctype_isNumAbstract (rt))
1336 (FLG_NUMABSTRACTINDEX,
1337 message ("Array fetch using numabstract type, %t: %s[%s]",
1339 exprNode_unparse (e1), exprNode_unparse (e2)),
1346 message ("Array fetch using non-integer, %t: %s[%s]",
1348 exprNode_unparse (e1), exprNode_unparse (e2)),
1352 multiVal_free (ind->val);
1353 ind->val = multiVal_unknown ();
1356 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1358 exprNode ret = exprNode_createSemiCopy (arr);
1359 multiVal m = exprNode_getValue (ind);
1361 ret->typ = ctype_baseArrayPtr (crarr);
1362 ret->kind = XPR_FETCH;
1364 if (multiVal_isInt (m))
1366 int i = (int) multiVal_forceInt (m);
1368 if (sRef_isValid (arr->sref)) {
1369 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1371 ret->sref = sRef_undefined;
1376 ret->sref = sRef_makeArrayFetch (arr->sref);
1379 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1380 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1381 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1383 /* (see comment on spurious errors above) */
1384 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1386 exprNode_checkUse (ret, ind->sref, ind->loc);
1387 exprNode_checkUse (ret, arr->sref, arr->loc);
1393 if (ctype_isUnknown (carr))
1395 exprNode ret = exprNode_createPartialCopy (arr);
1397 ret->kind = XPR_FETCH;
1398 ret->typ = ctype_unknown;
1399 ret->sets = sRefSet_union (ret->sets, ind->sets);
1400 ret->msets = sRefSet_union (ret->msets, ind->msets);
1401 ret->uses = sRefSet_union (ret->uses, ind->uses);
1403 /* (see comment on spurious errors above) */
1404 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1406 exprNode_checkUse (ret, ind->sref, ind->loc);
1407 exprNode_checkUse (ret, arr->sref, arr->loc);
1414 message ("Array fetch from non-array (%t): %s[%s]", carr,
1415 exprNode_unparse (e1), exprNode_unparse (e2)),
1418 exprNode_free (arr);
1419 exprNode_free (ind);
1421 return (exprNode_makeError ());
1431 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1432 exprNodeList args, exprNode ret)
1434 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1438 ** checkPrintfArgs --- checks arguments for printf-like functions
1439 ** Arguments before ... have already been checked.
1440 ** The argument before the ... is a char *.
1441 ** argno is the format string argument.
1445 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1446 exprNodeList args, exprNode ret, int argno)
1449 ** the last argument before the elips is the format string
1454 int nargs = exprNodeList_size (args);
1455 uentryList params = uentry_getParams (fcn);
1459 ** These should be ensured by checkSpecialFunction
1462 llassert (uentryList_size (params) == argno + 1);
1463 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1465 a = exprNodeList_getN (args, argno - 1);
1466 formatloc = fileloc_copy (exprNode_loc (a));
1468 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1469 && exprNode_knownStringValue (a))
1471 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1472 char *code = format;
1475 nargs = exprNodeList_size (args);
1477 while ((code = strchr (code, '%')) != NULL)
1479 char *origcode = code;
1480 cstring codetext = cstring_newEmpty ();
1481 char key = *(++code);
1482 ctype modtype = ctype_int;
1483 bool modified = FALSE;
1485 fileloc_addColumn (formatloc, code - ocode);
1487 codetext = cstring_appendChar (codetext, key);
1490 while (isFlagKey (key))
1493 codetext = cstring_appendChar (codetext, key);
1494 fileloc_incColumn (formatloc);
1497 if (key == 'm') /* skipped in syslog */
1502 /* ignore field width */
1503 while (isdigit ((int) key) != 0)
1506 codetext = cstring_appendChar (codetext, key);
1507 fileloc_incColumn (formatloc);
1510 /* ignore precision */
1514 codetext = cstring_appendChar (codetext, key);
1515 fileloc_incColumn (formatloc);
1518 ** In printf, '*' means: read the next arg as an int for the
1519 ** field width. This seems to be missing from my copy of the
1520 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1521 ** later) but never does.
1526 ; /* don't do anything --- handle later */
1530 while (isdigit ((int) key) != 0)
1533 codetext = cstring_appendChar (codetext, key);
1534 fileloc_incColumn (formatloc);
1541 modtype = ctype_sint; /* short */
1543 codetext = cstring_appendChar (codetext, key);
1544 fileloc_incColumn (formatloc);
1546 else if (key == 'l' || key == 'L')
1548 modtype = ctype_lint; /* long */
1550 codetext = cstring_appendChar (codetext, key);
1551 fileloc_incColumn (formatloc);
1553 if (key == 'l' || key == 'L') {
1554 modtype = ctype_llint; /* long long */
1556 codetext = cstring_appendChar (codetext, key);
1557 fileloc_incColumn (formatloc);
1565 /* now, key = type of conversion to apply */
1567 fileloc_incColumn (formatloc);
1575 message ("No argument corresponding to %q format "
1576 "code %d (%%%s): \"%s\"",
1577 uentry_getName (fcn),
1579 cstring_fromChars (format)),
1582 if (fileloc_isDefined (formatloc)
1583 && context_getFlag (FLG_SHOWCOL))
1585 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1593 a = exprNodeList_getN (args, i);
1596 if (!exprNode_isError (a))
1602 case '*': /* int argument for fieldwidth */
1603 expecttype = ctype_int;
1604 *(--code) = '%'; /* convert it for next code */
1605 fileloc_subColumn (formatloc, 1);
1606 /*@switchbreak@*/ break;
1609 expecttype = ctype_combine (ctype_uint, modtype);
1610 /*@switchbreak@*/ break;
1612 case 'i': /* int argument */
1614 expecttype = ctype_combine (ctype_int, modtype);
1615 /*@switchbreak@*/ break;
1617 case 'x': /* unsigned int */
1619 expecttype = ctype_combine (ctype_uint, modtype);
1621 /*@switchbreak@*/ break;
1627 case 'f': /* double */
1628 expecttype = ctype_combine (ctype_double, modtype);
1629 /*@switchbreak@*/ break;
1631 case 'c': /* int converted to char (check its a char?) */
1632 expecttype = ctype_makeConj (ctype_int,
1633 ctype_makeConj (ctype_char,
1635 /* evans 2001-10-05 - changed to reflect correct ISO spec:
1636 int converted to char */
1638 /*@switchbreak@*/ break;
1640 case 's': /* string */
1641 expecttype = ctype_string;
1642 /*@switchbreak@*/ break;
1645 while (((key = *(++code)) != ']')
1648 codetext = cstring_appendChar (codetext, key);
1649 fileloc_incColumn (formatloc);
1655 (message ("Bad character set format: %s",
1656 cstring_fromChars (origcode)));
1659 expecttype = ctype_string;
1660 /*@switchbreak@*/ break;
1662 case 'p': /* pointer */
1663 expecttype = ctype_makePointer (ctype_void);
1664 /* need not be defined */
1665 uentry_setDefState (regArg, SS_RELDEF);
1666 sRef_setPosNull (uentry_getSref (regArg),
1669 /*@switchbreak@*/ break;
1671 case 'n': /* pointer to int, modified by call! */
1672 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1674 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1675 /*@switchbreak@*/ break;
1677 case 'm': /* in a syslog, it doesn't consume an argument */
1678 /* should check we're really doing syslog */
1680 /*@switchbreak@*/ break;
1684 expecttype = ctype_unknown;
1688 message ("Unrecognized format code: %s",
1689 cstring_fromChars (origcode)),
1690 fileloc_isDefined (formatloc)
1691 ? formatloc : g_currentloc);
1693 /*@switchbreak@*/ break;
1696 if (!(exprNode_matchArgType (expecttype, a)))
1698 if (ctype_isVoidPointer (expecttype)
1699 && ctype_isRealAbstract (a->typ)
1700 && (context_getFlag (FLG_ABSTVOIDP)))
1706 if (llgenformattypeerror
1707 (expecttype, exprNode_undefined,
1709 message ("Format argument %d to %q (%%%s) expects "
1712 uentry_getName (fcn),
1715 a->typ, exprNode_unparse (a)),
1718 if (fileloc_isDefined (formatloc)
1719 && context_getFlag (FLG_SHOWCOL))
1722 (cstring_makeLiteral
1723 ("Corresponding format code"),
1730 uentry_setType (regArg, expecttype);
1731 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1733 if (ctype_equal (expecttype, ctype_string))
1735 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1738 uentry_setType (regArg, ctype_unknown);
1739 uentry_fixupSref (regArg);
1743 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1754 cstring_free (codetext);
1759 voptgenerror (FLG_TYPE,
1760 message ("Format string for %q has %d arg%&, given %d",
1761 uentry_getName (fcn), i - argno, nargs - argno),
1767 /* no checking possible for compile-time unknown format strings */
1768 if (exprNode_isDefined (a))
1772 message ("Format string parameter to %s is not a compile-time constant: %s",
1773 exprNode_unparse (f),
1774 exprNode_unparse (a)),
1779 fileloc_free (formatloc);
1783 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1784 exprNodeList args, exprNode ret, int argno)
1788 int nargs = exprNodeList_size (args);
1789 uentryList params = uentry_getParams (fcn);
1793 ** These should be ensured by checkSpecialFunction
1796 llassert (uentryList_size (params) == argno + 1);
1797 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1799 a = exprNodeList_getN (args, argno - 1);
1800 formatloc = fileloc_copy (exprNode_loc (a));
1802 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1803 && exprNode_knownStringValue (a))
1805 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1806 char *code = format;
1809 nargs = exprNodeList_size (args);
1811 while ((code = strchr (code, '%')) != NULL)
1813 char *origcode = code;
1814 char key = *(++code);
1815 cstring codetext = cstring_newEmpty ();
1816 ctype modtype = ctype_int;
1817 char modifier = '\0';
1818 bool modified = TRUE;
1819 bool ignore = FALSE;
1821 codetext = cstring_appendChar (codetext, key);
1822 fileloc_addColumn (formatloc, code - ocode);
1825 ** this is based on ANSI standard library description of fscanf
1826 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1829 /* '*' suppresses assignment (does not need match argument) */
1834 codetext = cstring_appendChar (codetext, key);
1837 fileloc_incColumn (formatloc);
1840 /* ignore field width */
1841 while (isdigit ((int) key) != 0)
1844 codetext = cstring_appendChar (codetext, key);
1845 fileloc_incColumn (formatloc);
1850 modtype = ctype_sint; /* short */
1852 codetext = cstring_appendChar (codetext, key);
1853 fileloc_incColumn (formatloc);
1855 else if (key == 'l' || key == 'L')
1857 modtype = ctype_lint; /* long */
1861 codetext = cstring_appendChar (codetext, key);
1863 fileloc_incColumn (formatloc);
1865 if (key == 'l' || key == 'L') {
1866 modtype = ctype_llint; /* long long */
1868 codetext = cstring_appendChar (codetext, key);
1869 fileloc_incColumn (formatloc);
1877 /* now, key = type of conversion to apply */
1879 fileloc_incColumn (formatloc);
1893 message ("No argument corresponding to %q format "
1894 "code %d (%%%s): \"%s\"",
1895 uentry_getName (fcn),
1897 cstring_fromChars (format)),
1900 if (fileloc_isDefined (formatloc)
1901 && context_getFlag (FLG_SHOWCOL))
1904 (cstring_makeLiteral ("Corresponding format code"),
1912 a = exprNodeList_getN (args, i);
1915 if (!exprNode_isError (a))
1921 case '*': /* int argument for fieldwidth */
1922 expecttype = ctype_makePointer (ctype_int);
1923 *(--code) = '%'; /* convert it for next code */
1924 fileloc_subColumn (formatloc, 1);
1925 /*@switchbreak@*/ break;
1928 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1929 /*@switchbreak@*/ break;
1934 case 'X': /* unsigned int */
1935 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1936 /*@switchbreak@*/ break;
1943 /* printf is double, scanf is float! */
1945 if (modifier == 'l')
1947 expecttype = ctype_makePointer (ctype_double);
1949 else if (modifier == 'L')
1951 expecttype = ctype_makePointer (ctype_ldouble);
1955 llassert (modifier == '\0');
1956 expecttype = ctype_makePointer (ctype_float);
1958 /*@switchbreak@*/ break;
1960 case 'c': /* int converted to char (check its a char?) */
1961 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1962 /*@switchbreak@*/ break;
1964 case 's': /* string */
1965 expecttype = ctype_string;
1966 /*@switchbreak@*/ break;
1970 while (((key = *(++code)) != ']')
1973 codetext = cstring_appendChar (codetext, key);
1974 fileloc_incColumn (formatloc);
1980 (message ("Bad character set format: %s",
1981 cstring_fromChars (origcode)));
1984 expecttype = ctype_string;
1985 /*@switchbreak@*/ break;
1988 case 'p': /* pointer */
1991 message ("Format code should not be used in scanf: %s",
1992 cstring_fromChars (origcode)),
1993 fileloc_isDefined (formatloc)
1994 ? formatloc : g_currentloc);
1996 expecttype = ctype_unknown;
1997 /*@switchbreak@*/ break;
1999 case 'n': /* pointer to int, modified by call! */
2000 expecttype = ctype_makePointer (ctype_int);
2001 /*@switchbreak@*/ break;
2004 expecttype = ctype_unknown;
2008 message ("Unrecognized format code: %s",
2009 cstring_fromChars (origcode)),
2010 fileloc_isDefined (formatloc)
2011 ? formatloc : g_currentloc);
2013 /*@switchbreak@*/ break;
2016 if (!(exprNode_matchArgType (expecttype, a)))
2018 if (ctype_isVoidPointer (expecttype)
2019 && ctype_isRealAbstract (a->typ)
2020 && (context_getFlag (FLG_ABSTVOIDP)))
2026 if (llgenformattypeerror
2027 (expecttype, exprNode_undefined,
2029 message ("Format argument %d to %q (%%%s) expects "
2032 uentry_getName (fcn),
2033 codetext, expecttype,
2034 a->typ, exprNode_unparse (a)),
2037 if (fileloc_isDefined (formatloc)
2038 && context_getFlag (FLG_SHOWCOL))
2041 (cstring_makeLiteral
2042 ("Corresponding format code"),
2049 uentry_setType (outArg, expecttype);
2050 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
2051 uentry_setType (outArg, ctype_unknown);
2052 uentry_fixupSref (outArg);
2056 exprNode_checkCallModifyVal (a->sref, args, f, ret);
2061 /* a->sref = sRef_undefined; */
2068 cstring_free (codetext);
2073 voptgenerror (FLG_TYPE,
2074 message ("Format string for %q has %d arg%&, given %d",
2075 uentry_getName (fcn), i - argno, nargs - argno),
2081 /* no checking possible for compile-time unknown format strings */
2084 fileloc_free (formatloc);
2088 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
2091 /*@unused@*/ int argno)
2094 ** the last argument before the elips is the format string
2097 int nargs = exprNodeList_size (args);
2102 a = exprNodeList_getN (args, argno - 1);
2103 formatloc = fileloc_copy (exprNode_loc (a));
2105 if (ctype_isUnknown (cstringType)) {
2106 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
2108 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
2112 if (ctype_isUnknown (ctypeType)) {
2113 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
2115 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
2119 if (ctype_isUnknown (filelocType)) {
2120 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
2122 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
2126 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
2127 && exprNode_knownStringValue (a))
2129 cstring format = multiVal_forceString (exprNode_getValue (a));
2130 char *code = cstring_toCharsSafe (format);
2133 nargs = exprNodeList_size (args);
2135 while ((code = strchr (code, '%')) != NULL)
2137 char *origcode = code;
2138 char key = *(++code);
2139 cstring codetext = cstring_newEmpty ();
2140 bool isOnly = FALSE;
2142 codetext = cstring_appendChar (codetext, key);
2144 fileloc_addColumn (formatloc, code - ocode);
2146 while (key >= '0' && key <= '9')
2149 codetext = cstring_appendChar (codetext, key);
2150 fileloc_incColumn (formatloc);
2154 fileloc_incColumn (formatloc);
2158 if (key == '&') /* plural marker */
2167 message ("Message missing format arg %d (%%%s): \"%s\"",
2168 i + 1, codetext, format),
2174 a = exprNodeList_getN (args, i);
2178 if (!exprNode_isError (a))
2182 /*@-loopswitchbreak@*/
2188 expecttype = ctype_char; break;
2190 expecttype = cstringType; break;
2192 expecttype = cstringType; isOnly = TRUE; break;
2194 expecttype = cstringType; isOnly = TRUE; break;
2195 case 'd': expecttype = ctype_int; break;
2196 case 'u': expecttype = ctype_uint; break;
2197 case 'w': expecttype = ctype_ulint; break;
2198 case 'f': expecttype = ctype_float; break;
2199 case 'b': expecttype = ctype_bool; break;
2200 case 't': expecttype = ctypeType; break;
2202 expecttype = ctype_makePointer (ctype_void);
2203 /* need not be defined */
2204 uentry_setDefState (regArg, SS_RELDEF);
2205 sRef_setPosNull (uentry_getSref (regArg),
2208 /*@switchbreak@*/ break;
2209 case 'l': expecttype = filelocType; break;
2210 case '&': /* a wee bit of a hack methinks */
2211 expecttype = ctype_int;
2213 case 'r': expecttype = ctype_bool; break;
2215 expecttype = ctype_unknown;
2218 message ("Unrecognized format code: %s",
2219 cstring_fromChars (origcode)),
2220 fileloc_isDefined (formatloc)
2221 ? formatloc : g_currentloc);
2224 /*@=loopswitchbreak@*/
2226 if (!(exprNode_matchArgType (expecttype, a)))
2228 if (ctype_isVoidPointer (expecttype)
2229 && ctype_isRealAbstract (a->typ)
2230 && (context_getFlag (FLG_ABSTVOIDP)))
2236 if (llgenformattypeerror
2237 (expecttype, exprNode_undefined,
2239 message ("Format argument %d to %q (%%%s) expects "
2242 uentry_getName (fcn),
2243 codetext, expecttype,
2244 a->typ, exprNode_unparse (a)),
2247 if (fileloc_isDefined (formatloc)
2248 && context_getFlag (FLG_SHOWCOL))
2251 (cstring_makeLiteral
2252 ("Corresponding format code"),
2259 if (ctype_equal (expecttype, cstringType))
2263 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
2264 uentry_fixupSref (csOnlyArg);
2268 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2269 uentry_fixupSref (csArg);
2274 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2275 uentry_fixupSref (regArg);
2281 cstring_free (codetext);
2286 voptgenerror (FLG_TYPE,
2287 message ("Format string for %q has %d arg%&, given %d",
2288 uentry_getName (fcn), i - argno, nargs -argno),
2294 /* no checking possible for compile-time unknown format strings */
2297 fileloc_free (formatloc);
2301 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2302 /*@notnull@*/ exprNode e2,
2308 bool hadUncon = FALSE;
2310 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e1->sref)) &&
2311 sRefSet_hasUnconstrained (sets2))
2314 (FLG_EVALORDERUNCON,
2316 ("Expression may have undefined behavior (%q used in right operand "
2317 "may set global variable %q used in left operand): %s %s %s",
2318 sRefSet_unparseUnconstrained (sets2),
2319 sRef_unparse (sRef_getRootBase (e1->sref)),
2320 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2324 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e2->sref)) &&
2325 sRefSet_hasUnconstrained (sets1))
2328 (FLG_EVALORDERUNCON,
2330 ("Expression has undefined behavior (%q used in left operand "
2331 "may set global variable %q used in right operand): %s %s %s",
2332 sRefSet_unparseUnconstrained (sets1),
2333 sRef_unparse (e2->sref),
2334 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2338 sRefSet_realElements (e1->uses, sr)
2340 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2345 ("Expression has undefined behavior (left operand uses %q, "
2346 "modified by right operand): %s %s %s",
2348 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2351 } end_sRefSet_realElements;
2353 sRefSet_realElements (sets1, sr)
2355 if (sRef_isMeaningful (sr))
2357 if (sRef_same (sr, e2->sref))
2362 ("Expression has undefined behavior (value of right operand "
2363 "modified by left operand): %s %s %s",
2364 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2367 else if (sRefSet_member (e2->uses, sr))
2372 ("Expression has undefined behavior (left operand modifies %q, "
2373 "used by right operand): %s %s %s",
2375 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2380 if (sRefSet_member (sets2, sr))
2382 if (sRef_isUnconstrained (sr))
2390 hadUncon = optgenerror
2391 (FLG_EVALORDERUNCON,
2393 ("Expression may have undefined behavior. Left operand "
2394 "calls %q; right operand calls %q. The unconstrained "
2395 "functions may modify global state used by "
2396 "the other operand): %s %s %s",
2397 sRefSet_unparseUnconstrained (sets1),
2398 sRefSet_unparseUnconstrained (sets2),
2399 exprNode_unparse (e1), lltok_unparse (op),
2400 exprNode_unparse (e2)),
2409 ("Expression has undefined behavior (both "
2410 "operands modify %q): %s %s %s",
2412 exprNode_unparse (e1),
2413 lltok_unparse (op), exprNode_unparse (e2)),
2419 } end_sRefSet_realElements;
2422 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2424 bool hasError = FALSE;
2426 if (exprNode_isError (e1) || exprNode_isError (e2))
2431 if (sRefSet_member (e2->sets, e1->sref))
2433 if (e2->kind == XPR_CALL)
2439 hasError = optgenerror
2441 message ("Expression has undefined behavior "
2442 "(value of left operand %s is modified "
2443 "by right operand %s): %s %s %s",
2444 exprNode_unparse (e1),
2445 exprNode_unparse (e2),
2446 exprNode_unparse (e1), lltok_unparse (op),
2447 exprNode_unparse (e2)),
2452 if (context_getFlag (FLG_EVALORDERUNCON))
2454 if (sRefSet_member (e2->msets, e1->sref))
2456 if (e2->kind == XPR_CALL)
2462 hasError = optgenerror
2465 ("Expression has undefined behavior (value of left "
2466 "operand may be modified by right operand): %s %s %s",
2467 exprNode_unparse (e1), lltok_unparse (op),
2468 exprNode_unparse (e2)),
2476 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2478 if (context_maybeSet (FLG_EVALORDERUNCON))
2480 checkExpressionDefinedAux (e1, e2, e1->msets,
2481 e2->msets, op, FLG_EVALORDERUNCON);
2486 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2489 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2490 exprNodeList args, bool isIter, exprNode ret)
2494 if (!exprNode_isError (f))
2496 if (!uentryList_isMissingParams (cl))
2498 int nargs = exprNodeList_size (args);
2499 int expectargs = uentryList_size (cl);
2503 if (expectargs == 0)
2511 message ("Iter %q invoked with %d args, "
2513 uentry_getName (fcn),
2521 message ("Function %s called with %d args, "
2523 exprNode_unparse (f), nargs),
2530 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2532 exprNodeList_reset (args);
2534 uentryList_elements (cl, current)
2536 ctype ct = uentry_getType (current);
2539 if (ctype_isElips (ct))
2542 ** do special checking for printf/scanf library functions
2544 ** this is kludgey code, just for handling the special case
2548 if (uentry_isPrintfLike (fcn))
2550 checkPrintfArgs (f, fcn, args, ret, i);
2553 else if (uentry_isScanfLike (fcn))
2555 checkScanfArgs (f, fcn, args, ret, i);
2558 else if (uentry_isMessageLike (fcn))
2560 checkMessageArgs (f, fcn, args, i);
2565 llassert (!uentry_isSpecialFunction (fcn));
2568 nargs = expectargs; /* avoid errors */
2573 if (i >= nargs) break;
2575 a = exprNodeList_current (args);
2576 exprNodeList_advance (args);
2580 if (exprNode_isError (a))
2587 probably necessary? I'm not sure about this one
2588 checkMacroParen (a);
2591 f->guards = guardSet_union (f->guards, a->guards);
2593 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2595 if (!(exprNode_matchArgType (ct, a)))
2597 DPRINTF (("Args mismatch!"));
2599 if (ctype_isVoidPointer (ct)
2600 && (ctype_isPointer (a->typ)
2601 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2606 ("Pointer to abstract type (%t) used "
2608 "(arg %d to %q): %s",
2610 uentry_getName (fcn),
2611 exprNode_unparse (a)),
2619 (ct, exprNode_undefined,
2622 ("Iter %q expects arg %d to "
2623 "be %t gets %t: %s",
2624 uentry_getName (fcn),
2625 i, ct, a->typ, exprNode_unparse (a)),
2636 ("Function %q expects arg %d to be %t gets %t: %s",
2637 uentry_getName (fcn),
2638 i, ct, a->typ, exprNode_unparse (a)),
2641 DPRINTF (("Types: %s / %s",
2643 ctype_unparse (a->typ)));
2647 ** Clear null marker for abstract types.
2648 ** (It is not revealed, so suppress future messages.)
2651 if (ctype_isAbstract (a->typ))
2653 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2660 } end_uentryList_elements ;
2663 if (expectargs != nargs) /* note: not != since we may have ... */
2665 if (ctype_isElips (last))
2669 message ("Function %s called with %d args, expects at least %d",
2670 exprNode_unparse (f),
2671 nargs, expectargs - 1),
2680 message ("Iter %q invoked with %d args, expects %d",
2681 uentry_getName (fcn), nargs, expectargs),
2688 message ("Function %s called with %d args, expects %d",
2689 exprNode_unparse (f),
2702 ** Check for undefined code sequences in function arguments:
2704 ** one parameter sets something used by another parameter
2705 ** one parameter sets something set by another parameter
2709 checkSequencingOne (exprNode f, exprNodeList args,
2710 /*@notnull@*/ exprNode el, int argno)
2713 ** Do second loop, iff +undefunspec
2717 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2719 for (checkloop = 0; checkloop < numloops; checkloop++)
2725 thissets = el->sets;
2729 llassert (checkloop == 1);
2730 thissets = el->msets;
2733 sRefSet_realElements (thissets, thisset)
2737 /*@access exprNodeList@*/
2738 for (j = 0; j < args->nelements; j++)
2740 exprNode jl = args->elements[j];
2741 int thisargno = j + 1;
2743 if (thisargno != argno && exprNode_isDefined (jl))
2745 sRefSet otheruses = jl->uses;
2747 if (sRef_isFileOrGlobalScope (sRef_getRootBase (jl->sref)) &&
2748 sRefSet_hasUnconstrained (thissets))
2751 (FLG_EVALORDERUNCON,
2754 ("%q used in argument %d may set "
2755 "global variable %q used by argument %d: %s(%q)",
2756 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2759 sRef_unparse (sRef_getRootBase (jl->sref)),
2761 exprNode_unparse (f), exprNodeList_unparse (args)),
2765 if (sRefSet_member (otheruses, thisset))
2767 if (sRef_isUnconstrained (thisset))
2770 (FLG_EVALORDERUNCON,
2772 ("Unconstrained functions used in arguments %d (%q) "
2773 "and %d (%s) may modify "
2774 "or use global state in undefined way: %s(%q)",
2776 sRefSet_unparseUnconstrainedPlain (otheruses),
2778 sRef_unconstrainedName (thisset),
2779 exprNode_unparse (f),
2780 exprNodeList_unparse (args)),
2788 ("Argument %d modifies %q, used by argument %d "
2789 "(order of evaluation of actual parameters is "
2790 "undefined): %s(%q)",
2791 argno, sRef_unparse (thisset), thisargno,
2792 exprNode_unparse (f), exprNodeList_unparse (args)),
2798 sRefSet othersets = jl->sets;
2800 if (sRefSet_member (othersets, thisset))
2802 if (sRef_isUnconstrained (thisset))
2805 (FLG_EVALORDERUNCON,
2807 ("Unconstrained functions used in "
2808 "arguments %d (%q) and %d (%s) may modify "
2809 "or use global state in undefined way: %s(%q)",
2811 sRefSet_unparseUnconstrainedPlain (othersets),
2813 sRef_unconstrainedName (thisset),
2814 exprNode_unparse (f), exprNodeList_unparse (args)),
2822 ("Argument %d modifies %q, set by argument %d (order of"
2823 " evaluation of actual parameters is undefined): %s(%q)",
2824 argno, sRef_unparse (thisset), thisargno,
2825 exprNode_unparse (f), exprNodeList_unparse (args)),
2832 /*@noaccess exprNodeList@*/
2833 } end_sRefSet_realElements;
2838 checkSequencing (exprNode f, exprNodeList args)
2840 if (exprNodeList_size (args) > 1)
2845 /*@access exprNodeList*/
2847 for (i = 0; i < args->nelements; i++)
2849 el = args->elements[i];
2851 if (!exprNode_isError (el))
2853 checkSequencingOne (f, args, el, i + 1);
2856 /*@noaccess exprNodeList*/
2861 ** requires le = exprNode_getUentry (f)
2865 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2866 uentry le, exprNodeList args,
2867 /*@notnull@*/ exprNode ret, int specialArgs)
2869 bool isSpec = FALSE;
2870 bool hasMods = FALSE;
2872 globSet usesGlobs = globSet_undefined;
2873 sRefSet mods = sRefSet_undefined;
2874 bool freshMods = FALSE;
2875 uentryList params = uentryList_undefined;
2877 DPRINTF (("Check glob mods: %s", exprNode_unparse (ret)));
2880 ** check globals and modifies
2885 if (!uentry_isValid (le))
2887 ctype fr = ctype_realType (f->typ);
2889 if (ctype_isFunction (fr))
2891 params = ctype_argsFunction (fr);
2895 params = uentryList_missingParams;
2898 if (!context_getFlag (FLG_MODNOMODS)
2899 && !context_getFlag (FLG_GLOBUNSPEC))
2901 checkUnspecCall (f, params, args);
2907 fname = uentry_rawName (le);
2911 if (uentry_isFunction (le))
2913 params = uentry_getParams (le);
2914 mods = uentry_getMods (le);
2915 hasMods = uentry_hasMods (le);
2916 usesGlobs = uentry_getGlobs (le);
2917 isSpec = uentry_isSpecified (le);
2919 else /* not a function */
2921 ctype ct = ctype_realType (uentry_getType (le));
2923 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2924 ("checkModGlobs: uentry not a function: %s",
2925 uentry_unparse (le)));
2927 params = ctype_argsFunction (ct);
2928 return; /* No checking for non-function */
2937 globSet_allElements (usesGlobs, el)
2939 if (sRef_isValid (el))
2941 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2943 context_usedGlobal (el);
2944 exprNode_checkUse (f, el, f->loc);
2946 if (context_checkInternalUse ())
2948 if (!context_globAccess (el))
2950 if (sRef_isSystemState (el)
2951 && !context_getFlag (FLG_MODFILESYSTEM))
2960 ("Called procedure %s may access %q, but "
2961 "globals list does not include globals %s",
2962 exprNode_unparse (f),
2964 cstring_makeLiteralTemp (sRef_isInternalState (el)
2972 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2978 uentry gle = sRef_getUentry (el);
2979 sRef sr = sRef_updateSref (el);
2981 if (sRef_isUndefGlob (el))
2983 sRef_setDefined (sr, f->loc);
2984 exprNode_checkSet (f, sr);
2992 if (sRef_isAllocated (el))
2994 exprNode_checkSet (f, sr);
2998 if (sRef_isStateUndefined (sr))
3003 ("%s %q used by function undefined before call: %s",
3004 sRef_getScopeName (sr),
3006 exprNode_unparse (f)),
3008 sRef_setDefined (sr, f->loc);
3010 exprNode_checkUse (f, sr, f->loc);
3013 checkGlobUse (gle, TRUE, f);
3016 if (sRef_isKilledGlob (el))
3018 sRef_kill (sr, f->loc);
3019 context_usedGlobal (sr);
3023 } end_globSet_allElements;
3029 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
3031 sRefSet smods = sRefSet_undefined;
3034 ** NEED to check for modifies anything
3038 ** check each sRef that called function modifies (ml), is
3044 sRefSet_allElements (mods, s) /* s is something which may be modified */
3046 DPRINTF (("Check modify: %s", sRef_unparse (s)));
3048 if (sRef_isKindSpecial (s))
3050 if (sRef_isSpecInternalState (s))
3052 if (context_getFlag (FLG_MODINTERNALSTRICT))
3054 exprNode_checkCallModifyVal (s, args, f, ret);
3058 sRefSet mmods = context_modList ();
3060 sRefSet_allElements (mmods, el)
3062 if (sRef_isInternalState (el))
3064 sRef_setModified (el);
3066 } end_sRefSet_allElements ;
3071 exprNode_checkCallModifyVal (s, args, f, ret);
3076 sRef rb = sRef_getRootBase (s);
3078 if (sRef_isFileOrGlobalScope (rb))
3080 context_usedGlobal (rb);
3083 if (sRef_isFileStatic (s)
3084 && !fileId_equal (fileloc_fileId (f->loc),
3085 fileloc_fileId (uentry_whereDefined (le))))
3087 smods = sRefSet_insert (smods, s);
3091 exprNode_checkCallModifyVal (s, args, f, ret);
3094 } end_sRefSet_allElements;
3099 ** Static elements in modifies set can have nasty consequences.
3100 ** (I think...have not been able to reproduce a possible bug.)
3103 if (!sRefSet_isDefined (smods))
3105 mods = sRefSet_newCopy (mods);
3108 sRefSet_allElements (smods, el)
3110 bool res = sRefSet_delete (mods, el);
3113 } end_sRefSet_allElements;
3115 sRefSet_free (smods);
3120 else if (sRefSet_isDefined (mods))
3121 { /* just check observers */
3124 sRefSet_allElements (mods, s) /* s is something which may be modified */
3126 sRef rb = sRef_getRootBase (s);
3130 if (sRef_isParam (rb))
3132 sRef b = sRef_fixBaseParam (s, args);
3134 if (sRef_isObserver (b))
3136 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
3140 message ("Function call may modify observer%q: %s",
3141 sRef_unparsePreOpt (b), exprNode_unparse (e)),
3144 sRef_showExpInfo (b);
3148 } end_sRefSet_allElements;
3152 if (!hasMods) /* no specified modifications */
3154 if (context_getFlag (FLG_MODOBSERVERUNCON))
3156 exprNodeList_elements (args, e)
3158 if (exprNode_isDefined (e))
3160 sRef s = exprNode_getSref (e);
3162 if (sRef_isObserver (s)
3163 && ctype_isMutable (sRef_getType (s)))
3166 (FLG_MODOBSERVERUNCON,
3168 ("Call to unconstrained function %s may modify observer%q: %s",
3169 exprNode_unparse (f),
3170 sRef_unparsePreOpt (s), exprNode_unparse (e)),
3173 sRef_showExpInfo (s);
3177 } end_exprNodeList_elements;
3182 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
3184 ret->uses = sRefSet_union (ret->uses, f->uses);
3185 ret->sets = sRefSet_union (ret->sets, f->sets);
3186 ret->msets = sRefSet_union (ret->msets, f->msets);
3191 ** Spurious errors reported, because splint can't tell
3192 ** mods must be fresh if freshMods is true.
3195 /*@i@*/ sRefSet_free (mods);
3201 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
3203 if (uentry_isVar (glob))
3205 if (context_inFunctionLike ())
3207 sRef sr = uentry_getSref (glob);
3209 context_usedGlobal (sr);
3211 if (context_checkGlobUse (glob))
3213 if (!context_globAccess (sr))
3219 message ("Called procedure %s may access %s %q",
3220 exprNode_unparse (e),
3221 sRef_unparseScope (sr),
3222 uentry_getName (glob)),
3229 message ("Undocumented use of %s %s",
3230 sRef_unparseScope (sr),
3231 exprNode_unparse (e)),
3240 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
3245 reflectEnsuresClause (exprNode ret, uentry le, exprNode f, exprNodeList args)
3247 DPRINTF (("Reflect ensures clause: %s(%s) / %s / %s",
3248 exprNode_unparse (f), exprNodeList_unparse (args),
3249 uentry_unparseFull (le),
3250 stateClauseList_unparse (uentry_getStateClauseList (le))));
3252 if (uentry_isValid (le) && uentry_isFunction (le))
3254 stateClauseList sclauses = uentry_getStateClauseList (le);
3256 if (stateClauseList_isDefined (sclauses))
3258 DPRINTF (("Reflect ensures: %s / %s / %s",
3259 uentry_unparse (le),
3260 exprNode_unparse (f), exprNodeList_unparse (args)));
3262 stateClauseList_elements (sclauses, cl)
3264 if (stateClause_hasEnsures (cl))
3266 /* Same in usymtab.c:1904 */
3267 if (stateClause_setsMetaState (cl))
3269 qual q = stateClause_getMetaQual (cl);
3270 annotationInfo ainfo = qual_getAnnotationInfo (q);
3271 metaStateInfo minfo = annotationInfo_getState (ainfo);
3272 cstring key = metaStateInfo_getName (minfo);
3273 int mvalue = annotationInfo_getValue (ainfo);
3275 sRefSet osrs = sRefSet_undefined;
3278 if (stateClause_isGlobal (cl))
3280 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3285 srs = stateClause_getRefs (cl);
3288 DPRINTF (("Reflect ensures clause: %s", stateClause_unparse (cl)));
3291 DPRINTF (("Sets meta state! %s", stateClause_unparse (cl)));
3293 sRefSet_elements (srs, sel)
3297 if (sRef_isResult (sRef_getRootBase (sel)))
3299 s = exprNode_getSref (ret);
3303 s = sRef_fixBaseParam (sel, args);
3306 DPRINTF (("Reflecting state clause on: %s / %s",
3307 sRef_unparse (sel), sRef_unparse (s)));
3309 sRef_setMetaStateValueComplete (s, key, mvalue, exprNode_loc (f));
3310 } end_sRefSet_elements;
3312 sRefSet_free (osrs);
3316 sRefSet srs = stateClause_getRefs (cl);
3317 sRefModVal modf = stateClause_getEnsuresFunction (cl);
3318 int eparam = stateClause_getStateParameter (cl);
3320 llassert (modf != NULL);
3322 DPRINTF (("Reflect after clause: %s / %s",
3323 stateClause_unparse (cl),
3324 sRefSet_unparse (srs)));
3326 sRefSet_elements (srs, sel)
3330 DPRINTF (("elements: %s", sRef_unparse (sel)));
3331 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3333 if (sRef_isResult (sRef_getRootBase (sel)))
3335 DPRINTF (("Fix base: %s / %s",
3336 sRef_unparse (sel), sRef_unparse (exprNode_getSref (ret))));
3337 s = sRef_fixBase (sel, exprNode_getSref (ret));
3338 DPRINTF (("==> %s", sRef_unparseFull (s)));
3342 s = sRef_fixBaseParam (sel, args);
3345 DPRINTF (("elements: %s", sRef_unparse (s)));
3346 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3348 DPRINTF (("Reflecting state clause on: %s / %s",
3349 sRef_unparseFull (sel), sRef_unparseFull (s)));
3351 /* evans 2001-08-24 - added aliasSetCompleteParam */
3352 sRef_aliasSetCompleteParam (modf, s, eparam, exprNode_loc (f));
3354 DPRINTF (("After reflecting state clause on: %s / %s",
3355 sRef_unparseFull (sel), sRef_unparseFull (s)));
3356 } end_sRefSet_elements;
3359 } end_stateClauseList_elements ;
3362 DPRINTF (("Here: %s / %s",
3363 uentry_unparseFull (le),
3364 bool_unparse (uentry_hasMetaStateEnsures (le))));
3366 if (uentry_hasMetaStateEnsures (le))
3368 fileloc loc = exprNode_loc (f);
3370 metaStateConstraintList mscl = uentry_getMetaStateEnsures (le);
3372 metaStateConstraintList_elements (mscl, msc)
3374 metaStateSpecifier msspec = metaStateConstraint_getSpecifier (msc);
3375 metaStateInfo msinfo = metaStateSpecifier_getMetaStateInfo (msspec);
3376 metaStateExpression msexpr = metaStateConstraint_getExpression (msc);
3377 cstring key = metaStateInfo_getName (msinfo);
3378 sRef mlsr = metaStateSpecifier_getSref (msspec);
3380 sRef lastref = sRef_undefined;
3381 stateValue sval = stateValue_undefined;
3383 DPRINTF (("Meta state constraint for %s: %s", uentry_unparse (le),
3384 metaStateConstraint_unparse (msc)));
3385 DPRINTF (("Matches left: %s", sRef_unparseDebug (mlsr)));
3387 if (sRef_isResult (sRef_getRootBase (mlsr)))
3389 s = exprNode_getSref (ret);
3393 s = sRef_fixBaseParam (mlsr, args);
3396 DPRINTF (("Setting state: %s", sRef_unparseFull (s)));
3398 while (metaStateExpression_isDefined (msexpr))
3400 metaStateSpecifier ms = metaStateExpression_getSpecifier (msexpr);
3401 metaStateInfo msi = metaStateSpecifier_getMetaStateInfo (ms);
3404 DPRINTF (("Check expression: %s", metaStateExpression_unparse (msexpr)));
3406 if (metaStateExpression_isMerge (msexpr))
3408 msexpr = metaStateExpression_getRest (msexpr);
3412 msexpr = metaStateExpression_undefined;
3415 if (metaStateInfo_isDefined (msi))
3417 /* Must match lhs state */
3418 llassert (metaStateInfo_equal (msinfo, msi));
3421 if (metaStateSpecifier_isElipsis (ms))
3424 ** For elipsis, we need to merge all the relevant elipsis parameters
3428 uentryList params = uentry_getParams (le);
3429 int paramno = uentryList_size (params) - 1;
3431 if (!uentry_isElipsisMarker (uentryList_getN (params, paramno)))
3435 message ("Ensures clauses uses ... for function without ... in parameter list: %q",
3436 uentry_getName (le)),
3437 uentry_whereLast (le));
3438 /*@innerbreak@*/ break;
3441 while (paramno < exprNodeList_size (args))
3443 exprNode arg = exprNodeList_getN (args, paramno);
3444 fs = exprNode_getSref (arg);
3445 DPRINTF (("Merge arg: %s", exprNode_unparse (arg)));
3447 /* cut and pasted... gack*/
3448 if (stateValue_isDefined (sval))
3450 /* Use combination table to merge old state value with new one: */
3451 stateValue tval = sRef_getMetaStateValue (fs, key);
3453 if (stateValue_isDefined (tval))
3455 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3456 cstring msg = cstring_undefined;
3457 int nval = stateCombinationTable_lookup (sctable,
3458 stateValue_getValue (sval),
3459 stateValue_getValue (tval),
3461 DPRINTF (("Combining: %s + %s -> %d",
3462 stateValue_unparseValue (sval, msinfo),
3463 stateValue_unparseValue (tval, msinfo),
3466 if (nval == stateValue_error)
3471 ("Attributes merged in ensures clause in states that "
3472 "cannot be combined (%q is %q, %q is %q)%q",
3473 sRef_unparse (lastref),
3474 stateValue_unparseValue (sval, msinfo),
3476 stateValue_unparseValue (tval, msinfo),
3477 cstring_isDefined (msg) ?
3478 message (": %s", msg) : cstring_undefined),
3481 sRef_showMetaStateInfo (fs, key);
3485 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3486 loc = exprNode_loc (arg);
3490 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3495 sval = sRef_getMetaStateValue (fs, key);
3500 if (stateValue_isError (sval))
3502 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3511 msr = metaStateSpecifier_getSref (ms);
3514 llassert (sRef_isParam (sRef_getRootBase (msr)));
3515 fs = sRef_fixBaseParam (msr, args);
3517 if (stateValue_isDefined (sval))
3519 /* Use combination table to merge old state value with new one: */
3520 stateValue tval = sRef_getMetaStateValue (fs, key);
3522 if (stateValue_isDefined (tval))
3524 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3525 cstring msg = cstring_undefined;
3526 int nval = stateCombinationTable_lookup (sctable,
3527 stateValue_getValue (sval),
3528 stateValue_getValue (tval),
3530 DPRINTF (("Combining: %s + %s -> %d",
3531 stateValue_unparseValue (sval, msinfo),
3532 stateValue_unparseValue (tval, msinfo),
3535 if (nval == stateValue_error)
3540 ("Attributes merged in ensures clause in states that "
3541 "cannot be combined (%q is %q, %q is %q)%q",
3542 sRef_unparse (lastref),
3543 stateValue_unparseValue (sval, msinfo),
3545 stateValue_unparseValue (tval, msinfo),
3546 cstring_isDefined (msg)
3547 ? message (": %s", msg) : cstring_undefined),
3550 sRef_showMetaStateInfo (fs, key);
3554 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3558 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3563 sval = sRef_getMetaStateValue (fs, key);
3568 if (stateValue_isError (sval))
3570 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3575 DPRINTF (("Setting: %s:%s <- %s", sRef_unparse (s), key, stateValue_unparse (sval)));
3577 if (stateValue_isDefined (sval))
3579 sRef_setMetaStateValueComplete (s, key, stateValue_getValue (sval), loc);
3583 DPRINTF (("Undefined state: %s", cstring_toCharsSafe (sRef_unparse (s))));
3585 } end_metaStateConstraintList_elements ;
3587 metaStateConstraintList_free (mscl);
3593 checkRequiresClause (uentry le, exprNode f, exprNodeList args)
3595 DPRINTF (("Check requires clause: %s(%s) / %s / %s",
3596 exprNode_unparse (f), exprNodeList_unparse (args),
3597 uentry_unparseFull (le),
3598 stateClauseList_unparse (uentry_getStateClauseList (le))));
3600 if (uentry_isValid (le) && uentry_isFunction (le))
3602 stateClauseList sclauses = uentry_getStateClauseList (le);
3604 if (stateClauseList_isDefined (sclauses))
3606 DPRINTF (("Check requires: %s / %s / %s",
3607 uentry_unparse (le),
3608 exprNode_unparse (f), exprNodeList_unparse (args)));
3610 stateClauseList_elements (sclauses, cl)
3612 DPRINTF (("Check clause: %s / %s",
3613 stateClause_unparse (cl),
3614 bool_unparse (stateClause_hasRequires (cl))));
3616 if (stateClause_hasRequires (cl))
3618 sRefSet osrs = sRefSet_undefined;
3621 if (stateClause_isGlobal (cl))
3623 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3628 srs = stateClause_getRefs (cl);
3631 DPRINTF (("Refs: %s", sRefSet_unparse (srs)));
3633 if (stateClause_setsMetaState (cl))
3635 qual q = stateClause_getMetaQual (cl);
3636 annotationInfo ainfo = qual_getAnnotationInfo (q);
3637 metaStateInfo minfo = annotationInfo_getState (ainfo);
3638 cstring key = metaStateInfo_getName (minfo);
3639 int mvalue = annotationInfo_getValue (ainfo);
3641 DPRINTF (("Requires meta state! %s = %d", key, mvalue));
3643 sRefSet_elements (srs, sel)
3645 sRef s = sRef_fixBaseParam (sel, args);
3647 if (sRef_isResult (sRef_getRootBase (sel)))
3653 DPRINTF (("Checking state clause on: %s / %s / %s = %d",
3654 sRef_unparseFull (sel), sRef_unparseFull (s),
3657 if (!sRef_checkMetaStateValue (s, key, mvalue))
3659 DPRINTF (("HERE: %s", sRef_unparse (s)));
3663 ("Requires clause of called function %q not satisfied%q (state is %q): %q",
3664 uentry_getName (le),
3665 sRef_isGlobalMarker (s)
3667 : message (" by %q", sRef_unparse (s)),
3668 stateValue_unparseValue (sRef_getMetaStateValue (s, key),
3670 stateClause_unparse (cl)),
3673 sRef_showAliasInfo (s);
3677 DPRINTF (("Error supressed!"));
3678 DPRINTF (("Loc: %s", fileloc_unparse (exprNode_loc (f))));
3679 DPRINTF (("Context supress: %s",
3680 bool_unparse (context_suppressFlagMsg (FLG_STATETRANSFER, exprNode_loc (f)))));
3684 } end_sRefSet_elements;
3688 sRefModVal modf = stateClause_getRequiresBodyFunction (cl);
3689 int eparam = stateClause_getStateParameter (cl);
3691 DPRINTF (("Reflect after clause: %s / %s",
3692 stateClause_unparse (cl),
3693 sRefSet_unparse (srs)));
3695 llassert (modf != NULL);
3697 sRefSet_elements (srs, sel)
3701 DPRINTF (("elements: %s", sRef_unparse (sel)));
3702 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3704 s = sRef_fixBaseParam (sel, args);
3706 DPRINTF (("elements: %s", sRef_unparse (s)));
3707 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3709 if (sRef_isResult (sRef_getRootBase (sel)))
3711 ; /* what do we do about results? */
3715 DPRINTF (("Reflecting state clause on: %s / %s",
3716 sRef_unparse (sel), sRef_unparse (s)));
3718 modf (s, eparam, exprNode_loc (f));
3720 } end_sRefSet_elements;
3723 sRefSet_free (osrs);
3725 } end_stateClauseList_elements ;
3730 static /*@only@*/ exprNode
3731 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
3732 ctype t, /*@keep@*/ exprNodeList args)
3734 /* requires f is a non-error exprNode, with type function */
3735 cstring fname = exprNode_unparse (f);
3736 uentry le = exprNode_getUentry (f);
3737 exprNode ret = exprNode_createPartialCopy (f);
3742 DPRINTF (("Call: %s %s",exprNode_unparse (f), exprNodeList_unparse (args)));
3744 ret->typ = ctype_getReturnType (t);
3745 ret->kind = XPR_CALL;
3747 ret->edata = exprData_makeCall (f, args);
3750 ** Order of these steps is very important!
3752 ** Must check for argument dependencies before messing up uses and sets.
3755 if (context_getFlag (FLG_EVALORDER))
3757 exprNodeList_elements (args, current)
3759 if (exprNode_isDefined (current))
3761 exprNode_addUse (current, current->sref);
3763 } end_exprNodeList_elements;
3765 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3767 checkSequencing (f, args);
3770 exprNodeList_elements (args, current)
3772 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3774 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3776 } end_exprNodeList_elements ;
3779 special = checkArgs (le, f, t, args, ret);
3780 checkGlobMods (f, le, args, ret, special);
3781 checkRequiresClause (le, f, args);
3784 if (uentry_isValid (le)
3785 && (uentry_isFunction (le)
3786 || (uentry_isVariable (le)
3787 && ctype_isFunction (uentry_getType (le)))))
3789 exitkind exk = uentry_getExitCode (le);
3791 /* f->typ is already set to the return type */
3793 DPRINTF (("Function: %s", uentry_unparseFull (le)));
3794 ret->sref = uentry_returnedRef (le, args, exprNode_loc (f));
3795 DPRINTF (("Returned: %s / %s",
3796 uentry_unparseFull (le),
3797 sRef_unparseFull (ret->sref)));
3799 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3801 qual nullPred = uentry_nullPred (le);
3803 if (qual_isTrueNull (nullPred))
3805 exprNode arg = exprNodeList_head (args);
3807 if (exprNode_isDefined (arg))
3809 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3812 else if (qual_isFalseNull (nullPred))
3814 exprNode arg = exprNodeList_head (args);
3816 if (exprNode_isDefined (arg))
3818 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3823 llassert (qual_isUnknown (nullPred));
3827 if (exitkind_isConditionalExit (exk))
3831 ** if (arg0) then { exit! } else { ; }
3833 ** if (arg0) then { ; } else { exit! }
3838 llassert (!exprNodeList_isEmpty (args));
3839 firstArg = exprNodeList_head (args);
3841 if (exprNode_isDefined (firstArg)
3842 && !guardSet_isEmpty (firstArg->guards))
3844 usymtab_trueBranch (guardSet_undefined);
3845 usymtab_altBranch (guardSet_undefined);
3847 if (exitkind_isTrueExit (exk))
3849 usymtab_popBranches (firstArg,
3850 exprNode_makeMustExit (),
3852 TRUE, TRUEEXITCLAUSE);
3856 usymtab_popBranches (firstArg,
3858 exprNode_makeMustExit (),
3859 TRUE, FALSEEXITCLAUSE);
3863 ret->exitCode = XK_MAYEXIT;
3865 else if (exitkind_mustExit (exk))
3867 ret->exitCode = XK_MUSTEXIT;
3869 else if (exitkind_couldExit (exk))
3871 ret->exitCode = XK_MAYEXIT;
3878 if (cstring_equalLit (fname, "exit"))
3880 if (exprNodeList_size (args) == 1)
3882 exprNode arg = exprNodeList_head (args);
3884 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3886 long int val = multiVal_forceInt (exprNode_getValue (arg));
3893 ("Argument to exit has implementation defined behavior: %s",
3894 exprNode_unparse (arg)),
3895 exprNode_loc (arg));
3903 ret->sref = sRef_undefined;
3904 exprNode_checkSetAny (ret, uentry_rawName (le));
3907 DPRINTF (("Before reflect: %s", sRef_unparseFull (ret->sref)));
3908 DPRINTF (("Reflect: %s", uentry_unparseFull (le)));
3909 reflectEnsuresClause (ret, le, f, args);
3912 DPRINTF (("Here: %s", sRef_unparseFull (ret->sref)));
3917 ** this is yucky! should keep the uentry as part of exprNode!
3920 uentry exprNode_getUentry (exprNode e)
3922 if (exprNode_isError (e))
3924 return uentry_undefined;
3928 cstring s = exprNode_rootVarName (e);
3929 uentry ue = usymtab_lookupSafe (s);
3936 ** Returns true iff e1 and e2 are both exactly the same storage
3940 static bool exprNode_sameStorage (exprNode e1, exprNode e2)
3942 sRef s1 = exprNode_getSref (e1);
3943 sRef s2 = exprNode_getSref (e2);
3945 return (sRef_realSame (s1, s2));
3949 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3951 exprNode ret = exprNode_createPlain (ctype_unknown);
3953 ret->kind = XPR_INITBLOCK;
3954 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3955 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3961 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3966 usymtab_checkAllValid ();
3969 if (exprNode_isUndefined (f))
3972 exprNodeList_free (args);
3973 return exprNode_undefined;
3976 t = exprNode_getType (f);
3978 if (sRef_isLocalVar (f->sref))
3980 exprNode_checkUse (f, f->sref, f->loc);
3982 if (sRef_possiblyNull (f->sref))
3984 if (!usymtab_isGuarded (f->sref))
3986 if (optgenerror (FLG_NULLDEREF,
3987 message ("Function call using %s pointer %q",
3988 sRef_nullMessage (f->sref),
3989 sRef_unparse (f->sref)),
3992 sRef_showNullInfo (f->sref);
3993 sRef_setNullError (f->sref);
4001 if (ctype_isRealFunction (t))
4003 exprNode ret = functionCallSafe (f, t, args);
4007 else if (ctype_isUnknown (t))
4009 exprNode ret = exprNode_createPartialCopy (f);
4015 exprNodeList_elements (args, current)
4017 if (exprNode_isDefined (current))
4019 exprNode_checkUse (ret, current->sref, ret->loc);
4022 ** also, anything derivable from current->sref may be used
4025 exprNode_addUse (ret, sRef_makeDerived (current->sref));
4026 exprNode_mergeUSs (ret, current);
4028 } end_exprNodeList_elements;
4030 ret->edata = exprData_makeCall (f, args);
4031 ret->kind = XPR_CALL;
4033 tstring = cstring_copy (exprNode_unparse (f));
4035 cstring_markOwned (tstring);
4036 exprNode_checkSetAny (ret, tstring);
4042 voptgenerror (FLG_TYPE,
4043 message ("Call to non-function (type %t): %s", t,
4044 exprNode_unparse (f)),
4047 exprNodeList_free (args);
4049 return (exprNode_makeError ());
4054 exprNode_fieldAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
4055 /*@only@*/ cstring f)
4057 exprNode ret = exprNode_createPartialCopy (s);
4059 ret->kind = XPR_FACCESS;
4061 if (exprNode_isError (s))
4063 ret->edata = exprData_makeField (s, f);
4068 ctype t = exprNode_getType (s);
4069 ctype tr = ctype_realType (t);
4071 checkMacroParen (s);
4073 ret->edata = exprData_makeField (s, f);
4075 if (ctype_isStructorUnion (tr))
4077 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
4079 if (uentry_isUndefined (tf))
4081 voptgenerror (FLG_TYPE,
4082 message ("Access non-existent field %s of %t: %s", f, t,
4083 exprNode_unparse (ret)),
4085 /*! cstring_free (f); */ /* evans 2001-03-25 self-detect */
4090 uentry_setUsed (tf, exprNode_loc (ret));
4092 ret->typ = uentry_getType (tf);
4093 checkSafeUse (ret, s->sref);
4095 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
4096 /*!? exprNode_free (s); */ /* evans 2001-03-25 self-detect */
4100 else /* isStructorUnion */
4102 if (ctype_isRealAbstract (tr))
4106 message ("Access field of abstract type (%t): %s.%s",
4107 t, exprNode_unparse (s), f),
4109 ret->typ = ctype_unknown;
4113 if (ctype_isKnown (tr))
4118 ("Access field of non-struct or union (%t): %s.%s",
4119 t, exprNode_unparse (s), f),
4122 ret->typ = ctype_unknown;
4126 cstring sn = cstring_copy (f);
4128 checkSafeUse (ret, s->sref);
4129 cstring_markOwned (sn);
4130 ret->sref = sRef_makeField (s->sref, sn);
4142 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ lltok dot,
4143 /*@only@*/ cstring f)
4145 exprNode res = exprNode_fieldAccessAux (s, lltok_getLoc (dot), f);
4151 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
4153 exprNode ret = exprNode_createPartialCopy (e);
4155 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
4156 ret->kind = XPR_PARENS;
4157 ret->edata = exprData_makeUop (e, lpar);
4159 if (!exprNode_isError (e))
4161 ret->exitCode = e->exitCode;
4162 ret->canBreak = e->canBreak;
4163 ret->mustBreak = e->mustBreak;
4164 ret->isJumpPoint = e->isJumpPoint;
4165 ret->sref = e->sref;
4172 exprNode_arrowAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
4173 /*@only@*/ cstring f)
4175 exprNode ret = exprNode_createPartialCopy (s);
4177 ret->edata = exprData_makeField (s, f);
4178 ret->kind = XPR_ARROW;
4180 if (exprNode_isError (s))
4186 ctype t = exprNode_getType (s);
4187 ctype tr = ctype_realType (t);
4189 checkMacroParen (s);
4191 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
4193 if (ctype_isRealPointer (tr))
4195 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
4197 if (ctype_isStructorUnion (b))
4199 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4201 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
4203 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
4207 message ("Arrow access from %s pointer%q: %s",
4208 sRef_nullMessage (s->sref),
4209 sRef_unparsePreOpt (s->sref),
4210 exprNode_unparse (ret)),
4213 sRef_showNullInfo (s->sref);
4214 sRef_setNullError (s->sref);
4219 if (uentry_isUndefined (fentry))
4223 message ("Access non-existent field %s of %t: %s",
4224 f, t, exprNode_unparse (ret)),
4226 ret->typ = ctype_unknown;
4232 ** was safeUse: shouldn't be safe!
4235 ** rec must be defined,
4236 ** *rec must be allocated
4237 ** rec->field need only be defined it if is an rvalue
4240 uentry_setUsed (fentry, exprNode_loc (ret));
4241 ret->typ = uentry_getType (fentry);
4243 exprNode_checkUse (ret, s->sref, s->loc);
4245 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
4246 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4250 else /* Pointer to something that is not a struct or union*/
4252 if (ctype_isRealAbstract (tr))
4254 ctype xrt = ctype_forceRealType (tr);
4258 message ("Arrow access field of abstract type (%t): %s->%s",
4259 t, exprNode_unparse (s), f),
4263 ** Set the state correctly, as if the abstraction is broken.
4266 if (ctype_isRealPointer (xrt) &&
4267 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
4268 ctype_isStructorUnion (b)))
4270 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4271 ret->typ = uentry_getType (fentry);
4272 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4276 ret->typ = ctype_unknown;
4277 ret->sref = sRef_undefined;
4280 else /* not a struct, union or abstract */
4282 if (ctype_isUnknown (tr)) {
4283 cstring sn = cstring_copy (f);
4285 DPRINTF (("Here: %s", exprNode_unparse (s)));
4287 exprNode_checkUse (ret, s->sref, s->loc);
4288 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4290 cstring_markOwned (sn);
4291 ret->sref = sRef_makeArrow (s->sref, sn);
4293 ret->kind = XPR_ARROW;
4298 message ("Arrow access field of non-struct or union "
4299 "pointer (%t): %s->%s",
4300 t, exprNode_unparse (s), f),
4303 ret->typ = ctype_unknown;
4304 ret->sref = sRef_undefined;
4309 else /* its not a pointer */
4311 if (!ctype_isUnknown (tr))
4315 message ("Arrow access of non-pointer (%t): %s->%s",
4316 t, exprNode_unparse (s), f),
4319 ret->typ = ctype_unknown;
4320 ret->sref = sRef_undefined;
4324 cstring sn = cstring_copy (f);
4326 DPRINTF (("Here: %s", exprNode_unparse (s)));
4328 exprNode_checkUse (ret, s->sref, s->loc);
4329 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4331 cstring_markOwned (sn);
4332 ret->sref = sRef_makeArrow (s->sref, sn);
4334 ret->kind = XPR_ARROW;
4345 exprNode_arrowAccess (/*@only@*/ exprNode s,
4346 /*@only@*/ lltok arrow,
4347 /*@only@*/ cstring f)
4349 exprNode res = exprNode_arrowAccessAux (s, lltok_getLoc (arrow), f);
4355 ** only postOp's in C: i++ and i--
4359 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4361 /* check modification also */
4362 /* cstring opname = lltok_unparse (op);*/
4364 exprNode ret = exprNode_createPartialCopy (e);
4366 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4367 ret->kind = XPR_POSTOP;
4368 ret->edata = exprData_makeUop (e, op);
4370 if (!exprNode_isDefined (e))
4375 checkMacroParen (e);
4377 exprNode_checkUse (ret, e->sref, e->loc);
4378 exprNode_checkSet (ret, e->sref);
4380 t = exprNode_getType (e);
4382 if (sRef_isUnsafe (e->sref))
4384 voptgenerror (FLG_MACROPARAMS,
4385 message ("Operand of %s is macro parameter (non-functional): %s%s",
4386 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
4388 sRef_makeSafe (e->sref);
4389 sRef_makeSafe (ret->sref);
4392 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
4398 if (ctype_isRealAbstract (t))
4400 if (ctype_isRealNumAbstract (t)) {
4401 ; /* Allow operations on numabstract types */
4405 message ("Operand of %s is abstract type (%t): %s",
4406 lltok_unparse (op), t, exprNode_unparse (e)),
4414 message ("Operand of %s is non-numeric (%t): %s",
4415 lltok_unparse (op), t, exprNode_unparse (e)),
4418 ret->typ = ctype_unknown;
4421 /* if (ctype_isZero (t)) e->typ = ctype_int; */
4423 exprNode_checkModify (e, ret);
4425 /* added 7/11/2000 D.L */
4427 /* updateEnvironmentForPostOp (e); */
4429 /* start modifications */
4430 /* added by Seejo on 4/16/2000 */
4432 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4434 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4436 ret->sref = sRef_copy (e->sref);
4439 if (lltok_getTok (op) == INC_OP) {
4440 if (sRef_getSize(e->sref) > 0) {
4442 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4444 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4445 /* Assumption: there is only 1 \0 in the buffer */
4446 /* This will not be correct if there are 2 \0's in the buffer */
4447 sRef_setNotNullTerminatedState(ret->sref);
4448 sRef_resetLen(ret->sref);
4450 sRef_setNullTerminatedState(ret->sref);
4451 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4453 if (sRef_isNullTerminated (ret->sref))
4454 printf ("ret->sref is Null Terminated\n");
4455 else if (sRef_isPossiblyNullTerminated (ret->sref))
4456 printf ("ret->sref is Possibly Null Terminated\n");
4457 else if (sRef_isNotNullTerminated (ret->sref))
4458 printf ("ret->sref is Not Null Terminated\n");
4465 if (lltok_getTok (op) == DEC_OP) {
4466 if (sRef_getSize(e->sref) >= 0) {
4467 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4468 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4472 /* end modifications */
4478 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4480 bool checkMod = FALSE;
4482 int opid = lltok_getTok (op);
4483 exprNode ret = exprNode_createSemiCopy (e);
4485 exprNode_copySets (ret, e);
4487 multiVal_free (ret->val);
4488 ret->val = multiVal_undefined;
4489 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4490 ret->kind = XPR_PREOP;
4491 ret->edata = exprData_makeUop (e, op);
4493 if (exprNode_isError (e))
4498 checkMacroParen (e);
4500 te = exprNode_getType (e);
4501 tr = ctype_realType (te);
4503 if (opid != TAMPERSAND)
4505 exprNode_checkUse (ret, e->sref, e->loc);
4507 if (ctype_isRealAbstract (tr)
4508 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
4510 if (ctype_isRealNumAbstract (tr))
4512 ; /* no warning for numabstract types */
4516 if (optgenerror (FLG_ABSTRACT,
4517 message ("Operand of %s is abstract type (%t): %s",
4518 lltok_unparse (op), tr,
4519 exprNode_unparse (ret)),
4522 tr = te = ctype_unknown;
4523 ret->typ = ctype_unknown;
4524 sRef_setNullError (e->sref);
4533 case DEC_OP: /* should also check modification! */
4534 if (sRef_isMacroParamRef (e->sref))
4538 message ("Operand of %s is macro parameter (non-functional): %s",
4539 lltok_unparse (op), exprNode_unparse (ret)),
4544 exprNode_checkSet (ret, e->sref);
4547 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
4552 if (context_msgStrictOps ())
4556 message ("Operand of %s is non-numeric (%t): %s",
4557 lltok_unparse (op), te, exprNode_unparse (ret)),
4560 ret->typ = ctype_int;
4563 /* start modifications */
4564 /* added by Seejo on 4/16/2000 */
4566 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4568 if ((sRef_isPossiblyNullTerminated (e->sref))
4569 || (sRef_isNullTerminated(e->sref))) {
4570 ret->sref = sRef_copy (e->sref);
4573 if (lltok_getTok (op) == INC_OP) {
4574 if (sRef_getSize(e->sref) > 0) {
4576 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4578 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4579 /* Assumption: there is only 1 \0 in the buffer */
4580 /* This will not be correct if there are 2 \0's in the buffer */
4581 sRef_setNotNullTerminatedState(ret->sref);
4582 sRef_resetLen (ret->sref);
4584 sRef_setNullTerminatedState(ret->sref);
4585 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4591 if (lltok_getTok (op) == DEC_OP) {
4592 if (sRef_getSize(e->sref) >= 0) {
4593 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4594 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4599 /* end modifications */
4606 if (ctype_isForceRealNumeric (&tr))
4610 ret->val = multiVal_invert (exprNode_getValue (e));
4614 ret->val = multiVal_copy (exprNode_getValue (e));
4619 if (context_msgStrictOps ())
4623 message ("Operand of %s is non-numeric (%t): %s",
4624 lltok_unparse (op), te, exprNode_unparse (ret)),
4628 ret->typ = ctype_int;
4632 case TEXCL: /* maybe this should be restricted */
4633 guardSet_flip (ret->guards);
4635 if (ctype_isRealBool (te) || ctype_isUnknown (te))
4641 if (ctype_isRealPointer (tr))
4643 if (sRef_isKnown (e->sref))
4645 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
4649 (FLG_BOOLOPS, FLG_PTRNEGATE,
4650 message ("Operand of %s is non-boolean (%t): %s",
4651 lltok_unparse (op), te, exprNode_unparse (ret)),
4658 message ("Operand of %s is non-boolean (%t): %s",
4659 lltok_unparse (op), te, exprNode_unparse (ret)),
4663 ret->typ = ctype_bool;
4668 if (ctype_isForceRealInt (&tr))
4673 if (context_msgStrictOps ())
4677 message ("Operand of %s is non-integer (%t): %s",
4678 lltok_unparse (op), te, exprNode_unparse (ret)),
4682 if (ctype_isInt (e->typ))
4688 ret->typ = ctype_int;
4694 ret->typ = ctype_makePointer (e->typ);
4696 if (sRef_isKnown (e->sref))
4698 ret->sref = sRef_makeAddress (e->sref);
4705 if (ctype_isAP (tr))
4707 ret->typ = ctype_baseArrayPtr (e->typ);
4711 if (ctype_isKnown (te))
4713 if (ctype_isFunction (te))
4719 message ("Dereference of function type (%t): %s",
4720 te, exprNode_unparse (ret)),
4725 voptgenerror (FLG_TYPE,
4726 message ("Dereference of non-pointer (%t): %s",
4727 te, exprNode_unparse (ret)),
4729 ret->typ = ctype_unknown;
4734 ret->typ = ctype_unknown;
4739 if (sRef_isKnown (e->sref))
4741 DPRINTF (("Checking possibly null: %s", sRef_unparseFull (e->sref)));
4743 if (sRef_possiblyNull (e->sref))
4745 DPRINTF (("Checking possibly null: %s", sRef_unparse (e->sref)));
4746 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
4750 message ("Dereference of %s pointer %q: %s",
4751 sRef_nullMessage (e->sref),
4752 sRef_unparse (e->sref),
4753 exprNode_unparse (ret)),
4756 sRef_showNullInfo (e->sref);
4757 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
4762 ret->sref = sRef_makePointer (e->sref);
4767 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
4772 exprNode_checkModify (e, ret);
4779 ** any reason to disallow sizeof (abstract type) ?
4783 ** used by both sizeof
4787 ctype sizeof_resultType (void)
4789 static ctype sizet = ctype_unknown;
4791 if (ctype_isUnknown (sizet))
4793 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
4795 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
4799 sizet = ctype_ulint;
4806 exprNode_sizeofType (/*@only@*/ qtype qt)
4808 exprNode ret = exprNode_create (sizeof_resultType ());
4809 ctype ct = qtype_getType (qt);
4811 ret->kind = XPR_SIZEOFT;
4812 ret->edata = exprData_makeSizeofType (qt);
4814 voptgenerror (FLG_SIZEOFTYPE,
4815 message ("Parameter to sizeof is type %s: %s",
4817 exprNode_unparse (ret)),
4824 exprNode_alignofType (/*@only@*/ qtype qt)
4826 exprNode ret = exprNode_create (sizeof_resultType ());
4827 ctype ct = qtype_getType (qt);
4829 ret->kind = XPR_ALIGNOFT;
4830 ret->edata = exprData_makeSizeofType (qt);
4832 voptgenerror (FLG_SIZEOFTYPE,
4833 message ("Parameter to alignof is type %s: %s",
4835 exprNode_unparse (ret)),
4841 exprNode exprNode_offsetof (qtype qt, cstringList s)
4843 exprNode ret = exprNode_create (sizeof_resultType ());
4844 ctype ct = qtype_getType (qt);
4846 ret->kind = XPR_OFFSETOF;
4847 ret->edata = exprData_makeOffsetof (qt, s);
4849 if (!ctype_isRealSU (ct))
4851 voptgenerror (FLG_TYPE,
4852 message ("First parameter to offsetof is not a "
4853 "struct or union type (type %s): %s",
4855 exprNode_unparse (ret)),
4862 cstringList_elements (s, el) {
4866 if (ctype_isUndefined (lt))
4870 else if (!ctype_isRealSU (lt))
4872 voptgenerror (FLG_TYPE,
4873 message ("Inner offsetof type is not a "
4874 "struct or union type (type %s before field %s): %s",
4875 ctype_unparse (lt), el,
4876 exprNode_unparse (ret)),
4882 fields = ctype_getFields (ctype_realType (lt));
4883 fld = uentryList_lookupField (fields, el);
4884 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4886 if (uentry_isUndefined (fld))
4888 if (ctype_equal (lt, ct)) {
4889 voptgenerror (FLG_TYPE,
4890 message ("Field %s in offsetof is not the "
4891 "name of a field of %s: %s",
4894 exprNode_unparse (ret)),
4897 voptgenerror (FLG_TYPE,
4898 message ("Deep field %s in offsetof is not the "
4899 "name of a field of %s: %s",
4902 exprNode_unparse (ret)),
4908 lt = uentry_getType (fld);
4911 } end_cstringList_elements;
4913 /* Should report error if its a bit field - behavior is undefined! */
4920 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4924 if (exprNode_isUndefined (e))
4926 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4927 ret->edata = exprData_makeSingle (e);
4928 ret->typ = sizeof_resultType ();
4929 ret->kind = XPR_SIZEOF;
4933 uentry u = exprNode_getUentry (e);
4935 ret = exprNode_createPartialCopy (e);
4936 ret->edata = exprData_makeSingle (e);
4938 ret->typ = sizeof_resultType ();
4939 ret->kind = XPR_SIZEOF;
4941 if (uentry_isValid (u)
4942 && uentry_isRefParam (u)
4943 && ctype_isRealArray (uentry_getType (u)))
4946 (FLG_SIZEOFFORMALARRAY,
4947 message ("Parameter to sizeof is an array-type function parameter: %s",
4948 exprNode_unparse (ret)),
4954 ** sizeof (x) doesn't "really" use x
4961 exprNode_alignofExpr (/*@only@*/ exprNode e)
4965 if (exprNode_isUndefined (e))
4967 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4971 ret = exprNode_createPartialCopy (e);
4974 ret->edata = exprData_makeSingle (e);
4975 ret->typ = sizeof_resultType ();
4976 ret->kind = XPR_ALIGNOF;
4979 ** sizeof (x) doesn't "really" use x
4986 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4992 if (exprNode_isError (e))
4996 return exprNode_undefined;
4999 checkMacroParen (e);
5001 c = qtype_getType (q);
5002 t = exprNode_getType (e);
5004 ret = exprNode_createPartialCopy (e);
5006 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
5008 ret->kind = XPR_CAST;
5009 ret->edata = exprData_makeCast (tok, e, q);
5011 ret->sref = sRef_copy (e->sref);
5013 DPRINTF (("Cast: -> %s", sRef_unparseFull (ret->sref)));
5015 if (!sRef_isConst (e->sref))
5017 usymtab_addForceMustAlias (ret->sref, e->sref);
5020 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
5021 sRef_setTypeFull (ret->sref, c);
5022 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
5028 ** void * <-> abstract * (if FLG_ABSTVOIDP)
5029 ** abstract * <-> void * (if FLG_ABSTVOIDP)
5032 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
5034 /* evans 2002-07-19: added this warning */
5035 DPRINTF (("Checking: %s / %s", exprNode_unparse (ret), sRef_unparseFull (ret->sref)));
5036 if (sRef_isFresh (ret->sref))
5040 message ("New fresh storage %q(type %s) cast to void (not released): %s",
5041 sRef_unparseOpt (ret->sref),
5042 ctype_unparse (exprNode_getType (ret)),
5043 exprNode_unparse (ret)),
5044 exprNode_loc (ret));
5047 else if (ctype_isRealAP (c)) /* casting to array or pointer */
5049 ctype bc = ctype_getBaseType (c);
5050 ctype bt = ctype_getBaseType (t);
5051 ctype rt = ctype_realType (t);
5053 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
5054 && (ctype_isArrayPtr (rt)
5055 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
5059 message ("Cast from function pointer type (%t) to "
5060 "non-function pointer (%t): %s",
5061 c, t, exprNode_unparse (ret)),
5065 if (!ctype_isFunction (ctype_baseArrayPtr (c))
5066 && (ctype_isArrayPtr (rt)
5067 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
5071 message ("Cast from non-function pointer type (%t) to "
5072 "function pointer (%t): %s",
5073 c, t, exprNode_unparse (ret)),
5077 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
5078 !(ctype_isRealAbstract (bc)
5079 && context_hasAccess (ctype_typeId (bc))))
5081 ; /* okay to cast zero */
5085 if (ctype_isRealAbstract (bc)
5086 && !context_hasAccess (ctype_typeId (bc)))
5088 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
5092 message ("Cast to underlying abstract type %t: %s",
5093 c, exprNode_unparse (ret)),
5100 message ("Cast to underlying abstract type %t: %s",
5101 c, exprNode_unparse (ret)),
5106 if (ctype_isRealAbstract (bt)
5107 && !context_hasAccess (ctype_typeId (bt)))
5109 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
5113 message ("Cast from underlying abstract type %t: %s",
5114 t, exprNode_unparse (ret)),
5121 message ("Cast from underlying abstract type %t: %s",
5122 t, exprNode_unparse (ret)),
5130 ctype bt = ctype_realType (ctype_getBaseType (t));
5131 ctype bc = ctype_realType (ctype_getBaseType (c));
5133 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
5135 if (ctype_match (c, t))
5137 if (ctype_equal (c, t))
5141 message ("Redundant cast involving abstract type %t: %s",
5142 bt, exprNode_unparse (ret)),
5150 message ("Cast from abstract type %t: %s",
5151 bt, exprNode_unparse (ret)),
5156 if (ctype_isAbstract (bc)
5157 && !context_hasAccess (ctype_typeId (bc)))
5159 if (ctype_match (c, t))
5165 if (ctype_isNumAbstract (bc))
5167 if (exprNode_isNumLiteral (e))
5170 (FLG_NUMABSTRACTCAST,
5171 message ("Cast from literal to numabstract type %t: %s", bc,
5172 exprNode_unparse (ret)),
5179 message ("Cast to numabstract type %t: %s", bc,
5180 exprNode_unparse (ret)),
5186 DPRINTF (("No access to: %s / %d",
5187 ctype_unparse (bc), ctype_typeId (bc)));
5188 DPRINTF (("Context %s %s",
5189 bool_unparse (context_inFunctionLike ()),
5190 context_unparse ()));
5193 message ("Cast to abstract type %t: %s", bc,
5194 exprNode_unparse (ret)),
5201 if (ctype_isAbstract (c))
5203 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
5205 /* okay, cast exposed to abstract */
5206 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
5210 if (ctype_isVisiblySharable (t)
5211 && sRef_isExternallyVisible (e->sref)
5212 && !(ctype_isAbstract (t)
5213 && context_hasAccess (ctype_typeId (t))))
5217 message ("Cast to abstract type from externally visible "
5218 "mutable storage exposes rep of %s: %s",
5220 exprNode_unparse (e)),
5230 evaluationOrderUndefined (lltok op)
5232 int opid = lltok_getTok (op);
5234 return (opid != AND_OP && opid != OR_OP);
5237 static bool checkIntegral (/*@notnull@*/ exprNode e1,
5238 /*@notnull@*/ exprNode e2,
5239 /*@notnull@*/ exprNode ret,
5244 ctype te1 = exprNode_getType (e1);
5245 ctype te2 = exprNode_getType (e2);
5247 ctype tr1 = ctype_realishType (te1);
5248 ctype tr2 = ctype_realishType (te2);
5250 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
5256 if (context_msgStrictOps ())
5258 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
5260 if (ctype_sameName (te1, te2))
5264 message ("Operands of %s are non-integer (%t): %s",
5265 lltok_unparse (op), te1,
5266 exprNode_unparse (ret)),
5273 message ("Operands of %s are non-integers (%t, %t): %s",
5274 lltok_unparse (op), te1, te2,
5275 exprNode_unparse (ret)),
5279 else if (!ctype_isInt (tr1))
5283 message ("Left operand of %s is non-integer (%t): %s",
5284 lltok_unparse (op), te1, exprNode_unparse (ret)),
5288 /* !ctype_isInt (te2) */
5292 message ("Right operand of %s is non-integer (%t): %s",
5293 lltok_unparse (op), te2, exprNode_unparse (ret)),
5303 ** returns exprNode representing e1 op e2
5305 ** uses msg if there are errors
5306 ** can be used for both assignment ops and regular ops
5311 static /*@only@*/ /*@notnull@*/ exprNode
5312 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
5313 /*@keep@*/ lltok op)
5315 ctype te1, te2, tr1, tr2, tret;
5316 int opid = lltok_getTok (op);
5317 bool hasError = FALSE;
5320 if (exprNode_isError (e1))
5322 ret = exprNode_createPartialNVCopy (e2);
5326 ret = exprNode_createPartialNVCopy (e1);
5329 ret->val = multiVal_undefined;
5332 ret->edata = exprData_makeOp (e1, e2, op);
5334 if (exprNode_isError (e1) || exprNode_isError (e2))
5336 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5337 || opid == EQ_OP || opid == NE_OP
5338 || opid == AND_OP || opid == OR_OP)
5340 ret->typ = ctype_bool;
5343 if (exprNode_isDefined (e1))
5345 exprNode_checkUse (ret, e1->sref, e1->loc);
5348 if (exprNode_isDefined (e2))
5350 exprNode_mergeUSs (ret, e2);
5351 exprNode_checkUse (ret, e2->sref, e2->loc);
5357 tret = ctype_unknown;
5358 te1 = exprNode_getType (e1);
5360 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
5362 te2 = exprNode_getType (e2);
5364 tr1 = ctype_realishType (te1);
5365 tr2 = ctype_realishType (te2);
5369 ret->guards = guardSet_or (ret->guards, e2->guards);
5371 else if (opid == AND_OP)
5373 ret->guards = guardSet_and (ret->guards, e2->guards);
5380 if (opid == EQ_OP || opid == NE_OP)
5382 exprNode temp1 = e1, temp2 = e2;
5384 /* could do NULL == x */
5386 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
5388 temp1 = e2; temp2 = e1;
5391 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
5393 reflectNullTest (temp1, (opid == NE_OP));
5394 guardSet_free (ret->guards);
5395 ret->guards = guardSet_copy (temp1->guards);
5399 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5400 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
5405 if (anyAbstract (tr1, tr2) &&
5406 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
5407 (opid == AND_OP || opid == OR_OP
5408 || opid == EQ_OP || opid == NE_OP))))
5410 if (abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc))
5412 tret = ctype_unknown;
5417 if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
5419 /* unknown types, no comparisons possible */
5425 case TMULT: /* multiplication and division: */
5427 case MUL_ASSIGN: /* numeric, numeric -> numeric */
5428 case DIV_ASSIGN: /* */
5429 if (opid == TMULT || opid == MUL_ASSIGN)
5431 ret->val = multiVal_multiply (exprNode_getValue (e1),
5432 exprNode_getValue (e2));
5436 ret->val = multiVal_divide (exprNode_getValue (e1),
5437 exprNode_getValue (e2));
5440 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5443 case TPLUS: /* addition and subtraction: */
5444 case TMINUS: /* pointer, int -> pointer */
5445 case SUB_ASSIGN: /* int, pointer -> pointer */
5446 case ADD_ASSIGN: /* numeric, numeric -> numeric */
5447 if (opid == TPLUS || opid == ADD_ASSIGN)
5449 ret->val = multiVal_add (exprNode_getValue (e1),
5450 exprNode_getValue (e2));
5454 ret->val = multiVal_subtract (exprNode_getValue (e1),
5455 exprNode_getValue (e2));
5458 tr1 = ctype_fixArrayPtr (tr1);
5460 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
5461 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
5465 if (context_msgPointerArith ())
5469 message ("Pointer arithmetic (%t, %t): %s",
5470 te1, te2, exprNode_unparse (ret)),
5475 ** Swap terms so e1 is always the pointer
5478 if (ctype_isRealPointer (tr1))
5484 exprNode_swap (e1, e2);
5487 if (sRef_possiblyNull (e1->sref)
5488 && !usymtab_isGuarded (e1->sref))
5491 (FLG_NULLPOINTERARITH,
5492 message ("Pointer arithmetic involving possibly "
5493 "null pointer %s: %s",
5494 exprNode_unparse (e1),
5495 exprNode_unparse (ret)),
5499 ret->sref = sRef_copy (e1->sref);
5501 /* start modifications */
5502 /* added by Seejo on 4/16/2000 */
5504 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5506 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
5509 added ugly fixed to stop
5510 program from crashing on point + int +int
5511 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
5513 if (!multiVal_isInt (e2->val) )
5517 val = (int) multiVal_forceInt (e2->val);
5519 /* Operator : + or += */
5520 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5521 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
5522 val should not result in a
5523 size < 0 (size = 0 is ok !) */
5525 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
5527 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
5528 sRef_setNotNullTerminatedState(ret->sref);
5529 sRef_resetLen (ret->sref);
5531 sRef_setNullTerminatedState(ret->sref);
5532 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
5537 /* Operator : - or -= */
5538 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5539 if (sRef_getSize(e1->sref) >= 0) {
5540 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
5541 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
5546 /* end modifications */
5548 sRef_setNullError (ret->sref);
5551 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5552 ** since is points to storage that should not be deallocated
5553 ** through this pointer.
5556 if (sRef_isOnly (ret->sref)
5557 || sRef_isFresh (ret->sref))
5559 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5564 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
5565 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
5567 if (context_msgPointerArith ())
5571 message ("Pointer arithmetic (%t, %t): %s",
5572 te1, te2, exprNode_unparse (ret)),
5576 if (sRef_possiblyNull (e1->sref)
5577 && !usymtab_isGuarded (e1->sref))
5580 (FLG_NULLPOINTERARITH,
5581 message ("Pointer arithmetic involving possibly "
5582 "null pointer %s: %s",
5583 exprNode_unparse (e2),
5584 exprNode_unparse (ret)),
5588 ret->sref = sRef_copy (e2->sref);
5590 /* start modifications */
5591 /* added by Seejo on 4/16/2000 */
5593 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5596 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
5597 if (multiVal_isDefined (e1->val))
5599 int val = (int) multiVal_forceInt (e1->val);
5601 /* Operator : + or += */
5602 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5603 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
5604 val should not result in a
5605 size < 0 (size = 0 is ok !) */
5607 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
5609 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
5610 sRef_setNotNullTerminatedState(ret->sref);
5611 sRef_resetLen (ret->sref);
5613 sRef_setNullTerminatedState(ret->sref);
5614 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
5619 /* Operator : - or -= */
5620 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5621 if (sRef_getSize(e2->sref) >= 0) {
5622 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
5623 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
5629 /* end modifications */
5631 sRef_setNullError (ret->sref);
5634 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5635 ** since is points to storage that should not be deallocated
5636 ** through this pointer.
5639 if (sRef_isOnly (ret->sref)
5640 || sRef_isFresh (ret->sref)) {
5641 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5645 ret->sref = e2->sref;
5649 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5658 case TAMPERSAND: /* bitwise & */
5660 case TCIRC: /* ^ (XOR) */
5665 bool reported = FALSE;
5671 if (opid == LEFT_OP || opid == LEFT_ASSIGN
5672 || opid == RIGHT_OP || opid == RIGHT_ASSIGN)
5675 ** evans 2002-01-01: fixed this to follow ISO 6.5.7.
5678 if (!ctype_isUnsigned (tr2)
5679 && !exprNode_isNonNegative (e2))
5681 reported = optgenerror
5683 message ("Right operand of %s may be negative (%t): %s",
5684 lltok_unparse (op), te2,
5685 exprNode_unparse (ret)),
5689 if (!ctype_isUnsigned (tr1)
5690 && !exprNode_isNonNegative (e1))
5692 reported = optgenerror
5693 (FLG_SHIFTIMPLEMENTATION,
5694 message ("Left operand of %s may be negative (%t): %s",
5695 lltok_unparse (op), te1,
5696 exprNode_unparse (ret)),
5701 ** Should check size of right operand also...
5707 if (!ctype_isUnsigned (tr1))
5709 if (exprNode_isNonNegative (e1)) {
5712 reported = optgenerror
5714 message ("Left operand of %s is not unsigned value (%t): %s",
5715 lltok_unparse (op), te1,
5716 exprNode_unparse (ret)),
5726 if (!ctype_isUnsigned (tr2))
5728 if (!exprNode_isNonNegative (e2)) {
5729 reported = optgenerror
5731 message ("Right operand of %s is not unsigned value (%t): %s",
5732 lltok_unparse (op), te2,
5733 exprNode_unparse (ret)),
5742 if (!checkIntegral (e1, e2, ret, op)) {
5743 te1 = ctype_unknown;
5747 DPRINTF (("Set: %s", ctype_unparse (te1)));
5750 ** tret is the widest type of te1 and te2
5753 tret = ctype_widest (te1, te2);
5758 if (checkIntegral (e1, e2, ret, op)) {
5761 tret = ctype_unknown;
5766 case TLT: /* comparisons */
5767 case TGT: /* numeric, numeric -> bool */
5769 DPRINTF (("Here we go: %s / %s",
5770 ctype_unparse (tr1), ctype_unparse (tr2)));
5772 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
5773 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
5776 bool fepsilon = FALSE;
5778 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
5783 if (opid == TLT || opid == TGT)
5785 uentry ue1 = exprNode_getUentry (e1);
5786 uentry ue2 = exprNode_getUentry (e2);
5789 ** FLT_EPSILON, etc. really is a variable, not
5793 if (uentry_isVariable (ue1))
5795 cstring uname = uentry_rawName (ue1);
5797 if (cstring_equalLit (uname, "FLT_EPSILON")
5798 || cstring_equalLit (uname, "DBL_EPSILON")
5799 || cstring_equalLit (uname, "LDBL_EPSILON"))
5805 if (uentry_isVariable (ue2))
5807 cstring uname = uentry_rawName (ue2);
5809 if (cstring_equalLit (uname, "FLT_EPSILON")
5810 || cstring_equalLit (uname, "DBL_EPSILON")
5811 || cstring_equalLit (uname, "LDBL_EPSILON"))
5820 ; /* Don't complain. */
5826 message ("Dangerous comparison involving %s types: %s",
5827 ctype_unparse (rtype),
5828 exprNode_unparse (ret)),
5837 ** Types should match.
5840 DPRINTF (("Match types: %s / %s", exprNode_unparse (e1),
5841 exprNode_unparse (e2)));
5843 if (!exprNode_matchTypes (e1, e2))
5845 hasError = gentypeerror
5847 message ("Operands of %s have incompatible types (%t, %t): %s",
5848 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5854 || (ctype_isForceRealNumeric (&tr1)
5855 && ctype_isForceRealNumeric (&tr2)) ||
5856 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
5862 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
5863 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
5867 message ("Comparison of pointer and numeric (%t, %t): %s",
5868 te1, te2, exprNode_unparse (ret)),
5873 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5878 /* certain comparisons on unsigned's and zero look suspicious */
5880 if (opid == TLT || opid == LE_OP || opid == GE_OP)
5882 if ((ctype_isUnsigned (tr1) && exprNode_isZero (e2))
5883 || (ctype_isUnsigned (tr2) && exprNode_isZero (e1)))
5886 (FLG_UNSIGNEDCOMPARE,
5887 message ("Comparison of unsigned value involving zero: %s",
5888 exprNode_unparse (ret)),
5893 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
5895 if ((opid == EQ_OP || opid == NE_OP) &&
5896 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
5899 ** is one a variable?
5902 if (uentry_isVariable (exprNode_getUentry (e1))
5903 || uentry_isVariable (exprNode_getUentry (e2)))
5906 ** comparisons with FALSE are okay
5909 if (exprNode_isFalseConstant (e1)
5910 || exprNode_isFalseConstant (e2))
5919 ("Use of %q with %s variables (risks inconsistency because "
5920 "of multiple true values): %s",
5921 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
5922 context_printBoolName (), exprNode_unparse (ret)),
5929 case AND_OP: /* bool, bool -> bool */
5931 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
5937 if (context_maybeSet (FLG_BOOLOPS))
5939 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
5941 if (ctype_sameName (te1, te2))
5945 message ("Operands of %s are non-boolean (%t): %s",
5946 lltok_unparse (op), te1,
5947 exprNode_unparse (ret)),
5955 ("Operands of %s are non-booleans (%t, %t): %s",
5956 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5960 else if (!ctype_isRealBool (te1))
5964 message ("Left operand of %s is non-boolean (%t): %s",
5965 lltok_unparse (op), te1, exprNode_unparse (ret)),
5968 else if (!ctype_isRealBool (te2))
5972 message ("Right operand of %s is non-boolean (%t): %s",
5973 lltok_unparse (op), te2, exprNode_unparse (ret)),
5986 (cstring_makeLiteral
5987 ("There has been a problem in the parser. This is believed to result "
5988 "from a problem with bison v. 1.25. Please try rebuidling Splint "
5989 "using the pre-compiled grammar files by commenting out the "
5990 "BISON= line in the top-level Makefile."));
5995 DPRINTF (("Return type %s: %s", exprNode_unparse (ret), ctype_unparse (tret)));
5997 exprNode_checkUse (ret, e1->sref, e1->loc);
5998 exprNode_mergeUSs (ret, e2);
5999 exprNode_checkUse (ret, e2->sref, e2->loc);
6005 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
6006 /*@only@*/ lltok op)
6010 checkMacroParen (e1);
6011 checkMacroParen (e2);
6013 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
6015 checkExpressionDefined (e1, e2, op);
6018 ret = exprNode_makeOp (e1, e2, op);
6023 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
6026 ** This is somewhat bogus!
6028 ** Assigning to a nested observer in a non-observer datatype
6029 ** should not produce an error.
6032 sRef ref = exprNode_getSref (e1);
6034 DPRINTF (("Check assign mod: %s",
6035 sRef_unparseFull (ref)));
6037 if (sRef_isObserver (ref)
6038 || ((sRef_isFileStatic (ref) || sRef_isFileOrGlobalScope (ref))
6039 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
6041 sRef base = sRef_getBase (ref);
6043 if (sRef_isValid (base) && sRef_isObserver (base))
6045 exprNode_checkModify (e1, ret);
6049 exprNode_checkModifyVal (e1, ret);
6054 exprNode_checkModify (e1, ret);
6059 exprNode_assign (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2, /*@only@*/ lltok op)
6061 bool isalloc = FALSE;
6062 bool isjustalloc = FALSE;
6063 bool noalias = FALSE;
6066 DPRINTF (("%s [%s] <- %s [%s]",
6067 exprNode_unparse (e1),
6068 ctype_unparse (e1->typ),
6069 exprNode_unparse (e2),
6070 ctype_unparse (e2->typ)));
6072 if (lltok_getTok (op) != TASSIGN)
6074 ret = exprNode_makeOp (e1, e2, op);
6076 DPRINTF (("Here goes: %s %s",
6077 ctype_unparse (e1->typ),
6078 ctype_unparse (e2->typ)));
6080 if (exprNode_isDefined (e1)
6081 && exprNode_isDefined (e2))
6083 if (ctype_isNumeric (e2->typ)
6084 || ctype_isNumeric (e1->typ))
6086 /* Its a pointer arithmetic expression like ptr += i */
6093 ret = exprNode_createPartialCopy (e1);
6094 ret->kind = XPR_ASSIGN;
6095 ret->edata = exprData_makeOp (e1, e2, op);
6097 if (!exprNode_isError (e2))
6099 ret->sets = sRefSet_union (ret->sets, e2->sets);
6100 ret->msets = sRefSet_union (ret->msets, e2->msets);
6101 ret->uses = sRefSet_union (ret->uses, e2->uses);
6105 checkExpressionDefined (e1, e2, op);
6107 if (exprNode_isError (e1))
6109 if (!exprNode_isError (e2))
6111 ret->loc = fileloc_update (ret->loc, e2->loc);
6115 ret->loc = fileloc_update (ret->loc, g_currentloc);
6119 if (!exprNode_isError (e2))
6121 checkMacroParen (e2);
6124 if (exprNode_isDefined (e1))
6126 if (sRef_isMacroParamRef (e1->sref))
6128 if (context_inIterDef ())
6130 uentry ue = sRef_getUentry (e1->sref);
6132 if (uentry_isYield (ue))
6138 if (fileloc_isDefined (e1->loc))
6142 message ("Assignment to non-yield iter parameter: %q",
6143 sRef_unparse (e1->sref)),
6150 message ("Assignment to non-yield iter parameter: %q",
6151 sRef_unparse (e1->sref)),
6158 if (fileloc_isDefined (e1->loc))
6162 message ("Assignment to macro parameter: %q",
6163 sRef_unparse (e1->sref)),
6170 message ("Assignment to macro parameter: %q",
6171 sRef_unparse (e1->sref)),
6175 exprNode_checkAssignMod (e1, ret); /* evans 2001-07-22 */
6180 exprNode_checkAssignMod (e1, ret);
6183 if (exprNode_isDefined (e2))
6185 if (lltok_getTok (op) == TASSIGN)
6187 ctype te1 = exprNode_getType (e1);
6188 ctype te2 = exprNode_getType (e2);
6190 if (ctype_isVoid (te2))
6194 message ("Assignment of void value to %t: %s %s %s",
6195 te1, exprNode_unparse (e1),
6197 exprNode_unparse (e2)),
6200 else if (!ctype_forceMatch (te1, te2))
6202 if (exprNode_matchLiteral (te1, e2))
6204 DPRINTF (("Literals match: %s / %s",
6205 ctype_unparse (te1), exprNode_unparse (e2)));
6206 if (ctype_isNumAbstract (te1)) {
6207 if (!context_flagOn (FLG_NUMABSTRACTLIT, e1->loc)) {
6208 (void) llgenhinterror
6211 ("Assignment of %t literal to numabstract type %t: %s %s %s",
6213 exprNode_unparse (e1),
6215 exprNode_unparse (e2)),
6217 ("Use +numabstractlit to allow numeric literals to be used as numabstract values"),
6226 message ("Assignment of %t to %t: %s %s %s",
6227 te2, te1, exprNode_unparse (e1),
6229 exprNode_unparse (e2)),
6235 /* Type checks okay */
6239 exprNode_mergeUSs (ret, e2);
6240 exprNode_checkUse (ret, e2->sref, e2->loc);
6242 DPRINTF (("Do assign! %s %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6249 doAssign (e1, e2, FALSE);
6252 ret->sref = e1->sref;
6256 if (exprNode_isDefined (e2))
6258 exprNode_mergeUSs (ret, e2);
6259 exprNode_checkUse (ret, e2->sref, e2->loc);
6263 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
6265 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
6268 isjustalloc = sRef_isJustAllocated (e1->sref);
6269 isalloc = sRef_isAllocated (e1->sref);
6271 if (sRef_isField (e1->sref))
6273 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
6275 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
6277 exprNode_checkUse (ret, root, e1->loc);
6283 ** be careful! this defines e1->sref.
6286 /* evans 2001-07-22: removed if (!sRef_isMacroParamRef (e1->sref)) */
6288 DPRINTF (("Setting: %s -> %s", exprNode_unparse (ret), sRef_unparse (e1->sref)));
6289 exprNode_checkSet (ret, e1->sref);
6293 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
6294 ? e2->loc : e1->loc);
6300 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
6309 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
6310 /*@keep@*/ exprNode elseclause)
6314 if (!exprNode_isError (pred))
6316 ret = exprNode_createPartialCopy (pred);
6317 checkMacroParen (pred);
6318 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
6320 if (!exprNode_isError (ifclause))
6322 checkMacroParen (ifclause); /* update macro counts! */
6324 if (!exprNode_isError (elseclause))
6326 checkMacroParen (elseclause);
6328 if (!exprNode_matchTypes (ifclause, elseclause))
6331 (exprNode_getType (ifclause),
6333 exprNode_getType (elseclause),
6335 message ("Conditional clauses are not of same type: "
6337 exprNode_unparse (ifclause),
6338 exprNode_getType (ifclause),
6339 exprNode_unparse (elseclause),
6340 exprNode_getType (elseclause)),
6343 ret->sref = sRef_undefined;
6344 ret->typ = ctype_unknown;
6349 /* for now...should merge the states */
6350 ret->sref = ifclause->sref;
6351 ret->typ = ifclause->typ;
6353 if (exprNode_isNullValue (ifclause))
6355 ret->typ = elseclause->typ;
6359 exprNode_checkUse (ret, pred->sref, pred->loc);
6360 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6361 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6363 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6368 ret->typ = ifclause->typ;
6370 exprNode_checkUse (pred, pred->sref, pred->loc);
6371 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6373 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
6378 if (!exprNode_isError (elseclause))
6380 ret->typ = elseclause->typ;
6382 exprNode_checkUse (pred, pred->sref, pred->loc);
6383 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6385 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6389 else /* pred is error */
6391 if (!exprNode_isError (ifclause))
6393 ret = exprNode_createSemiCopy (ifclause);
6395 checkMacroParen (ifclause); /* update macro counts! */
6397 if (!exprNode_isError (elseclause))
6399 checkMacroParen (elseclause);
6401 ret->typ = ifclause->typ;
6403 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
6406 (exprNode_getType (ifclause),
6408 exprNode_getType (elseclause),
6410 message ("Conditional clauses are not of same type: "
6412 exprNode_unparse (ifclause),
6413 exprNode_getType (ifclause),
6414 exprNode_unparse (elseclause),
6415 exprNode_getType (elseclause)),
6418 ret->typ = ctype_unknown;
6422 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6423 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6425 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6428 else if (!exprNode_isError (elseclause)) /* pred, if errors */
6430 ret = exprNode_createSemiCopy (ifclause);
6432 ret->typ = elseclause->typ;
6433 checkMacroParen (elseclause);
6435 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6436 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6438 else /* all errors! */
6440 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6444 ret->kind = XPR_COND;
6445 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
6447 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
6449 exprNode_combineControl (ret, ifclause, elseclause);
6456 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
6458 ctype totype = qtype_getType (qt);
6460 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
6464 ** check use of va_arg : <valist>, type -> type
6467 if (exprNode_isError (arg))
6472 targ = exprNode_getType (arg);
6475 ** arg should have be a pointer
6478 if (!ctype_isUA (targ) ||
6479 (!typeId_equal (ctype_typeId (targ),
6480 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
6484 message ("First argument to va_arg is not a va_list (type %t): %s",
6485 targ, exprNode_unparse (arg)),
6489 exprNode_checkSet (ret, arg->sref);
6493 ** return type is totype
6497 ret->kind = XPR_VAARG;
6498 ret->edata = exprData_makeCast (tok, arg, qt);
6503 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
6505 exprNode ret = exprNode_createPlain (ctype_undefined);
6506 ret->kind = XPR_LABEL;
6507 ret->edata = exprData_makeLiteral (label);
6508 ret->isJumpPoint = TRUE;
6510 return (ret); /* for now, ignore label */
6513 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
6515 if (exprNode_isDefined (stmt))
6517 stmt->isJumpPoint = TRUE;
6519 /* This prevent stray no return path errors, etc. */
6520 stmt->exitCode = XK_MUSTEXIT;
6526 bool exprNode_isDefaultMarker (exprNode e)
6528 if (exprNode_isDefined (e))
6530 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
6536 bool exprNode_isCaseMarker (exprNode e)
6538 if (exprNode_isDefined (e))
6540 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
6546 bool exprNode_isLabelMarker (exprNode e)
6548 if (exprNode_isDefined (e))
6550 return (e->kind == XPR_LABEL);
6556 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
6558 exprNode ret = exprNode_createPartialCopy (test);
6560 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6562 if (exprNode_isError (test)) {
6566 exprNode_checkUse (ret, test->sref, test->loc);
6568 usymtab_setExitCode (ret->exitCode);
6572 usymtab_setMustBreak ();
6575 ret->edata = exprData_makeSingle (test);
6576 ret->isJumpPoint = TRUE;
6582 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
6584 exprNode ret = exprNode_createPartialCopy (test);
6586 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6587 ret->edata = exprData_makePair (test, stmt);
6588 ret->isJumpPoint = TRUE;
6590 if (exprNode_isError (test))
6595 exprNode_checkUse (ret, test->sref, test->loc);
6597 if (exprNode_isError (stmt))
6602 exprNode_mergeUSs (ret, stmt);
6604 ret->exitCode = stmt->exitCode;
6605 ret->mustBreak = stmt->mustBreak;
6606 ret->canBreak = stmt->canBreak;
6608 usymtab_setExitCode (ret->exitCode);
6612 usymtab_setMustBreak ();
6619 /*@notnull@*/ /*@only@*/ exprNode
6620 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
6622 exprNode ret = exprNode_createTok (def);
6624 ret->isJumpPoint = TRUE;
6625 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
6630 exprNode_mayEscape (exprNode e)
6632 if (exprNode_isDefined (e))
6634 return exitkind_couldEscape (e->exitCode);
6640 exprNode_mustBreak (exprNode e)
6642 if (exprNode_isDefined (e))
6644 return e->mustBreak;
6651 exprNode_mustEscape (exprNode e)
6653 if (exprNode_isDefined (e))
6655 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
6662 exprNode_errorEscape (exprNode e)
6664 if (exprNode_isDefined (e))
6666 return exitkind_isError (e->exitCode);
6672 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
6674 exprNode ret = exprNode_createPartialCopy (e1);
6676 DPRINTF (("Concat: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6678 ret->edata = exprData_makePair (e1, e2);
6679 ret->kind = XPR_STMTLIST;
6681 if (exprNode_isDefined (e1))
6683 ret->isJumpPoint = e1->isJumpPoint;
6684 ret->canBreak = e1->canBreak;
6688 if (exprNode_isDefined (e2))
6690 ret->loc = fileloc_update (ret->loc, e2->loc);
6694 if (exprNode_isDefined (e2))
6696 ret->exitCode = e2->exitCode;
6697 ret->mustBreak = e2->mustBreak;
6698 if (e2->canBreak) ret->canBreak = TRUE;
6702 ** if e1 must return, then e2 is unreachable!
6705 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
6707 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
6708 && !(e2->isJumpPoint))
6710 if (context_getFlag (FLG_UNREACHABLE))
6714 if (e2->kind == XPR_STMT)
6716 nr = exprData_getUopNode (e2->edata);
6719 if ((nr->kind == XPR_TOK
6720 && lltok_isSemi (exprData_getTok (nr->edata))))
6722 /* okay to have unreachable ";" */
6723 ret->exitCode = XK_MUSTEXIT;
6724 ret->canBreak = TRUE;
6728 if (optgenerror (FLG_UNREACHABLE,
6729 message ("Unreachable code: %s",
6730 exprNode_unparseFirst (nr)),
6733 ret->isJumpPoint = TRUE;
6734 ret->mustBreak = FALSE;
6735 ret->exitCode = XK_ERROR;
6736 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
6740 ret->exitCode = XK_MUSTEXIT;
6741 ret->canBreak = TRUE;
6749 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
6752 ** We want a warning anytime we have:
6754 ** yyy; <<<- no break or return
6758 exprNode lastStmt = exprNode_lastStatement (e1);
6760 if (exprNode_isDefined (lastStmt)
6761 && !exprNode_mustEscape (lastStmt)
6762 && !exprNode_mustBreak (lastStmt)
6763 && !exprNode_isCaseMarker (lastStmt)
6764 && !exprNode_isDefaultMarker (lastStmt)
6765 && !exprNode_isLabelMarker (lastStmt))
6767 voptgenerror (FLG_CASEBREAK,
6769 ("Fall through case (no preceding break)"),
6776 exprNode_mergeUSs (ret, e2);
6778 usymtab_setExitCode (ret->exitCode);
6782 usymtab_setMustBreak ();
6785 DPRINTF (("==> %s", exprNode_unparse (ret)));
6789 exprNode exprNode_createTok (/*@only@*/ lltok t)
6791 exprNode ret = exprNode_create (ctype_unknown);
6792 ret->kind = XPR_TOK;
6793 ret->edata = exprData_makeTok (t);
6797 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6799 if (!exprNode_isError (e))
6801 exprChecks_checkStatementEffect(e);
6804 return (exprNode_statementError (e, t));
6807 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6809 exprNode ret = exprNode_createPartialCopy (e);
6811 if (!exprNode_isError (e))
6813 if (e->kind != XPR_ASSIGN)
6815 exprNode_checkUse (ret, e->sref, e->loc);
6818 ret->exitCode = e->exitCode;
6819 ret->canBreak = e->canBreak;
6820 ret->mustBreak = e->mustBreak;
6823 ret->edata = exprData_makeUop (e, t);
6824 ret->kind = XPR_STMT;
6829 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
6831 if (!exprNode_isError (e))
6833 if (e->kind != XPR_ASSIGN)
6835 exprNode_checkUse (e, e->sref, e->loc);
6842 void exprNode_produceGuards (exprNode pred)
6844 if (!exprNode_isError (pred))
6846 if (ctype_isRealPointer (pred->typ))
6848 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
6851 exprNode_checkUse (pred, pred->sref, pred->loc);
6852 exprNode_resetSref (pred);
6856 exprNode exprNode_compoundStatementExpression (/*@only@*/ lltok tlparen, /*@only@*/ exprNode e)
6860 DPRINTF (("Compound: %s", exprNode_unparse (e)));
6862 if (!context_flagOn (FLG_GNUEXTENSIONS, exprNode_loc (e)))
6864 (void) llgenhinterror
6866 message ("Compound statement expressions is not supported by ISO C99"),
6867 message ("Use +gnuextensions to allow compound statement expressions (and other GNU language extensions) "
6868 "without this warning"),
6873 ** The type of a compoundStatementExpression is the type of the last statement
6876 llassert (exprNode_isBlock (e));
6877 laststmt = exprNode_lastStatement (e);
6879 DPRINTF (("Last statement: %s / %s", exprNode_unparse (laststmt), ctype_unparse (exprNode_getType (laststmt))));
6880 DPRINTF (("e: %s", exprNode_unparse (e)));
6881 e->typ = exprNode_getType (laststmt);
6882 return exprNode_addParens (tlparen, e);
6886 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
6888 exprNode ret = exprNode_createPartialCopy (e);
6890 if (!exprNode_isError (e))
6892 ret->exitCode = e->exitCode;
6893 ret->canBreak = e->canBreak;
6894 ret->mustBreak = e->mustBreak;
6897 DPRINTF (("Block e: %s", exprNode_unparse (e)));
6898 ret->edata = exprData_makeSingle (e);
6899 ret->kind = XPR_BLOCK;
6900 DPRINTF (("Block: %s", exprNode_unparse (ret)));
6904 bool exprNode_isBlock (exprNode e)
6906 return (exprNode_isDefined (e)
6907 && ((e)->kind == XPR_BLOCK));
6910 bool exprNode_isStatement (exprNode e)
6912 return (exprNode_isDefined (e)
6913 && ((e)->kind == XPR_STMT));
6916 bool exprNode_isAssign (exprNode e)
6918 if (exprNode_isDefined (e))
6920 return (e->kind == XPR_ASSIGN);
6926 bool exprNode_isEmptyStatement (exprNode e)
6928 return (exprNode_isDefined (e)
6929 && (e->kind == XPR_TOK)
6930 && (lltok_isSemi (exprData_getTok (e->edata))));
6933 bool exprNode_isMultiStatement (exprNode e)
6935 return (exprNode_isDefined (e)
6936 && ((e->kind == XPR_FOR)
6937 || (e->kind == XPR_FORPRED)
6938 || (e->kind == XPR_IF)
6939 || (e->kind == XPR_IFELSE)
6940 || (e->kind == XPR_WHILE)
6941 || (e->kind == XPR_WHILEPRED)
6942 || (e->kind == XPR_DOWHILE)
6943 || (e->kind == XPR_BLOCK)
6944 || (e->kind == XPR_STMT)
6945 || (e->kind == XPR_STMTLIST)
6946 || (e->kind == XPR_SWITCH)));
6949 void exprNode_checkIfPred (exprNode pred)
6951 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6954 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
6957 bool emptyErr = FALSE;
6959 if (context_maybeSet (FLG_IFEMPTY))
6961 if (exprNode_isEmptyStatement (tclause))
6963 emptyErr = optgenerror (FLG_IFEMPTY,
6965 ("Body of if statement is empty"),
6966 exprNode_loc (tclause));
6970 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
6972 if (exprNode_isDefined (tclause)
6973 && !exprNode_isBlock (tclause))
6975 voptgenerror (FLG_IFBLOCK,
6977 ("Body of if statement is not a block: %s",
6978 exprNode_unparse (tclause)),
6979 exprNode_loc (tclause));
6983 if (exprNode_isError (pred))
6985 if (exprNode_isError (tclause))
6987 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6991 ret = exprNode_createPartialCopy (tclause);
6996 if (exprNode_mustEscape (pred))
7000 message ("Predicate always exits: %s", exprNode_unparse (pred)),
7001 exprNode_loc (pred));
7004 exprNode_checkUse (pred, pred->sref, pred->loc);
7006 if (!exprNode_isError (tclause))
7008 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
7011 ret = exprNode_createPartialCopy (pred);
7015 ret->edata = exprData_makePair (pred, tclause);
7017 ret->exitCode = XK_UNKNOWN;
7019 if (exprNode_isDefined (tclause))
7021 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
7022 ret->canBreak = tclause->canBreak;
7023 ret->sets = sRefSet_union (ret->sets, tclause->sets);
7024 ret->msets = sRefSet_union (ret->msets, tclause->msets);
7025 ret->uses = sRefSet_union (ret->uses, tclause->uses);
7028 ret->mustBreak = FALSE;
7033 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
7034 /*@only@*/ exprNode tclause,
7035 /*@only@*/ exprNode eclause)
7038 bool tEmptyErr = FALSE;
7039 bool eEmptyErr = FALSE;
7041 if (context_maybeSet (FLG_IFEMPTY))
7043 if (exprNode_isEmptyStatement (tclause))
7045 tEmptyErr = optgenerror
7048 ("Body of if clause of if statement is empty"),
7049 exprNode_loc (tclause));
7052 if (exprNode_isEmptyStatement (eclause))
7054 eEmptyErr = optgenerror
7057 ("Body of else clause of if statement is empty"),
7058 exprNode_loc (eclause));
7062 if (context_maybeSet (FLG_IFBLOCK))
7065 && exprNode_isDefined (tclause)
7066 && !exprNode_isBlock (tclause))
7068 voptgenerror (FLG_IFBLOCK,
7070 ("Body of if clause of if statement is not a block: %s",
7071 exprNode_unparse (tclause)),
7072 exprNode_loc (tclause));
7076 && exprNode_isDefined (eclause)
7077 && !exprNode_isBlock (eclause)
7078 && !(eclause->kind == XPR_IF)
7079 && !(eclause->kind == XPR_IFELSE))
7084 ("Body of else clause of if statement is not a block: %s",
7085 exprNode_unparse (eclause)),
7086 exprNode_loc (eclause));
7090 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
7092 if (exprNode_isDefined (eclause)
7093 && (eclause->kind == XPR_IF))
7095 voptgenerror (FLG_ELSEIFCOMPLETE,
7096 message ("Incomplete else if logic (no final else): %s",
7097 exprNode_unparse (eclause)),
7098 exprNode_loc (eclause));
7102 if (exprNode_isError (pred))
7104 if (exprNode_isError (tclause))
7106 if (exprNode_isError (eclause))
7108 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7112 ret = exprNode_createPartialCopy (eclause);
7117 ret = exprNode_createPartialCopy (tclause);
7120 else /* pred is okay */
7122 ret = exprNode_createPartialCopy (pred);
7124 if (exprNode_mustEscape (pred))
7128 message ("Predicate always exits: %s", exprNode_unparse (pred)),
7129 exprNode_loc (pred));
7132 exprNode_checkUse (ret, pred->sref, pred->loc);
7133 exprNode_mergeCondUSs (ret, tclause, eclause);
7136 ret->kind = XPR_IFELSE;
7137 ret->edata = exprData_makeCond (pred, tclause, eclause);
7139 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
7141 exprNode_combineControl (ret, tclause, eclause);
7142 ret->loc = fileloc_update (ret->loc, eclause->loc);
7149 ** *allpaths <- TRUE iff all executions paths must go through the switch
7153 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
7155 exprNodeSList el = exprNode_flatten (e);
7156 bool mustReturn = TRUE; /* find a branch that doesn't */
7157 bool thisReturn = FALSE;
7158 bool hasDefault = FALSE;
7159 bool hasAllMembers = FALSE;
7160 bool inSwitch = FALSE;
7161 bool isEnumSwitch = FALSE;
7162 bool canBreak = FALSE;
7163 bool fallThrough = FALSE;
7164 ctype ct = ctype_unknown;
7165 enumNameSList usedEnums;
7168 if (exprNode_isDefined (test))
7173 ttype = ctype_realType (ct);
7175 if (ctype_isEnum (ttype))
7177 isEnumSwitch = TRUE;
7178 enums = ctype_elist (ttype);
7179 usedEnums = enumNameSList_new ();
7183 exprNodeSList_elements (el, current)
7186 DPRINTF ((message("checkSwitchExpr current = %s ", exprNode_unparse(current) ) ));
7188 if (exprNode_isDefined (current))
7190 switch (current->kind)
7197 (FLG_DUPLICATECASES,
7198 message ("Duplicate default cases in switch"),
7199 exprNode_loc (current));
7204 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
7212 exprNode st = exprData_getSingle (current->edata);
7213 uentry ue = exprNode_getUentry (st);
7215 if (uentry_isValid (ue))
7217 cstring cname = uentry_rawName (ue);
7219 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
7221 if (enumNameSList_member
7222 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
7225 (FLG_DUPLICATECASES,
7226 message ("Duplicate case in switch: %s",
7232 enumNameSList_addh (usedEnums, cname);
7239 message ("Case in switch not %s member: %s",
7240 ctype_unparse (ct), cname),
7247 if (inSwitch && !fallThrough)
7249 if (!thisReturn || canBreak)
7259 /*@switchbreak@*/ break;
7261 thisReturn = thisReturn || exprNode_mustEscape (current);
7262 canBreak = canBreak || current->canBreak;
7263 if (canBreak) fallThrough = FALSE;
7266 } end_exprNodeSList_elements;
7268 if (inSwitch) /* check the last one! */
7270 if (!thisReturn || canBreak)
7279 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
7280 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
7282 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
7284 voptgenerror (FLG_MISSCASE,
7285 message ("Missing case%s in switch: %q",
7286 cstring_makeLiteralTemp
7287 ((enumNameSList_size (unused) > 1) ? "s" : ""),
7288 enumNameSList_unparse (unused)),
7291 enumNameSList_free (unused);
7292 *allpaths = FALSE; /* evans 2002-01-01 */
7296 hasAllMembers = TRUE;
7300 enumNameSList_free (usedEnums);
7304 *allpaths = hasDefault;
7307 exprNodeSList_free (el);
7308 return ((hasDefault || hasAllMembers) && mustReturn);
7311 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
7313 exprNode ret = exprNode_createPartialCopy (e);
7316 DPRINTF (("Switch: %s", exprNode_unparse (s)));
7318 ret->kind = XPR_SWITCH;
7319 ret->edata = exprData_makePair (e, s);
7321 if (!exprNode_isError (s))
7323 exprNode fs = exprNode_firstStatement (s);
7324 ret->loc = fileloc_update (ret->loc, s->loc);
7326 if (exprNode_isUndefined (fs)
7327 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
7328 || exprNode_isDefaultMarker (fs)) {
7331 voptgenerror (FLG_FIRSTCASE,
7333 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
7338 if (!exprNode_isError (e))
7340 if (checkSwitchExpr (e, s, &allpaths))
7342 ret->exitCode = XK_MUSTRETURN;
7346 ret->exitCode = e->exitCode;
7349 ret->canBreak = e->canBreak;
7350 ret->mustBreak = e->mustBreak;
7354 ** exprNode.c:3883,32: Variable allpaths used before definition
7361 DPRINTF (("Context exit switch!"));
7362 context_exitSwitch (ret, allpaths);
7363 DPRINTF (("Context exit switch done!"));
7368 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
7369 /*@notnull@*/ exprNode body)
7371 sRefSet tuses = test->uses;
7373 if (!sRefSet_isEmpty (test->uses))
7375 sRefSet sets = sRefSet_newCopy (body->sets);
7376 bool hasError = TRUE;
7377 bool innerState = FALSE;
7378 sRefSet tuncon = sRefSet_undefined;
7380 sets = sRefSet_union (sets, test->sets);
7381 sets = sRefSet_union (sets, body->msets);
7382 sets = sRefSet_union (sets, test->msets);
7384 sRefSet_allElements (tuses, el)
7386 if (sRef_isUnconstrained (el))
7388 tuncon = sRefSet_insert (tuncon, el);
7392 if (sRefSet_member (sets, el))
7399 if (sRef_isInternalState (el)
7400 || sRef_isFileStatic (sRef_getRootBase (el)))
7404 } end_sRefSet_allElements ;
7408 sRefSet suncon = sRefSet_undefined;
7409 bool sinner = FALSE;
7411 sRefSet_allElements (sets, el)
7413 if (sRef_isUnconstrained (el))
7415 suncon = sRefSet_insert (suncon, el);
7417 else if (sRef_isInternalState (el))
7425 } end_sRefSet_allElements ;
7427 if (sinner && innerState)
7431 else if (sRefSet_isEmpty (tuncon)
7432 && sRefSet_isEmpty (suncon))
7437 ("Suspected infinite loop. No value used in loop test (%q) "
7438 "is modified by test or loop body.",
7439 sRefSet_unparsePlain (tuses)),
7444 if (sRefSet_isEmpty (tuncon))
7448 message ("Suspected infinite loop. No condition values "
7449 "modified. Modification possible through "
7450 "unconstrained calls: %q",
7451 sRefSet_unparsePlain (suncon)),
7458 message ("Suspected infinite loop. No condition values "
7459 "modified. Possible undetected dependency through "
7460 "unconstrained calls in loop test: %q",
7461 sRefSet_unparsePlain (tuncon)),
7467 sRefSet_free (sets);
7471 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
7474 bool emptyErr = FALSE;
7476 if (context_maybeSet (FLG_WHILEEMPTY))
7478 if (exprNode_isEmptyStatement (b))
7480 emptyErr = optgenerror
7483 ("Body of while statement is empty"),
7488 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
7490 if (exprNode_isDefined (b)
7491 && !exprNode_isBlock (b))
7493 if (context_inIterDef ()
7494 && (b->kind == XPR_STMTLIST
7495 || b->kind == XPR_TOK))
7501 voptgenerror (FLG_WHILEBLOCK,
7503 ("Body of while statement is not a block: %s",
7504 exprNode_unparse (b)),
7510 if (exprNode_isError (t))
7512 if (exprNode_isError (b))
7514 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7518 ret = exprNode_createPartialCopy (b);
7525 ret = exprNode_createPartialCopy (t);
7527 llassert (t->kind == XPR_WHILEPRED);
7529 test = exprData_getSingle (t->edata);
7531 if (!exprNode_isError (b) && exprNode_isDefined (test))
7533 if (context_maybeSet (FLG_INFLOOPS)
7534 || context_maybeSet (FLG_INFLOOPSUNCON))
7537 ** check that some variable in the predicate is set by the body
7538 ** if the predicate uses any variables
7541 checkInfiniteLoop (test, b);
7544 exprNode_mergeUSs (ret, b);
7546 if (exprNode_isDefined (b))
7548 ret->exitCode = exitkind_makeConditional (b->exitCode);
7553 ret->edata = exprData_makePair (t, b);
7554 ret->kind = XPR_WHILE;
7556 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
7560 message ("Predicate always exits: %s", exprNode_unparse (t)),
7564 ret->exitCode = XK_NEVERESCAPE;
7567 ** If loop is infinite, and there is no break inside,
7568 ** exit code is never reach.
7571 if (exprNode_knownIntValue (t))
7573 if (!exprNode_isZero (t))
7575 if (exprNode_isDefined (b))
7579 /* Really, it means never reached. */
7580 ret->exitCode = XK_MUSTEXIT;
7590 ret->canBreak = FALSE;
7591 ret->mustBreak = FALSE;
7597 ** do { b } while (t);
7599 ** note: body passed as first argument
7602 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
7606 DPRINTF (("Do while: %s / %s",
7607 exprNode_unparse (b), exprNode_unparse (t)));
7609 if (exprNode_isError (t))
7611 if (exprNode_isError (b))
7613 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7617 ret = exprNode_createPartialCopy (b);
7619 ret->exitCode = exitkind_makeConditional (b->exitCode);
7620 exprNode_checkUse (ret, b->sref, b->loc);
7621 ret->exitCode = b->exitCode;
7622 ret->canBreak = b->canBreak;
7623 ret->mustBreak = FALSE;
7628 DPRINTF (("Do while: %s / %s",
7629 exitkind_unparse (t->exitCode),
7630 exitkind_unparse (b->exitCode)));
7632 ret = exprNode_createPartialCopy (t);
7633 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
7635 if (!exprNode_isError (b))
7638 ** forgot the copy's --- why wasn't this detected??
7641 ret->sets = sRefSet_copyInto (ret->sets, b->sets);
7642 ret->msets = sRefSet_copyInto (ret->msets, b->msets);
7643 ret->uses = sRefSet_copyInto (ret->uses, b->uses);
7645 /* left this out --- causes and aliasing bug (infinite loop)
7646 should be detected?? */
7648 exprNode_checkUse (ret, b->sref, b->loc);
7649 exprNode_mergeUSs (ret, t);
7650 exprNode_checkUse (ret, t->sref, t->loc);
7652 /* evans 2001-10-05: while loop can break */
7653 ret->exitCode = exitkind_makeConditional (b->exitCode);
7655 DPRINTF (("Do while: %s",
7656 exitkind_unparse (ret->exitCode)));
7658 ret->canBreak = b->canBreak;
7660 /* Always FALSE for doWhile loops - break's when test is false */
7661 ret->mustBreak = FALSE; /* b->mustBreak; */
7665 context_exitDoWhileClause (t);
7667 ret->kind = XPR_DOWHILE;
7668 ret->edata = exprData_makePair (t, b);
7672 bool exprNode_loopMustExec (exprNode forPred)
7675 ** Returns true if it is obvious that the loop always executes at least once
7677 ** For now, we only identify the most obvious cases. Should be true anytime
7678 ** we can prove init => !test.
7681 if (exprNode_isDefined (forPred))
7683 exprNode init, test, inc;
7686 llassert (forPred->kind == XPR_FORPRED);
7688 edata = forPred->edata;
7689 init = exprData_getTripleInit (edata);
7690 test = exprData_getTripleTest (edata);
7691 inc = exprData_getTripleInc (edata);
7693 if (exprNode_isAssign (init))
7695 exprNode loopVar = exprData_getOpA (init->edata);
7696 exprNode loopInit = exprData_getOpB (init->edata);
7698 if (exprNode_isDefined (test) && test->kind == XPR_OP)
7700 exprNode testVar = exprData_getOpA (test->edata);
7701 exprNode testVal = exprData_getOpB (test->edata);
7702 lltok comp = exprData_getOpTok (test->edata);
7703 int opid = lltok_getTok (comp);
7705 DPRINTF (("Same storage: %s / %s", exprNode_unparse (loopVar),
7706 exprNode_unparse (testVar)));
7708 if (exprNode_sameStorage (loopVar, testVar))
7710 multiVal valinit = exprNode_getValue (loopInit);
7711 multiVal valtest = exprNode_getValue (testVal);
7713 DPRINTF (("Values: %s / %s", multiVal_unparse (valinit),
7714 multiVal_unparse (valtest)));
7716 if (multiVal_isInt (valinit) && multiVal_isInt (valtest))
7718 long v1 = multiVal_forceInt (valinit);
7719 long v2 = multiVal_forceInt (valtest);
7721 DPRINTF (("Here: %ld %ld", v1, v2));
7723 if ((opid == EQ_OP && v1 < v2)
7724 || (opid == NE_OP && v1 != v2)
7725 || (opid == TLT && v1 <= v2)
7726 || (opid == TGT && v1 >= v2)
7727 || (opid == LE_OP && v1 < v2)
7728 || (opid == GE_OP && v1 > v2))
7730 DPRINTF (("mustexec if inc"));
7739 DPRINTF (("loop must exec: FALSE"));
7743 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
7746 bool emptyErr = FALSE;
7748 if (context_maybeSet (FLG_FOREMPTY))
7750 if (exprNode_isEmptyStatement (body))
7752 emptyErr = optgenerror
7755 ("Body of for statement is empty"),
7756 exprNode_loc (body));
7760 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
7762 if (exprNode_isDefined (body)
7763 && !exprNode_isBlock (body))
7765 if (context_inIterDef ()
7766 && (body->kind == XPR_STMTLIST
7767 || body->kind == XPR_TOK))
7773 voptgenerror (FLG_FORBLOCK,
7775 ("Body of for statement is not a block: %s",
7776 exprNode_unparse (body)),
7777 exprNode_loc (body));
7783 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
7786 if (exprNode_isError (body))
7788 ret = exprNode_createPartialCopy (inc);
7792 ret = exprNode_createPartialCopy (body);
7794 ret->exitCode = exitkind_makeConditional (body->exitCode);
7796 exprNode_mergeUSs (inc, body);
7798 if (exprNode_isDefined (inc))
7802 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
7804 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
7805 exprNode_freeShallow (tmp);
7807 context_clearMessageAnnote ();
7808 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
7810 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
7811 exprNode_freeShallow (tmp);
7813 context_clearMessageAnnote ();
7815 ret->uses = sRefSet_copyInto (ret->uses, inc->uses);
7816 ret->sets = sRefSet_copyInto (ret->sets, inc->sets);
7817 ret->msets = sRefSet_copyInto (ret->msets, inc->msets);
7821 ret->kind = XPR_FOR;
7822 ret->edata = exprData_makePair (inc, body);
7824 if (exprNode_isDefined (inc)) {
7825 exprNode test = exprData_getTripleTest (inc->edata);
7827 if (exprNode_isUndefined (test)) {
7828 if (exprNode_isDefined (body)) {
7829 if (!body->canBreak) {
7830 /* Really, it means never reached. */
7831 ret->exitCode = XK_MUSTEXIT;
7841 ** for (init; test; inc)
7844 ** while (test) { body; inc; }
7846 ** Now: check use of init (may set vars for test)
7847 ** check use of test
7851 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
7855 if (exprNode_isError (pred)) return guardSet_undefined;
7857 llassert (pred->kind == XPR_FORPRED);
7859 test = exprData_getTripleTest (pred->edata);
7861 if (!exprNode_isError (test))
7863 return (test->guards);
7866 return guardSet_undefined;
7869 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
7871 exprNode ret = exprNode_createSemiCopy (test);
7873 if (exprNode_isDefined (test))
7875 exprNode_copySets (ret, test);
7876 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
7877 exprNode_checkUse (ret, test->sref, test->loc);
7879 exprNode_produceGuards (test);
7881 ret->guards = guardSet_copy (test->guards);
7884 ret->edata = exprData_makeSingle (test);
7885 ret->kind = XPR_WHILEPRED;
7889 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
7890 /*@only@*/ exprNode inc)
7895 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
7898 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
7900 if (!exprNode_isError (inc))
7902 ret = exprNode_createPartialCopy (inc);
7906 if (!exprNode_isError (init))
7908 ret = exprNode_createPartialCopy (init);
7910 else if (!exprNode_isError (test))
7912 ret = exprNode_createPartialCopy (test);
7916 ret = exprNode_createUnknown ();
7920 exprNode_mergeUSs (ret, init);
7922 if (exprNode_isDefined (init))
7924 exprNode_checkUse (ret, init->sref, init->loc);
7927 exprNode_mergeUSs (ret, test);
7929 if (exprNode_isDefined (test))
7931 exprNode_checkUse (ret, test->sref, test->loc);
7934 ret->kind = XPR_FORPRED;
7935 ret->edata = exprData_makeFor (init, test, inc);
7939 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
7941 exprNode ret = exprNode_createUnknown ();
7943 if (context_inMacro ())
7945 voptgenerror (FLG_MACROSTMT,
7946 message ("Macro %s uses goto (not functional)",
7947 context_inFunctionName ()),
7951 ret->kind = XPR_GOTO;
7952 ret->edata = exprData_makeLiteral (label);
7953 ret->mustBreak = TRUE;
7954 ret->exitCode = XK_GOTO;
7955 ret->canBreak = TRUE;
7959 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
7961 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7963 ret->kind = XPR_CONTINUE;
7964 ret->edata = exprData_makeTok (l);
7965 ret->canBreak = TRUE;
7966 ret->mustBreak = TRUE;
7968 if (qcontinue == QSAFEBREAK)
7972 else if (qcontinue == QINNERCONTINUE)
7974 if (!context_inDeepLoop ())
7977 (FLG_LOOPLOOPCONTINUE,
7978 cstring_makeLiteral ("Continue statement marked with innercontinue "
7979 "is not inside a nested loop"),
7980 exprNode_loc (ret));
7983 else if (qcontinue == BADTOK)
7985 if (context_inDeepLoop ())
7988 (FLG_LOOPLOOPCONTINUE,
7989 cstring_makeLiteral ("Continue statement in nested loop"),
7990 exprNode_loc (ret));
7995 llbuglit ("exprNode_continue: bad qcontinue");
8001 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
8003 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
8004 clause breakClause = context_breakClause ();
8006 ret->kind = XPR_BREAK;
8007 ret->edata = exprData_makeTok (l);
8008 ret->canBreak = TRUE;
8009 ret->mustBreak = TRUE;
8011 if (breakClause == NOCLAUSE)
8015 cstring_makeLiteral ("Break not inside while, for or switch statement"),
8016 exprNode_loc (ret));
8020 if (bqual != BADTOK)
8027 if (breakClause == SWITCHCLAUSE)
8029 if (!context_inDeepSwitch ())
8031 voptgenerror (FLG_SYNTAX,
8033 ("Break preceded by innerbreak is not in a deep switch"),
8034 exprNode_loc (ret));
8039 if (!context_inDeepLoop ())
8041 voptgenerror (FLG_SYNTAX,
8043 ("Break preceded by innerbreak is not in a deep loop"),
8044 exprNode_loc (ret));
8049 if (breakClause == SWITCHCLAUSE)
8051 voptgenerror (FLG_SYNTAX,
8053 ("Break preceded by loopbreak is breaking a switch"),
8054 exprNode_loc (ret));
8058 if (breakClause != SWITCHCLAUSE)
8062 message ("Break preceded by switchbreak is breaking %s",
8063 cstring_makeLiteralTemp
8064 ((breakClause == WHILECLAUSE
8065 || breakClause == DOWHILECLAUSE) ? "a while loop"
8066 : (breakClause == FORCLAUSE) ? "a for loop"
8067 : (breakClause == ITERCLAUSE) ? "an iterator"
8069 exprNode_loc (ret));
8077 if (breakClause == SWITCHCLAUSE)
8079 clause nextBreakClause = context_nextBreakClause ();
8081 switch (nextBreakClause)
8083 case NOCLAUSE: break;
8089 (FLG_LOOPSWITCHBREAK,
8090 cstring_makeLiteral ("Break statement in switch inside loop"),
8091 exprNode_loc (ret));
8095 (FLG_SWITCHSWITCHBREAK,
8096 cstring_makeLiteral ("Break statement in switch inside switch"),
8097 exprNode_loc (ret));
8104 if (context_inDeepLoop ())
8108 cstring_makeLiteral ("Break statement in nested loop"),
8109 exprNode_loc (ret));
8113 if (context_inDeepLoopSwitch ())
8116 (FLG_SWITCHLOOPBREAK,
8117 cstring_makeLiteral ("Break statement in loop inside switch"),
8118 exprNode_loc (ret));
8128 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
8130 fileloc loc = lltok_getLoc (t);
8131 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
8133 context_returnFunction ();
8134 exprChecks_checkNullReturn (loc);
8136 ret->kind = XPR_NULLRETURN;
8137 ret->edata = exprData_makeTok (t);
8138 ret->exitCode = XK_MUSTRETURN;
8142 exprNode exprNode_return (/*@only@*/ exprNode e)
8146 if (exprNode_isError (e))
8148 ret = exprNode_createUnknown ();
8152 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
8154 exprNode_checkUse (ret, e->sref, e->loc);
8155 exprNode_checkReturn (e);
8158 context_returnFunction ();
8159 ret->kind = XPR_RETURN;
8160 ret->edata = exprData_makeSingle (e);
8161 ret->exitCode = XK_MUSTRETURN;
8166 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
8170 if (exprNode_isError (e1))
8172 if (exprNode_isError (e2))
8174 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
8178 ret = exprNode_createPartialCopy (e2);
8179 exprNode_checkUse (ret, e2->sref, e2->loc);
8180 ret->sref = e2->sref;
8185 ret = exprNode_createPartialCopy (e1);
8187 exprNode_checkUse (ret, e1->sref, e1->loc);
8189 if (!exprNode_isError (e2))
8191 exprNode_mergeUSs (ret, e2);
8192 exprNode_checkUse (ret, e2->sref, e2->loc);
8193 ret->sref = e2->sref;
8197 ret->kind = XPR_COMMA;
8198 ret->edata = exprData_makePair (e1, e2);
8200 if (exprNode_isDefined (e1))
8202 if (exprNode_isDefined (e2))
8206 if (exprNode_mustEscape (e1) || e1->mustBreak)
8210 message ("Second clause of comma expression is unreachable: %s",
8211 exprNode_unparse (e2)),
8215 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
8216 ret->mustBreak = e1->mustBreak || e2->mustBreak;
8217 ret->canBreak = e1->canBreak || e2->canBreak;
8221 if (exprNode_mustEscape (e1) || e1->mustBreak)
8225 message ("Second clause of comma expression is unreachable: %s",
8226 exprNode_unparse (e2)),
8230 ret->exitCode = e1->exitCode;
8231 ret->canBreak = e1->canBreak;
8236 if (exprNode_isDefined (e2))
8238 ret->exitCode = e2->exitCode;
8239 ret->mustBreak = e2->mustBreak;
8240 ret->canBreak = e2->canBreak;
8247 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
8249 ctype t1 = exprNode_getType (el);
8250 ctype t2 = exprNode_getType (val);
8251 bool hasError = FALSE;
8253 DPRINTF (("Check one init: %s / %s",
8254 exprNode_unparse (el),
8255 exprNode_unparse (val)));
8257 if (ctype_isUnknown (t1))
8259 voptgenerror (FLG_IMPTYPE,
8260 message ("Variable has unknown (implicitly int) type: %s",
8261 exprNode_unparse (el)),
8265 el->typ = ctype_int;
8268 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
8270 exprNodeList vals = exprData_getArgs (val->edata);
8272 DPRINTF (("Check one init: %s", exprNodeList_unparse (vals)));
8273 DPRINTF (("Type: %s", ctype_unparse (t1)));
8275 if (ctype_isRealAP (t1))
8280 if (ctype_isFixedArray (t1))
8282 size_t nelements = ctype_getArraySize (t1);
8284 DPRINTF (("Checked array: %s / %d",
8285 ctype_unparse (t1), nelements));
8287 if (exprNode_isStringLiteral (val))
8289 exprNode_checkStringLiteralLength (t1, val);
8293 if (exprNodeList_size (vals) != size_toInt (nelements))
8295 hasError = optgenerror
8296 (exprNodeList_size (vals) > size_toInt (nelements)
8297 ? FLG_INITSIZE : FLG_INITALLELEMENTS,
8298 message ("Initializer block for "
8299 "%s has %d element%&, but declared as %s: %q",
8300 exprNode_unparse (el),
8301 exprNodeList_size (vals),
8303 exprNodeList_unparse (vals)),
8309 exprNodeList_elements (vals, oneval)
8311 cstring istring = message ("%d", i);
8314 (exprNode_fakeCopy (el),
8315 exprNode_numLiteral (ctype_int, istring,
8316 fileloc_copy (el->loc), i));
8318 if (exprNode_isDefined (newel))
8320 if (exprNodeList_size (vals) == 1
8321 && ctype_isString (exprNode_getType (oneval))
8322 && ctype_isChar (exprNode_getType (newel)))
8324 exprNode_freeIniter (newel);
8328 if (exprNode_checkOneInit (newel, oneval))
8333 if (nerrors > 3 && exprNodeList_size (vals) > 6)
8336 (message ("Additional initialization errors "
8337 "for %s not reported",
8338 exprNode_unparse (el)),
8340 exprNode_freeIniter (newel);
8345 exprNode_freeIniter (newel);
8350 exprNode_freeIniter (newel);
8355 cstring_free (istring);
8358 } end_exprNodeList_elements;
8361 else if (ctype_isStruct (ctype_realType (t1)))
8363 uentryList fields = ctype_getFields (t1);
8366 if (uentryList_size (fields) != exprNodeList_size (vals))
8368 if (uentryList_size (fields) > exprNodeList_size (vals))
8370 hasError = optgenerror
8372 message ("Initializer block for "
8373 "%s has %d field%&, but %s has %d field%&: %q",
8374 exprNode_unparse (el),
8375 exprNodeList_size (vals),
8377 uentryList_size (fields),
8378 exprNodeList_unparse (vals)),
8383 hasError = optgenerror
8385 message ("Initializer block for "
8386 "%s has %d field%&, but %s has %d field%&: %q",
8387 exprNode_unparse (el),
8388 exprNodeList_size (vals),
8390 uentryList_size (fields),
8391 exprNodeList_unparse (vals)),
8397 exprNodeList_elements (vals, oneval)
8399 uentry thisfield = uentryList_getN (fields, i);
8401 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
8403 uentry_getName (thisfield));
8405 if (exprNode_isDefined (newel))
8407 if (exprNode_checkOneInit (newel, oneval))
8412 exprNode_freeIniter (newel);
8416 } end_exprNodeList_elements;
8419 /* evans 2001-12-30: added to fix bug reported by Jim Zelenka */
8420 else if (ctype_isUnion (ctype_realType (t1)))
8422 uentryList fields = ctype_getFields (t1);
8426 ** Union initializers set the first member always.
8429 DPRINTF (("Union initializer: %s / %s",
8430 exprNode_unparse (el), ctype_unparse (ctype_realType (t1))));
8432 if (exprNodeList_size (vals) != 1)
8434 hasError = optgenerror
8436 message ("Initializer block for union "
8437 "%s has %d elements, union initializers should have one element: %q",
8438 exprNode_unparse (el),
8439 exprNodeList_size (vals),
8440 exprNodeList_unparse (vals)),
8445 exprNode oneval = exprNodeList_head (vals);
8446 uentry thisfield = uentryList_getN (fields, i);
8448 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
8450 uentry_getName (thisfield));
8452 if (exprNode_isDefined (newel))
8454 if (exprNode_checkOneInit (newel, oneval))
8459 exprNode_freeIniter (newel);
8465 hasError = optgenerror
8467 message ("Initializer block used for "
8468 "%s where %t is expected: %s",
8469 exprNode_unparse (el), t1, exprNode_unparse (val)),
8475 if (exprNode_isDefined (val))
8477 doAssign (el, val, TRUE);
8479 if (!exprNode_matchType (t1, val))
8481 hasError = gentypeerror
8483 message ("Initial value of %s is type %t, "
8485 exprNode_unparse (el),
8486 t2, t1, exprNode_unparse (val)),
8495 static /*@notnull@*/ exprNode
8496 exprNode_makeInitializationAux (/*@temp@*/ idDecl t)
8500 DPRINTF (("Initialization: %s", idDecl_unparse (t)));
8502 if (usymtab_exists (idDecl_observeId (t)))
8504 uentry ue = usymtab_lookup (idDecl_observeId (t));
8505 ret = exprNode_createId (ue);
8511 DPRINTF (("Unrecognized: %s", idDecl_unparse (t)));
8513 ue = uentry_makeUnrecognized (idDecl_observeId (t), fileloc_copy (g_currentloc));
8514 ret = exprNode_fromIdentifierAux (ue);
8517 ** No error - this happens in old style declarations:
8521 message ("Unrecognized identifier in intializer: %s", idDecl_observeId (t)),
8528 exprData_free (ret->edata, ret->kind);
8529 ret->edata = exprData_undefined;
8530 ret->exitCode = XK_NEVERESCAPE;
8531 ret->mustBreak = FALSE;
8532 ret->kind = XPR_INIT;
8536 exprNode exprNode_makeEmptyInitialization (/*@only@*/ idDecl t)
8538 exprNode ret = exprNode_makeInitializationAux (t);
8539 llassert (ret->edata == exprData_undefined);
8540 ret->edata = exprData_makeInit (t, exprNode_undefined);
8544 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
8545 /*@only@*/ exprNode e)
8547 uentry ue = usymtab_lookup (idDecl_observeId (t));
8548 exprNode ret = exprNode_makeInitializationAux (t);
8549 fileloc loc = exprNode_loc (e);
8551 DPRINTF (("initialization: %s = %s", idDecl_unparse (t), exprNode_unparse (e)));
8553 if (exprNode_isError (e))
8555 e = exprNode_createUnknown ();
8556 /* error: assume initializer is defined */
8557 sRef_setDefined (ret->sref, g_currentloc);
8558 ret->edata = exprData_makeInit (t, e);
8562 ctype ct = ctype_realishType (ret->typ);
8567 ** was addSafeUse --- what's the problem?
8569 ** int x = 3, y = x ?
8572 exprData_free (ret->edata, ret->kind);
8573 ret->edata = exprData_makeInit (t, e);
8574 DPRINTF (("ret: %s", exprNode_unparse (ret)));
8576 exprNode_checkUse (ret, e->sref, e->loc);
8578 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
8580 exprNode lhs = exprNode_createId (ue);
8583 ** static storage should be undefined before initializing
8586 if (uentry_isStatic (ue))
8588 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
8591 (void) exprNode_checkOneInit (lhs, e);
8593 if (uentry_isStatic (ue))
8595 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
8598 exprNode_free (lhs);
8602 if (!exprNode_matchType (ct, e))
8604 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
8611 (exprNode_getType (e), e, exprNode_getType (ret), ret,
8613 ("Variable %q initialized to type %t, expects %t: %s",
8614 uentry_getName (ue), exprNode_getType (e),
8615 exprNode_getType (ret),
8616 exprNode_unparse (e)),
8622 if (uentry_isStatic (ue))
8624 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
8627 if (exprNode_isStringLiteral (e)
8628 && (ctype_isArray (ct))
8629 && (ctype_isChar (ctype_realType (ctype_baseArrayPtr (ct)))))
8632 ** If t is a char [], the literal is copied.
8635 exprNode_checkStringLiteralLength (ct, e);
8636 sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
8637 ret->val = multiVal_copy (e->val);
8639 sRef_setNullTerminatedState (ret->sref);
8641 if (multiVal_isDefined (e->val))
8643 cstring slit = multiVal_forceString (e->val);
8644 sRef_setLen (ret->sref, size_toInt (cstring_length (slit) + 1));
8647 if (ctype_isFixedArray (ct))
8649 sRef_setSize (ret->sref, size_toInt (ctype_getArraySize (ct)));
8654 doAssign (ret, e, TRUE);
8657 if (uentry_isStatic (ue))
8659 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
8663 if (context_inIterDef ())
8665 /* should check if it is yield */
8666 uentry_setUsed (ue, loc);
8673 exprNode_mergeUSs (ret, e);
8674 DPRINTF (("Ret: %s %p %p",
8675 exprNode_unparse (ret),
8676 ret->requiresConstraints,
8677 ret->ensuresConstraints));
8679 DPRINTF (("Ret: %s %s %s",
8680 exprNode_unparse (ret),
8681 constraintList_unparse (ret->requiresConstraints),
8682 constraintList_unparse (ret->ensuresConstraints)));
8686 exprNode exprNode_iter (/*@observer@*/ uentry name,
8687 /*@only@*/ exprNodeList alist,
8688 /*@only@*/ exprNode body,
8689 /*@observer@*/ uentry end)
8694 llassert (uentry_isValid (name));
8696 uentry_setUsed (name, exprNode_loc (body));
8698 ret = exprNode_createPartialCopy (body);
8699 iname = uentry_getName (name);
8701 if (uentry_isInvalid (end))
8703 llerror (FLG_ITERBALANCE,
8704 message ("Iter %s not balanced with end_%s", iname, iname));
8708 cstring ename = uentry_getName (end);
8710 if (!cstring_equalPrefixLit (ename, "end_"))
8712 llerror (FLG_ITERBALANCE, message ("Iter %s not balanced with end_%s: %s",
8713 iname, iname, ename));
8717 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
8719 llerror (FLG_ITERBALANCE,
8720 message ("Iter %s not balanced with end_%s: %s",
8721 iname, iname, ename));
8725 cstring_free (ename);
8728 context_exitIterClause (body);
8730 ret->kind = XPR_ITER;
8731 ret->edata = exprData_makeIter (name, alist, body, end);
8733 if (uentry_isIter (name))
8735 (void) checkArgsReal (name, body,
8736 uentry_getParams (name), alist, TRUE, ret);
8739 cstring_free (iname);
8745 exprNode_iterNewId (/*@only@*/ cstring s)
8747 exprNode e = exprNode_new ();
8748 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
8750 llassert (processingIterVars ());
8752 e->loc = context_getSaveLocation ();
8754 if (fileloc_isUndefined (e->loc))
8756 fileloc_free (e->loc);
8757 e->loc = fileloc_copy (g_currentloc);
8760 e->uses = sRefSet_new ();
8761 e->sets = sRefSet_new ();
8762 e->msets = sRefSet_new ();
8764 e->val = multiVal_unknown ();
8765 e->guards = guardSet_new ();
8766 e->sref = sRef_undefined;
8767 e->isJumpPoint = FALSE;
8768 e->exitCode = XK_NEVERESCAPE;
8770 /*> missing fields, detected by splint <*/
8771 e->canBreak = FALSE;
8772 e->mustBreak = FALSE;
8773 e->etext = cstring_undefined;
8775 if (uentry_isYield (ue))
8777 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
8778 fileloc_copy (e->loc),
8782 uue = usymtab_supEntrySrefReturn (uue);
8784 sr = uentry_getSref (uue);
8785 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
8786 sr = uentry_getSref (uue);
8787 sRef_setDefined (sr, e->loc);
8789 e->typ = uentry_getType (uue);
8791 e->edata = exprData_makeId (uue);
8792 uentry_setUsed (uue, g_currentloc);
8798 sRef_setGlobalScope ();
8799 uue = uentry_makeVariableLoc (s, ctype_unknown);
8801 e->typ = ctype_unknown;
8802 e->edata = exprData_makeId (uue);
8804 uentry_setUsed (uue, e->loc);
8805 uentry_setHasNameError (uue);
8807 if (context_getFlag (FLG_REPEATUNRECOG))
8809 uentry_markOwned (uue);
8813 usymtab_supGlobalEntry (uue);
8816 sRef_clearGlobalScope ();
8818 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
8825 exprNode_defineConstraints(e);
8830 exprNode_iterExpr (/*@returned@*/ exprNode e)
8832 if (!processingIterVars ())
8834 llcontbuglit ("checkIterParam: not in iter");
8838 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
8841 if (exprNode_isDefined (e))
8843 if (fileloc_isDefined (e->loc))
8847 message ("Yield parameter is not simple identifier: %s",
8848 exprNode_unparse (e)),
8855 message ("Yield parameter is not simple identifier: %s",
8856 exprNode_unparse (e)),
8866 exprNode_iterId (/*@observer@*/ uentry c)
8870 llassert (processingIterVars ());
8872 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
8875 if (uentry_isYield (ue))
8877 ctype ct = uentry_getType (ue);
8878 exprNode e = exprNode_createPlain (ct);
8879 cstring name = uentry_getName (c);
8880 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
8882 uentry_setUsed (ue, g_currentloc);
8883 uentry_setHasNameError (ue);
8885 cstring_free (name);
8888 e->edata = exprData_makeId (le);
8889 e->loc = context_getSaveLocation ();
8890 e->sref = uentry_getSref (le);
8892 usymtab_supEntrySref (le);
8894 if (!context_inHeader ())
8898 message ("Yield parameter shadows local declaration: %q",
8899 uentry_getName (c)),
8900 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
8902 uentry_showWhereDeclared (c);
8909 return (exprNode_fromIdentifierAux (c));
8912 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
8914 exprNode ret = exprNode_create (ctype_unknown);
8916 ret->kind = XPR_ITERCALL;
8917 ret->edata = exprData_makeIterCall (name, alist);
8919 if (uentry_isIter (name))
8921 uentryList params = uentry_getParams (name);
8923 if (context_inIterDef ()
8924 && uentryList_size (params) == exprNodeList_size (alist))
8928 exprNodeList_elements (alist, arg)
8930 uentry parg = uentryList_getN (params, i);
8932 if (uentry_isYield (parg))
8934 uentry ue = exprNode_getUentry (arg);
8936 if (uentry_isValid (ue))
8943 } end_exprNodeList_elements;
8946 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
8947 checkUnspecCall (ret, params, alist);
8953 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
8955 if (exprNode_isDefined (e))
8957 if (sRef_isInvalid (e->sref))
8960 e->sref = sRef_makeUnknown ();
8961 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
8972 return sRef_undefined;
8976 /*@observer@*/ cstring
8977 exprNode_unparseFirst (exprNode e)
8979 if (exprNode_isDefined (e))
8983 if (e->kind == XPR_STMTLIST
8984 || e->kind == XPR_COMMA || e->kind == XPR_COND)
8986 exprNode first = exprData_getPairA (e->edata);
8988 if (exprNode_isDefined (first))
8990 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
8994 return (cstring_makeLiteralTemp ("..."));
8998 ret = cstring_elide (exprNode_unparse (e), 20);
8999 cstring_markOwned (ret);
9005 return cstring_makeLiteralTemp ("<error>");
9009 /*@observer@*/ cstring
9010 exprNode_unparse (/*@temp@*/ exprNode e)
9012 if (exprNode_isError (e))
9014 return cstring_makeLiteralTemp ("<error>");
9017 if (cstring_isDefined (e->etext))
9023 cstring ret = exprNode_doUnparse (e);
9025 /*@-modifies@*/ /* benevolent */
9032 /*@observer@*/ fileloc
9033 exprNode_loc (exprNode e)
9035 if (exprNode_isError (e))
9037 return (g_currentloc);
9046 ** executes exprNode e
9047 ** recursively rexecutes as though in original parse using
9048 ** information in e->edata
9051 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
9053 exprNodeList ret = exprNodeList_new ();
9055 exprNodeList_elements (e, current)
9057 exprNodeList_addh (ret, exprNode_effect (current));
9058 } end_exprNodeList_elements;
9063 static /*@only@*/ exprNode exprNode_effect (exprNode e)
9064 /*@globals internalState@*/
9066 bool innerEffect = inEffect;
9072 context_clearJustPopped ();
9074 if (exprNode_isError (e))
9076 ret = exprNode_undefined;
9081 ** Turn off expose and dependent transfer checking.
9082 ** Need to pass exposed internal nodes,
9083 ** [ copying would be a waste! ]
9084 ** [ Actually, I think I wasted a lot more time than its worth ]
9085 ** [ trying to do this. ]
9089 /*@-observertrans@*/
9090 /*@-dependenttrans@*/
9097 ret = exprNode_addParens (exprData_getUopTok (data),
9098 exprNode_effect (exprData_getUopNode (data)));
9101 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
9102 exprNode_effect (exprData_getOpB (data)),
9103 exprData_getOpTok (data));
9106 ret = exprNode_undefined;
9109 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
9110 exprNodeList_effect (exprData_getArgs (data)));
9123 cstring id = exprData_getId (data);
9124 uentry ue = usymtab_lookupSafe (id);
9126 ret = exprNode_fromIdentifierAux (ue);
9127 ret->loc = fileloc_update (ret->loc, e->loc);
9134 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
9135 exprNode_effect (exprData_getPairB (data)));
9139 ** evans 2002-03-15: for && and ||, need to do the guards also
9140 ** this is what cgrammar.y does - should be
9141 ** able to avoid duplication, but need to
9142 ** time with grammar productions.
9145 DPRINTF (("Effect: %s", exprNode_unparse (e)));
9147 if (lltok_getTok (exprData_getOpTok (data)) == AND_OP)
9149 exprNode e1 = exprNode_effect (exprData_getOpA (data));
9151 exprNode_produceGuards (e1);
9152 context_enterAndClause (e1);
9153 e2 = exprNode_effect (exprData_getOpB (data));
9155 ret = exprNode_op (e1, e2,
9156 exprData_getOpTok (data));
9158 context_exitAndClause (ret, e2);
9160 else if (lltok_getTok (exprData_getOpTok (data)) == OR_OP)
9162 exprNode e1 = exprNode_effect (exprData_getOpA (data));
9164 exprNode_produceGuards (e1);
9165 context_enterOrClause (e1);
9166 e2 = exprNode_effect (exprData_getOpB (data));
9168 ret = exprNode_op (e1, e2,
9169 exprData_getOpTok (data));
9171 context_exitOrClause (ret, e2);
9175 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
9176 exprNode_effect (exprData_getOpB (data)),
9177 exprData_getOpTok (data));
9182 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
9183 exprData_getUopTok (data));
9186 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
9187 exprData_getUopTok (data));
9199 ret = exprNode_vaArg (exprData_getCastTok (data),
9200 exprNode_effect (exprData_getCastNode (data)),
9201 exprData_getCastType (data));
9205 ret = exprNode_cast (exprData_getCastTok (data),
9206 exprNode_effect (exprData_getCastNode (data)),
9207 exprData_getCastType (data));
9210 ret = exprNode_iterStart (exprData_getIterCallIter (data),
9212 (exprData_getIterCallArgs (data)));
9216 ret = exprNode_iter (exprData_getIterSname (data),
9217 exprNodeList_effect (exprData_getIterAlist (data)),
9218 exprNode_effect (exprData_getIterBody (data)),
9219 exprData_getIterEname (data));
9223 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
9224 exprNode_effect (exprData_getPairB (data)));
9228 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
9229 exprNode_effect (exprData_getTripleTest (data)),
9230 exprNode_effect (exprData_getTripleInc (data)));
9234 ret = exprNode_createTok (exprData_getTok (data));
9238 ret = exprNode_goto (exprData_getLiteral (data));
9239 ret->loc = fileloc_update (ret->loc, e->loc);
9243 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
9247 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
9251 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
9254 case XPR_NULLRETURN:
9255 ret = exprNode_nullReturn (exprData_getTok (data));
9259 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
9260 exprNode_effect (exprData_getPairB (data)));
9264 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
9265 exprNode_effect (exprData_getTripleTrue (data)),
9266 exprNode_effect (exprData_getTripleFalse (data)));
9269 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
9270 exprNode_effect (exprData_getPairB (data)));
9274 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
9275 exprNode_effect (exprData_getTripleTrue (data)),
9276 exprNode_effect (exprData_getTripleFalse (data)));
9279 ret = exprNode_whilePred (exprData_getSingle (data));
9283 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
9284 exprNode_effect (exprData_getPairB (data)));
9288 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
9289 exprNode_effect (exprData_getPairB (data)));
9293 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
9297 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
9298 exprData_getUopTok (data));
9302 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
9303 exprNode_effect (exprData_getPairB (data)));
9308 ret = exprNode_caseMarker
9309 (exprNode_effect (exprData_getSingle (data)),
9315 ret = exprNode_createTok (exprData_getTok (data));
9319 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
9320 exprNode_effect (exprData_getPairB (data)));
9324 ret = exprNode_makeInitialization
9325 (exprData_getInitId (data),
9326 exprNode_effect (exprData_getInitNode (data)));
9330 ret = exprNode_fieldAccessAux
9331 (exprNode_effect (exprData_getFieldNode (data)),
9332 exprNode_loc (exprData_getFieldNode (data)),
9333 cstring_copy (exprData_getFieldName (data)));
9337 ret = exprNode_arrowAccessAux
9338 (exprNode_effect (exprData_getFieldNode (data)),
9339 exprNode_loc (exprData_getFieldNode (data)),
9340 cstring_copy (exprData_getFieldName (data)));
9343 case XPR_STRINGLITERAL:
9357 /*@=observertrans@*/
9359 /*@=dependenttrans@*/
9370 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
9375 if (exprNode_isError (e))
9377 return cstring_undefined;
9385 ret = exprNode_rootVarName (exprData_getUopNode (data));
9388 ret = exprNode_rootVarName (exprData_getOpA (data));
9392 ret = exprData_getId (data);
9395 ret = idDecl_getName (exprData_getInitId (data));
9420 case XPR_NULLRETURN:
9442 case XPR_STRINGLITERAL:
9443 ret = cstring_undefined;
9450 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
9455 if (exprNode_isError (e))
9457 static /*@only@*/ cstring error = cstring_undefined;
9459 if (!cstring_isDefined (error))
9461 error = cstring_makeLiteral ("<error>");
9472 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
9475 ret = message ("%s %s %s",
9476 exprNode_unparse (exprData_getOpA (data)),
9477 lltok_unparse (exprData_getOpTok (data)),
9478 exprNode_unparse (exprData_getOpB (data)));
9481 ret = message ("%s(%q)",
9482 exprNode_unparse (exprData_getFcn (data)),
9483 exprNodeList_unparse (exprData_getArgs (data)));
9486 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
9489 ret = cstring_undefined;
9492 ret = message ("%s:", exprData_getId (data));
9496 ret = cstring_copy (exprData_getId (data));
9499 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
9500 exprNode_unparse (exprData_getPairB (data)));
9503 ret = message ("<body>");
9506 ret = message ("%s %s %s",
9507 exprNode_unparse (exprData_getOpA (data)),
9508 lltok_unparse (exprData_getOpTok (data)),
9509 exprNode_unparse (exprData_getOpB (data)));
9513 ret = message ("%s%s",
9514 lltok_unparse (exprData_getUopTok (data)),
9515 exprNode_unparse (exprData_getUopNode (data)));
9519 ret = message ("%s%s",
9520 exprNode_unparse (exprData_getUopNode (data)),
9521 lltok_unparse (exprData_getUopTok (data)));
9525 ret = message ("offsetof(%s,%q)",
9526 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
9527 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
9531 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
9535 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
9539 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
9543 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
9547 ret = message ("va_arg(%s, %q)",
9548 exprNode_unparse (exprData_getCastNode (data)),
9549 qtype_unparse (exprData_getCastType (data)));
9553 ret = message ("%q(%q)",
9554 uentry_getName (exprData_getIterCallIter (data)),
9555 exprNodeList_unparse (exprData_getIterCallArgs (data)));
9558 ret = message ("%q(%q) %s %q",
9559 uentry_getName (exprData_getIterSname (data)),
9560 exprNodeList_unparse (exprData_getIterAlist (data)),
9561 exprNode_unparse (exprData_getIterBody (data)),
9562 uentry_getName (exprData_getIterEname (data)));
9565 ret = message ("(%q)%s",
9566 qtype_unparse (exprData_getCastType (data)),
9567 exprNode_unparse (exprData_getCastNode (data)));
9571 ret = message ("%s %s",
9572 exprNode_unparse (exprData_getPairA (data)),
9573 exprNode_unparse (exprData_getPairB (data)));
9577 ret = message ("for (%s; %s; %s)",
9578 exprNode_unparse (exprData_getTripleInit (data)),
9579 exprNode_unparse (exprData_getTripleTest (data)),
9580 exprNode_unparse (exprData_getTripleInc (data)));
9584 ret = message ("goto %s", exprData_getLiteral (data));
9588 ret = cstring_makeLiteral ("continue");
9592 ret = cstring_makeLiteral ("break");
9596 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
9599 case XPR_NULLRETURN:
9600 ret = cstring_makeLiteral ("return");
9604 ret = message ("%s, %s",
9605 exprNode_unparse (exprData_getPairA (data)),
9606 exprNode_unparse (exprData_getPairB (data)));
9610 ret = message ("%s ? %s : %s",
9611 exprNode_unparse (exprData_getTriplePred (data)),
9612 exprNode_unparse (exprData_getTripleTrue (data)),
9613 exprNode_unparse (exprData_getTripleFalse (data)));
9616 ret = message ("if (%s) %s",
9617 exprNode_unparse (exprData_getPairA (data)),
9618 exprNode_unparse (exprData_getPairB (data)));
9622 ret = message ("if (%s) %s else %s",
9623 exprNode_unparse (exprData_getTriplePred (data)),
9624 exprNode_unparse (exprData_getTripleTrue (data)),
9625 exprNode_unparse (exprData_getTripleFalse (data)));
9628 ret = message ("while (%s) %s",
9629 exprNode_unparse (exprData_getPairA (data)),
9630 exprNode_unparse (exprData_getPairB (data)));
9634 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
9638 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
9642 ret = message ("do { %s } while (%s)",
9643 exprNode_unparse (exprData_getPairB (data)),
9644 exprNode_unparse (exprData_getPairA (data)));
9648 ret = message ("{ %s }", exprNode_unparse (exprData_getSingle (data)));
9649 /* evans 2002-02-20 was unparseFirst! */
9653 ret = message ("%s;", exprNode_unparse (exprData_getUopNode (data)));
9657 if (exprNode_isStatement (exprData_getPairA (data)))
9660 ** statement expressions already print the ;
9663 ret = message ("%s %s",
9664 exprNode_unparse (exprData_getPairA (data)),
9665 exprNode_unparse (exprData_getPairB (data)));
9669 ret = message ("%s; %s",
9670 exprNode_unparse (exprData_getPairA (data)),
9671 exprNode_unparse (exprData_getPairB (data)));
9677 ret = cstring_makeLiteral ("default:");
9681 ret = message ("switch (%s) %s",
9682 exprNode_unparse (exprData_getPairA (data)),
9683 exprNode_unparse (exprData_getPairB (data)));
9688 ret = message ("case %s:",
9689 exprNode_unparse (exprData_getSingle (data)));
9693 if (exprNode_isError (exprData_getInitNode (data)))
9695 ret = message ("%q", idDecl_unparseC (exprData_getInitId (data)));
9699 ret = message ("%q = %s",
9700 idDecl_unparseC (exprData_getInitId (data)),
9701 exprNode_unparse (exprData_getInitNode (data)));
9706 ret = message ("%s.%s",
9707 exprNode_unparse (exprData_getFieldNode (data)),
9708 exprData_getFieldName (data));
9712 ret = message ("%s->%s",
9713 exprNode_unparse (exprData_getFieldNode (data)),
9714 exprData_getFieldName (data));
9717 case XPR_STRINGLITERAL:
9718 if (ctype_isWideString (e->typ))
9720 ret = message ("L\"%s\"", exprData_getLiteral (data));
9724 ret = message ("\"%s\"", exprData_getLiteral (data));
9729 ret = cstring_copy (exprData_getLiteral (data));
9733 ret = cstring_makeLiteral ("<node>");
9741 exprNode_isInitializer (exprNode e)
9743 return (exprNode_isDefined (e)
9744 && e->kind == XPR_INIT);
9748 exprNode_isCharLiteral (exprNode e)
9750 if (exprNode_isDefined (e))
9752 return (multiVal_isChar (exprNode_getValue (e)));
9761 exprNode_isNumLiteral (exprNode e)
9763 if (exprNode_isDefined (e))
9765 return (multiVal_isInt (exprNode_getValue (e)));
9774 exprNode_isFalseConstant (exprNode e)
9776 if (exprNode_isDefined (e))
9778 cstring s = exprNode_rootVarName (e);
9780 if (cstring_equal (s, context_getFalseName ()))
9790 exprNode_matchLiteral (ctype expected, exprNode e)
9792 if (exprNode_isDefined (e))
9794 multiVal m = exprNode_getValue (e);
9796 if (multiVal_isDefined (m))
9798 if (multiVal_isInt (m))
9800 long int val = multiVal_forceInt (m);
9802 if (ctype_isNumAbstract (expected)
9803 && context_flagOn (FLG_NUMABSTRACTLIT, exprNode_loc (e)))
9808 if (ctype_isDirectBool (ctype_realishType (expected)))
9812 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
9820 if (ctype_isRealInt (expected))
9823 ** unsigned <- [ constant >= 0 is okay ]
9826 if (ctype_isUnsigned (expected))
9835 ** No checks on sizes of integers...maybe add
9839 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
9840 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
9841 bool_unparse (ctype_isInt (exprNode_getType (e)))));
9843 if (context_getFlag (FLG_NUMLITERAL)
9844 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
9850 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
9854 else if (ctype_isChar (expected))
9858 else if (ctype_isArrayPtr (expected))
9861 ** evans 2001-10-14: We allow 0 to match any pointer, but only if the type matches or is void *.
9866 if (ctype_match (exprNode_getType (e), expected)
9867 || ctype_isVoidPointer (exprNode_getType (e)))
9877 else if (ctype_isAnyFloat (expected))
9879 return (context_getFlag (FLG_NUMLITERAL));
9886 else if (multiVal_isDouble (m))
9888 if (ctype_isAnyFloat (expected))
9893 else if (multiVal_isChar (m))
9895 /*signed? */ char val = multiVal_forceChar (m);
9897 if (ctype_isChar (expected))
9899 if (ctype_isUnsigned (expected) && ((int) val) < 0)
9920 exprNode_matchType (ctype expected, exprNode e)
9924 if (!exprNode_isDefined (e)) return TRUE;
9926 actual = ctype_realishType (exprNode_getType (e));
9928 if (ctype_match (ctype_realishType (expected), actual))
9933 llassert (!exprNode_isError (e));
9934 return (exprNode_matchLiteral (expected, e));
9938 exprNode_matchTypes (exprNode e1, exprNode e2)
9943 if (!exprNode_isDefined (e1)) return TRUE;
9944 if (!exprNode_isDefined (e2)) return TRUE;
9947 ** realish type --- keep bools, bools
9950 t1 = ctype_realishType (exprNode_getType (e1));
9951 t2 = ctype_realishType (exprNode_getType (e2));
9953 if (ctype_match (t1, t2))
9958 DPRINTF (("Matching literal! %s %s %s %s",
9959 ctype_unparse (t1), exprNode_unparse (e2),
9960 ctype_unparse (t2), exprNode_unparse (e1)));
9962 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
9970 exprNode_matchArgType (ctype ct, exprNode e)
9974 if (!exprNode_isDefined (e))
9979 et = ctype_realType (exprNode_getType (e));
9981 if (ctype_matchArg (ct, et)) return TRUE;
9983 llassert (!exprNode_isError (e));
9984 return (exprNode_matchLiteral (ct, e));
9987 static /*@only@*/ exprNodeSList
9988 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
9990 if (exprNode_isDefined (e))
9992 if (e->kind == XPR_STMTLIST)
9994 return (exprNodeSList_append
9995 (exprNode_flatten (exprData_getPairA (e->edata)),
9996 exprNode_flatten (exprData_getPairB (e->edata))));
9998 else if (e->kind == XPR_BLOCK)
10000 return (exprNode_flatten (exprData_getSingle (e->edata)));
10004 return (exprNodeSList_singleton (e));
10008 return exprNodeSList_new ();
10011 static /*@exposed@*/ exprNode
10012 exprNode_lastStatement (/*@returned@*/ exprNode e)
10014 if (exprNode_isDefined (e))
10016 if (e->kind == XPR_STMTLIST)
10018 exprNode b = exprData_getPairB (e->edata);
10020 if (exprNode_isDefined (b))
10022 return exprNode_lastStatement (b);
10026 return exprNode_lastStatement (exprData_getPairA (e->edata));
10029 else if (e->kind == XPR_BLOCK)
10031 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
10039 return exprNode_undefined;
10042 static /*@exposed@*/ exprNode
10043 exprNode_firstStatement (/*@returned@*/ exprNode e)
10045 if (exprNode_isDefined (e))
10047 if (e->kind == XPR_STMTLIST)
10049 exprNode b = exprData_getPairA (e->edata);
10051 if (exprNode_isDefined (b))
10053 return exprNode_firstStatement (b);
10057 return exprNode_firstStatement (exprData_getPairB (e->edata));
10060 else if (e->kind == XPR_BLOCK)
10062 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
10070 return exprNode_undefined;
10074 exprNode_mergeUSs (exprNode res, exprNode other)
10076 if (exprNode_isDefined (res) && exprNode_isDefined (other))
10078 res->msets = sRefSet_union (res->msets, other->msets);
10079 res->sets = sRefSet_union (res->sets, other->sets);
10080 res->uses = sRefSet_union (res->uses, other->uses);
10085 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
10087 if (exprNode_isDefined (res))
10089 if (exprNode_isDefined (other1))
10091 res->sets = sRefSet_union (res->sets, other1->sets);
10092 res->msets = sRefSet_union (res->msets, other1->msets);
10093 res->uses = sRefSet_union (res->uses, other1->uses);
10095 if (exprNode_isDefined (other2))
10097 res->sets = sRefSet_union (res->sets, other2->sets);
10098 res->msets = sRefSet_union (res->msets, other2->msets);
10099 res->uses = sRefSet_union (res->uses, other2->uses);
10105 ** modifies e->uses
10107 ** Reports errors is s is not defined.
10111 exprNode_addUse (exprNode e, /*@exposed@*/ sRef s)
10113 if (exprNode_isDefined (e))
10115 e->uses = sRefSet_insert (e->uses, s);
10120 exprNode_checkUse (exprNode e, /*@exposed@*/ sRef s, fileloc loc)
10122 if (sRef_isKnown (s) && !sRef_isConst (s))
10125 ** need to check all outer types are useable
10128 DPRINTF (("Check use: %s / %s",
10129 exprNode_unparse (e), sRef_unparse (s)));
10131 exprNode_addUse (e, s);
10133 if (!context_inProtectVars ())
10136 ** only report the deepest error
10139 sRef errorRef = sRef_undefined;
10140 sRef lastRef = sRef_undefined;
10141 bool deadRef = FALSE;
10142 bool unuseable = FALSE;
10143 bool errorMaybe = FALSE;
10145 while (sRef_isValid (s) && sRef_isKnown (s))
10147 ynm readable = sRef_isValidLvalue (s);
10149 DPRINTF (("Readable: %s / %s",
10150 sRef_unparseFull (s), ynm_unparse (readable)));
10152 if (!(ynm_toBoolStrict (readable)))
10154 if (ynm_isMaybe (readable))
10156 lastRef = errorRef;
10158 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
10159 deadRef = sRef_isPossiblyDead (errorRef);
10160 unuseable = sRef_isUnuseable (errorRef);
10165 lastRef = errorRef;
10167 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
10168 deadRef = sRef_isDead (errorRef);
10169 unuseable = sRef_isUnuseable (errorRef);
10170 errorMaybe = FALSE;
10174 if (!sRef_isPartial (s))
10176 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
10177 sRef_setDefined (s, loc);
10178 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
10183 s = sRef_getBaseSafe (s);
10186 if (sRef_isValid (errorRef))
10188 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
10189 && sRef_isPointer (errorRef))
10191 errorRef = lastRef;
10192 DPRINTF (("errorRef: %s", sRef_unparseFull (errorRef)));
10197 if (sRef_isThroughArrayFetch (errorRef))
10200 (FLG_STRICTUSERELEASED,
10201 message ("%q %q may be used after being released",
10202 sRef_unparseKindNamePlain (errorRef),
10203 sRef_unparse (errorRef)),
10206 sRef_showRefKilled (errorRef);
10208 if (sRef_isKept (errorRef))
10210 sRef_clearAliasState (errorRef, loc);
10216 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
10220 message ("%q %q %qused after being released",
10221 sRef_unparseKindNamePlain (errorRef),
10222 sRef_unparse (errorRef),
10223 cstring_makeLiteral (errorMaybe
10224 ? "may be " : "")),
10227 sRef_showRefKilled (errorRef);
10229 if (sRef_isKept (errorRef))
10231 sRef_clearAliasState (errorRef, loc);
10236 else if (unuseable)
10240 message ("%q %q%qused in inconsistent state",
10241 sRef_unparseKindName (errorRef),
10242 sRef_unparseOpt (errorRef),
10243 cstring_makeLiteral (errorMaybe ? "may be " : "")),
10246 sRef_showStateInconsistent (errorRef);
10251 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
10255 message ("%q %q%qused before definition",
10256 sRef_unparseKindName (errorRef),
10257 sRef_unparseOpt (errorRef),
10258 cstring_makeLiteral (errorMaybe ? "may be " : "")),
10264 DPRINTF (("Error: %s", sRef_unparseFull (errorRef)));
10267 sRef_setDefined (errorRef, loc);
10269 if (sRef_isAddress (errorRef))
10271 sRef_setDefined (sRef_getRootBase (errorRef), loc);
10273 } /* end is error */
10281 checkSafeUse (exprNode e, /*@exposed@*/ sRef s)
10283 if (exprNode_isDefined (e) && sRef_isKnown (s))
10285 e->uses = sRefSet_insert (e->uses, s);
10290 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
10292 if (exprNode_isDefined (e))
10294 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
10299 exprNode_checkSet (exprNode e, /*@exposed@*/ sRef s)
10301 sRef defines = sRef_undefined;
10303 if (sRef_isValid (s) && !sRef_isNothing (s))
10305 uentry ue = sRef_getBaseUentry (s);
10307 if (uentry_isValid (ue))
10309 uentry_setLset (ue);
10312 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
10314 voptgenerror (FLG_USEDEF,
10315 message ("Attempt to set unuseable storage: %q",
10320 if (sRef_isMeaningful (s))
10322 if (sRef_isDead (s))
10324 sRef base = sRef_getBaseSafe (s);
10326 if (sRef_isValid (base)
10327 && sRef_isDead (base))
10329 sRef_setPartial (s, exprNode_loc (e));
10332 defines = s; /* okay - modifies for only param */
10334 else if (sRef_isPartial (s))
10336 sRef eref = exprNode_getSref (e);
10338 if (!sRef_isPartial (eref))
10341 ** should do something different here???
10344 sRef_setDefinedComplete (eref, exprNode_loc (e));
10348 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
10351 if (sRef_isMeaningful (eref))
10360 else if (sRef_isAllocated (s))
10362 sRef eref = exprNode_getSref (e);
10365 if (!sRef_isAllocated (eref))
10367 sRef_setDefinedComplete (eref, exprNode_loc (e));
10371 sRef base = sRef_getBaseSafe (eref);
10373 if (sRef_isValid (base))
10375 sRef_setPdefined (base, exprNode_loc (e));
10383 sRef_setDefinedNCComplete (s, exprNode_loc (e));
10388 else /* not meaningful...but still need to insert it */
10394 if (exprNode_isDefined (e) && sRef_isValid (defines))
10396 e->sets = sRefSet_insert (e->sets, defines);
10401 exprNode_checkMSet (exprNode e, /*@exposed@*/ sRef s)
10403 if (sRef_isValid (s) && !sRef_isNothing (s))
10405 uentry ue = sRef_getBaseUentry (s);
10407 if (uentry_isValid (ue))
10409 uentry_setLset (ue);
10412 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
10414 voptgenerror (FLG_USEDEF,
10415 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
10419 if (sRef_isMeaningful (s))
10421 sRef_setDefinedComplete (s, exprNode_loc (e));
10424 if (exprNode_isDefined (e))
10426 e->msets = sRefSet_insert (e->msets, s);
10432 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
10434 checkAnyCall (fcn, cstring_undefined, params, args,
10435 FALSE, sRefSet_undefined, FALSE, 0);
10439 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
10440 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
10444 if (uentry_isYield (ucurrent))
10446 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
10447 exprNode_checkSet (current, current->sref);
10451 if (uentry_isSefParam (ucurrent))
10453 sRefSet sets = current->sets;
10454 sRef ref = exprNode_getSref (current);
10456 if (sRef_isMacroParamRef (ref))
10458 uentry ue = sRef_getUentry (ref);
10460 if (!uentry_isSefParam (ue))
10465 ("Parameter %d to %s is declared sef, but "
10466 "the argument is a macro parameter declared "
10468 argno, exprNode_unparse (fcn),
10469 exprNode_unparse (current)),
10470 exprNode_loc (current));
10474 if (!sRefSet_isEmpty (sets))
10476 sRefSet reported = sRefSet_undefined;
10478 sRefSet_realElements (current->sets, el)
10480 if (sRefSet_isSameNameMember (reported, el))
10482 ; /* don't report again */
10486 if (sRef_isUnconstrained (el))
10491 ("Parameter %d to %s is declared sef, but "
10492 "the argument calls unconstrained function %s "
10493 "(no guarantee it will not modify something): %s",
10494 argno, exprNode_unparse (fcn),
10495 sRef_unconstrainedName (el),
10496 exprNode_unparse (current)),
10497 exprNode_loc (current));
10504 ("Parameter %d to %s is declared sef, but "
10505 "the argument may modify %q: %s",
10506 argno, exprNode_unparse (fcn),
10508 exprNode_unparse (current)),
10509 exprNode_loc (current));
10512 } end_sRefSet_realElements;
10516 transferChecks_passParam (current, ucurrent, isSpec, fcn, argno, totargs);
10517 exprNode_mergeUSs (fcn, current);
10522 checkAnyCall (/*@dependent@*/ exprNode fcn,
10523 /*@dependent@*/ cstring fname,
10526 bool hasMods, sRefSet mods,
10531 int nargs = exprNodeList_size (args);
10536 ** concat all args ud's to f, add each arg sref as a use unless
10537 ** it was specified as "out", in which case it is a def.
10540 uentryList_reset (pn);
10543 ** aliasing checks:
10545 ** if paramn is only or unique, no other arg may alias argn
10548 exprNodeList_elements (args, current)
10552 if (exprNode_isDefined (current))
10554 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
10556 uentry ucurrent = uentryList_current (pn);
10558 if (specialArgs == 0
10559 || (paramno < specialArgs))
10561 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
10563 if (context_maybeSet (FLG_ALIASUNIQUE))
10565 if (uentry_isOnly (ucurrent)
10566 || uentry_isUnique (ucurrent))
10568 checkUniqueParams (fcn, current, args,
10569 paramno, ucurrent);
10574 else /* uentry is undefined */
10576 if (specialArgs == 0)
10578 exprNode_checkUseParam (current);
10581 exprNode_mergeUSs (fcn, current);
10584 uentryList_advanceSafe (pn);
10585 } end_exprNodeList_elements;
10591 sRefSet_allElements (mods, s)
10594 sRef rb = sRef_getRootBase (s);
10596 if (sRef_isFileOrGlobalScope (rb))
10598 context_usedGlobal (rb);
10601 fb = sRef_fixBaseParam (s, args);
10603 if (!sRef_isMacroParamRef (fb))
10605 if (sRef_isNothing (fb))
10611 if (sRef_isValid (fb))
10613 uentry ue = sRef_getBaseUentry (s);
10615 if (uentry_isValid (ue))
10617 uentry_setLset (ue);
10621 fcn->sets = sRefSet_insert (fcn->sets, fb);
10624 sRef_clearDerivedComplete (s);
10625 } end_sRefSet_allElements;
10631 if (context_hasMods ())
10633 if (context_maybeSet (FLG_MODUNCON))
10637 message ("Undetected modification possible "
10638 "from call to unconstrained function %s: %s",
10640 exprNode_unparse (fcn)),
10641 exprNode_loc (fcn));
10646 if (context_maybeSet (FLG_MODUNCONNOMODS)
10647 && !(context_inIterDef () || context_inIterEnd ()))
10650 (FLG_MODUNCONNOMODS,
10651 message ("Undetected modification possible "
10652 "from call to unconstrained function %s: %s",
10654 exprNode_unparse (fcn)),
10655 exprNode_loc (fcn));
10659 exprNode_checkSetAny (fcn, fname);
10663 void exprNode_checkUseParam (exprNode current)
10665 if (exprNode_isDefined (current))
10667 exprNode_checkUse (current, current->sref, current->loc);
10672 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
10673 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10678 if (!ctype_match (tr1, tr2))
10680 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
10681 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
10683 DPRINTF (("No error: [%s] %s / [%s] %s",
10684 exprNode_unparse (e1), ctype_unparse (tr1),
10685 exprNode_unparse (e2), ctype_unparse (tr2)));
10688 ** evans 2003-06-15: changed this so if either type is a literal,
10689 ** the other type is used.
10690 ** (Need to look at the ISO C99 rules on this...)
10693 if (exprNode_isNumLiteral (e1)) {
10695 } else if (exprNode_isNumLiteral (e2)) {
10698 ret = ctype_biggerType (tr1, tr2);
10703 if (ctype_isNumAbstract (tr1)
10704 && exprNode_isNumLiteral (e2)
10705 && context_flagOn (FLG_NUMABSTRACTLIT, e1->loc))
10707 ret = tr1; /* No error */
10709 else if (ctype_isNumAbstract (tr2)
10710 && exprNode_isNumLiteral (e1)
10711 && context_flagOn (FLG_NUMABSTRACTLIT, e1->loc))
10719 message ("Incompatible types for %s (%s, %s): %s %s %s",
10720 lltok_unparse (op),
10721 ctype_unparse (te1),
10722 ctype_unparse (te2),
10723 exprNode_unparse (e1), lltok_unparse (op),
10724 exprNode_unparse (e2)),
10727 ret = ctype_unknown;
10731 ret = ctype_biggerType (tr1, tr2);
10738 if (ctype_isNumAbstract (tr1))
10742 else if (ctype_isForceRealNumeric (&tr1)
10743 && ctype_isForceRealNumeric (&tr2))
10745 ret = ctype_resolveNumerics (tr1, tr2);
10747 else if (!context_msgStrictOps ())
10749 if (ctype_isPointer (tr1))
10751 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
10755 else if (ctype_isInt (tr2))
10761 ret = ctype_unknown;
10764 else if (ctype_isPointer (tr2))
10766 if (ctype_isPointer (tr1))
10770 else if (ctype_isInt (tr1))
10776 ret = ctype_unknown;
10781 ret = ctype_resolveNumerics (tr1, tr2);
10786 int opid = lltok_getTok (op);
10787 bool comparop = (opid == EQ_OP || opid == NE_OP
10788 || opid == TLT || opid == TGT
10789 || opid == LE_OP || opid == GE_OP);
10791 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
10794 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
10795 || (ctype_isBool (tr1) && ctype_isBool (tr2))
10796 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
10802 if (ctype_sameName (te1, te2))
10806 message ("Operands of %s are non-numeric (%t): %s %s %s",
10807 lltok_unparse (op), te1,
10808 exprNode_unparse (e1), lltok_unparse (op),
10809 exprNode_unparse (e2)),
10816 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
10817 lltok_unparse (op), te1, te2,
10818 exprNode_unparse (e1), lltok_unparse (op),
10819 exprNode_unparse (e2)),
10824 else if (!ctype_isNumeric (tr1))
10828 message ("Right operand of %s is non-numeric (%t): %s %s %s",
10829 lltok_unparse (op), te1,
10830 exprNode_unparse (e1), lltok_unparse (op),
10831 exprNode_unparse (e2)),
10836 if (!ctype_isNumeric (tr2))
10840 message ("Left operand of %s is non-numeric (%t): %s %s %s",
10841 lltok_unparse (op), te2,
10842 exprNode_unparse (e1), lltok_unparse (op),
10843 exprNode_unparse (e2)),
10848 ret = ctype_unknown;
10856 abstractOpError (ctype tr1, ctype tr2, lltok op,
10857 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10858 fileloc loc1, fileloc loc2)
10860 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
10862 if (ctype_match (tr1, tr2))
10864 if (ctype_isRealNumAbstract (tr1))
10866 ; /* No warning for numabstract types */
10870 if (lltok_isEqOp (op) || lltok_isNotEqOp (op))
10873 (FLG_ABSTRACTCOMPARE,
10874 message ("Object equality comparison (%s) on objects of abstract type (%t): %s %s %s",
10875 lltok_unparse (op), tr1,
10876 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10883 message ("Operands of %s are abstract type (%t): %s %s %s",
10884 lltok_unparse (op), tr1,
10885 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10892 if (ctype_isRealNumAbstract (tr1) && ctype_isRealNumAbstract (tr2))
10897 ("Operands of %s are different numabstract types (%t, %t): %s %s %s",
10898 lltok_unparse (op), tr1, tr2,
10899 exprNode_unparse (e1),
10900 lltok_unparse (op), exprNode_unparse (e2)),
10907 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
10908 lltok_unparse (op), tr1, tr2,
10909 exprNode_unparse (e1), lltok_unparse (op),
10910 exprNode_unparse (e2)),
10915 else if (ctype_isRealAbstract (tr1) && !ctype_isRealNumAbstract (tr1))
10919 message ("Left operand of %s is abstract type (%t): %s %s %s",
10920 lltok_unparse (op), tr1,
10921 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10926 if (ctype_isRealAbstract (tr2) && !ctype_isRealNumAbstract (tr2))
10930 message ("Right operand of %s is abstract type (%t): %s %s %s",
10931 lltok_unparse (op), tr2,
10932 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10943 ** requies e1 and e2 and not error exprNode's.
10947 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
10948 ** the rep of the abstract type is exposed.
10950 ** The order is very important:
10952 ** check rep expose (move into check transfer)
10958 ** This isn't really a sensible procedure, but the indententation
10959 ** was getting too deep.
10963 checkOneRepExpose (sRef ysr, sRef base,
10964 /*@notnull@*/ exprNode e1,
10965 /*@notnull@*/ exprNode e2, ctype ct,
10968 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
10969 || sRef_isOwned (ysr)
10970 || sRef_isExposed (ysr)))
10972 if (sRef_isAnyParam (base) && !sRef_isExposed (base)
10973 && !sRef_isObserver (base)) /* evans 2001-07-11: added isObserver */
10976 if (sRef_isIReference (ysr))
10978 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10983 ("Assignment of mutable component of parameter %q "
10984 "to component of abstract "
10985 "type %s exposes rep: %s = %s",
10986 sRef_unparse (base),
10987 ctype_unparse (ct),
10988 exprNode_unparse (e1), exprNode_unparse (e2)),
10996 ("Assignment of mutable component of parameter %q "
10997 "(through alias %q) to component of abstract "
10998 "type %s exposes rep: %s = %s",
10999 sRef_unparse (base),
11000 sRef_unparse (e2->sref),
11001 ctype_unparse (ct),
11002 exprNode_unparse (e1), exprNode_unparse (e2)),
11008 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
11012 message ("Assignment of mutable parameter %q "
11013 "to component of abstract type %s "
11014 "exposes rep: %s = %s",
11015 sRef_unparse (base),
11016 ctype_unparse (ct),
11017 exprNode_unparse (e1),
11018 exprNode_unparse (e2)),
11025 message ("Assignment of mutable parameter %q "
11026 "(through alias %q) to "
11027 "component of abstract type %s exposes "
11029 sRef_unparse (base),
11030 sRef_unparse (e2->sref),
11031 ctype_unparse (ct),
11032 exprNode_unparse (e1),
11033 exprNode_unparse (e2)),
11039 if (sRef_isFileOrGlobalScope (s2b))
11041 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
11045 message ("Assignment of global %q "
11047 "abstract type %s exposes rep: %s = %s",
11048 sRef_unparse (base),
11049 ctype_unparse (ct),
11050 exprNode_unparse (e1), exprNode_unparse (e2)),
11057 message ("Assignment of global %q (through alias %q) "
11059 "abstract type %s exposes rep: %s = %s",
11060 sRef_unparse (base),
11061 sRef_unparse (e2->sref),
11062 ctype_unparse (ct),
11063 exprNode_unparse (e1), exprNode_unparse (e2)),
11071 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
11073 DPRINTF (("Do assign: %s <- %s",
11074 exprNode_unparse (e1), exprNode_unparse (e2)));
11075 DPRINTF (("Ctype: %s", ctype_unparse (exprNode_getType (e1))));
11077 if (ctype_isRealFunction (exprNode_getType (e1))
11078 && !ctype_isRealPointer (exprNode_getType (e1)))
11082 message ("Invalid left-hand side of assignment (function type %s): %s",
11083 ctype_unparse (exprNode_getType (e1)),
11084 exprNode_unparse (e1)),
11088 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
11090 ctype t2 = exprNode_getType (e2);
11091 sRef sr = sRef_getRootBase (e1->sref);
11092 ctype ct = sRef_getType (sr);
11094 if (ctype_isAbstract (t2)
11095 && !ctype_isNumAbstract (t2)
11096 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
11098 /* it is immutable, okay to reference */
11099 goto donerepexpose;
11102 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
11104 sRef s2b = sRef_getRootBase (e2->sref);
11105 sRef s1 = e1->sref;
11106 sRef s1b = sRef_getRootBase (s1);
11109 aliases = usymtab_canAlias (e2->sref);
11111 if (!sRef_similar (s2b, s1b)
11112 && !sRef_isExposed (s1)
11113 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
11115 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
11116 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
11117 && !sRef_isExposed (s2b))
11119 if (sRef_isIReference (e2->sref))
11124 ("Assignment of mutable component of parameter %q "
11125 "to component of abstract type %s exposes rep: %s = %s",
11126 sRef_unparse (s2b),
11127 ctype_unparse (ct),
11128 exprNode_unparse (e1), exprNode_unparse (e2)),
11135 message ("Assignment of mutable parameter %q to "
11136 "component of abstract type %s exposes rep: %s = %s",
11137 sRef_unparse (s2b),
11138 ctype_unparse (ct),
11139 exprNode_unparse (e1), exprNode_unparse (e2)),
11144 if (sRef_isFileOrGlobalScope (s2b))
11148 message ("Assignment of global %q to component of "
11149 "abstract type %s exposes rep: %s = %s",
11150 sRef_unparse (s2b),
11151 ctype_unparse (ct),
11152 exprNode_unparse (e1), exprNode_unparse (e2)),
11156 sRefSet_realElements (aliases, ysr)
11158 sRef base = sRef_getRootBase (ysr);
11160 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
11161 || sRef_sameName (base, s1b))
11163 ; /* error already reported or same sref */
11167 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
11169 } end_sRefSet_realElements;
11171 sRefSet_free (aliases);
11178 ** function variables don't really work...
11181 if (!ctype_isFunction (ctype_realType (e2->typ)))
11185 DPRINTF (("Check init: %s / %s",
11186 exprNode_unparse (e1), exprNode_unparse (e2)));
11187 transferChecks_initialization (e1, e2);
11191 transferChecks_assign (e1, e2);
11196 sRef fref = e2->sref;
11198 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
11199 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
11201 /* Need to typecheck the annotation on the parameters */
11203 if (ctype_isRealFunction (e1->typ)) {
11204 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
11205 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
11207 if (!uentryList_isMissingParams (e1p)
11208 && !uentryList_isMissingParams (e2p)
11209 && uentryList_size (e1p) > 0) {
11210 if (uentryList_size (e1p) == uentryList_size (e2p)) {
11213 uentryList_elements (e1p, el1) {
11216 el2 = uentryList_getN (e2p, n);
11218 uentry_checkMatchParam (el1, el2, n, e2);
11219 } end_uentryList_elements;
11225 if (exprNode_isStringLiteral (e2))
11227 exprNode_checkStringLiteralLength (exprNode_getType (e1), e2);
11230 if (isInit && sRef_isFileOrGlobalScope (e1->sref))
11236 DPRINTF (("Update aliases: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
11237 updateAliases (e1, e2);
11242 checkMacroParen (exprNode e)
11244 if (exprNode_isError (e) || e->kind == XPR_CAST)
11250 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
11254 message ("Macro parameter used without parentheses: %s",
11255 exprNode_unparse (e)),
11262 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
11266 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
11270 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
11277 ** if e2 is a parameter or global derived location which
11278 ** can be modified (that is, e2 is a mutable abstract type,
11279 ** or a derived pointer), then e1 can alias e2.
11281 ** e1 can alias everything which e2 can alias.
11283 ** Also, if e1 is guarded, remove from guard sets!
11286 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
11288 if (!context_inProtectVars ())
11291 ** depends on types of e1 and e2
11294 sRef s1 = e1->sref;
11295 sRef s2 = e2->sref;
11296 ctype t1 = exprNode_getType (e1);
11298 /* handle pointer sRefs, record fields, arrays, etc... */
11300 if (!ctype_isRealSU (t1))
11302 DPRINTF (("Copying real! %s", ctype_unparse (t1)));
11303 sRef_copyRealDerivedComplete (s1, s2);
11308 ** Fields should alias
11311 DPRINTF (("Not COPYING!: %s", ctype_unparse (t1)));
11314 if (ctype_isMutable (t1) && sRef_isKnown (s1))
11316 usymtab_clearAlias (s1);
11317 usymtab_addMustAlias (s1, s2);
11318 DPRINTF (("Add must alias: %s / %s", sRef_unparse (s1), sRef_unparse (s2)));
11322 DPRINTF (("Not mutable: %s", ctype_unparse (t1)));
11325 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
11327 usymtab_unguard (s1);
11332 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
11334 if (exprNode_isDefined (e))
11336 e->loc = fileloc_update (e->loc, loc);
11340 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
11346 static void checkUniqueParams (exprNode fcn,
11347 /*@notnull@*/ exprNode current,
11349 int paramno, uentry ucurrent)
11352 sRef thisref = exprNode_getSref (current);
11355 ** Check if any argument could match this argument.
11358 exprNodeList_elements (args, icurrent)
11362 if (iparamno != paramno)
11364 sRef sr = exprNode_getSref (icurrent);
11366 if (sRef_similarRelaxed (thisref, sr))
11368 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
11373 ("Parameter %d (%s) to function %s is declared %s but "
11374 "is aliased by parameter %d (%s)",
11376 exprNode_unparse (current),
11377 exprNode_unparse (fcn),
11378 alkind_unparse (uentry_getAliasKind (ucurrent)),
11379 iparamno, exprNode_unparse (icurrent)),
11385 sRefSet aliases = usymtab_canAlias (sr);
11387 sRefSet_allElements (aliases, asr)
11389 if (ctype_isUnknown (sRef_getType (thisref)))
11391 sRef_setType (thisref, uentry_getType (ucurrent));
11394 if (sRef_similarRelaxed (thisref, asr))
11396 if (sRef_isExternal (asr))
11398 if (sRef_isLocalState (thisref))
11404 sRef base = sRef_getRootBase (asr);
11406 if (!sRef_similar (sRef_getBase (asr), thisref))
11408 if (sRef_isUnique (base) || sRef_isOnly (base)
11409 || sRef_isKept (base)
11410 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
11411 || (sRef_isAddress (thisref)
11412 && sRef_isLocalVar (sRef_getRootBase (thisref))))
11414 ; /* okay, no error */
11419 (FLG_MAYALIASUNIQUE,
11421 ("Parameter %d (%s) to function %s is declared %s but "
11422 "may be aliased externally by parameter %d (%s)",
11424 exprNode_unparse (current),
11425 exprNode_unparse (fcn),
11426 alkind_unparse (uentry_getAliasKind (ucurrent)),
11427 iparamno, exprNode_unparse (icurrent)),
11438 ("Parameter %d (%s) to function %s is declared %s but "
11439 "is aliased externally by parameter %d (%s) through "
11442 exprNode_unparse (current),
11443 exprNode_unparse (fcn),
11444 alkind_unparse (uentry_getAliasKind (ucurrent)),
11445 iparamno, exprNode_unparse (icurrent),
11446 sRef_unparse (asr)),
11450 } end_sRefSet_allElements;
11451 sRefSet_free (aliases);
11454 } end_exprNodeList_elements;
11457 long exprNode_getLongValue (exprNode e)
11461 if (exprNode_hasValue (e) && multiVal_isInt (exprNode_getValue (e)))
11463 value = multiVal_forceInt (exprNode_getValue (e));
11467 value = 0; /* Unknown value */
11473 /*@only@*/ fileloc exprNode_getNextSequencePoint (exprNode e)
11476 ** Returns the location of the sequence point following e.
11478 ** Only works for statements (for now).
11481 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
11482 lltok t = exprData_getUopTok (e->edata);
11483 return fileloc_copy(lltok_getLoc (t));
11485 /* drl possible problem : warning fix
11486 llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
11488 return fileloc_undefined;
11492 exprNode exprNode_createNew(ctype c)
11496 ret = exprNode_createPlain (c);
11501 bool exprNode_isInitBlock (exprNode e)
11503 return (exprNode_isDefined(e) && e->kind == XPR_INITBLOCK);
11506 /*drl 3/2/2003 moved this function out of constraint.c */
11507 exprNode exprNode_copyConstraints (/*@returned@*/ exprNode dst, exprNode src)
11510 llassert (exprNode_isDefined (dst) );
11511 llassert (exprNode_isDefined (src) );
11513 constraintList_free (dst->ensuresConstraints);
11514 constraintList_free (dst->requiresConstraints);
11515 constraintList_free (dst->trueEnsuresConstraints);
11516 constraintList_free (dst->falseEnsuresConstraints);
11518 dst->ensuresConstraints = constraintList_copy (src->ensuresConstraints);
11519 dst->requiresConstraints = constraintList_copy (src->requiresConstraints);
11520 dst->trueEnsuresConstraints = constraintList_copy (src->trueEnsuresConstraints);
11521 dst->falseEnsuresConstraints = constraintList_copy (src->falseEnsuresConstraints);
11525 void exprNode_revealState (exprNode e)
11527 if (exprNode_isDefined (e)) {
11528 llmsg (message ("%s: State of %s: %s", fileloc_unparse (exprNode_loc (e)),
11529 exprNode_unparse (e), sRef_unparseFull (e->sref)));
11531 llmsg (message ("%s: Reveal state undefined", fileloc_unparse (g_currentloc)));