2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
28 # include <ctype.h> /* for isdigit */
29 # include "lclintMacros.nf"
31 # include "cgrammar.h"
32 # include "cgrammar_tokens.h"
34 # include "exprChecks.h"
35 # include "transferChecks.h"
36 # include "exprNodeSList.h"
38 static bool exprNode_isEmptyStatement (exprNode p_e);
39 static /*@exposed@*/ exprNode exprNode_firstStatement (/*@returned@*/ exprNode p_e);
40 static bool exprNode_isFalseConstant (exprNode p_e) /*@*/ ;
41 static bool exprNode_isBlock (exprNode p_e);
42 static void checkGlobUse (uentry p_glob, bool p_isCall, /*@notnull@*/ exprNode p_e);
43 static void exprNode_addUse (exprNode p_e, /*@exposed@*/ sRef p_s);
44 static bool exprNode_matchArgType (ctype p_ct, exprNode p_e);
45 static exprNode exprNode_fakeCopy (exprNode p_e) /*@*/ ;
46 static exprNode exprNode_statementError (/*@only@*/ exprNode p_e, /*@only@*/ lltok p_t);
47 static bool exprNode_matchTypes (exprNode p_e1, exprNode p_e2);
48 static void checkUniqueParams (exprNode p_fcn,
49 /*@notnull@*/ exprNode p_current, exprNodeList p_args,
50 int p_paramno, uentry p_ucurrent);
51 static void updateAliases (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2);
52 static void abstractOpError (ctype p_tr1, ctype p_tr2, lltok p_op,
53 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2,
54 fileloc p_loc1, fileloc p_loc2);
55 static ctype checkNumerics (ctype p_tr1, ctype p_tr2, ctype p_te1, ctype p_te2,
56 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, lltok p_op);
57 static void doAssign (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, bool p_isInit);
58 static void checkSafeUse (exprNode p_e, /*@exposed@*/ sRef p_s);
59 static void reflectNullTest (/*@notnull@*/ exprNode p_e, bool p_isnull);
60 static void checkMacroParen (exprNode p_e);
61 static exprNodeSList exprNode_flatten (/*@dependent@*/ exprNode p_e);
62 static void exprNode_checkSetAny (exprNode p_e, /*@dependent@*/ cstring p_name);
63 static void exprNode_checkUse (exprNode p_e, /*@exposed@*/ sRef p_s, fileloc p_loc);
64 static void exprNode_mergeUSs (exprNode p_res, exprNode p_other);
65 static void exprNode_mergeCondUSs (exprNode p_res, exprNode p_other1, exprNode p_other2);
66 static /*@only@*/ /*@notnull@*/ exprNode exprNode_fromIdentifierAux (/*@observer@*/ uentry p_c);
67 static void checkAnyCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn,
68 /*@dependent@*/ cstring p_fname,
69 uentryList p_pn, exprNodeList p_args,
70 bool p_hasMods, sRefSet p_mods, bool p_isSpec,
72 static void checkOneArg (uentry p_ucurrent, /*@notnull@*/ exprNode p_current,
73 /*@dependent@*/ exprNode p_fcn, bool p_isSpec, int p_argno, int p_totargs);
75 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn, uentryList p_params, exprNodeList p_args);
77 static /*@only@*/ exprNode exprNode_effect (exprNode p_e)
78 /*@globals internalState@*/ ;
79 static /*@only@*/ cstring exprNode_doUnparse (exprNode p_e);
80 static /*@observer@*/ cstring exprNode_rootVarName (exprNode p_e);
81 static /*@exposed@*/ exprNode
82 exprNode_lastStatement (/*@returned@*/ exprNode p_e);
84 static /*@null@*/ sRef defref = sRef_undefined;
85 static /*@only@*/ exprNode mustExitNode = exprNode_undefined;
87 static int checkArgsReal (uentry p_fcn, /*@dependent@*/ exprNode p_f,
89 exprNodeList p_args, bool p_isIter, exprNode p_ret);
91 static bool inEffect = FALSE;
92 static int nowalloc = 0;
93 static int totalloc = 0;
94 static int maxalloc = 0;
96 static /*@only@*/ uentry regArg;
97 static /*@only@*/ uentry outArg;
98 static /*@only@*/ uentry outStringArg;
99 static /*@exposed@*/ sRef stdinRef;
100 static /*@exposed@*/ sRef stdoutRef;
101 static /*@only@*/ uentry csArg;
102 static /*@only@*/ uentry csOnlyArg;
103 static ctype cstringType;
104 static ctype ctypeType;
105 static ctype filelocType;
106 static bool initMod = FALSE;
108 /*@function void exprNode_swap (sef exprNode, sef exprNode)@*/
110 # define exprNode_swap(e1,e2) do { exprNode m_tmp = (e1); (e1) = (e2); (e2) = m_tmp; } while (FALSE)
113 static void exprNode_defineConstraints(/*@sef@*/ /*@special@*/ /*@notnull@*/ exprNode e)
114 /*@defines e->requiresConstraints, e->ensuresConstraints,
115 e->trueEnsuresConstraints, e->falseEnsuresConstraints @*/
117 e->requiresConstraints = constraintList_makeNew ();
118 e->ensuresConstraints = constraintList_makeNew ();
119 e->trueEnsuresConstraints = constraintList_makeNew ();
120 e->falseEnsuresConstraints = constraintList_makeNew ();
124 ** must occur after library has been read
127 void exprNode_initMod (void)
128 /*@globals undef regArg, undef outArg, undef outStringArg,
129 undef csOnlyArg, undef csArg;
136 cstringType = ctype_unknown;
137 ctypeType = ctype_unknown;
138 filelocType = ctype_unknown;
140 defref = sRef_undefined;
142 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
144 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
147 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
149 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
152 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
154 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
157 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdin")))
159 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdin"));
161 else /* define stdin */
163 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdin"),
165 fileloc_getBuiltin (),
167 uentry_setHasNameError (ue);
168 ue = usymtab_supGlobalEntryReturn (ue);
171 stdinRef = sRef_makePointer (uentry_getSref (ue));
173 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdout")))
175 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdout"));
179 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdout"),
181 fileloc_getBuiltin (),
183 uentry_setHasNameError (ue);
184 ue = usymtab_supGlobalEntryReturn (ue);
187 stdoutRef = sRef_makePointer (uentry_getSref (ue));
189 tmp = idDecl_create (cstring_undefined, qtype_create (ctype_unknown));
191 regArg = uentry_makeParam (tmp, PARAMUNKNOWN);
194 qtype_addQual (qtype_create (ctype_makePointer (ctype_unknown)),
197 outArg = uentry_makeParam (tmp, PARAMUNKNOWN);
199 idDecl_setTyp (tmp, qtype_addQual (qtype_create (ctype_string),
202 outStringArg = uentry_makeParam (tmp, PARAMUNKNOWN);
204 idDecl_setTyp (tmp, qtype_addQual (qtype_addQual (qtype_create (cstringType),
206 qual_createNull ()));
208 csOnlyArg = uentry_makeParam (tmp, PARAMUNKNOWN);
210 idDecl_setTyp (tmp, qtype_addQual (qtype_create (cstringType), qual_createNull ()));
211 csArg = uentry_makeParam (tmp, PARAMUNKNOWN);
217 exprNode_destroyMod (void)
218 /*@globals killed regArg, killed outArg, killed outStringArg,
219 killed mustExitNode, initMod @*/
223 uentry_free (regArg);
224 uentry_free (outArg);
225 uentry_free (outStringArg);
227 exprNode_free (mustExitNode);
234 static void exprNode_resetSref (/*@notnull@*/ exprNode e)
239 exprNode exprNode_fakeCopy (exprNode e)
241 /*@-temptrans@*/ /*@-retalias@*/
243 /*@=temptrans@*/ /*@=retalias@*/
246 static bool isFlagKey (char key)
248 return (key == '-' || key == '+' || key == ' ' || key == '#');
251 static void exprNode_combineControl (/*@notnull@*/ exprNode ret,
252 /*@notnull@*/ exprNode ifclause,
253 /*@notnull@*/ exprNode elseclause)
255 ret->canBreak = ifclause->canBreak || elseclause->canBreak;
258 (ifclause->mustBreak || exprNode_mustEscape (ifclause))
259 && (elseclause->mustBreak || exprNode_mustEscape (elseclause));
261 ret->exitCode = exitkind_combine (ifclause->exitCode,
262 elseclause->exitCode);
267 ** For exprNode's returned by exprNode_effect.
270 static bool shallowKind (exprKind kind)
272 return (kind == XPR_STRINGLITERAL
273 || kind == XPR_NUMLIT
276 || kind == XPR_NODE);
280 exprNode_freeIniter (/*@only@*/ exprNode e)
282 if (!exprNode_isError (e))
288 ** Its a fake copy, don't free the field->rec and field->field
293 sfree (e->edata->field);
299 exprNode_free (e->edata->op->b);
300 /*@-compdestroy@*/ sfree (e->edata->op); /*@=compdestroy@*/
304 llbug (message ("other: %s", exprNode_unparse (e)));
307 multiVal_free (e->val);
308 cstring_free (e->etext);
309 fileloc_free (e->loc);
310 sRefSet_free (e->uses);
311 sRefSet_free (e->sets);
312 sRefSet_free (e->msets);
313 guardSet_free (e->guards);
315 constraintList_free(e->requiresConstraints);
316 constraintList_free(e->ensuresConstraints);
317 constraintList_free(e->trueEnsuresConstraints);
318 constraintList_free(e->falseEnsuresConstraints);
320 e->requiresConstraints = NULL;
321 e->ensuresConstraints = NULL;
322 e->trueEnsuresConstraints = NULL;
323 e->falseEnsuresConstraints = NULL;
330 exprNode_freeShallow (/*@only@*/ exprNode e)
332 if (!exprNode_isError (e))
334 if (shallowKind (e->kind))
341 if (e->kind == XPR_EMPTY
342 || e->kind == XPR_BODY
343 || e->kind == XPR_STRINGLITERAL
344 || e->kind == XPR_NUMLIT
345 || e->kind == XPR_NODE
346 || e->kind == XPR_OFFSETOF
347 || e->kind == XPR_ALIGNOFT
348 || e->kind == XPR_ALIGNOF
349 || e->kind == XPR_SIZEOFT
350 || e->kind == XPR_SIZEOF)
352 /* don't free anything */
356 /* multiVal_free (e->val); */
357 cstring_free (e->etext);
358 fileloc_free (e->loc);
359 sRefSet_free (e->uses);
360 sRefSet_free (e->sets);
361 sRefSet_free (e->msets);
362 guardSet_free (e->guards);
363 exprData_freeShallow (e->edata, e->kind);
365 /*@-compdestroy@*/ sfree (e); /*@=compdestroy@*/
374 exprNode_free (exprNode e)
376 if (!exprNode_isError (e))
380 multiVal_free (e->val);
381 cstring_free (e->etext);
382 fileloc_free (e->loc);
383 sRefSet_free (e->uses);
384 sRefSet_free (e->sets);
385 sRefSet_free (e->msets);
386 guardSet_free (e->guards);
387 exprData_free (e->edata, e->kind);
389 constraintList_free(e->requiresConstraints);
390 constraintList_free(e->ensuresConstraints);
391 constraintList_free(e->trueEnsuresConstraints);
392 constraintList_free(e->falseEnsuresConstraints);
394 e->requiresConstraints = NULL;
395 e->ensuresConstraints = NULL;
396 e->trueEnsuresConstraints = NULL;
397 e->falseEnsuresConstraints = NULL;
407 exprNode_makeError ()
409 return exprNode_undefined;
412 static /*@out@*/ /*@only@*/ /*@notnull@*/ exprNode
415 exprNode ret = (exprNode) dmalloc (sizeof (*ret));
416 /* static int lastexpnodes = 0; */
421 if (nowalloc > maxalloc)
429 static /*@notnull@*/ /*@special@*/ exprNode
430 exprNode_createPlain (ctype c)
432 /*@ensures isnull result->edata, result->loc, result->val, result->guards,
433 result->uses, result->sets, result->msets, result->etext @*/
436 exprNode e = exprNode_new ();
440 e->val = multiVal_undefined;
442 e->etext = cstring_undefined;
443 e->loc = fileloc_undefined;
444 e->guards = guardSet_undefined;
445 e->uses = sRefSet_undefined;
446 e->sets = sRefSet_undefined;
447 e->msets = sRefSet_undefined;
448 e->edata = exprData_undefined;
449 e->exitCode = XK_NEVERESCAPE;
451 e->mustBreak = FALSE;
452 e->isJumpPoint = FALSE;
454 exprNode_defineConstraints(e);
459 /*@observer@*/ exprNode exprNode_makeMustExit (void)
461 if (exprNode_isUndefined (mustExitNode))
463 mustExitNode = exprNode_createPlain (ctype_unknown);
464 mustExitNode->exitCode = XK_MUSTEXIT;
471 static /*@notnull@*/ /*@special@*/ exprNode exprNode_create (ctype c)
473 /*@post:isnull result->edata, result->guards, result->val,
474 result->uses, result->sets, result->msets@*/
477 exprNode e = exprNode_createPlain (c);
478 e->loc = fileloc_copy (g_currentloc);
482 static /*@notnull@*/ /*@special@*/ exprNode exprNode_createUnknown (void)
484 /*@post:isnull result->edata, result->guards,
485 result->uses, result->sets, result->msets@*/
488 return (exprNode_create (ctype_unknown));
491 static /*@notnull@*/ /*@special@*/ exprNode
492 exprNode_createLoc (ctype c, /*@keep@*/ fileloc loc)
494 /*@post:isnull result->edata, result->guards, result->val,
495 result->uses, result->sets, result->msets@*/
498 exprNode e = exprNode_createPlain (c);
504 exprNode_copySets (/*@special@*/ /*@notnull@*/ exprNode ret, exprNode e)
505 /*@defines ret->guards, ret->uses, ret->sets, ret->msets@*/
507 if (exprNode_isDefined (e))
509 ret->guards = guardSet_copy (e->guards);
510 ret->uses = sRefSet_newCopy (e->uses);
511 ret->sets = sRefSet_newCopy (e->sets);
512 ret->msets = sRefSet_newCopy (e->msets);
516 ret->guards = guardSet_undefined;
517 ret->uses = sRefSet_undefined;
518 ret->sets = sRefSet_undefined;
519 ret->msets = sRefSet_undefined;
523 static /*@notnull@*/ /*@special@*/ exprNode
524 exprNode_createPartialLocCopy (exprNode e, /*@only@*/ fileloc loc)
526 /*@post:isnull result->edata, result->etext@*/
529 exprNode ret = exprNode_new ();
531 if (exprNode_isError (e))
533 ret->typ = ctype_unknown;
534 ret->val = multiVal_undefined;
536 ret->guards = guardSet_undefined;
537 ret->uses = sRefSet_undefined;
538 ret->sets = sRefSet_undefined;
539 ret->msets = sRefSet_undefined;
544 ret->val = multiVal_copy (e->val);
546 ret->guards = guardSet_copy (e->guards);
547 ret->uses = sRefSet_newCopy (e->uses);
548 ret->sets = sRefSet_newCopy (e->sets);
549 ret->msets = sRefSet_newCopy (e->msets);
552 ret->kind = XPR_EMPTY;
554 ret->etext = cstring_undefined;
555 ret->exitCode = XK_NEVERESCAPE;
556 ret->canBreak = FALSE;
557 ret->mustBreak = FALSE;
558 ret->isJumpPoint = FALSE;
559 ret->edata = exprData_undefined;
561 exprNode_defineConstraints(ret);
567 static /*@notnull@*/ /*@special@*/ exprNode
568 exprNode_createPartialCopy (exprNode e)
570 /*@post:isnull result->edata, result->etext@*/
573 return (exprNode_createPartialLocCopy (e, fileloc_copy (exprNode_loc (e))));
576 static /*@notnull@*/ /*@special@*/ exprNode
577 exprNode_createPartialNVCopy (exprNode e)
579 /*@post:isnull result->edata, result->etext, result->val @*/
582 exprNode ret = exprNode_new ();
584 if (exprNode_isError (e))
586 ret->typ = ctype_unknown;
587 ret->loc = fileloc_undefined;
588 ret->guards = guardSet_undefined;
589 ret->uses = sRefSet_undefined;
590 ret->sets = sRefSet_undefined;
591 ret->msets = sRefSet_undefined;
596 ret->loc = fileloc_copy (e->loc);
597 ret->guards = guardSet_copy (e->guards);
598 ret->uses = sRefSet_newCopy (e->uses);
599 ret->sets = sRefSet_newCopy (e->sets);
600 ret->msets = sRefSet_newCopy (e->msets);
603 ret->val = multiVal_undefined;
604 ret->kind = XPR_EMPTY;
606 ret->etext = cstring_undefined;
607 ret->exitCode = XK_NEVERESCAPE;
608 ret->canBreak = FALSE;
609 ret->mustBreak = FALSE;
610 ret->isJumpPoint = FALSE;
611 ret->edata = exprData_undefined;
613 exprNode_defineConstraints(ret);
618 static /*@notnull@*/ /*@special@*/ exprNode
619 exprNode_createSemiCopy (exprNode e)
621 /*@post:isnull result->edata, result->etext, result->sets,
622 result->msets, result->uses, result->guards@*/
625 if (exprNode_isError (e))
627 return exprNode_createPlain (ctype_unknown);
631 exprNode ret = exprNode_new ();
634 ret->val = multiVal_copy (e->val);
635 ret->loc = fileloc_copy (e->loc);
636 ret->guards = guardSet_undefined;
637 ret->uses = sRefSet_undefined;
638 ret->sets = sRefSet_undefined;
639 ret->msets = sRefSet_undefined;
641 ret->kind = XPR_EMPTY;
643 ret->etext = cstring_undefined;
644 ret->exitCode = XK_NEVERESCAPE;
645 ret->canBreak = FALSE;
646 ret->mustBreak = FALSE;
647 ret->isJumpPoint = FALSE;
648 ret->edata = exprData_undefined;
650 exprNode_defineConstraints(ret);
657 exprNode_isNullValue (exprNode e)
659 if (exprNode_isDefined (e))
661 multiVal m = exprNode_getValue (e);
663 if (multiVal_isInt (m))
665 return (multiVal_forceInt (m) == 0);
673 exprNode_isUnknownConstant (/*@notnull@*/ exprNode e)
675 while (e->kind == XPR_PARENS)
677 e = exprData_getUopNode (e->edata);
678 llassert (exprNode_isDefined (e));
681 if (e->kind == XPR_CONST)
683 multiVal m = exprNode_getValue (e);
685 if (multiVal_isUnknown (m))
695 exprNode_numLiteral (ctype c, /*@temp@*/ cstring t,
696 /*@only@*/ fileloc loc, long val)
698 exprNode e = exprNode_createLoc (c, loc);
700 e->kind = XPR_NUMLIT;
702 llassert (multiVal_isUndefined (e->val));
703 e->val = multiVal_makeInt (val);
704 e->edata = exprData_makeLiteral (cstring_copy (t));
708 e->sref = sRef_makeUnknown ();
709 sRef_setDefNull (e->sref, e->loc);
712 DPRINTF (("Num lit: %s / %s", exprNode_unparse (e), ctype_unparse (exprNode_getType (e))));
717 exprNode_charLiteral (char c, cstring text, /*@only@*/ fileloc loc)
719 exprNode e = exprNode_createLoc (ctype_char, loc);
721 if (context_getFlag (FLG_CHARINTLITERAL))
723 e->typ = ctype_makeConj (ctype_char, ctype_int);
726 e->kind = XPR_NUMLIT;
727 e->val = multiVal_makeChar (c);
729 e->edata = exprData_makeLiteral (cstring_copy (text));
734 exprNode_floatLiteral (double d, ctype ct, cstring text, /*@only@*/ fileloc loc)
736 exprNode e = exprNode_createLoc (ct, loc);
738 e->kind = XPR_NUMLIT;
739 e->val = multiVal_makeDouble (d);
740 e->edata = exprData_makeLiteral (cstring_copy (text));
744 multiVal exprNode_getValue (exprNode e)
746 while (exprNode_isInParens (e)) {
747 if (e->edata != NULL) {
748 e = exprData_getUopNode (e->edata);
754 if (exprNode_isDefined (e)) {
757 return multiVal_undefined;
762 exprNode_combineLiterals (exprNode e, exprNode rest)
766 /* Both must be string literals. */
768 if (exprNode_isUndefined (rest) || exprNode_isUndefined (e))
770 exprNode_free (rest);
774 if (!exprNode_isStringLiteral (e))
778 message ("Constant concatentation is ungrammatical: %s %s", exprNode_unparse (e),
779 exprNode_unparse (rest)),
781 exprNode_free (rest);
785 if (!exprNode_isStringLiteral (rest))
789 message ("Constant concatentation is ungrammatical: %s %s", exprNode_unparse (e), exprNode_unparse (rest)),
792 exprNode_free (rest);
796 ns = cstring_concat (multiVal_forceString (exprNode_getValue (e)),
797 multiVal_forceString (exprNode_getValue (rest)));
799 multiVal_free (e->val);
800 exprData_free (e->edata, e->kind);
801 e->edata = exprData_makeLiteral (cstring_copy (ns));
802 e->val = multiVal_makeString (ns);
803 exprNode_free (rest);
808 exprNode_rawStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
810 exprNode e = exprNode_createLoc (ctype_string, loc);
811 int len = cstring_length (t);
813 if (context_getFlag (FLG_STRINGLITERALLEN))
815 if (len > context_getValue (FLG_STRINGLITERALLEN))
817 voptgenerror (FLG_STRINGLITERALLEN,
819 ("String literal length (%d) exceeds maximum "
820 "length (%d): \"%s\"",
822 context_getValue (FLG_STRINGLITERALLEN),
828 e->kind = XPR_STRINGLITERAL;
829 e->val = multiVal_makeString (cstring_copy (t));
830 e->edata = exprData_makeLiteral (t);
831 e->sref = sRef_makeConst (ctype_string);
833 if (context_getFlag (FLG_READONLYSTRINGS))
835 sRef_setAliasKind (e->sref, AK_STATIC, fileloc_undefined);
836 sRef_setExKind (e->sref, XO_OBSERVER, loc);
840 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
843 return (e); /* s released */
847 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
849 int len = cstring_length (t) - 2;
850 char *ts = cstring_toCharsSafe (t);
851 char *s = cstring_toCharsSafe (cstring_create (len + 1));
853 llassert (*ts == '\"' && *(ts + len + 1) == '\"');
854 strncpy (s, ts+1, size_fromInt (len));
857 return exprNode_rawStringLiteral (cstring_fromCharsO (s), loc);
860 exprNode exprNode_fromUIO (cstring c)
862 fileloc loc = context_getSaveLocation ();
863 exprNode e = exprNode_createPlain (ctype_unknown);
867 if (fileloc_isUndefined (loc))
869 loc = fileloc_copy (g_currentloc);
872 e->loc = loc; /* save loc was mangled */
875 if (usymtab_exists (c))
877 uentry ue = usymtab_lookupEither (c);
879 if (uentry_isDatatype (ue)
880 && uentry_isSpecified (ue))
883 (message ("%q: Specified datatype %s used in code, but not defined. "
884 "(Cannot continue reasonably from this error.)",
885 fileloc_unparse (e->loc), c));
893 llassertprint (!usymtab_exists (c), ("Entry exists: %s", c));
896 ** was supercedeGlobalEntry...is this better?
899 if (!context_inIterEnd ())
901 if (context_inMacro ())
903 if (context_getFlag (FLG_UNRECOG))
907 message ("Unrecognized identifier in macro definition: %s", c), e->loc);
911 flagcode_recordSuppressed (FLG_UNRECOG);
917 (FLG_UNRECOG, message ("Unrecognized identifier: %s", c), e->loc);
921 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
923 /* No alias errors for unrecognized identifiers */
924 sRef_setAliasKind (e->sref, AK_ERROR, loc);
929 exprNode exprNode_createId (/*@observer@*/ uentry c)
931 if (uentry_isValid (c))
933 exprNode e = exprNode_new ();
935 e->typ = uentry_getType (c);
937 if (uentry_isFunction (c)
938 && !sRef_isLocalVar (uentry_getSref (c)))
940 e->sref = sRef_undefined;
944 e->sref = uentry_getSref (c);
947 if (sRef_isStateUnknown (e->sref) && uentry_isNonLocal (c))
949 sRef_setDefined (e->sref, fileloc_undefined);
953 ** yoikes! leaving this out was a heinous bug...that would have been
954 ** caught if i had lclint working first. gag!
957 e->etext = cstring_undefined;
959 if (uentry_isEitherConstant (c))
962 e->val = multiVal_copy (uentry_getConstantValue (c));
967 e->val = multiVal_unknown ();
970 e->edata = exprData_makeId (c);
971 e->loc = context_getSaveLocation ();
973 if (fileloc_isUndefined (e->loc))
975 fileloc_free (e->loc);
976 e->loc = fileloc_copy (g_currentloc);
979 e->guards = guardSet_new ();
980 e->sets = sRefSet_new ();
981 e->msets = sRefSet_new ();
982 e->uses = sRefSet_new ();
984 /*> missing fields, detected by lclint <*/
985 e->exitCode = XK_NEVERESCAPE;
986 e->isJumpPoint = FALSE;
988 e->mustBreak = FALSE;
990 exprNode_defineConstraints(e);
996 return exprNode_createUnknown ();
1000 /*@notnull@*/ exprNode
1001 exprNode_fromIdentifier (/*@observer@*/ uentry c)
1005 if (context_justPopped ()) /* watch out! c could be dead */
1007 uentry ce = usymtab_lookupSafe (LastIdentifier ());
1009 if (uentry_isValid (ce))
1015 llbuglit ("Looks like Aunt Millie forgot to walk to dog again.");
1019 ret = exprNode_fromIdentifierAux (c);
1024 static /*@only@*/ /*@notnull@*/ exprNode
1025 exprNode_fromIdentifierAux (/*@observer@*/ uentry c)
1027 exprNode e = exprNode_createId (c);
1030 uentry_setUsed (c, e->loc);
1032 if (uentry_isVar (c) && sRef_isFileOrGlobalScope (sr))
1034 checkGlobUse (c, FALSE, e);
1041 exprNode_isZero (exprNode e)
1043 if (exprNode_isDefined (e))
1045 multiVal m = exprNode_getValue (e);
1047 if (multiVal_isInt (m))
1049 return (multiVal_forceInt (m) == 0);
1057 exprNode_isNonNegative (exprNode e)
1059 if (exprNode_isDefined (e))
1061 multiVal m = exprNode_getValue (e);
1063 if (multiVal_isInt (m))
1065 return (multiVal_forceInt (m) >= 0);
1073 ** a[x] - uses a but NOT a[]
1074 ** result sref = a[] (set/use in assignment)
1076 ** The syntax x[a] is also legal in C, and has the same
1077 ** semantics. If ind is an array, and arr is an int, flip
1082 exprNode_arrayFetch (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
1085 ** error in arr, error propagates (no new messages)
1086 ** error in ind, assume valid and continue
1089 if (exprNode_isError (e1))
1092 return (exprNode_makeError ());
1098 ctype carr = exprNode_getType (e1);
1099 ctype crarr = ctype_realType (carr);
1102 ** this sets up funny aliasing, that leads to spurious
1103 ** lclint errors. Hence, the i2 comments.
1106 if (!ctype_isRealArray (crarr)
1107 && ctype_isRealNumeric (crarr)
1108 && !exprNode_isError (e2)
1109 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1114 carr = exprNode_getType (arr);
1115 crarr = ctype_realType (carr);
1123 if (sRef_possiblyNull (arr->sref))
1125 if (!usymtab_isGuarded (arr->sref))
1127 if (optgenerror (FLG_NULLDEREF,
1128 message ("Index of %s pointer %q: %s",
1129 sRef_nullMessage (arr->sref),
1130 sRef_unparse (arr->sref),
1131 exprNode_unparse (arr)),
1134 sRef_showNullInfo (arr->sref);
1136 /* suppress future messages */
1137 sRef_setNullError (arr->sref);
1142 if (exprNode_isError (ind))
1144 if ((ctype_isArrayPtr (crarr)
1145 && !ctype_isFunction (crarr))
1146 || ctype_isUnknown (carr))
1148 exprNode ret = exprNode_createPartialCopy (arr);
1150 if (ctype_isKnown (carr))
1152 ret->typ = ctype_baseArrayPtr (crarr);
1156 ret->typ = ctype_unknown;
1159 ret->sref = sRef_makeArrayFetch (arr->sref);
1161 ret->kind = XPR_FETCH;
1164 ** Because of funny aliasing (when arr and ind are
1165 ** flipped) spurious errors would be reported here.
1168 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1169 checkSafeUse (ret, arr->sref);
1174 voptgenerror (FLG_TYPE,
1175 message ("Array fetch from non-array (%t): %s[%s]", carr,
1176 exprNode_unparse (e1), exprNode_unparse (e2)),
1178 exprNode_free (arr);
1179 return (exprNode_makeError ());
1184 if (!ctype_isForceRealInt (&(ind->typ)))
1186 ctype rt = ctype_realType (ind->typ);
1188 if (ctype_isChar (rt))
1192 message ("Array fetch using non-integer, %t: %s[%s]",
1194 exprNode_unparse (e1), exprNode_unparse (e2)),
1197 else if (ctype_isEnum (rt))
1201 message ("Array fetch using non-integer, %t: %s[%s]",
1203 exprNode_unparse (e1), exprNode_unparse (e2)),
1210 message ("Array fetch using non-integer, %t: %s[%s]",
1212 exprNode_unparse (e1), exprNode_unparse (e2)),
1216 multiVal_free (ind->val);
1217 ind->val = multiVal_unknown ();
1220 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1222 exprNode ret = exprNode_createSemiCopy (arr);
1223 multiVal m = exprNode_getValue (ind);
1225 ret->typ = ctype_baseArrayPtr (crarr);
1226 ret->kind = XPR_FETCH;
1228 if (multiVal_isInt (m))
1230 int i = (int) multiVal_forceInt (m);
1232 if (sRef_isValid (arr->sref)) {
1233 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1235 ret->sref = sRef_undefined;
1240 ret->sref = sRef_makeArrayFetch (arr->sref);
1243 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1244 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1245 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1247 /* (see comment on spurious errors above) */
1248 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1250 exprNode_checkUse (ret, ind->sref, ind->loc);
1251 exprNode_checkUse (ret, arr->sref, arr->loc);
1257 if (ctype_isUnknown (carr))
1259 exprNode ret = exprNode_createPartialCopy (arr);
1261 ret->kind = XPR_FETCH;
1262 ret->typ = ctype_unknown;
1263 ret->sets = sRefSet_union (ret->sets, ind->sets);
1264 ret->msets = sRefSet_union (ret->msets, ind->msets);
1265 ret->uses = sRefSet_union (ret->uses, ind->uses);
1267 /* (see comment on spurious errors above) */
1268 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1270 exprNode_checkUse (ret, ind->sref, ind->loc);
1271 exprNode_checkUse (ret, arr->sref, arr->loc);
1278 message ("Array fetch from non-array (%t): %s[%s]", carr,
1279 exprNode_unparse (e1), exprNode_unparse (e2)),
1282 exprNode_free (arr);
1283 exprNode_free (ind);
1285 return (exprNode_makeError ());
1295 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1296 exprNodeList args, exprNode ret)
1298 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1302 ** checkPrintfArgs --- checks arguments for printf-like functions
1303 ** Arguments before ... have already been checked.
1304 ** The argument before the ... is a char *.
1305 ** argno is the format string argument.
1309 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1310 exprNodeList args, exprNode ret, int argno)
1313 ** the last argument before the elips is the format string
1318 int nargs = exprNodeList_size (args);
1319 uentryList params = uentry_getParams (fcn);
1323 ** These should be ensured by checkSpecialFunction
1326 llassert (uentryList_size (params) == argno + 1);
1327 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1329 a = exprNodeList_getN (args, argno - 1);
1330 formatloc = fileloc_copy (exprNode_loc (a));
1332 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1333 && exprNode_knownStringValue (a))
1335 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1336 char *code = format;
1339 nargs = exprNodeList_size (args);
1341 while ((code = strchr (code, '%')) != NULL)
1343 char *origcode = code;
1344 cstring codetext = cstring_newEmpty ();
1345 char key = *(++code);
1346 ctype modtype = ctype_int;
1347 bool modified = FALSE;
1349 fileloc_addColumn (formatloc, code - ocode);
1351 codetext = cstring_appendChar (codetext, key);
1354 while (isFlagKey (key))
1357 codetext = cstring_appendChar (codetext, key);
1358 fileloc_incColumn (formatloc);
1361 if (key == 'm') /* skipped in syslog */
1366 /* ignore field width */
1367 while (isdigit ((int) key) != 0)
1370 codetext = cstring_appendChar (codetext, key);
1371 fileloc_incColumn (formatloc);
1374 /* ignore precision */
1378 codetext = cstring_appendChar (codetext, key);
1379 fileloc_incColumn (formatloc);
1382 ** In printf, '*' means: read the next arg as an int for the
1383 ** field width. This seems to be missing from my copy of the
1384 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1385 ** later) but never does.
1390 ; /* don't do anything --- handle later */
1394 while (isdigit ((int) key) != 0)
1397 codetext = cstring_appendChar (codetext, key);
1398 fileloc_incColumn (formatloc);
1405 modtype = ctype_sint; /* short */
1407 codetext = cstring_appendChar (codetext, key);
1408 fileloc_incColumn (formatloc);
1410 else if (key == 'l' || key == 'L')
1412 modtype = ctype_lint; /* long */
1414 codetext = cstring_appendChar (codetext, key);
1415 fileloc_incColumn (formatloc);
1417 if (key == 'l' || key == 'L') {
1418 modtype = ctype_llint; /* long long */
1420 codetext = cstring_appendChar (codetext, key);
1421 fileloc_incColumn (formatloc);
1429 /* now, key = type of conversion to apply */
1431 fileloc_incColumn (formatloc);
1439 message ("No argument corresponding to %q format "
1440 "code %d (%%%s): \"%s\"",
1441 uentry_getName (fcn),
1443 cstring_fromChars (format)),
1446 if (fileloc_isDefined (formatloc)
1447 && context_getFlag (FLG_SHOWCOL))
1449 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1457 a = exprNodeList_getN (args, i);
1460 if (!exprNode_isError (a))
1466 case '*': /* int argument for fieldwidth */
1467 expecttype = ctype_int;
1468 *(--code) = '%'; /* convert it for next code */
1469 fileloc_subColumn (formatloc, 1);
1470 /*@switchbreak@*/ break;
1473 expecttype = ctype_combine (ctype_uint, modtype);
1474 /*@switchbreak@*/ break;
1476 case 'i': /* int argument */
1478 expecttype = ctype_combine (ctype_int, modtype);
1479 /*@switchbreak@*/ break;
1481 case 'x': /* unsigned int */
1483 expecttype = ctype_combine (ctype_uint, modtype);
1485 /*@switchbreak@*/ break;
1491 case 'f': /* double */
1492 expecttype = ctype_combine (ctype_double, modtype);
1493 /*@switchbreak@*/ break;
1495 case 'c': /* int converted to char (check its a char?) */
1496 expecttype = ctype_makeConj (ctype_char, ctype_uchar);
1497 /*@switchbreak@*/ break;
1499 case 's': /* string */
1500 expecttype = ctype_string;
1501 /*@switchbreak@*/ break;
1504 while (((key = *(++code)) != ']')
1507 codetext = cstring_appendChar (codetext, key);
1508 fileloc_incColumn (formatloc);
1514 (message ("Bad character set format: %s",
1515 cstring_fromChars (origcode)));
1518 expecttype = ctype_string;
1519 /*@switchbreak@*/ break;
1521 case 'p': /* pointer */
1522 expecttype = ctype_makePointer (ctype_void);
1523 uentry_setDefState (regArg, SS_RELDEF); /* need not be defined */
1524 sRef_setPosNull (uentry_getSref (regArg), fileloc_undefined); /* could be null */
1525 /*@switchbreak@*/ break;
1527 case 'n': /* pointer to int, modified by call! */
1528 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1530 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1531 /*@switchbreak@*/ break;
1533 case 'm': /* in a syslog, it doesn't consume an argument */
1534 /* should check we're really doing syslog */
1536 /*@switchbreak@*/ break;
1540 expecttype = ctype_unknown;
1544 message ("Unrecognized format code: %s",
1545 cstring_fromChars (origcode)),
1546 fileloc_isDefined (formatloc)
1547 ? formatloc : g_currentloc);
1549 /*@switchbreak@*/ break;
1552 if (!(exprNode_matchArgType (expecttype, a)))
1554 if (ctype_isVoidPointer (expecttype)
1555 && ctype_isRealAbstract (a->typ)
1556 && (context_getFlag (FLG_ABSTVOIDP)))
1562 if (llgenformattypeerror
1563 (expecttype, exprNode_undefined,
1565 message ("Format argument %d to %q (%%%s) expects "
1568 uentry_getName (fcn),
1571 a->typ, exprNode_unparse (a)),
1574 if (fileloc_isDefined (formatloc)
1575 && context_getFlag (FLG_SHOWCOL))
1578 (cstring_makeLiteral
1579 ("Corresponding format code"),
1586 uentry_setType (regArg, expecttype);
1587 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1589 if (ctype_equal (expecttype, ctype_string))
1591 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1594 uentry_setType (regArg, ctype_unknown);
1595 uentry_fixupSref (regArg);
1599 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1610 cstring_free (codetext);
1615 voptgenerror (FLG_TYPE,
1616 message ("Format string for %q has %d arg%&, given %d",
1617 uentry_getName (fcn), i - argno, nargs - argno),
1623 /* no checking possible for compile-time unknown format strings */
1624 if (exprNode_isDefined (a))
1628 message ("Format string parameter to %s is not a compile-time constant: %s",
1629 exprNode_unparse (f),
1630 exprNode_unparse (a)),
1635 fileloc_free (formatloc);
1639 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1640 exprNodeList args, exprNode ret, int argno)
1644 int nargs = exprNodeList_size (args);
1645 uentryList params = uentry_getParams (fcn);
1649 ** These should be ensured by checkSpecialFunction
1652 llassert (uentryList_size (params) == argno + 1);
1653 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1655 a = exprNodeList_getN (args, argno - 1);
1656 formatloc = fileloc_copy (exprNode_loc (a));
1658 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1659 && exprNode_knownStringValue (a))
1661 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1662 char *code = format;
1665 nargs = exprNodeList_size (args);
1667 while ((code = strchr (code, '%')) != NULL)
1669 char *origcode = code;
1670 char key = *(++code);
1671 cstring codetext = cstring_newEmpty ();
1672 ctype modtype = ctype_int;
1673 char modifier = '\0';
1674 bool modified = TRUE;
1675 bool ignore = FALSE;
1677 codetext = cstring_appendChar (codetext, key);
1678 fileloc_addColumn (formatloc, code - ocode);
1681 ** this is based on ANSI standard library description of fscanf
1682 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1685 /* '*' suppresses assignment (does not need match argument) */
1690 codetext = cstring_appendChar (codetext, key);
1693 fileloc_incColumn (formatloc);
1696 /* ignore field width */
1697 while (isdigit ((int) key) != 0)
1700 codetext = cstring_appendChar (codetext, key);
1701 fileloc_incColumn (formatloc);
1706 modtype = ctype_sint; /* short */
1708 codetext = cstring_appendChar (codetext, key);
1709 fileloc_incColumn (formatloc);
1711 else if (key == 'l' || key == 'L')
1713 modtype = ctype_lint; /* long */
1717 codetext = cstring_appendChar (codetext, key);
1719 fileloc_incColumn (formatloc);
1721 if (key == 'l' || key == 'L') {
1722 modtype = ctype_llint; /* long long */
1724 codetext = cstring_appendChar (codetext, key);
1725 fileloc_incColumn (formatloc);
1733 /* now, key = type of conversion to apply */
1735 fileloc_incColumn (formatloc);
1749 message ("No argument corresponding to %q format "
1750 "code %d (%%%s): \"%s\"",
1751 uentry_getName (fcn),
1753 cstring_fromChars (format)),
1756 if (fileloc_isDefined (formatloc)
1757 && context_getFlag (FLG_SHOWCOL))
1760 (cstring_makeLiteral ("Corresponding format code"),
1768 a = exprNodeList_getN (args, i);
1771 if (!exprNode_isError (a))
1777 case '*': /* int argument for fieldwidth */
1778 expecttype = ctype_makePointer (ctype_int);
1779 *(--code) = '%'; /* convert it for next code */
1780 fileloc_subColumn (formatloc, 1);
1781 /*@switchbreak@*/ break;
1784 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1785 /*@switchbreak@*/ break;
1790 case 'X': /* unsigned int */
1791 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1792 /*@switchbreak@*/ break;
1799 /* printf is double, scanf is float! */
1801 if (modifier == 'l')
1803 expecttype = ctype_makePointer (ctype_double);
1805 else if (modifier == 'L')
1807 expecttype = ctype_makePointer (ctype_ldouble);
1811 llassert (modifier == '\0');
1812 expecttype = ctype_makePointer (ctype_float);
1814 /*@switchbreak@*/ break;
1816 case 'c': /* int converted to char (check its a char?) */
1817 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1818 /*@switchbreak@*/ break;
1820 case 's': /* string */
1821 expecttype = ctype_string;
1822 /*@switchbreak@*/ break;
1826 while (((key = *(++code)) != ']')
1829 codetext = cstring_appendChar (codetext, key);
1830 fileloc_incColumn (formatloc);
1836 (message ("Bad character set format: %s",
1837 cstring_fromChars (origcode)));
1840 expecttype = ctype_string;
1841 /*@switchbreak@*/ break;
1844 case 'p': /* pointer */
1847 message ("Format code should not be used in scanf: %s",
1848 cstring_fromChars (origcode)),
1849 fileloc_isDefined (formatloc)
1850 ? formatloc : g_currentloc);
1852 expecttype = ctype_unknown;
1853 /*@switchbreak@*/ break;
1855 case 'n': /* pointer to int, modified by call! */
1856 expecttype = ctype_makePointer (ctype_int);
1857 /*@switchbreak@*/ break;
1860 expecttype = ctype_unknown;
1864 message ("Unrecognized format code: %s",
1865 cstring_fromChars (origcode)),
1866 fileloc_isDefined (formatloc)
1867 ? formatloc : g_currentloc);
1869 /*@switchbreak@*/ break;
1872 if (!(exprNode_matchArgType (expecttype, a)))
1874 if (ctype_isVoidPointer (expecttype)
1875 && ctype_isRealAbstract (a->typ)
1876 && (context_getFlag (FLG_ABSTVOIDP)))
1882 if (llgenformattypeerror
1883 (expecttype, exprNode_undefined,
1885 message ("Format argument %d to %q (%%%s) expects "
1888 uentry_getName (fcn),
1889 codetext, expecttype,
1890 a->typ, exprNode_unparse (a)),
1893 if (fileloc_isDefined (formatloc)
1894 && context_getFlag (FLG_SHOWCOL))
1897 (cstring_makeLiteral
1898 ("Corresponding format code"),
1905 uentry_setType (outArg, expecttype);
1906 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
1907 uentry_setType (outArg, ctype_unknown);
1908 uentry_fixupSref (outArg);
1912 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1917 /* a->sref = defref; */
1924 cstring_free (codetext);
1929 voptgenerror (FLG_TYPE,
1930 message ("Format string for %q has %d arg%&, given %d",
1931 uentry_getName (fcn), i - argno, nargs - argno),
1937 /* no checking possible for compile-time unknown format strings */
1940 fileloc_free (formatloc);
1944 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
1947 /*@unused@*/ int argno)
1950 ** the last argument before the elips is the format string
1953 int nargs = exprNodeList_size (args);
1958 a = exprNodeList_getN (args, argno - 1);
1959 formatloc = fileloc_copy (exprNode_loc (a));
1961 if (ctype_isUnknown (cstringType)) {
1962 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
1964 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
1968 if (ctype_isUnknown (ctypeType)) {
1969 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
1971 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
1975 if (ctype_isUnknown (filelocType)) {
1976 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
1978 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
1982 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1983 && exprNode_knownStringValue (a))
1985 cstring format = multiVal_forceString (exprNode_getValue (a));
1986 char *code = cstring_toCharsSafe (format);
1989 nargs = exprNodeList_size (args);
1991 while ((code = strchr (code, '%')) != NULL)
1993 char *origcode = code;
1994 char key = *(++code);
1995 cstring codetext = cstring_newEmpty ();
1996 bool isOnly = FALSE;
1998 codetext = cstring_appendChar (codetext, key);
2000 fileloc_addColumn (formatloc, code - ocode);
2002 while (key >= '0' && key <= '9')
2005 codetext = cstring_appendChar (codetext, key);
2006 fileloc_incColumn (formatloc);
2010 fileloc_incColumn (formatloc);
2014 if (key == '&') /* plural marker */
2023 message ("Message missing format arg %d (%%%s): \"%s\"",
2024 i + 1, codetext, format),
2030 a = exprNodeList_getN (args, i);
2034 if (!exprNode_isError (a))
2038 /*@-loopswitchbreak@*/
2044 expecttype = ctype_char; break;
2046 expecttype = cstringType; break;
2048 expecttype = cstringType; isOnly = TRUE; break;
2050 expecttype = cstringType; isOnly = TRUE; break;
2051 case 'd': expecttype = ctype_int; break;
2052 case 'u': expecttype = ctype_uint; break;
2053 case 'w': expecttype = ctype_ulint; break;
2054 case 'f': expecttype = ctype_float; break;
2055 case 'b': expecttype = ctype_bool; break;
2056 case 't': expecttype = ctypeType; break;
2057 case 'l': expecttype = filelocType; break;
2058 case '&': /* a wee bit of a hack methinks */
2059 expecttype = ctype_int;
2061 case 'r': expecttype = ctype_bool; break;
2063 expecttype = ctype_unknown;
2066 message ("Unrecognized format code: %s",
2067 cstring_fromChars (origcode)),
2068 fileloc_isDefined (formatloc)
2069 ? formatloc : g_currentloc);
2072 /*@=loopswitchbreak@*/
2074 if (!(exprNode_matchArgType (expecttype, a)))
2076 if (ctype_isVoidPointer (expecttype)
2077 && ctype_isRealAbstract (a->typ)
2078 && (context_getFlag (FLG_ABSTVOIDP)))
2084 if (llgenformattypeerror
2085 (expecttype, exprNode_undefined,
2087 message ("Format argument %d to %q (%%%s) expects "
2090 uentry_getName (fcn),
2091 codetext, expecttype,
2092 a->typ, exprNode_unparse (a)),
2095 if (fileloc_isDefined (formatloc)
2096 && context_getFlag (FLG_SHOWCOL))
2099 (cstring_makeLiteral
2100 ("Corresponding format code"),
2107 if (ctype_equal (expecttype, cstringType))
2111 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
2112 uentry_fixupSref (csOnlyArg);
2116 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2117 uentry_fixupSref (csArg);
2122 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2123 uentry_fixupSref (regArg);
2129 cstring_free (codetext);
2134 voptgenerror (FLG_TYPE,
2135 message ("Format string for %q has %d arg%&, given %d",
2136 uentry_getName (fcn), i - argno, nargs -argno),
2142 /* no checking possible for compile-time unknown format strings */
2145 fileloc_free (formatloc);
2149 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2150 /*@notnull@*/ exprNode e2,
2156 bool hadUncon = FALSE;
2158 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e1->sref)) &&
2159 sRefSet_hasUnconstrained (sets2))
2162 (FLG_EVALORDERUNCON,
2164 ("Expression may have undefined behavior (%q used in right operand "
2165 "may set global variable %q used in left operand): %s %s %s",
2166 sRefSet_unparseUnconstrained (sets2),
2167 sRef_unparse (sRef_getRootBase (e1->sref)),
2168 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2172 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e2->sref)) &&
2173 sRefSet_hasUnconstrained (sets1))
2176 (FLG_EVALORDERUNCON,
2178 ("Expression has undefined behavior (%q used in left operand "
2179 "may set global variable %q used in right operand): %s %s %s",
2180 sRefSet_unparseUnconstrained (sets1),
2181 sRef_unparse (e2->sref),
2182 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2186 sRefSet_realElements (e1->uses, sr)
2188 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2193 ("Expression has undefined behavior (left operand uses %q, "
2194 "modified by right operand): %s %s %s",
2196 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2199 } end_sRefSet_realElements;
2201 sRefSet_realElements (sets1, sr)
2203 if (sRef_isMeaningful (sr))
2205 if (sRef_same (sr, e2->sref))
2210 ("Expression has undefined behavior (value of right operand "
2211 "modified by left operand): %s %s %s",
2212 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2215 else if (sRefSet_member (e2->uses, sr))
2220 ("Expression has undefined behavior (left operand modifies %q, "
2221 "used by right operand): %s %s %s",
2223 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2228 if (sRefSet_member (sets2, sr))
2230 if (sRef_isUnconstrained (sr))
2238 hadUncon = optgenerror
2239 (FLG_EVALORDERUNCON,
2241 ("Expression may have undefined behavior. Left operand "
2242 "calls %q; right operand calls %q. The unconstrained "
2243 "functions may modify global state used by "
2244 "the other operand): %s %s %s",
2245 sRefSet_unparseUnconstrained (sets1),
2246 sRefSet_unparseUnconstrained (sets2),
2247 exprNode_unparse (e1), lltok_unparse (op),
2248 exprNode_unparse (e2)),
2257 ("Expression has undefined behavior (both "
2258 "operands modify %q): %s %s %s",
2260 exprNode_unparse (e1),
2261 lltok_unparse (op), exprNode_unparse (e2)),
2267 } end_sRefSet_realElements;
2270 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2272 bool hasError = FALSE;
2274 if (exprNode_isError (e1) || exprNode_isError (e2))
2279 if (sRefSet_member (e2->sets, e1->sref))
2281 if (e2->kind == XPR_CALL)
2287 hasError = optgenerror
2289 message ("Expression has undefined behavior "
2290 "(value of left operand %s is modified "
2291 "by right operand %s): %s %s %s",
2292 exprNode_unparse (e1),
2293 exprNode_unparse (e2),
2294 exprNode_unparse (e1), lltok_unparse (op),
2295 exprNode_unparse (e2)),
2300 if (context_getFlag (FLG_EVALORDERUNCON))
2302 if (sRefSet_member (e2->msets, e1->sref))
2304 if (e2->kind == XPR_CALL)
2310 hasError = optgenerror
2313 ("Expression has undefined behavior (value of left "
2314 "operand may be modified by right operand): %s %s %s",
2315 exprNode_unparse (e1), lltok_unparse (op),
2316 exprNode_unparse (e2)),
2324 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2326 if (context_maybeSet (FLG_EVALORDERUNCON))
2328 checkExpressionDefinedAux (e1, e2, e1->msets,
2329 e2->msets, op, FLG_EVALORDERUNCON);
2334 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2337 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2338 exprNodeList args, bool isIter, exprNode ret)
2342 if (!exprNode_isError (f))
2344 if (!uentryList_isMissingParams (cl))
2346 int nargs = exprNodeList_size (args);
2347 int expectargs = uentryList_size (cl);
2351 if (expectargs == 0)
2359 message ("Iter %q invoked with %d args, "
2361 uentry_getName (fcn),
2369 message ("Function %s called with %d args, "
2371 exprNode_unparse (f), nargs),
2378 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2380 exprNodeList_reset (args);
2382 uentryList_elements (cl, current)
2384 ctype ct = uentry_getType (current);
2387 if (ctype_isElips (ct))
2390 ** do special checking for printf/scanf library functions
2392 ** this is kludgey code, just for handling the special case
2396 if (uentry_isPrintfLike (fcn))
2398 checkPrintfArgs (f, fcn, args, ret, i);
2401 else if (uentry_isScanfLike (fcn))
2403 checkScanfArgs (f, fcn, args, ret, i);
2406 else if (uentry_isMessageLike (fcn))
2408 checkMessageArgs (f, fcn, args, i);
2413 llassert (!uentry_isSpecialFunction (fcn));
2416 nargs = expectargs; /* avoid errors */
2421 if (i >= nargs) break;
2423 a = exprNodeList_current (args);
2424 exprNodeList_advance (args);
2428 if (exprNode_isError (a))
2435 probably necessary? I'm not sure about this one
2436 checkMacroParen (a);
2439 f->guards = guardSet_union (f->guards, a->guards);
2441 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2443 if (!(exprNode_matchArgType (ct, a)))
2445 DPRINTF (("Args mismatch!"));
2447 if (ctype_isVoidPointer (ct)
2448 && (ctype_isPointer (a->typ)
2449 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2454 ("Pointer to abstract type (%t) used "
2456 "(arg %d to %q): %s",
2458 uentry_getName (fcn),
2459 exprNode_unparse (a)),
2467 (ct, exprNode_undefined,
2470 ("Iter %q expects arg %d to "
2471 "be %t gets %t: %s",
2472 uentry_getName (fcn),
2473 i, ct, a->typ, exprNode_unparse (a)),
2484 ("Function %q expects arg %d to be %t gets %t: %s",
2485 uentry_getName (fcn),
2486 i, ct, a->typ, exprNode_unparse (a)),
2489 DPRINTF (("Types: %s / %s",
2491 ctype_unparse (a->typ)));
2495 ** Clear null marker for abstract types.
2496 ** (It is not revealed, so suppress future messages.)
2499 if (ctype_isAbstract (a->typ))
2501 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2508 } end_uentryList_elements ;
2511 if (expectargs != nargs) /* note: not != since we may have ... */
2513 if (ctype_isElips (last))
2517 message ("Function %s called with %d args, expects at least %d",
2518 exprNode_unparse (f),
2519 nargs, expectargs - 1),
2528 message ("Iter %q invoked with %d args, expects %d",
2529 uentry_getName (fcn), nargs, expectargs),
2536 message ("Function %s called with %d args, expects %d",
2537 exprNode_unparse (f),
2550 ** Check for undefined code sequences in function arguments:
2552 ** one parameter sets something used by another parameter
2553 ** one parameter sets something set by another parameter
2557 checkSequencingOne (exprNode f, exprNodeList args,
2558 /*@notnull@*/ exprNode el, int argno)
2561 ** Do second loop, iff +undefunspec
2565 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2567 for (checkloop = 0; checkloop < numloops; checkloop++)
2573 thissets = el->sets;
2577 llassert (checkloop == 1);
2578 thissets = el->msets;
2581 sRefSet_realElements (thissets, thisset)
2585 /*@access exprNodeList@*/
2586 for (j = 0; j < args->nelements; j++)
2588 exprNode jl = args->elements[j];
2589 int thisargno = j + 1;
2591 if (thisargno != argno && exprNode_isDefined (jl))
2593 sRefSet otheruses = jl->uses;
2595 if (sRef_isFileOrGlobalScope (sRef_getRootBase (jl->sref)) &&
2596 sRefSet_hasUnconstrained (thissets))
2599 (FLG_EVALORDERUNCON,
2602 ("%q used in argument %d may set "
2603 "global variable %q used by argument %d: %s(%q)",
2604 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2607 sRef_unparse (sRef_getRootBase (jl->sref)),
2609 exprNode_unparse (f), exprNodeList_unparse (args)),
2613 if (sRefSet_member (otheruses, thisset))
2615 if (sRef_isUnconstrained (thisset))
2618 (FLG_EVALORDERUNCON,
2620 ("Unconstrained functions used in arguments %d (%q) "
2621 "and %d (%s) may modify "
2622 "or use global state in undefined way: %s(%q)",
2624 sRefSet_unparseUnconstrainedPlain (otheruses),
2626 sRef_unconstrainedName (thisset),
2627 exprNode_unparse (f),
2628 exprNodeList_unparse (args)),
2636 ("Argument %d modifies %q, used by argument %d "
2637 "(order of evaluation of actual parameters is "
2638 "undefined): %s(%q)",
2639 argno, sRef_unparse (thisset), thisargno,
2640 exprNode_unparse (f), exprNodeList_unparse (args)),
2646 sRefSet othersets = jl->sets;
2648 if (sRefSet_member (othersets, thisset))
2650 if (sRef_isUnconstrained (thisset))
2653 (FLG_EVALORDERUNCON,
2655 ("Unconstrained functions used in "
2656 "arguments %d (%q) and %d (%s) may modify "
2657 "or use global state in undefined way: %s(%q)",
2659 sRefSet_unparseUnconstrainedPlain (othersets),
2661 sRef_unconstrainedName (thisset),
2662 exprNode_unparse (f), exprNodeList_unparse (args)),
2670 ("Argument %d modifies %q, set by argument %d (order of"
2671 " evaluation of actual parameters is undefined): %s(%q)",
2672 argno, sRef_unparse (thisset), thisargno,
2673 exprNode_unparse (f), exprNodeList_unparse (args)),
2680 /*@noaccess exprNodeList@*/
2681 } end_sRefSet_realElements;
2686 checkSequencing (exprNode f, exprNodeList args)
2688 if (exprNodeList_size (args) > 1)
2693 /*@access exprNodeList*/
2695 for (i = 0; i < args->nelements; i++)
2697 el = args->elements[i];
2699 if (!exprNode_isError (el))
2701 checkSequencingOne (f, args, el, i + 1);
2704 /*@noaccess exprNodeList*/
2709 ** requires le = exprNode_getUentry (f)
2713 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2714 uentry le, exprNodeList args,
2715 /*@notnull@*/ exprNode ret, int specialArgs)
2717 bool isSpec = FALSE;
2718 bool hasMods = FALSE;
2720 globSet usesGlobs = globSet_undefined;
2721 sRefSet mods = sRefSet_undefined;
2722 bool freshMods = FALSE;
2723 uentryList params = uentryList_undefined;
2725 DPRINTF (("Check glob mods: %s", exprNode_unparse (ret)));
2728 ** check globals and modifies
2733 if (!uentry_isValid (le))
2735 ctype fr = ctype_realType (f->typ);
2737 if (ctype_isFunction (fr))
2739 params = ctype_argsFunction (fr);
2743 params = uentryList_missingParams;
2746 if (!context_getFlag (FLG_MODNOMODS)
2747 && !context_getFlag (FLG_GLOBUNSPEC))
2749 checkUnspecCall (f, params, args);
2755 fname = uentry_rawName (le);
2759 if (uentry_isFunction (le))
2761 params = uentry_getParams (le);
2762 mods = uentry_getMods (le);
2763 hasMods = uentry_hasMods (le);
2764 usesGlobs = uentry_getGlobs (le);
2765 isSpec = uentry_isSpecified (le);
2767 else /* not a function */
2769 ctype ct = ctype_realType (uentry_getType (le));
2771 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2772 ("checkModGlobs: uentry not a function: %s",
2773 uentry_unparse (le)));
2775 params = ctype_argsFunction (ct);
2776 return; /*@32 ! remove this? */
2785 globSet_allElements (usesGlobs, el)
2787 if (sRef_isValid (el))
2789 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2791 context_usedGlobal (el);
2792 exprNode_checkUse (f, el, f->loc);
2794 if (context_checkInternalUse ())
2796 if (!context_globAccess (el))
2798 if (sRef_isSystemState (el)
2799 && !context_getFlag (FLG_MODFILESYSTEM))
2808 ("Called procedure %s may access %q, but "
2809 "globals list does not include globals %s",
2810 exprNode_unparse (f),
2812 cstring_makeLiteralTemp (sRef_isInternalState (el)
2820 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2826 uentry gle = sRef_getUentry (el);
2827 sRef sr = sRef_updateSref (el);
2829 if (sRef_isUndefGlob (el))
2831 sRef_setDefined (sr, f->loc);
2832 exprNode_checkSet (f, sr);
2840 if (sRef_isAllocated (el))
2842 exprNode_checkSet (f, sr);
2846 if (sRef_isStateUndefined (sr))
2851 ("%s %q used by function undefined before call: %s",
2852 sRef_getScopeName (sr),
2854 exprNode_unparse (f)),
2856 sRef_setDefined (sr, f->loc);
2858 exprNode_checkUse (f, sr, f->loc);
2861 checkGlobUse (gle, TRUE, f);
2864 if (sRef_isKilledGlob (el))
2866 sRef_kill (sr, f->loc);
2867 context_usedGlobal (sr);
2871 } end_globSet_allElements;
2877 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
2879 sRefSet smods = sRefSet_undefined;
2882 ** NEED to check for modifies anything
2886 ** check each sRef that called function modifies (ml), is
2892 sRefSet_allElements (mods, s) /* s is something which may be modified */
2894 DPRINTF (("Check modify: %s", sRef_unparse (s)));
2896 if (sRef_isKindSpecial (s))
2898 if (sRef_isSpecInternalState (s))
2900 if (context_getFlag (FLG_MODINTERNALSTRICT))
2902 exprNode_checkCallModifyVal (s, args, f, ret);
2906 sRefSet mmods = context_modList ();
2908 sRefSet_allElements (mmods, el)
2910 if (sRef_isInternalState (el))
2912 sRef_setModified (el);
2914 } end_sRefSet_allElements ;
2919 exprNode_checkCallModifyVal (s, args, f, ret);
2924 sRef rb = sRef_getRootBase (s);
2926 if (sRef_isFileOrGlobalScope (rb))
2928 context_usedGlobal (rb);
2931 if (sRef_isFileStatic (s)
2932 && !fileId_equal (fileloc_fileId (f->loc),
2933 fileloc_fileId (uentry_whereDefined (le))))
2935 smods = sRefSet_insert (smods, s);
2939 exprNode_checkCallModifyVal (s, args, f, ret);
2942 } end_sRefSet_allElements;
2947 ** Static elements in modifies set can have nasty consequences.
2948 ** (I think...have not been able to reproduce a possible bug.)
2951 if (!sRefSet_isDefined (smods))
2953 mods = sRefSet_newCopy (mods);
2956 sRefSet_allElements (smods, el)
2958 bool res = sRefSet_delete (mods, el);
2961 } end_sRefSet_allElements;
2963 sRefSet_free (smods);
2968 else if (sRefSet_isDefined (mods))
2969 { /* just check observers */
2972 sRefSet_allElements (mods, s) /* s is something which may be modified */
2974 sRef rb = sRef_getRootBase (s);
2978 if (sRef_isParam (rb))
2980 sRef b = sRef_fixBaseParam (s, args);
2982 if (sRef_isObserver (b))
2984 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
2988 message ("Function call may modify observer%q: %s",
2989 sRef_unparsePreOpt (b), exprNode_unparse (e)),
2992 sRef_showExpInfo (b);
2996 } end_sRefSet_allElements;
3000 if (!hasMods) /* no specified modifications */
3002 if (context_getFlag (FLG_MODOBSERVERUNCON))
3004 exprNodeList_elements (args, e)
3006 if (exprNode_isDefined (e))
3008 sRef s = exprNode_getSref (e);
3010 if (sRef_isObserver (s)
3011 && ctype_isMutable (sRef_getType (s)))
3014 (FLG_MODOBSERVERUNCON,
3016 ("Call to unconstrained function %s may modify observer%q: %s",
3017 exprNode_unparse (f),
3018 sRef_unparsePreOpt (s), exprNode_unparse (e)),
3021 sRef_showExpInfo (s);
3025 } end_exprNodeList_elements;
3030 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
3032 ret->uses = sRefSet_union (ret->uses, f->uses);
3033 ret->sets = sRefSet_union (ret->sets, f->sets);
3034 ret->msets = sRefSet_union (ret->msets, f->msets);
3039 ** Spurious errors reported, because lclint can't tell
3040 ** mods must be fresh if freshMods is true.
3043 /*@i@*/ sRefSet_free (mods);
3049 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
3051 if (uentry_isVar (glob))
3053 if (context_inFunctionLike ())
3055 sRef sr = uentry_getSref (glob);
3057 context_usedGlobal (sr);
3059 if (context_checkGlobUse (glob))
3061 if (!context_globAccess (sr))
3067 message ("Called procedure %s may access %s %q",
3068 exprNode_unparse (e),
3069 sRef_unparseScope (sr),
3070 uentry_getName (glob)),
3077 message ("Undocumented use of %s %s",
3078 sRef_unparseScope (sr),
3079 exprNode_unparse (e)),
3088 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
3093 reflectEnsuresClause (exprNode ret, uentry le, exprNode f, exprNodeList args)
3095 DPRINTF (("Reflect ensures clause: %s(%s) / %s / %s",
3096 exprNode_unparse (f), exprNodeList_unparse (args),
3097 uentry_unparseFull (le),
3098 stateClauseList_unparse (uentry_getStateClauseList (le))));
3100 if (uentry_isValid (le) && uentry_isFunction (le))
3102 stateClauseList sclauses = uentry_getStateClauseList (le);
3104 if (stateClauseList_isDefined (sclauses))
3106 DPRINTF (("Reflect ensures: %s / %s / %s",
3107 uentry_unparse (le),
3108 exprNode_unparse (f), exprNodeList_unparse (args)));
3110 stateClauseList_elements (sclauses, cl)
3112 if (stateClause_hasEnsures (cl))
3114 /* Same in usymtab.c:1904 */
3115 if (stateClause_setsMetaState (cl))
3117 qual q = stateClause_getMetaQual (cl);
3118 annotationInfo ainfo = qual_getAnnotationInfo (q);
3119 metaStateInfo minfo = annotationInfo_getState (ainfo);
3120 cstring key = metaStateInfo_getName (minfo);
3121 int mvalue = annotationInfo_getValue (ainfo);
3123 sRefSet osrs = sRefSet_undefined;
3126 if (stateClause_isGlobal (cl))
3128 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3133 srs = stateClause_getRefs (cl);
3136 DPRINTF (("Reflect ensures clause: %s", stateClause_unparse (cl)));
3139 DPRINTF (("Sets meta state! %s", stateClause_unparse (cl)));
3141 sRefSet_elements (srs, sel)
3145 if (sRef_isResult (sRef_getRootBase (sel)))
3147 s = exprNode_getSref (ret);
3151 s = sRef_fixBaseParam (sel, args);
3154 DPRINTF (("Reflecting state clause on: %s / %s",
3155 sRef_unparse (sel), sRef_unparse (s)));
3157 sRef_setMetaStateValueComplete (s, key, mvalue, exprNode_loc (f));
3158 } end_sRefSet_elements;
3160 sRefSet_free (osrs);
3164 sRefSet srs = stateClause_getRefs (cl);
3165 sRefModVal modf = stateClause_getEnsuresFunction (cl);
3166 int eparam = stateClause_getStateParameter (cl);
3168 DPRINTF (("Reflect after clause: %s / %s",
3169 stateClause_unparse (cl),
3170 sRefSet_unparse (srs)));
3172 sRefSet_elements (srs, sel)
3176 DPRINTF (("elements: %s", sRef_unparse (sel)));
3177 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3179 if (sRef_isResult (sRef_getRootBase (sel)))
3181 DPRINTF (("Fix base: %s / %s",
3182 sRef_unparse (sel), sRef_unparse (exprNode_getSref (ret))));
3183 s = sRef_fixBase (sel, exprNode_getSref (ret));
3184 DPRINTF (("==> %s", sRef_unparseFull (s)));
3188 s = sRef_fixBaseParam (sel, args);
3191 DPRINTF (("elements: %s", sRef_unparse (s)));
3192 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3194 DPRINTF (("Reflecting state clause on: %s / %s",
3195 sRef_unparse (sel), sRef_unparse (s)));
3197 modf (s, eparam, exprNode_loc (f));
3198 } end_sRefSet_elements;
3201 } end_stateClauseList_elements ;
3204 DPRINTF (("Here: %s / %s",
3205 uentry_unparseFull (le),
3206 bool_unparse (uentry_hasMetaStateEnsures (le))));
3208 if (uentry_hasMetaStateEnsures (le))
3210 fileloc loc = exprNode_loc (f);
3212 metaStateConstraintList mscl = uentry_getMetaStateEnsures (le);
3214 metaStateConstraintList_elements (mscl, msc)
3216 metaStateSpecifier msspec = metaStateConstraint_getSpecifier (msc);
3217 metaStateInfo msinfo = metaStateSpecifier_getMetaStateInfo (msspec);
3218 metaStateExpression msexpr = metaStateConstraint_getExpression (msc);
3219 cstring key = metaStateInfo_getName (msinfo);
3220 sRef mlsr = metaStateSpecifier_getSref (msspec);
3222 sRef lastref = sRef_undefined;
3223 stateValue sval = stateValue_undefined;
3225 DPRINTF (("Meta state constraint for %s: %s", uentry_unparse (le),
3226 metaStateConstraint_unparse (msc)));
3227 DPRINTF (("Matches left: %s", sRef_unparseDebug (mlsr)));
3229 if (sRef_isResult (sRef_getRootBase (mlsr)))
3231 s = exprNode_getSref (ret);
3235 s = sRef_fixBaseParam (mlsr, args);
3238 DPRINTF (("Setting state: %s", sRef_unparseFull (s)));
3240 while (metaStateExpression_isDefined (msexpr))
3242 metaStateSpecifier ms = metaStateExpression_getSpecifier (msexpr);
3243 metaStateInfo msi = metaStateSpecifier_getMetaStateInfo (ms);
3246 DPRINTF (("Check expression: %s", metaStateExpression_unparse (msexpr)));
3248 if (metaStateExpression_isMerge (msexpr))
3250 msexpr = metaStateExpression_getRest (msexpr);
3254 msexpr = metaStateExpression_undefined;
3257 if (metaStateInfo_isDefined (msi))
3259 /* Must match lhs state */
3260 llassert (metaStateInfo_equal (msinfo, msi));
3263 if (metaStateSpecifier_isElipsis (ms))
3266 ** For elipsis, we need to merge all the relevant elipsis parameters
3270 uentryList params = uentry_getParams (le);
3271 int paramno = uentryList_size (params) - 1;
3273 if (!uentry_isElipsisMarker (uentryList_getN (params, paramno)))
3277 message ("Ensures clauses uses ... for function without ... in parameter list: %q",
3278 uentry_getName (le)),
3279 uentry_whereLast (le));
3280 /*@innerbreak@*/ break;
3283 while (paramno < exprNodeList_size (args))
3285 exprNode arg = exprNodeList_getN (args, paramno);
3286 fs = exprNode_getSref (arg);
3287 DPRINTF (("Merge arg: %s", exprNode_unparse (arg)));
3289 /* cut and pasted... gack*/
3290 if (stateValue_isDefined (sval))
3292 /* Use combination table to merge old state value with new one: */
3293 stateValue tval = sRef_getMetaStateValue (fs, key);
3295 if (stateValue_isDefined (tval))
3297 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3298 cstring msg = cstring_undefined;
3299 int nval = stateCombinationTable_lookup (sctable,
3300 stateValue_getValue (sval),
3301 stateValue_getValue (tval),
3303 DPRINTF (("Combining: %s + %s -> %d",
3304 stateValue_unparseValue (sval, msinfo),
3305 stateValue_unparseValue (tval, msinfo),
3308 if (nval == stateValue_error)
3313 ("Attributes merged in ensures clause in states that "
3314 "cannot be combined (%q is %q, %q is %q)%q",
3315 sRef_unparse (lastref),
3316 stateValue_unparseValue (sval, msinfo),
3318 stateValue_unparseValue (tval, msinfo),
3319 cstring_isDefined (msg) ?
3320 message (": %s", msg) : cstring_undefined),
3323 sRef_showMetaStateInfo (fs, key);
3327 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3328 loc = exprNode_loc (arg);
3332 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3337 sval = sRef_getMetaStateValue (fs, key);
3342 if (stateValue_isError (sval))
3344 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3353 msr = metaStateSpecifier_getSref (ms);
3356 llassert (sRef_isParam (sRef_getRootBase (msr)));
3357 fs = sRef_fixBaseParam (msr, args);
3359 if (stateValue_isDefined (sval))
3361 /* Use combination table to merge old state value with new one: */
3362 stateValue tval = sRef_getMetaStateValue (fs, key);
3364 if (stateValue_isDefined (tval))
3366 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3367 cstring msg = cstring_undefined;
3368 int nval = stateCombinationTable_lookup (sctable,
3369 stateValue_getValue (sval),
3370 stateValue_getValue (tval),
3372 DPRINTF (("Combining: %s + %s -> %d",
3373 stateValue_unparseValue (sval, msinfo),
3374 stateValue_unparseValue (tval, msinfo),
3377 if (nval == stateValue_error)
3382 ("Attributes merged in ensures clause in states that "
3383 "cannot be combined (%q is %q, %q is %q)%q",
3384 sRef_unparse (lastref),
3385 stateValue_unparseValue (sval, msinfo),
3387 stateValue_unparseValue (tval, msinfo),
3388 cstring_isDefined (msg)
3389 ? message (": %s", msg) : cstring_undefined),
3392 sRef_showMetaStateInfo (fs, key);
3396 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3400 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3405 sval = sRef_getMetaStateValue (fs, key);
3410 if (stateValue_isError (sval))
3412 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3417 DPRINTF (("Setting: %s:%s <- %s", sRef_unparse (s), key, stateValue_unparse (sval)));
3419 if (stateValue_isDefined (sval))
3421 sRef_setMetaStateValueComplete (s, key, stateValue_getValue (sval), loc);
3425 DPRINTF (("Undefined state: %s", cstring_toCharsSafe (sRef_unparse (s))));
3427 } end_metaStateConstraintList_elements ;
3429 metaStateConstraintList_free (mscl);
3435 checkRequiresClause (uentry le, exprNode f, exprNodeList args)
3437 DPRINTF (("Check requires clause: %s(%s) / %s / %s",
3438 exprNode_unparse (f), exprNodeList_unparse (args),
3439 uentry_unparseFull (le),
3440 stateClauseList_unparse (uentry_getStateClauseList (le))));
3442 if (uentry_isValid (le) && uentry_isFunction (le))
3444 stateClauseList sclauses = uentry_getStateClauseList (le);
3446 if (stateClauseList_isDefined (sclauses))
3448 DPRINTF (("Check requires: %s / %s / %s",
3449 uentry_unparse (le),
3450 exprNode_unparse (f), exprNodeList_unparse (args)));
3452 stateClauseList_elements (sclauses, cl)
3454 DPRINTF (("Check clause: %s / %s",
3455 stateClause_unparse (cl),
3456 bool_unparse (stateClause_hasRequires (cl))));
3458 if (stateClause_hasRequires (cl))
3460 sRefSet osrs = sRefSet_undefined;
3463 if (stateClause_isGlobal (cl))
3465 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3470 srs = stateClause_getRefs (cl);
3473 DPRINTF (("Refs: %s", sRefSet_unparse (srs)));
3475 if (stateClause_setsMetaState (cl))
3477 qual q = stateClause_getMetaQual (cl);
3478 annotationInfo ainfo = qual_getAnnotationInfo (q);
3479 metaStateInfo minfo = annotationInfo_getState (ainfo);
3480 cstring key = metaStateInfo_getName (minfo);
3481 int mvalue = annotationInfo_getValue (ainfo);
3483 DPRINTF (("Requires meta state! %s = %d", key, mvalue));
3485 sRefSet_elements (srs, sel)
3487 sRef s = sRef_fixBaseParam (sel, args);
3489 if (sRef_isResult (sRef_getRootBase (sel)))
3495 DPRINTF (("Checking state clause on: %s / %s / %s = %d",
3496 sRef_unparseFull (sel), sRef_unparseFull (s),
3499 if (!sRef_checkMetaStateValue (s, key, mvalue))
3501 DPRINTF (("HERE: %s", sRef_unparse (s)));
3505 ("Requires clause of called function %q not satisfied%q (state is %q): %q",
3506 uentry_getName (le),
3507 sRef_isGlobalMarker (s)
3509 : message (" by %q", sRef_unparse (s)),
3510 stateValue_unparseValue (sRef_getMetaStateValue (s, key),
3512 stateClause_unparse (cl)),
3515 sRef_showAliasInfo (s);
3519 DPRINTF (("Error supressed!"));
3520 DPRINTF (("Loc: %s", fileloc_unparse (exprNode_loc (f))));
3521 DPRINTF (("Context supress: %s",
3522 bool_unparse (context_suppressFlagMsg (FLG_STATETRANSFER, exprNode_loc (f)))));
3526 } end_sRefSet_elements;
3530 sRefModVal modf = stateClause_getRequiresBodyFunction (cl);
3531 int eparam = stateClause_getStateParameter (cl);
3533 DPRINTF (("Reflect after clause: %s / %s",
3534 stateClause_unparse (cl),
3535 sRefSet_unparse (srs)));
3537 sRefSet_elements (srs, sel)
3541 DPRINTF (("elements: %s", sRef_unparse (sel)));
3542 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3544 s = sRef_fixBaseParam (sel, args);
3546 DPRINTF (("elements: %s", sRef_unparse (s)));
3547 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3549 if (sRef_isResult (sRef_getRootBase (sel)))
3551 ; /*@i423 what do we do about results */
3555 DPRINTF (("Reflecting state clause on: %s / %s",
3556 sRef_unparse (sel), sRef_unparse (s)));
3558 modf (s, eparam, exprNode_loc (f));
3560 } end_sRefSet_elements;
3563 sRefSet_free (osrs);
3565 } end_stateClauseList_elements ;
3570 static /*@only@*/ exprNode
3571 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
3572 ctype t, /*@keep@*/ exprNodeList args)
3574 /* requires f is a non-error exprNode, with type function */
3575 cstring fname = exprNode_unparse (f);
3576 uentry le = exprNode_getUentry (f);
3577 exprNode ret = exprNode_createPartialCopy (f);
3582 DPRINTF (("Call: %s %s",exprNode_unparse (f), exprNodeList_unparse (args)));
3584 ret->typ = ctype_getReturnType (t);
3585 ret->kind = XPR_CALL;
3587 ret->edata = exprData_makeCall (f, args);
3590 ** Order of these steps is very important!
3592 ** Must check for argument dependencies before messing up uses and sets.
3595 if (context_getFlag (FLG_EVALORDER))
3597 exprNodeList_elements (args, current)
3599 if (exprNode_isDefined (current))
3601 exprNode_addUse (current, current->sref);
3603 } end_exprNodeList_elements;
3605 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3607 checkSequencing (f, args);
3610 exprNodeList_elements (args, current)
3612 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3614 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3616 } end_exprNodeList_elements ;
3619 special = checkArgs (le, f, t, args, ret);
3620 checkGlobMods (f, le, args, ret, special);
3621 checkRequiresClause (le, f, args);
3624 if (uentry_isValid (le)
3625 && (uentry_isFunction (le)
3626 || (uentry_isVariable (le)
3627 && ctype_isFunction (uentry_getType (le)))))
3629 exitkind exk = uentry_getExitCode (le);
3631 /* f->typ is already set to the return type */
3633 DPRINTF (("Function: %s", uentry_unparseFull (le)));
3634 ret->sref = uentry_returnedRef (le, args);
3635 DPRINTF (("Returned: %s / %s",
3636 uentry_unparseFull (le),
3637 sRef_unparseFull (ret->sref)));
3639 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3641 qual nullPred = uentry_nullPred (le);
3643 if (qual_isTrueNull (nullPred))
3645 exprNode arg = exprNodeList_head (args);
3647 if (exprNode_isDefined (arg))
3649 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3652 else if (qual_isFalseNull (nullPred))
3654 exprNode arg = exprNodeList_head (args);
3656 if (exprNode_isDefined (arg))
3658 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3663 llassert (qual_isUnknown (nullPred));
3667 if (exitkind_isConditionalExit (exk))
3671 ** if (arg0) then { exit! } else { ; }
3673 ** if (arg0) then { ; } else { exit! }
3678 llassert (!exprNodeList_isEmpty (args));
3679 firstArg = exprNodeList_head (args);
3681 if (exprNode_isDefined (firstArg)
3682 && !guardSet_isEmpty (firstArg->guards))
3684 usymtab_trueBranch (guardSet_undefined);
3685 usymtab_altBranch (guardSet_undefined);
3687 if (exitkind_isTrueExit (exk))
3689 usymtab_popBranches (firstArg,
3690 exprNode_makeMustExit (),
3692 TRUE, TRUEEXITCLAUSE);
3696 usymtab_popBranches (firstArg,
3698 exprNode_makeMustExit (),
3699 TRUE, FALSEEXITCLAUSE);
3703 ret->exitCode = XK_MAYEXIT;
3705 else if (exitkind_mustExit (exk))
3707 ret->exitCode = XK_MUSTEXIT;
3709 else if (exitkind_couldExit (exk))
3711 ret->exitCode = XK_MAYEXIT;
3718 if (cstring_equalLit (fname, "exit"))
3720 if (exprNodeList_size (args) == 1)
3722 exprNode arg = exprNodeList_head (args);
3724 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3726 long int val = multiVal_forceInt (exprNode_getValue (arg));
3733 ("Argument to exit has implementation defined behavior: %s",
3734 exprNode_unparse (arg)),
3735 exprNode_loc (arg));
3744 exprNode_checkSetAny (ret, uentry_rawName (le));
3747 DPRINTF (("Before reflect: %s", sRef_unparseFull (ret->sref)));
3748 DPRINTF (("Reflect: %s", uentry_unparseFull (le)));
3749 reflectEnsuresClause (ret, le, f, args);
3756 ** this is yucky! should keep the uentry as part of exprNode!
3759 uentry exprNode_getUentry (exprNode e)
3761 if (exprNode_isError (e))
3763 return uentry_undefined;
3767 cstring s = exprNode_rootVarName (e);
3768 uentry ue = usymtab_lookupSafe (s);
3775 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3777 exprNode ret = exprNode_createPlain (ctype_unknown);
3779 ret->kind = XPR_INITBLOCK;
3780 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3781 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3787 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3793 if (exprNode_isUndefined (f))
3796 exprNodeList_free (args);
3797 return exprNode_undefined;
3800 t = exprNode_getType (f);
3802 if (sRef_isLocalVar (f->sref))
3804 exprNode_checkUse (f, f->sref, f->loc);
3806 if (sRef_possiblyNull (f->sref))
3808 if (!usymtab_isGuarded (f->sref))
3810 if (optgenerror (FLG_NULLDEREF,
3811 message ("Function call using %s pointer %q",
3812 sRef_nullMessage (f->sref),
3813 sRef_unparse (f->sref)),
3816 sRef_showNullInfo (f->sref);
3817 sRef_setNullError (f->sref);
3825 if (ctype_isRealFunction (t))
3827 exprNode ret = functionCallSafe (f, t, args);
3831 else if (ctype_isUnknown (t))
3833 exprNode ret = exprNode_createPartialCopy (f);
3839 exprNodeList_elements (args, current)
3841 if (exprNode_isDefined (current))
3843 exprNode_checkUse (ret, current->sref, ret->loc);
3846 ** also, anything derivable from current->sref may be used
3849 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3850 exprNode_mergeUSs (ret, current);
3852 } end_exprNodeList_elements;
3854 ret->edata = exprData_makeCall (f, args);
3855 ret->kind = XPR_CALL;
3857 tstring = cstring_copy (exprNode_unparse (f));
3859 cstring_markOwned (tstring);
3860 exprNode_checkSetAny (ret, tstring);
3866 voptgenerror (FLG_TYPE,
3867 message ("Call to non-function (type %t): %s", t,
3868 exprNode_unparse (f)),
3871 exprNodeList_free (args);
3873 return (exprNode_makeError ());
3878 exprNode_fieldAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
3879 /*@only@*/ cstring f)
3881 exprNode ret = exprNode_createPartialCopy (s);
3883 ret->kind = XPR_FACCESS;
3885 if (exprNode_isError (s))
3887 ret->edata = exprData_makeField (s, f);
3892 ctype t = exprNode_getType (s);
3893 ctype tr = ctype_realType (t);
3895 checkMacroParen (s);
3897 ret->edata = exprData_makeField (s, f);
3899 if (ctype_isStructorUnion (tr))
3901 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
3903 if (uentry_isUndefined (tf))
3905 voptgenerror (FLG_TYPE,
3906 message ("Access non-existent field %s of %t: %s", f, t,
3907 exprNode_unparse (ret)),
3909 /*! cstring_free (f); */ /* evans 2001-03-25 self-detect */
3914 uentry_setUsed (tf, exprNode_loc (ret));
3916 ret->typ = uentry_getType (tf);
3917 checkSafeUse (ret, s->sref);
3919 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
3920 /*!? exprNode_free (s); */ /* evans 2001-03-25 self-detect */
3924 else /* isStructorUnion */
3926 if (ctype_isRealAbstract (tr))
3930 message ("Access field of abstract type (%t): %s.%s",
3931 t, exprNode_unparse (s), f),
3933 ret->typ = ctype_unknown;
3937 if (ctype_isKnown (tr))
3942 ("Access field of non-struct or union (%t): %s.%s",
3943 t, exprNode_unparse (s), f),
3946 ret->typ = ctype_unknown;
3950 cstring sn = cstring_copy (f);
3952 checkSafeUse (ret, s->sref);
3953 cstring_markOwned (sn);
3954 ret->sref = sRef_makeField (s->sref, sn);
3966 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ lltok dot,
3967 /*@only@*/ cstring f)
3969 exprNode res = exprNode_fieldAccessAux (s, lltok_getLoc (dot), f);
3970 lltok_release (dot);
3975 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
3977 exprNode ret = exprNode_createPartialCopy (e);
3979 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
3980 ret->kind = XPR_PARENS;
3981 ret->edata = exprData_makeUop (e, lpar);
3983 if (!exprNode_isError (e))
3985 ret->exitCode = e->exitCode;
3986 ret->canBreak = e->canBreak;
3987 ret->mustBreak = e->mustBreak;
3988 ret->isJumpPoint = e->isJumpPoint;
3989 ret->sref = e->sref;
3996 exprNode_arrowAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
3997 /*@only@*/ cstring f)
3999 exprNode ret = exprNode_createPartialCopy (s);
4001 ret->edata = exprData_makeField (s, f);
4002 ret->kind = XPR_ARROW;
4004 if (exprNode_isError (s))
4010 ctype t = exprNode_getType (s);
4011 ctype tr = ctype_realType (t);
4013 checkMacroParen (s);
4015 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
4017 if (ctype_isRealPointer (tr))
4019 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
4021 if (ctype_isStructorUnion (b))
4023 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4025 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
4027 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
4031 message ("Arrow access from %s pointer%q: %s",
4032 sRef_nullMessage (s->sref),
4033 sRef_unparsePreOpt (s->sref),
4034 exprNode_unparse (ret)),
4037 sRef_showNullInfo (s->sref);
4038 sRef_setNullError (s->sref);
4043 if (uentry_isUndefined (fentry))
4047 message ("Access non-existent field %s of %t: %s",
4048 f, t, exprNode_unparse (ret)),
4050 ret->typ = ctype_unknown;
4056 ** was safeUse: shouldn't be safe!
4059 ** rec must be defined,
4060 ** *rec must be allocated
4061 ** rec->field need only be defined it if is an rvalue
4064 uentry_setUsed (fentry, exprNode_loc (ret));
4065 ret->typ = uentry_getType (fentry);
4067 exprNode_checkUse (ret, s->sref, s->loc);
4069 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
4070 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4074 else /* Pointer to something that is not a struct or union*/
4076 if (ctype_isRealAbstract (tr))
4078 ctype xrt = ctype_forceRealType (tr);
4082 message ("Arrow access field of abstract type (%t): %s->%s",
4083 t, exprNode_unparse (s), f),
4087 ** Set the state correctly, as if the abstraction is broken.
4090 if (ctype_isRealPointer (xrt) &&
4091 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
4092 ctype_isStructorUnion (b)))
4094 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4095 ret->typ = uentry_getType (fentry);
4096 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4100 ret->typ = ctype_unknown;
4101 ret->sref = sRef_undefined;
4104 else /* not a struct, union or abstract */
4106 if (ctype_isUnknown (tr)) {
4107 cstring sn = cstring_copy (f);
4109 DPRINTF (("Here: %s", exprNode_unparse (s)));
4111 exprNode_checkUse (ret, s->sref, s->loc);
4112 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4114 cstring_markOwned (sn);
4115 ret->sref = sRef_makeArrow (s->sref, sn);
4117 ret->kind = XPR_ARROW;
4122 message ("Arrow access field of non-struct or union "
4123 "pointer (%t): %s->%s",
4124 t, exprNode_unparse (s), f),
4127 ret->typ = ctype_unknown;
4128 ret->sref = sRef_undefined;
4133 else /* its not a pointer */
4135 if (!ctype_isUnknown (tr))
4139 message ("Arrow access of non-pointer (%t): %s->%s",
4140 t, exprNode_unparse (s), f),
4143 ret->typ = ctype_unknown;
4144 ret->sref = sRef_undefined;
4148 cstring sn = cstring_copy (f);
4150 DPRINTF (("Here: %s", exprNode_unparse (s)));
4152 exprNode_checkUse (ret, s->sref, s->loc);
4153 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4155 cstring_markOwned (sn);
4156 ret->sref = sRef_makeArrow (s->sref, sn);
4158 ret->kind = XPR_ARROW;
4169 exprNode_arrowAccess (/*@only@*/ exprNode s,
4170 /*@only@*/ lltok arrow,
4171 /*@only@*/ cstring f)
4173 exprNode res = exprNode_arrowAccessAux (s, lltok_getLoc (arrow), f);
4174 lltok_release (arrow);
4179 ** only postOp's in C: i++ and i--
4183 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4185 /* check modification also */
4186 /* cstring opname = lltok_unparse (op);*/
4188 exprNode ret = exprNode_createPartialCopy (e);
4190 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4191 ret->kind = XPR_POSTOP;
4192 ret->edata = exprData_makeUop (e, op);
4194 if (!exprNode_isDefined (e))
4199 checkMacroParen (e);
4201 exprNode_checkUse (ret, e->sref, e->loc);
4202 exprNode_checkSet (ret, e->sref);
4204 t = exprNode_getType (e);
4206 if (sRef_isUnsafe (e->sref))
4208 voptgenerror (FLG_MACROPARAMS,
4209 message ("Operand of %s is macro parameter (non-functional): %s%s",
4210 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
4212 sRef_makeSafe (e->sref);
4213 sRef_makeSafe (ret->sref);
4216 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
4222 if (ctype_isRealAbstract (t))
4226 message ("Operand of %s is abstract type (%t): %s",
4227 lltok_unparse (op), t, exprNode_unparse (e)),
4234 message ("Operand of %s is non-numeric (%t): %s",
4235 lltok_unparse (op), t, exprNode_unparse (e)),
4238 ret->typ = ctype_unknown;
4241 /* if (ctype_isZero (t)) e->typ = ctype_int; */
4243 exprNode_checkModify (e, ret);
4245 /* added 7/11/2000 D.L */
4247 /*DRL 6/8/01 I decided to disable all LCLint Warning here since the code
4248 probably needs a rewrite any way */
4253 /* updateEnvironmentForPostOp (e); */
4255 /* start modifications */
4256 /* added by Seejo on 4/16/2000 */
4258 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4260 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4262 ret->sref = sRef_copy (e->sref);
4265 if (lltok_getTok (op) == INC_OP) {
4266 if (sRef_getSize(e->sref) > 0) {
4268 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4270 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4271 /* Assumption: there is only 1 \0 in the buffer */
4272 /* This will not be correct if there are 2 \0's in the buffer */
4273 sRef_setNotNullTerminatedState(ret->sref);
4274 sRef_resetLen(ret->sref);
4276 sRef_setNullTerminatedState(ret->sref);
4277 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4279 if (sRef_isNullTerminated (ret->sref))
4280 printf ("ret->sref is Null Terminated\n");
4281 else if (sRef_isPossiblyNullTerminated (ret->sref))
4282 printf ("ret->sref is Possibly Null Terminated\n");
4283 else if (sRef_isNotNullTerminated (ret->sref))
4284 printf ("ret->sref is Not Null Terminated\n");
4289 if (lltok_getTok (op) == DEC_OP) {
4290 if (sRef_getSize(e->sref) >= 0) {
4291 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4292 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4297 /* end modifications */
4303 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4305 bool checkMod = FALSE;
4307 int opid = lltok_getTok (op);
4308 exprNode ret = exprNode_createSemiCopy (e);
4310 exprNode_copySets (ret, e);
4312 multiVal_free (ret->val);
4313 ret->val = multiVal_undefined;
4314 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4315 ret->kind = XPR_PREOP;
4316 ret->edata = exprData_makeUop (e, op);
4318 if (exprNode_isError (e))
4323 checkMacroParen (e);
4325 te = exprNode_getType (e);
4326 tr = ctype_realType (te);
4328 if (opid != TAMPERSAND)
4330 exprNode_checkUse (ret, e->sref, e->loc);
4332 if (ctype_isRealAbstract (tr)
4333 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
4335 if (optgenerror (FLG_ABSTRACT,
4336 message ("Operand of %s is abstract type (%t): %s",
4337 lltok_unparse (op), tr,
4338 exprNode_unparse (ret)),
4341 tr = te = ctype_unknown;
4342 ret->typ = ctype_unknown;
4343 sRef_setNullError (e->sref);
4351 case DEC_OP: /* should also check modification! */
4352 if (sRef_isMacroParamRef (e->sref))
4356 message ("Operand of %s is macro parameter (non-functional): %s",
4357 lltok_unparse (op), exprNode_unparse (ret)),
4362 exprNode_checkSet (ret, e->sref);
4365 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
4370 if (context_msgStrictOps ())
4374 message ("Operand of %s is non-numeric (%t): %s",
4375 lltok_unparse (op), te, exprNode_unparse (ret)),
4378 ret->typ = ctype_int;
4381 /* start modifications */
4382 /* added by Seejo on 4/16/2000 */
4384 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4386 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4388 ret->sref = sRef_copy (e->sref);
4391 if (lltok_getTok (op) == INC_OP) {
4392 if (sRef_getSize(e->sref) > 0) {
4394 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4396 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4397 /* Assumption: there is only 1 \0 in the buffer */
4398 /* This will not be correct if there are 2 \0's in the buffer */
4399 sRef_setNotNullTerminatedState(ret->sref);
4400 sRef_resetLen (ret->sref);
4402 sRef_setNullTerminatedState(ret->sref);
4403 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4409 if (lltok_getTok (op) == DEC_OP) {
4410 if (sRef_getSize(e->sref) >= 0) {
4411 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4412 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4417 /* end modifications */
4424 if (ctype_isForceRealNumeric (&tr))
4428 ret->val = multiVal_invert (exprNode_getValue (e));
4432 ret->val = multiVal_copy (exprNode_getValue (e));
4437 if (context_msgStrictOps ())
4441 message ("Operand of %s is non-numeric (%t): %s",
4442 lltok_unparse (op), te, exprNode_unparse (ret)),
4446 ret->typ = ctype_int;
4450 case TEXCL: /* maybe this should be restricted */
4451 guardSet_flip (ret->guards);
4453 if (ctype_isRealBool (te) || ctype_isUnknown (te))
4459 if (ctype_isRealPointer (tr))
4461 if (sRef_isKnown (e->sref))
4463 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
4467 (FLG_BOOLOPS, FLG_PTRNEGATE,
4468 message ("Operand of %s is non-boolean (%t): %s",
4469 lltok_unparse (op), te, exprNode_unparse (ret)),
4476 message ("Operand of %s is non-boolean (%t): %s",
4477 lltok_unparse (op), te, exprNode_unparse (ret)),
4481 ret->typ = ctype_bool;
4486 if (ctype_isForceRealInt (&tr))
4491 if (context_msgStrictOps ())
4495 message ("Operand of %s is non-integer (%t): %s",
4496 lltok_unparse (op), te, exprNode_unparse (ret)),
4500 if (ctype_isInt (e->typ))
4506 ret->typ = ctype_int;
4512 ret->typ = ctype_makePointer (e->typ);
4514 if (sRef_isKnown (e->sref))
4516 ret->sref = sRef_makeAddress (e->sref);
4523 if (ctype_isAP (tr))
4525 ret->typ = ctype_baseArrayPtr (e->typ);
4529 if (ctype_isKnown (te))
4531 if (ctype_isFunction (te))
4537 message ("Dereference of function type (%t): %s",
4538 te, exprNode_unparse (ret)),
4543 voptgenerror (FLG_TYPE,
4544 message ("Dereference of non-pointer (%t): %s",
4545 te, exprNode_unparse (ret)),
4547 ret->typ = ctype_unknown;
4552 ret->typ = ctype_unknown;
4557 if (sRef_isKnown (e->sref))
4559 if (sRef_possiblyNull (e->sref))
4561 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
4565 message ("Dereference of %s pointer %q: %s",
4566 sRef_nullMessage (e->sref),
4567 sRef_unparse (e->sref),
4568 exprNode_unparse (ret)),
4571 sRef_showNullInfo (e->sref);
4572 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
4577 ret->sref = sRef_makePointer (e->sref);
4582 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
4587 exprNode_checkModify (e, ret);
4594 ** any reason to disallow sizeof (abstract type) ?
4598 ** used by both sizeof
4602 ctype sizeof_resultType (void)
4604 static ctype sizet = ctype_unknown;
4606 if (ctype_isUnknown (sizet))
4608 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
4610 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
4614 sizet = ctype_ulint;
4621 exprNode_sizeofType (/*@only@*/ qtype qt)
4623 exprNode ret = exprNode_create (sizeof_resultType ());
4624 ctype ct = qtype_getType (qt);
4626 ret->kind = XPR_SIZEOFT;
4627 ret->edata = exprData_makeSizeofType (qt);
4629 voptgenerror (FLG_SIZEOFTYPE,
4630 message ("Parameter to sizeof is type %s: %s",
4632 exprNode_unparse (ret)),
4639 exprNode_alignofType (/*@only@*/ qtype qt)
4641 exprNode ret = exprNode_create (sizeof_resultType ());
4642 ctype ct = qtype_getType (qt);
4644 ret->kind = XPR_ALIGNOFT;
4645 ret->edata = exprData_makeSizeofType (qt);
4647 voptgenerror (FLG_SIZEOFTYPE,
4648 message ("Parameter to alignof is type %s: %s",
4650 exprNode_unparse (ret)),
4656 exprNode exprNode_offsetof (qtype qt, cstringList s)
4658 exprNode ret = exprNode_create (sizeof_resultType ());
4659 ctype ct = qtype_getType (qt);
4661 ret->kind = XPR_OFFSETOF;
4662 ret->edata = exprData_makeOffsetof (qt, s);
4664 if (!ctype_isRealSU (ct))
4666 voptgenerror (FLG_TYPE,
4667 message ("First parameter to offsetof is not a "
4668 "struct or union type (type %s): %s",
4670 exprNode_unparse (ret)),
4677 cstringList_elements (s, el) {
4681 if (ctype_isUndefined (lt))
4685 else if (!ctype_isRealSU (lt))
4687 voptgenerror (FLG_TYPE,
4688 message ("Inner offsetof type is not a "
4689 "struct or union type (type %s before field %s): %s",
4690 ctype_unparse (lt), el,
4691 exprNode_unparse (ret)),
4697 fields = ctype_getFields (ctype_realType (lt));
4698 fld = uentryList_lookupField (fields, el);
4699 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4701 if (uentry_isUndefined (fld))
4703 if (ctype_equal (lt, ct)) {
4704 voptgenerror (FLG_TYPE,
4705 message ("Field %s in offsetof is not the "
4706 "name of a field of %s: %s",
4709 exprNode_unparse (ret)),
4712 voptgenerror (FLG_TYPE,
4713 message ("Deep field %s in offsetof is not the "
4714 "name of a field of %s: %s",
4717 exprNode_unparse (ret)),
4723 lt = uentry_getType (fld);
4726 } end_cstringList_elements;
4728 /* Should report error if its a bit field - behavior is undefined! */
4735 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4739 if (exprNode_isUndefined (e))
4741 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4742 ret->edata = exprData_makeSingle (e);
4743 ret->typ = sizeof_resultType ();
4744 ret->kind = XPR_SIZEOF;
4748 uentry u = exprNode_getUentry (e);
4750 ret = exprNode_createPartialCopy (e);
4751 ret->edata = exprData_makeSingle (e);
4753 ret->typ = sizeof_resultType ();
4754 ret->kind = XPR_SIZEOF;
4756 if (uentry_isValid (u)
4757 && uentry_isRefParam (u)
4758 && ctype_isRealArray (uentry_getType (u)))
4761 (FLG_SIZEOFFORMALARRAY,
4762 message ("Parameter to sizeof is an array-type function parameter: %s",
4763 exprNode_unparse (ret)),
4769 ** sizeof (x) doesn't "really" use x
4776 exprNode_alignofExpr (/*@only@*/ exprNode e)
4780 if (exprNode_isUndefined (e))
4782 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4786 ret = exprNode_createPartialCopy (e);
4789 ret->edata = exprData_makeSingle (e);
4790 ret->typ = sizeof_resultType ();
4791 ret->kind = XPR_ALIGNOF;
4794 ** sizeof (x) doesn't "really" use x
4801 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4807 if (exprNode_isError (e))
4810 lltok_release (tok);
4811 return exprNode_undefined;
4814 checkMacroParen (e);
4816 c = qtype_getType (q);
4817 t = exprNode_getType (e);
4819 ret = exprNode_createPartialCopy (e);
4821 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
4823 ret->kind = XPR_CAST;
4824 ret->edata = exprData_makeCast (tok, e, q);
4826 if (ctype_isRealSU (ctype_getBaseType (sRef_getType (e->sref))))
4829 ** This is a bit of a hack to avoid a problem
4830 ** when the code does,
4831 ** (some other struct) x
4836 ret->sref = sRef_copy (e->sref);
4837 usymtab_addForceMustAlias (ret->sref, e->sref);
4838 sRef_setTypeFull (ret->sref, c);
4839 DPRINTF (("Cast: %s -> %s", sRef_unparseFull (e->sref),
4840 sRef_unparseFull (ret->sref)));
4844 ret->sref = e->sref;
4845 sRef_setTypeFull (ret->sref, c);
4846 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
4853 ** void * <-> abstract * (if FLG_ABSTVOIDP)
4854 ** abstract * <-> void * (if FLG_ABSTVOIDP)
4857 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
4861 else if (ctype_isRealAP (c)) /* casting to array or pointer */
4863 ctype bc = ctype_getBaseType (c);
4864 ctype bt = ctype_getBaseType (t);
4865 ctype rt = ctype_realType (t);
4867 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
4868 && (ctype_isArrayPtr (rt)
4869 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4873 message ("Cast from function pointer type (%t) to "
4874 "non-function pointer (%t): %s",
4875 c, t, exprNode_unparse (ret)),
4879 if (!ctype_isFunction (ctype_baseArrayPtr (c))
4880 && (ctype_isArrayPtr (rt)
4881 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4885 message ("Cast from non-function pointer type (%t) to "
4886 "function pointer (%t): %s",
4887 c, t, exprNode_unparse (ret)),
4891 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
4892 !(ctype_isRealAbstract (bc)
4893 && context_hasAccess (ctype_typeId (bc))))
4895 ; /* okay to cast zero */
4899 if (ctype_isRealAbstract (bc)
4900 && !context_hasAccess (ctype_typeId (bc)))
4902 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
4906 message ("Cast to underlying abstract type %t: %s",
4907 c, exprNode_unparse (ret)),
4914 message ("Cast to underlying abstract type %t: %s",
4915 c, exprNode_unparse (ret)),
4920 if (ctype_isRealAbstract (bt)
4921 && !context_hasAccess (ctype_typeId (bt)))
4923 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
4927 message ("Cast from underlying abstract type %t: %s",
4928 t, exprNode_unparse (ret)),
4935 message ("Cast from underlying abstract type %t: %s",
4936 t, exprNode_unparse (ret)),
4944 ctype bt = ctype_realType (ctype_getBaseType (t));
4945 ctype bc = ctype_realType (ctype_getBaseType (c));
4947 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
4949 if (ctype_match (c, t))
4951 if (ctype_equal (c, t))
4955 message ("Redundant cast involving abstract type %t: %s",
4956 bt, exprNode_unparse (ret)),
4964 message ("Cast from abstract type %t: %s",
4965 bt, exprNode_unparse (ret)),
4970 if (ctype_isAbstract (bc)
4971 && !context_hasAccess (ctype_typeId (bc)))
4973 if (ctype_match (c, t))
4979 DPRINTF (("No access to: %s / %d",
4980 ctype_unparse (bc), ctype_typeId (bc)));
4981 DPRINTF (("Context %s %s",
4982 bool_unparse (context_inFunctionLike ()),
4983 context_unparse ()));
4986 message ("Cast to abstract type %t: %s", bc,
4987 exprNode_unparse (ret)),
4993 if (ctype_isAbstract (c))
4995 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
4997 /* okay, cast exposed to abstract */
4998 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
5002 if (ctype_isVisiblySharable (t)
5003 && sRef_isExternallyVisible (e->sref)
5004 && !(ctype_isAbstract (t)
5005 && context_hasAccess (ctype_typeId (t))))
5009 message ("Cast to abstract type from externally visible "
5010 "mutable storage exposes rep of %s: %s",
5012 exprNode_unparse (e)),
5022 evaluationOrderUndefined (lltok op)
5024 int opid = lltok_getTok (op);
5026 return (opid != AND_OP && opid != OR_OP);
5029 static bool checkIntegral (/*@notnull@*/ exprNode e1,
5030 /*@notnull@*/ exprNode e2,
5031 /*@notnull@*/ exprNode ret,
5036 ctype te1 = exprNode_getType (e1);
5037 ctype te2 = exprNode_getType (e2);
5039 ctype tr1 = ctype_realishType (te1);
5040 ctype tr2 = ctype_realishType (te2);
5042 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
5048 if (context_msgStrictOps ())
5050 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
5052 if (ctype_sameName (te1, te2))
5056 message ("Operands of %s are non-integer (%t): %s",
5057 lltok_unparse (op), te1,
5058 exprNode_unparse (ret)),
5065 message ("Operands of %s are non-integers (%t, %t): %s",
5066 lltok_unparse (op), te1, te2,
5067 exprNode_unparse (ret)),
5071 else if (!ctype_isInt (tr1))
5075 message ("Left operand of %s is non-integer (%t): %s",
5076 lltok_unparse (op), te1, exprNode_unparse (ret)),
5080 /* !ctype_isInt (te2) */
5084 message ("Right operand of %s is non-integer (%t): %s",
5085 lltok_unparse (op), te2, exprNode_unparse (ret)),
5095 ** returns exprNode representing e1 op e2
5097 ** uses msg if there are errors
5098 ** can be used for both assignment ops and regular ops
5103 static /*@only@*/ /*@notnull@*/ exprNode
5104 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
5105 /*@keep@*/ lltok op)
5107 ctype te1, te2, tr1, tr2, tret;
5108 int opid = lltok_getTok (op);
5109 bool hasError = FALSE;
5112 if (exprNode_isError (e1))
5114 ret = exprNode_createPartialNVCopy (e2);
5118 ret = exprNode_createPartialNVCopy (e1);
5121 ret->val = multiVal_undefined;
5123 ret->edata = exprData_makeOp (e1, e2, op);
5125 if (exprNode_isError (e1) || exprNode_isError (e2))
5127 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5128 || opid == EQ_OP || opid == NE_OP
5129 || opid == AND_OP || opid == OR_OP)
5131 ret->typ = ctype_bool;
5134 if (exprNode_isDefined (e1))
5136 exprNode_checkUse (ret, e1->sref, e1->loc);
5139 if (exprNode_isDefined (e2))
5141 exprNode_mergeUSs (ret, e2);
5142 exprNode_checkUse (ret, e2->sref, e2->loc);
5148 tret = ctype_unknown;
5149 te1 = exprNode_getType (e1);
5150 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
5152 te2 = exprNode_getType (e2);
5154 tr1 = ctype_realishType (te1);
5155 tr2 = ctype_realishType (te2);
5159 ret->guards = guardSet_or (ret->guards, e2->guards);
5161 else if (opid == AND_OP)
5163 ret->guards = guardSet_and (ret->guards, e2->guards);
5170 if (opid == EQ_OP || opid == NE_OP)
5172 exprNode temp1 = e1, temp2 = e2;
5174 /* could do NULL == x */
5176 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
5178 temp1 = e2; temp2 = e1;
5181 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
5183 reflectNullTest (temp1, (opid == NE_OP));
5184 guardSet_free (ret->guards);
5185 ret->guards = guardSet_copy (temp1->guards);
5189 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5190 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
5195 if (anyAbstract (tr1, tr2) &&
5196 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
5197 (opid == AND_OP || opid == OR_OP
5198 || opid == EQ_OP || opid == NE_OP))))
5200 abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc);
5202 else if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
5204 /* unknown types, no comparisons possible */
5210 case TMULT: /* multiplication and division: */
5212 case MUL_ASSIGN: /* numeric, numeric -> numeric */
5213 case DIV_ASSIGN: /* */
5215 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5218 case TPLUS: /* addition and subtraction: */
5219 case TMINUS: /* pointer, int -> pointer */
5220 case SUB_ASSIGN: /* int, pointer -> pointer */
5221 case ADD_ASSIGN: /* numeric, numeric -> numeric */
5223 tr1 = ctype_fixArrayPtr (tr1);
5225 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
5226 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
5230 if (context_msgPointerArith ())
5234 message ("Pointer arithmetic (%t, %t): %s",
5235 te1, te2, exprNode_unparse (ret)),
5240 ** Swap terms so e1 is always the pointer
5243 if (ctype_isRealPointer (tr1))
5249 exprNode_swap (e1, e2);
5253 if (sRef_possiblyNull (e1->sref)
5254 && !usymtab_isGuarded (e1->sref))
5257 (FLG_NULLPOINTERARITH,
5258 message ("Pointer arithmetic involving possibly "
5259 "null pointer %s: %s",
5260 exprNode_unparse (e1),
5261 exprNode_unparse (ret)),
5265 ret->sref = sRef_copy (e1->sref);
5267 /* start modifications */
5268 /* added by Seejo on 4/16/2000 */
5270 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5272 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
5275 added ugly fixed to stop
5276 program from crashing on point + int +int
5277 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
5279 if (!multiVal_isInt (e2->val) )
5283 val = (int) multiVal_forceInt (e2->val);
5285 /* Operator : + or += */
5286 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5287 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
5288 val should not result in a
5289 size < 0 (size = 0 is ok !) */
5291 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
5293 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
5294 sRef_setNotNullTerminatedState(ret->sref);
5295 sRef_resetLen (ret->sref);
5297 sRef_setNullTerminatedState(ret->sref);
5298 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
5303 /* Operator : - or -= */
5304 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5305 if (sRef_getSize(e1->sref) >= 0) {
5306 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
5307 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
5312 /* end modifications */
5314 sRef_setNullError (ret->sref);
5317 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5318 ** since is points to storage that should not be deallocated
5319 ** through this pointer.
5322 if (sRef_isOnly (ret->sref)
5323 || sRef_isFresh (ret->sref))
5325 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5330 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
5331 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
5333 if (context_msgPointerArith ())
5337 message ("Pointer arithmetic (%t, %t): %s",
5338 te1, te2, exprNode_unparse (ret)),
5342 if (sRef_possiblyNull (e1->sref)
5343 && !usymtab_isGuarded (e1->sref))
5346 (FLG_NULLPOINTERARITH,
5347 message ("Pointer arithmetic involving possibly "
5348 "null pointer %s: %s",
5349 exprNode_unparse (e2),
5350 exprNode_unparse (ret)),
5354 ret->sref = sRef_copy (e2->sref);
5356 /* start modifications */
5357 /* added by Seejo on 4/16/2000 */
5359 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5362 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
5363 int val = (int) multiVal_forceInt (e1->val);
5365 /* Operator : + or += */
5366 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5367 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
5368 val should not result in a
5369 size < 0 (size = 0 is ok !) */
5371 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
5373 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
5374 sRef_setNotNullTerminatedState(ret->sref);
5375 sRef_resetLen (ret->sref);
5377 sRef_setNullTerminatedState(ret->sref);
5378 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
5383 /* Operator : - or -= */
5384 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5385 if (sRef_getSize(e2->sref) >= 0) {
5386 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
5387 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
5392 /* end modifications */
5394 sRef_setNullError (ret->sref);
5397 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5398 ** since is points to storage that should not be deallocated
5399 ** through this pointer.
5402 if (sRef_isOnly (ret->sref)
5403 || sRef_isFresh (ret->sref)) {
5404 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5408 ret->sref = e2->sref;
5412 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5417 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
5421 case TAMPERSAND: /* bitwise & */
5423 case TCIRC: /* ^ (XOR) */
5428 bool reported = FALSE;
5429 flagcode code = FLG_BITWISEOPS;
5431 if (opid == LEFT_OP || opid == LEFT_ASSIGN
5432 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
5433 code = FLG_SHIFTSIGNED;
5436 if (!ctype_isUnsigned (tr1))
5438 if (exprNode_isNonNegative (e1)) {
5441 reported = optgenerror
5443 message ("Left operand of %s is not unsigned value (%t): %s",
5444 lltok_unparse (op), te1,
5445 exprNode_unparse (ret)),
5455 /* right need not be signed for shifts */
5456 if (code != FLG_SHIFTSIGNED
5457 && !ctype_isUnsigned (tr2))
5459 if (!exprNode_isNonNegative (e2)) {
5460 reported = optgenerror
5462 message ("Right operand of %s is not unsigned value (%t): %s",
5463 lltok_unparse (op), te2,
5464 exprNode_unparse (ret)),
5472 if (!checkIntegral (e1, e2, ret, op)) {
5473 te1 = ctype_unknown;
5477 DPRINTF (("Set: %s", ctype_unparse (te1)));
5480 ** tret is the widest type of te1 and te2
5483 tret = ctype_widest (te1, te2);
5488 if (checkIntegral (e1, e2, ret, op)) {
5491 tret = ctype_unknown;
5496 case TLT: /* comparisons */
5497 case TGT: /* numeric, numeric -> bool */
5498 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
5499 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
5502 bool fepsilon = FALSE;
5504 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
5509 if (opid == TLT || opid == TGT)
5511 uentry ue1 = exprNode_getUentry (e1);
5512 uentry ue2 = exprNode_getUentry (e2);
5515 ** FLT_EPSILON, etc. really is a variable, not
5519 if (uentry_isVariable (ue1))
5521 cstring uname = uentry_rawName (ue1);
5523 if (cstring_equalLit (uname, "FLT_EPSILON")
5524 || cstring_equalLit (uname, "DBL_EPSILON")
5525 || cstring_equalLit (uname, "LDBL_EPSILON"))
5531 if (uentry_isVariable (ue2))
5533 cstring uname = uentry_rawName (ue2);
5535 if (cstring_equalLit (uname, "FLT_EPSILON")
5536 || cstring_equalLit (uname, "DBL_EPSILON")
5537 || cstring_equalLit (uname, "LDBL_EPSILON"))
5546 ; /* Don't complain. */
5552 message ("Dangerous comparison involving %s types: %s",
5553 ctype_unparse (rtype),
5554 exprNode_unparse (ret)),
5563 ** Types should match.
5566 if (!exprNode_matchTypes (e1, e2))
5568 hasError = gentypeerror
5570 message ("Operands of %s have incompatible types (%t, %t): %s",
5571 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5577 || (ctype_isForceRealNumeric (&tr1)
5578 && ctype_isForceRealNumeric (&tr2)) ||
5579 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
5585 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
5586 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
5590 message ("Comparison of pointer and numeric (%t, %t): %s",
5591 te1, te2, exprNode_unparse (ret)),
5596 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5601 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
5603 if ((opid == EQ_OP || opid == NE_OP) &&
5604 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
5607 ** is one a variable?
5610 if (uentry_isVariable (exprNode_getUentry (e1))
5611 || uentry_isVariable (exprNode_getUentry (e2)))
5614 ** comparisons with FALSE are okay
5617 if (exprNode_isFalseConstant (e1)
5618 || exprNode_isFalseConstant (e2))
5627 ("Use of %q with %s variables (risks inconsistency because "
5628 "of multiple true values): %s",
5629 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
5630 context_printBoolName (), exprNode_unparse (ret)),
5637 case AND_OP: /* bool, bool -> bool */
5640 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
5646 if (context_maybeSet (FLG_BOOLOPS))
5648 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
5650 if (ctype_sameName (te1, te2))
5654 message ("Operands of %s are non-boolean (%t): %s",
5655 lltok_unparse (op), te1,
5656 exprNode_unparse (ret)),
5664 ("Operands of %s are non-booleans (%t, %t): %s",
5665 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5669 else if (!ctype_isRealBool (te1))
5673 message ("Left operand of %s is non-boolean (%t): %s",
5674 lltok_unparse (op), te1, exprNode_unparse (ret)),
5677 else if (!ctype_isRealBool (te2))
5681 message ("Right operand of %s is non-boolean (%t): %s",
5682 lltok_unparse (op), te2, exprNode_unparse (ret)),
5695 (cstring_makeLiteral
5696 ("There has been a problem in the parser. This is believed to result "
5697 "from a problem with bison v. 1.25. Please try rebuidling LCLint "
5698 "using the pre-compiled grammar files by commenting out the "
5699 "BISON= line in the top-level Makefile."));
5704 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5707 exprNode_checkUse (ret, e1->sref, e1->loc);
5708 exprNode_mergeUSs (ret, e2);
5709 exprNode_checkUse (ret, e2->sref, e2->loc);
5715 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5716 /*@only@*/ lltok op)
5720 checkMacroParen (e1);
5721 checkMacroParen (e2);
5723 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5725 checkExpressionDefined (e1, e2, op);
5728 ret = exprNode_makeOp (e1, e2, op);
5733 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5736 ** This is somewhat bogus!
5738 ** Assigning to a nested observer in a non-observer datatype
5739 ** should not produce an error.
5742 sRef ref = exprNode_getSref (e1);
5744 DPRINTF (("Check assign mod: %s",
5745 sRef_unparseFull (ref)));
5747 if (sRef_isObserver (ref)
5748 || ((sRef_isFileStatic (ref) || sRef_isFileOrGlobalScope (ref))
5749 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5751 sRef base = sRef_getBase (ref);
5753 if (sRef_isValid (base) && sRef_isObserver (base))
5755 exprNode_checkModify (e1, ret);
5759 exprNode_checkModifyVal (e1, ret);
5764 exprNode_checkModify (e1, ret);
5769 exprNode_assign (/*@only@*/ exprNode e1,
5770 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5772 bool isalloc = FALSE;
5773 bool isjustalloc = FALSE;
5776 DPRINTF (("%s [%s] <- %s [%s]",
5777 exprNode_unparse (e1),
5778 ctype_unparse (e1->typ),
5779 exprNode_unparse (e2),
5780 ctype_unparse (e2->typ)));
5782 if (lltok_getTok (op) != TASSIGN)
5784 ret = exprNode_makeOp (e1, e2, op);
5788 ret = exprNode_createPartialCopy (e1);
5789 ret->kind = XPR_ASSIGN;
5790 ret->edata = exprData_makeOp (e1, e2, op);
5792 if (!exprNode_isError (e2))
5794 ret->sets = sRefSet_union (ret->sets, e2->sets);
5795 ret->msets = sRefSet_union (ret->msets, e2->msets);
5796 ret->uses = sRefSet_union (ret->uses, e2->uses);
5800 checkExpressionDefined (e1, e2, op);
5802 if (exprNode_isError (e1))
5804 if (!exprNode_isError (e2))
5806 ret->loc = fileloc_update (ret->loc, e2->loc);
5810 ret->loc = fileloc_update (ret->loc, g_currentloc);
5814 if (!exprNode_isError (e2))
5816 checkMacroParen (e2);
5819 if (exprNode_isDefined (e1))
5821 if (sRef_isMacroParamRef (e1->sref))
5823 if (context_inIterDef ())
5825 uentry ue = sRef_getUentry (e1->sref);
5827 if (uentry_isYield (ue))
5833 if (fileloc_isDefined (e1->loc))
5837 message ("Assignment to non-yield iter parameter: %q",
5838 sRef_unparse (e1->sref)),
5845 message ("Assignment to non-yield iter parameter: %q",
5846 sRef_unparse (e1->sref)),
5853 if (fileloc_isDefined (e1->loc))
5857 message ("Assignment to macro parameter: %q",
5858 sRef_unparse (e1->sref)),
5865 message ("Assignment to macro parameter: %q",
5866 sRef_unparse (e1->sref)),
5870 exprNode_checkAssignMod (e1, ret); /* evans 2001-07-22 */
5875 exprNode_checkAssignMod (e1, ret);
5878 if (exprNode_isDefined (e2))
5880 if (lltok_getTok (op) == TASSIGN)
5882 ctype te1 = exprNode_getType (e1);
5883 ctype te2 = exprNode_getType (e2);
5885 if (!ctype_forceMatch (te1, te2))
5887 if (exprNode_matchLiteral (te1, e2))
5895 message ("Assignment of %t to %t: %s %s %s",
5896 te2, te1, exprNode_unparse (e1),
5898 exprNode_unparse (e2)),
5904 exprNode_mergeUSs (ret, e2);
5905 exprNode_checkUse (ret, e2->sref, e2->loc);
5907 doAssign (e1, e2, FALSE);
5908 ret->sref = e1->sref;
5912 if (exprNode_isDefined (e2))
5914 exprNode_mergeUSs (ret, e2);
5915 exprNode_checkUse (ret, e2->sref, e2->loc);
5919 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5921 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5924 isjustalloc = sRef_isJustAllocated (e1->sref);
5925 isalloc = sRef_isAllocated (e1->sref);
5927 if (sRef_isField (e1->sref))
5929 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5931 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5933 exprNode_checkUse (ret, root, e1->loc);
5939 ** be careful! this defines e1->sref.
5942 /* evans 2001-07-22: removed if (!sRef_isMacroParamRef (e1->sref)) */
5944 exprNode_checkSet (ret, e1->sref);
5948 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5949 ? e2->loc : e1->loc);
5955 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5964 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5965 /*@keep@*/ exprNode elseclause)
5969 if (!exprNode_isError (pred))
5971 ret = exprNode_createPartialCopy (pred);
5972 checkMacroParen (pred);
5973 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
5975 if (!exprNode_isError (ifclause))
5977 checkMacroParen (ifclause); /* update macro counts! */
5979 if (!exprNode_isError (elseclause))
5981 checkMacroParen (elseclause);
5983 if (!exprNode_matchTypes (ifclause, elseclause))
5986 (exprNode_getType (ifclause),
5988 exprNode_getType (elseclause),
5990 message ("Conditional clauses are not of same type: "
5992 exprNode_unparse (ifclause),
5993 exprNode_getType (ifclause),
5994 exprNode_unparse (elseclause),
5995 exprNode_getType (elseclause)),
5998 ret->sref = sRef_undefined;
5999 ret->typ = ctype_unknown;
6004 /* for now...should merge the states */
6005 ret->sref = ifclause->sref;
6006 ret->typ = ifclause->typ;
6008 if (exprNode_isNullValue (ifclause))
6010 ret->typ = elseclause->typ;
6014 exprNode_checkUse (ret, pred->sref, pred->loc);
6015 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6016 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6018 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6023 ret->typ = ifclause->typ;
6025 exprNode_checkUse (pred, pred->sref, pred->loc);
6026 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6028 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
6033 if (!exprNode_isError (elseclause))
6035 ret->typ = elseclause->typ;
6037 exprNode_checkUse (pred, pred->sref, pred->loc);
6038 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6040 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6044 else /* pred is error */
6046 if (!exprNode_isError (ifclause))
6048 ret = exprNode_createSemiCopy (ifclause);
6050 checkMacroParen (ifclause); /* update macro counts! */
6052 if (!exprNode_isError (elseclause))
6054 checkMacroParen (elseclause);
6056 ret->typ = ifclause->typ;
6058 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
6061 (exprNode_getType (ifclause),
6063 exprNode_getType (elseclause),
6065 message ("Conditional clauses are not of same type: "
6067 exprNode_unparse (ifclause),
6068 exprNode_getType (ifclause),
6069 exprNode_unparse (elseclause),
6070 exprNode_getType (elseclause)),
6073 ret->typ = ctype_unknown;
6077 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6078 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6080 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6083 else if (!exprNode_isError (elseclause)) /* pred, if errors */
6085 ret = exprNode_createSemiCopy (ifclause);
6087 ret->typ = elseclause->typ;
6088 checkMacroParen (elseclause);
6090 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6091 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6093 else /* all errors! */
6095 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6099 ret->kind = XPR_COND;
6100 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
6102 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
6104 exprNode_combineControl (ret, ifclause, elseclause);
6111 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
6113 ctype totype = qtype_getType (qt);
6115 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
6119 ** check use of va_arg : <valist>, type -> type
6122 if (exprNode_isError (arg))
6127 targ = exprNode_getType (arg);
6130 ** arg should have be a pointer
6133 if (!ctype_isUA (targ) ||
6134 (!usymId_equal (ctype_typeId (targ),
6135 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
6139 message ("First argument to va_arg is not a va_list (type %t): %s",
6140 targ, exprNode_unparse (arg)),
6144 exprNode_checkSet (ret, arg->sref);
6148 ** return type is totype
6152 ret->kind = XPR_VAARG;
6153 ret->edata = exprData_makeCast (tok, arg, qt);
6158 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
6160 exprNode ret = exprNode_createPlain (ctype_undefined);
6161 ret->kind = XPR_LABEL;
6162 ret->edata = exprData_makeLiteral (label);
6163 ret->isJumpPoint = TRUE;
6165 return (ret); /* for now, ignore label */
6168 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
6170 if (exprNode_isDefined (stmt))
6172 stmt->isJumpPoint = TRUE;
6174 /* This prevent stray no return path errors, etc. */
6175 stmt->exitCode = XK_MUSTEXIT;
6181 bool exprNode_isDefaultMarker (exprNode e)
6183 if (exprNode_isDefined (e))
6185 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
6191 bool exprNode_isCaseMarker (exprNode e)
6193 if (exprNode_isDefined (e))
6195 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
6201 bool exprNode_isLabelMarker (exprNode e)
6203 if (exprNode_isDefined (e))
6205 return (e->kind == XPR_LABEL);
6211 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
6213 exprNode ret = exprNode_createPartialCopy (test);
6215 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6217 if (exprNode_isError (test)) {
6221 exprNode_checkUse (ret, test->sref, test->loc);
6223 usymtab_setExitCode (ret->exitCode);
6227 usymtab_setMustBreak ();
6230 ret->edata = exprData_makeSingle (test);
6231 ret->isJumpPoint = TRUE;
6237 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
6239 exprNode ret = exprNode_createPartialCopy (test);
6241 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6242 ret->edata = exprData_makePair (test, stmt);
6243 ret->isJumpPoint = TRUE;
6245 if (exprNode_isError (test))
6250 exprNode_checkUse (ret, test->sref, test->loc);
6252 if (exprNode_isError (stmt))
6257 exprNode_mergeUSs (ret, stmt);
6259 ret->exitCode = stmt->exitCode;
6260 ret->mustBreak = stmt->mustBreak;
6261 ret->canBreak = stmt->canBreak;
6263 usymtab_setExitCode (ret->exitCode);
6267 usymtab_setMustBreak ();
6274 /*@notnull@*/ /*@only@*/ exprNode
6275 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
6277 exprNode ret = exprNode_createTok (def);
6279 ret->isJumpPoint = TRUE;
6280 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
6285 exprNode_mayEscape (exprNode e)
6287 if (exprNode_isDefined (e))
6289 return exitkind_couldEscape (e->exitCode);
6295 exprNode_mustBreak (exprNode e)
6297 if (exprNode_isDefined (e))
6299 return e->mustBreak;
6305 exprNode_mustEscape (exprNode e)
6307 if (exprNode_isDefined (e))
6309 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
6316 exprNode_errorEscape (exprNode e)
6318 if (exprNode_isDefined (e))
6320 return exitkind_isError (e->exitCode);
6326 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
6328 exprNode ret = exprNode_createPartialCopy (e1);
6330 DPRINTF (("Concat: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6332 ret->edata = exprData_makePair (e1, e2);
6333 ret->kind = XPR_STMTLIST;
6335 if (exprNode_isDefined (e1))
6337 ret->isJumpPoint = e1->isJumpPoint;
6338 ret->canBreak = e1->canBreak;
6342 if (exprNode_isDefined (e2))
6344 ret->loc = fileloc_update (ret->loc, e2->loc);
6348 if (exprNode_isDefined (e2))
6350 ret->exitCode = e2->exitCode;
6351 ret->mustBreak = e2->mustBreak;
6352 if (e2->canBreak) ret->canBreak = TRUE;
6356 ** if e1 must return, then e2 is unreachable!
6359 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
6361 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
6362 && !(e2->isJumpPoint))
6364 if (context_getFlag (FLG_UNREACHABLE))
6368 if (e2->kind == XPR_STMT)
6370 nr = exprData_getUopNode (e2->edata);
6373 if ((nr->kind == XPR_TOK
6374 && lltok_isSemi (exprData_getTok (nr->edata))))
6376 /* okay to have unreachable ";" */
6377 ret->exitCode = XK_MUSTEXIT;
6378 ret->canBreak = TRUE;
6382 if (optgenerror (FLG_UNREACHABLE,
6383 message ("Unreachable code: %s",
6384 exprNode_unparseFirst (nr)),
6387 ret->isJumpPoint = TRUE;
6388 ret->mustBreak = FALSE;
6389 ret->exitCode = XK_ERROR;
6390 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
6394 ret->exitCode = XK_MUSTEXIT;
6395 ret->canBreak = TRUE;
6403 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
6406 ** We want a warning anytime we have:
6408 ** yyy; <<<- no break or return
6412 exprNode lastStmt = exprNode_lastStatement (e1);
6414 if (exprNode_isDefined (lastStmt)
6415 && !exprNode_mustEscape (lastStmt)
6416 && !exprNode_mustBreak (lastStmt)
6417 && !exprNode_isCaseMarker (lastStmt)
6418 && !exprNode_isDefaultMarker (lastStmt)
6419 && !exprNode_isLabelMarker (lastStmt))
6421 voptgenerror (FLG_CASEBREAK,
6423 ("Fall through case (no preceeding break)"),
6430 exprNode_mergeUSs (ret, e2);
6432 usymtab_setExitCode (ret->exitCode);
6436 usymtab_setMustBreak ();
6442 exprNode exprNode_createTok (/*@only@*/ lltok t)
6444 exprNode ret; /*@i23 if on same line, bad things happen...!@*/
6445 ret = exprNode_create (ctype_unknown);
6446 ret->kind = XPR_TOK;
6447 ret->edata = exprData_makeTok (t);
6451 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6453 if (!exprNode_isError (e))
6455 exprNode_checkStatement(e);
6458 return (exprNode_statementError (e, t));
6461 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6463 exprNode ret = exprNode_createPartialCopy (e);
6465 if (!exprNode_isError (e))
6467 if (e->kind != XPR_ASSIGN)
6469 exprNode_checkUse (ret, e->sref, e->loc);
6472 ret->exitCode = e->exitCode;
6473 ret->canBreak = e->canBreak;
6474 ret->mustBreak = e->mustBreak;
6477 ret->edata = exprData_makeUop (e, t);
6478 ret->kind = XPR_STMT;
6483 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
6485 if (!exprNode_isError (e))
6487 if (e->kind != XPR_ASSIGN)
6489 exprNode_checkUse (e, e->sref, e->loc);
6496 void exprNode_produceGuards (exprNode pred)
6498 if (!exprNode_isError (pred))
6500 if (ctype_isRealPointer (pred->typ))
6502 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
6505 exprNode_checkUse (pred, pred->sref, pred->loc);
6506 exprNode_resetSref (pred);
6510 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
6512 exprNode ret = exprNode_createPartialCopy (e);
6514 if (!exprNode_isError (e))
6516 ret->exitCode = e->exitCode;
6517 ret->canBreak = e->canBreak;
6518 ret->mustBreak = e->mustBreak;
6521 ret->edata = exprData_makeSingle (e);
6522 ret->kind = XPR_BLOCK;
6526 bool exprNode_isBlock (exprNode e)
6528 return (exprNode_isDefined (e)
6529 && ((e)->kind == XPR_BLOCK));
6532 bool exprNode_isAssign (exprNode e)
6534 if (exprNode_isDefined (e))
6536 return (e->kind == XPR_ASSIGN);
6542 bool exprNode_isEmptyStatement (exprNode e)
6544 return (exprNode_isDefined (e)
6545 && (e->kind == XPR_TOK)
6546 && (lltok_isSemi (exprData_getTok (e->edata))));
6549 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
6552 bool emptyErr = FALSE;
6554 if (context_maybeSet (FLG_IFEMPTY))
6556 if (exprNode_isEmptyStatement (tclause))
6558 emptyErr = optgenerror (FLG_IFEMPTY,
6560 ("Body of if statement is empty"),
6561 exprNode_loc (tclause));
6565 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
6567 if (exprNode_isDefined (tclause)
6568 && !exprNode_isBlock (tclause))
6570 voptgenerror (FLG_IFBLOCK,
6572 ("Body of if statement is not a block: %s",
6573 exprNode_unparse (tclause)),
6574 exprNode_loc (tclause));
6578 if (exprNode_isError (pred))
6580 if (exprNode_isError (tclause))
6582 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6586 ret = exprNode_createPartialCopy (tclause);
6591 if (exprNode_mustEscape (pred))
6595 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6596 exprNode_loc (pred));
6599 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6600 exprNode_checkUse (pred, pred->sref, pred->loc);
6602 if (!exprNode_isError (tclause))
6604 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
6607 ret = exprNode_createPartialCopy (pred);
6611 ret->edata = exprData_makePair (pred, tclause);
6613 ret->exitCode = XK_UNKNOWN;
6615 if (exprNode_isDefined (tclause))
6617 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
6618 ret->canBreak = tclause->canBreak;
6619 ret->sets = sRefSet_union (ret->sets, tclause->sets);
6620 ret->msets = sRefSet_union (ret->msets, tclause->msets);
6621 ret->uses = sRefSet_union (ret->uses, tclause->uses);
6624 ret->mustBreak = FALSE;
6629 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
6630 /*@only@*/ exprNode tclause,
6631 /*@only@*/ exprNode eclause)
6634 bool tEmptyErr = FALSE;
6635 bool eEmptyErr = FALSE;
6637 if (context_maybeSet (FLG_IFEMPTY))
6639 if (exprNode_isEmptyStatement (tclause))
6641 tEmptyErr = optgenerror
6644 ("Body of if clause of if statement is empty"),
6645 exprNode_loc (tclause));
6648 if (exprNode_isEmptyStatement (eclause))
6650 eEmptyErr = optgenerror
6653 ("Body of else clause of if statement is empty"),
6654 exprNode_loc (eclause));
6658 if (context_maybeSet (FLG_IFBLOCK))
6661 && exprNode_isDefined (tclause)
6662 && !exprNode_isBlock (tclause))
6664 voptgenerror (FLG_IFBLOCK,
6666 ("Body of if clause of if statement is not a block: %s",
6667 exprNode_unparse (tclause)),
6668 exprNode_loc (tclause));
6672 && exprNode_isDefined (eclause)
6673 && !exprNode_isBlock (eclause)
6674 && !(eclause->kind == XPR_IF)
6675 && !(eclause->kind == XPR_IFELSE))
6680 ("Body of else clause of if statement is not a block: %s",
6681 exprNode_unparse (eclause)),
6682 exprNode_loc (eclause));
6686 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6688 if (exprNode_isDefined (eclause)
6689 && (eclause->kind == XPR_IF))
6691 voptgenerror (FLG_ELSEIFCOMPLETE,
6692 message ("Incomplete else if logic (no final else): %s",
6693 exprNode_unparse (eclause)),
6694 exprNode_loc (eclause));
6698 if (exprNode_isError (pred))
6700 if (exprNode_isError (tclause))
6702 if (exprNode_isError (eclause))
6704 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6708 ret = exprNode_createPartialCopy (eclause);
6713 ret = exprNode_createPartialCopy (tclause);
6716 else /* pred is okay */
6718 ret = exprNode_createPartialCopy (pred);
6720 if (exprNode_mustEscape (pred))
6724 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6725 exprNode_loc (pred));
6728 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6729 exprNode_checkUse (ret, pred->sref, pred->loc);
6731 exprNode_mergeCondUSs (ret, tclause, eclause);
6734 ret->kind = XPR_IFELSE;
6735 ret->edata = exprData_makeCond (pred, tclause, eclause);
6737 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6739 exprNode_combineControl (ret, tclause, eclause);
6740 ret->loc = fileloc_update (ret->loc, eclause->loc);
6747 ** *allpaths <- TRUE iff all executions paths must go through the switch
6751 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6753 exprNodeSList el = exprNode_flatten (e);
6754 bool mustReturn = TRUE; /* find a branch that doesn't */
6755 bool thisReturn = FALSE;
6756 bool hasDefault = FALSE;
6757 bool hasAllMembers = FALSE;
6758 bool inSwitch = FALSE;
6759 bool isEnumSwitch = FALSE;
6760 bool canBreak = FALSE;
6761 bool fallThrough = FALSE;
6762 ctype ct = ctype_unknown;
6763 enumNameSList usedEnums;
6766 if (exprNode_isDefined (test))
6771 ttype = ctype_realType (ct);
6773 if (ctype_isEnum (ttype))
6775 isEnumSwitch = TRUE;
6776 enums = ctype_elist (ttype);
6777 usedEnums = enumNameSList_new ();
6781 exprNodeSList_elements (el, current)
6783 if (exprNode_isDefined (current))
6785 switch (current->kind)
6793 message ("Duplicate default cases in switch"),
6794 exprNode_loc (current));
6799 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6807 exprNode st = exprData_getSingle (current->edata);
6808 uentry ue = exprNode_getUentry (st);
6810 if (uentry_isValid (ue))
6812 cstring cname = uentry_rawName (ue);
6814 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6816 if (enumNameSList_member
6817 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6821 message ("Duplicate case in switch: %s",
6827 enumNameSList_addh (usedEnums, cname);
6834 message ("Case in switch not %s member: %s",
6835 ctype_unparse (ct), cname),
6842 if (inSwitch && !fallThrough)
6844 if (!thisReturn || canBreak)
6854 /*@switchbreak@*/ break;
6856 thisReturn = thisReturn || exprNode_mustEscape (current);
6857 canBreak = canBreak || current->canBreak;
6858 if (canBreak) fallThrough = FALSE;
6861 } end_exprNodeSList_elements;
6863 if (inSwitch) /* check the last one! */
6865 if (!thisReturn || canBreak)
6874 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6875 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6877 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6879 voptgenerror (FLG_MISSCASE,
6880 message ("Missing case%s in switch: %q",
6881 cstring_makeLiteralTemp
6882 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6883 enumNameSList_unparse (unused)),
6886 enumNameSList_free (unused);
6890 hasAllMembers = TRUE;
6894 enumNameSList_free (usedEnums);
6898 *allpaths = hasDefault;
6901 exprNodeSList_free (el);
6902 return ((hasDefault || hasAllMembers) && mustReturn);
6905 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6907 exprNode ret = exprNode_createPartialCopy (e);
6910 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6912 ret->kind = XPR_SWITCH;
6913 ret->edata = exprData_makePair (e, s);
6915 if (!exprNode_isError (s))
6917 exprNode fs = exprNode_firstStatement (s);
6918 ret->loc = fileloc_update (ret->loc, s->loc);
6920 if (exprNode_isUndefined (fs)
6921 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6922 || exprNode_isDefaultMarker (fs)) {
6925 voptgenerror (FLG_FIRSTCASE,
6927 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6932 if (!exprNode_isError (e))
6934 if (checkSwitchExpr (e, s, &allpaths))
6936 ret->exitCode = XK_MUSTRETURN;
6940 ret->exitCode = e->exitCode;
6943 ret->canBreak = e->canBreak;
6944 ret->mustBreak = e->mustBreak;
6948 ** exprNode.c:3883,32: Variable allpaths used before definition
6955 DPRINTF (("Context exit switch!"));
6956 context_exitSwitch (ret, allpaths);
6957 DPRINTF (("Context exit switch done!"));
6962 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6963 /*@notnull@*/ exprNode body)
6965 sRefSet tuses = test->uses;
6967 if (!sRefSet_isEmpty (test->uses))
6969 sRefSet sets = sRefSet_newCopy (body->sets);
6970 bool hasError = TRUE;
6971 bool innerState = FALSE;
6972 sRefSet tuncon = sRefSet_undefined;
6974 sets = sRefSet_union (sets, test->sets);
6975 sets = sRefSet_union (sets, body->msets);
6976 sets = sRefSet_union (sets, test->msets);
6978 sRefSet_allElements (tuses, el)
6980 if (sRef_isUnconstrained (el))
6982 tuncon = sRefSet_insert (tuncon, el);
6986 if (sRefSet_member (sets, el))
6993 if (sRef_isInternalState (el)
6994 || sRef_isFileStatic (sRef_getRootBase (el)))
6998 } end_sRefSet_allElements ;
7002 sRefSet suncon = sRefSet_undefined;
7003 bool sinner = FALSE;
7005 sRefSet_allElements (sets, el)
7007 if (sRef_isUnconstrained (el))
7009 suncon = sRefSet_insert (suncon, el);
7011 else if (sRef_isInternalState (el))
7019 } end_sRefSet_allElements ;
7021 if (sinner && innerState)
7025 else if (sRefSet_isEmpty (tuncon)
7026 && sRefSet_isEmpty (suncon))
7031 ("Suspected infinite loop. No value used in loop test (%q) "
7032 "is modified by test or loop body.",
7033 sRefSet_unparsePlain (tuses)),
7038 if (sRefSet_isEmpty (tuncon))
7042 message ("Suspected infinite loop. No condition values "
7043 "modified. Modification possible through "
7044 "unconstrained calls: %q",
7045 sRefSet_unparsePlain (suncon)),
7052 message ("Suspected infinite loop. No condition values "
7053 "modified. Possible undetected dependency through "
7054 "unconstrained calls in loop test: %q",
7055 sRefSet_unparsePlain (tuncon)),
7061 sRefSet_free (sets);
7065 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
7068 bool emptyErr = FALSE;
7070 if (context_maybeSet (FLG_WHILEEMPTY))
7072 if (exprNode_isEmptyStatement (b))
7074 emptyErr = optgenerror
7077 ("Body of while statement is empty"),
7082 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
7084 if (exprNode_isDefined (b)
7085 && !exprNode_isBlock (b))
7087 if (context_inIterDef ()
7088 && (b->kind == XPR_STMTLIST
7089 || b->kind == XPR_TOK))
7095 voptgenerror (FLG_WHILEBLOCK,
7097 ("Body of while statement is not a block: %s",
7098 exprNode_unparse (b)),
7104 if (exprNode_isError (t))
7106 if (exprNode_isError (b))
7108 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7112 ret = exprNode_createPartialCopy (b);
7119 ret = exprNode_createPartialCopy (t);
7121 llassert (t->kind == XPR_WHILEPRED);
7123 test = exprData_getSingle (t->edata);
7125 if (!exprNode_isError (b) && exprNode_isDefined (test))
7127 if (context_maybeSet (FLG_INFLOOPS)
7128 || context_maybeSet (FLG_INFLOOPSUNCON))
7131 ** check that some variable in the predicate is set by the body
7132 ** if the predicate uses any variables
7135 checkInfiniteLoop (test, b);
7138 exprNode_mergeUSs (ret, b);
7140 if (exprNode_isDefined (b))
7142 ret->exitCode = exitkind_makeConditional (b->exitCode);
7147 ret->edata = exprData_makePair (t, b);
7148 ret->kind = XPR_WHILE;
7150 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
7154 message ("Predicate always exits: %s", exprNode_unparse (t)),
7158 ret->exitCode = XK_NEVERESCAPE;
7161 ** If loop is infinite, and there is no break inside,
7162 ** exit code is never reach.
7165 if (exprNode_knownIntValue (t))
7167 if (!exprNode_isZero (t))
7169 if (exprNode_isDefined (b))
7173 /* Really, it means never reached. */
7174 ret->exitCode = XK_MUSTEXIT;
7184 ret->canBreak = FALSE;
7185 ret->mustBreak = FALSE;
7191 ** do { b } while (t);
7193 ** note: body passed as first argument
7196 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
7200 if (exprNode_isError (t))
7202 if (exprNode_isError (b))
7204 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7208 ret = exprNode_createPartialCopy (b);
7210 ret->exitCode = exitkind_makeConditional (b->exitCode);
7211 exprNode_checkUse (ret, b->sref, b->loc);
7212 ret->exitCode = b->exitCode;
7213 ret->canBreak = b->canBreak;
7214 ret->mustBreak = b->mustBreak;
7219 ret = exprNode_createPartialCopy (t);
7220 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
7222 if (!exprNode_isError (b))
7225 ** forgot the copy's --- why wasn't this detected??
7228 ret->sets = sRefSet_copyInto (ret->sets, b->sets);
7229 ret->msets = sRefSet_copyInto (ret->msets, b->msets);
7230 ret->uses = sRefSet_copyInto (ret->uses, b->uses);
7232 /* left this out --- causes and aliasing bug (infinite loop)
7233 should be detected?? */
7235 exprNode_checkUse (ret, b->sref, b->loc);
7236 exprNode_mergeUSs (ret, t);
7237 exprNode_checkUse (ret, t->sref, t->loc);
7239 ret->exitCode = b->exitCode;
7240 ret->canBreak = b->canBreak;
7241 ret->mustBreak = b->mustBreak;
7245 context_exitDoWhileClause (t);
7247 ret->kind = XPR_DOWHILE;
7248 ret->edata = exprData_makePair (t, b);
7252 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
7255 bool emptyErr = FALSE;
7257 if (context_maybeSet (FLG_FOREMPTY))
7259 if (exprNode_isEmptyStatement (body))
7261 emptyErr = optgenerror
7264 ("Body of for statement is empty"),
7265 exprNode_loc (body));
7269 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
7271 if (exprNode_isDefined (body)
7272 && !exprNode_isBlock (body))
7274 if (context_inIterDef ()
7275 && (body->kind == XPR_STMTLIST
7276 || body->kind == XPR_TOK))
7282 voptgenerror (FLG_FORBLOCK,
7284 ("Body of for statement is not a block: %s",
7285 exprNode_unparse (body)),
7286 exprNode_loc (body));
7292 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
7295 if (exprNode_isError (body))
7297 ret = exprNode_createPartialCopy (inc);
7301 ret = exprNode_createPartialCopy (body);
7303 ret->exitCode = exitkind_makeConditional (body->exitCode);
7305 exprNode_mergeUSs (inc, body);
7307 if (exprNode_isDefined (inc))
7311 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
7314 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
7315 exprNode_freeShallow (tmp);
7317 context_clearMessageAnnote ();
7318 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
7320 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
7321 exprNode_freeShallow (tmp);
7323 context_clearMessageAnnote ();
7325 ret->uses = sRefSet_copyInto (ret->uses, inc->uses);
7326 ret->sets = sRefSet_copyInto (ret->sets, inc->sets);
7327 ret->msets = sRefSet_copyInto (ret->msets, inc->msets);
7331 ret->kind = XPR_FOR;
7332 ret->edata = exprData_makePair (inc, body);
7334 if (exprNode_isDefined (inc)) {
7335 exprNode test = exprData_getTripleTest (inc->edata);
7337 if (exprNode_isUndefined (test)) {
7338 if (exprNode_isDefined (body)) {
7339 if (!body->canBreak) {
7340 /* Really, it means never reached. */
7341 ret->exitCode = XK_MUSTEXIT;
7351 ** for (init; test; inc)
7354 ** while (test) { body; inc; }
7356 ** Now: check use of init (may set vars for test)
7357 ** check use of test
7361 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
7365 if (exprNode_isError (pred)) return guardSet_undefined;
7367 llassert (pred->kind == XPR_FORPRED);
7369 test = exprData_getTripleTest (pred->edata);
7371 if (!exprNode_isError (test))
7373 return (test->guards);
7376 return guardSet_undefined;
7379 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
7381 exprNode ret = exprNode_createSemiCopy (test);
7383 if (exprNode_isDefined (test))
7385 exprNode_copySets (ret, test);
7386 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
7387 exprNode_checkUse (ret, test->sref, test->loc);
7389 exprNode_produceGuards (test);
7391 ret->guards = guardSet_copy (test->guards);
7394 ret->edata = exprData_makeSingle (test);
7395 ret->kind = XPR_WHILEPRED;
7399 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
7400 /*@only@*/ exprNode inc)
7405 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
7408 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
7410 if (!exprNode_isError (inc))
7412 ret = exprNode_createPartialCopy (inc);
7416 if (!exprNode_isError (init))
7418 ret = exprNode_createPartialCopy (init);
7420 else if (!exprNode_isError (test))
7422 ret = exprNode_createPartialCopy (test);
7426 ret = exprNode_createUnknown ();
7430 exprNode_mergeUSs (ret, init);
7432 if (exprNode_isDefined (init))
7434 exprNode_checkUse (ret, init->sref, init->loc);
7437 exprNode_mergeUSs (ret, test);
7439 if (exprNode_isDefined (test))
7441 exprNode_checkUse (ret, test->sref, test->loc);
7444 ret->kind = XPR_FORPRED;
7445 ret->edata = exprData_makeFor (init, test, inc);
7449 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
7451 exprNode ret = exprNode_createUnknown ();
7453 if (context_inMacro ())
7455 voptgenerror (FLG_MACROSTMT,
7456 message ("Macro %s uses goto (not functional)",
7457 context_inFunctionName ()),
7461 ret->kind = XPR_GOTO;
7462 ret->edata = exprData_makeLiteral (label);
7463 ret->mustBreak = TRUE;
7464 ret->exitCode = XK_GOTO;
7465 ret->canBreak = TRUE;
7469 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
7471 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7473 ret->kind = XPR_CONTINUE;
7474 ret->edata = exprData_makeTok (l);
7475 ret->canBreak = TRUE;
7476 ret->mustBreak = TRUE;
7478 if (qcontinue == QSAFEBREAK)
7482 else if (qcontinue == QINNERCONTINUE)
7484 if (!context_inDeepLoop ())
7487 (FLG_LOOPLOOPCONTINUE,
7488 cstring_makeLiteral ("Continue statement marked with innercontinue "
7489 "is not inside a nested loop"),
7490 exprNode_loc (ret));
7493 else if (qcontinue == BADTOK)
7495 if (context_inDeepLoop ())
7498 (FLG_LOOPLOOPCONTINUE,
7499 cstring_makeLiteral ("Continue statement in nested loop"),
7500 exprNode_loc (ret));
7505 llbuglit ("exprNode_continue: bad qcontinue");
7511 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
7513 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7514 clause breakClause = context_breakClause ();
7516 ret->kind = XPR_BREAK;
7517 ret->edata = exprData_makeTok (l);
7518 ret->canBreak = TRUE;
7519 ret->mustBreak = TRUE;
7521 if (breakClause == NOCLAUSE)
7525 cstring_makeLiteral ("Break not inside while, for or switch statement"),
7526 exprNode_loc (ret));
7530 if (bqual != BADTOK)
7537 if (breakClause == SWITCHCLAUSE)
7539 if (!context_inDeepSwitch ())
7541 voptgenerror (FLG_SYNTAX,
7543 ("Break preceded by innerbreak is not in a deep switch"),
7544 exprNode_loc (ret));
7549 if (!context_inDeepLoop ())
7551 voptgenerror (FLG_SYNTAX,
7553 ("Break preceded by innerbreak is not in a deep loop"),
7554 exprNode_loc (ret));
7559 if (breakClause == SWITCHCLAUSE)
7561 voptgenerror (FLG_SYNTAX,
7563 ("Break preceded by loopbreak is breaking a switch"),
7564 exprNode_loc (ret));
7568 if (breakClause != SWITCHCLAUSE)
7572 message ("Break preceded by switchbreak is breaking %s",
7573 cstring_makeLiteralTemp
7574 ((breakClause == WHILECLAUSE
7575 || breakClause == DOWHILECLAUSE) ? "a while loop"
7576 : (breakClause == FORCLAUSE) ? "a for loop"
7577 : (breakClause == ITERCLAUSE) ? "an iterator"
7579 exprNode_loc (ret));
7587 if (breakClause == SWITCHCLAUSE)
7589 clause nextBreakClause = context_nextBreakClause ();
7591 switch (nextBreakClause)
7593 case NOCLAUSE: break;
7599 (FLG_LOOPSWITCHBREAK,
7600 cstring_makeLiteral ("Break statement in switch inside loop"),
7601 exprNode_loc (ret));
7605 (FLG_SWITCHSWITCHBREAK,
7606 cstring_makeLiteral ("Break statement in switch inside switch"),
7607 exprNode_loc (ret));
7614 if (context_inDeepLoop ())
7618 cstring_makeLiteral ("Break statement in nested loop"),
7619 exprNode_loc (ret));
7623 if (context_inDeepLoopSwitch ())
7626 (FLG_SWITCHLOOPBREAK,
7627 cstring_makeLiteral ("Break statement in loop inside switch"),
7628 exprNode_loc (ret));
7638 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
7640 fileloc loc = lltok_getLoc (t);
7641 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
7643 context_returnFunction ();
7644 exprChecks_checkNullReturn (loc);
7646 ret->kind = XPR_NULLRETURN;
7647 ret->edata = exprData_makeTok (t);
7648 ret->exitCode = XK_MUSTRETURN;
7652 exprNode exprNode_return (/*@only@*/ exprNode e)
7656 if (exprNode_isError (e))
7658 ret = exprNode_createUnknown ();
7662 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7664 exprNode_checkUse (ret, e->sref, e->loc);
7665 exprNode_checkReturn (e);
7668 context_returnFunction ();
7669 ret->kind = XPR_RETURN;
7670 ret->edata = exprData_makeSingle (e);
7671 ret->exitCode = XK_MUSTRETURN;
7676 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7680 if (exprNode_isError (e1))
7682 if (exprNode_isError (e2))
7684 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7688 ret = exprNode_createPartialCopy (e2);
7689 exprNode_checkUse (ret, e2->sref, e2->loc);
7690 ret->sref = e2->sref;
7695 ret = exprNode_createPartialCopy (e1);
7697 exprNode_checkUse (ret, e1->sref, e1->loc);
7699 if (!exprNode_isError (e2))
7701 exprNode_mergeUSs (ret, e2);
7702 exprNode_checkUse (ret, e2->sref, e2->loc);
7703 ret->sref = e2->sref;
7707 ret->kind = XPR_COMMA;
7708 ret->edata = exprData_makePair (e1, e2);
7710 if (exprNode_isDefined (e1))
7712 if (exprNode_isDefined (e2))
7716 if (exprNode_mustEscape (e1) || e1->mustBreak)
7720 message ("Second clause of comma expression is unreachable: %s",
7721 exprNode_unparse (e2)),
7725 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7726 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7727 ret->canBreak = e1->canBreak || e2->canBreak;
7731 if (exprNode_mustEscape (e1) || e1->mustBreak)
7735 message ("Second clause of comma expression is unreachable: %s",
7736 exprNode_unparse (e2)),
7740 ret->exitCode = e1->exitCode;
7741 ret->canBreak = e1->canBreak;
7746 if (exprNode_isDefined (e2))
7748 ret->exitCode = e2->exitCode;
7749 ret->mustBreak = e2->mustBreak;
7750 ret->canBreak = e2->canBreak;
7757 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7759 ctype t1 = exprNode_getType (el);
7760 ctype t2 = exprNode_getType (val);
7761 bool hasError = FALSE;
7763 if (ctype_isUnknown (t1))
7765 voptgenerror (FLG_IMPTYPE,
7766 message ("Variable has unknown (implicitly int) type: %s",
7767 exprNode_unparse (el)),
7771 el->typ = ctype_int;
7774 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7776 exprNodeList vals = exprData_getArgs (val->edata);
7778 if (ctype_isRealAP (t1))
7783 /*@i423 check number of entries int a[3] = { 1, 2, 3, 4 } ; */
7785 exprNodeList_elements (vals, oneval)
7787 cstring istring = message ("%d", i);
7790 (exprNode_fakeCopy (el),
7791 exprNode_numLiteral (ctype_int, istring,
7792 fileloc_copy (el->loc), i));
7794 if (exprNode_isDefined (newel))
7796 if (exprNodeList_size (vals) == 1
7797 && ctype_isString (exprNode_getType (oneval))
7798 && ctype_isChar (exprNode_getType (newel)))
7800 exprNode_freeIniter (newel);
7804 if (exprNode_checkOneInit (newel, oneval))
7809 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7812 (message ("Additional initialization errors "
7813 "for %s not reported",
7814 exprNode_unparse (el)),
7816 exprNode_freeIniter (newel);
7821 exprNode_freeIniter (newel);
7826 exprNode_freeIniter (newel);
7831 cstring_free (istring);
7834 } end_exprNodeList_elements;
7837 else if (ctype_isStruct (ctype_realType (t1)))
7839 uentryList fields = ctype_getFields (t1);
7842 if (uentryList_size (fields) != exprNodeList_size (vals))
7844 if (uentryList_size (fields) > exprNodeList_size (vals))
7846 hasError = optgenerror
7848 message ("Initializer block for "
7849 "%s has %d field%&, but %s has %d field%&: %q",
7850 exprNode_unparse (el),
7851 exprNodeList_size (vals),
7853 uentryList_size (fields),
7854 exprNodeList_unparse (vals)),
7859 hasError = optgenerror
7861 message ("Initializer block for "
7862 "%s has %d field%&, but %s has %d field%&: %q",
7863 exprNode_unparse (el),
7864 exprNodeList_size (vals),
7866 uentryList_size (fields),
7867 exprNodeList_unparse (vals)),
7873 exprNodeList_elements (vals, oneval)
7875 uentry thisfield = uentryList_getN (fields, i);
7877 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
7879 uentry_getName (thisfield));
7881 if (exprNode_isDefined (newel))
7883 if (exprNode_checkOneInit (newel, oneval))
7888 exprNode_freeIniter (newel);
7892 } end_exprNodeList_elements;
7897 hasError = optgenerror
7899 message ("Initializer block used for "
7900 "%s where %t is expected: %s",
7901 exprNode_unparse (el), t1, exprNode_unparse (val)),
7907 if (exprNode_isDefined (val))
7909 doAssign (el, val, TRUE);
7911 if (!exprNode_matchType (t1, val))
7913 hasError = gentypeerror
7915 message ("Initial value of %s is type %t, "
7917 exprNode_unparse (el),
7918 t2, t1, exprNode_unparse (val)),
7928 exprNode_makeInitializationAux (/*@temp@*/ idDecl t)
7932 if (usymtab_exists (idDecl_observeId (t)))
7934 uentry ue = usymtab_lookup (idDecl_observeId (t));
7935 ret = exprNode_createId (ue);
7937 /*@i723 don't do this...but why? */
7939 ct = ctype_realishType (ret->typ);
7941 DPRINTF (("Type: %s", ctype_unparse (ret->typ)));
7943 if (ctype_isUnknown (ct))
7945 if (uentry_isAnyTag (ue))
7949 message ("%s used but not previously declared: %s",
7950 uentry_ekindName (ue),
7951 idDecl_getName (t)),
7959 message ("Variable has unknown (implicitly int) type: %s",
7960 idDecl_getName (t)),
7972 DPRINTF (("Unrecognized: %s", idDecl_unparse (t)));
7974 ue = uentry_makeUnrecognized (idDecl_observeId (t), fileloc_copy (g_currentloc));
7975 /*!! fileloc_copy (g_currentloc)); */
7976 /*@i32!!! should get error without this */
7977 ret = exprNode_fromIdentifierAux (ue);
7980 ** No error - this happens in old style declarations:
7984 message ("Unrecognized identifier in intializer: %s", idDecl_observeId (t)),
7991 exprData_free (ret->edata, ret->kind);
7992 ret->edata = exprData_undefined;
7994 ret->exitCode = XK_NEVERESCAPE;
7995 ret->mustBreak = FALSE;
7996 ret->kind = XPR_INIT;
8000 exprNode exprNode_makeEmptyInitialization (/*@only@*/ idDecl t)
8002 exprNode ret = exprNode_makeInitializationAux (t);
8003 llassert (ret->edata == exprData_undefined);
8004 ret->edata = exprData_makeInit (t, exprNode_undefined);
8008 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
8009 /*@only@*/ exprNode e)
8011 uentry ue = usymtab_lookup (idDecl_observeId (t));
8012 exprNode ret = exprNode_makeInitializationAux (t);
8013 fileloc loc = exprNode_loc (e);
8015 if (exprNode_isError (e))
8017 e = exprNode_createUnknown ();
8020 /* error: assume initializer is defined */
8021 sRef_setDefined (ret->sref, g_currentloc);
8025 ctype ct = ctype_realishType (ret->typ);
8030 ** was addSafeUse --- what's the problem?
8032 ** int x = 3, y = x ?
8035 exprData_free (ret->edata, ret->kind);
8036 ret->edata = exprData_makeInit (t, e);
8038 exprNode_checkUse (ret, e->sref, e->loc);
8040 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
8042 exprNode lhs = exprNode_createId (ue);
8045 ** static storage should be undefined before initializing
8048 if (uentry_isStatic (ue))
8050 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
8053 (void) exprNode_checkOneInit (lhs, e);
8055 if (uentry_isStatic (ue))
8057 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
8060 exprNode_free (lhs);
8064 if (!exprNode_matchType (ct, e))
8066 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
8073 (exprNode_getType (e), e, exprNode_getType (ret), ret,
8075 ("Variable %q initialized to type %t, expects %t: %s",
8076 uentry_getName (ue), exprNode_getType (e),
8077 exprNode_getType (ret),
8078 exprNode_unparse (e)),
8084 if (uentry_isStatic (ue))
8086 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
8089 doAssign (ret, e, TRUE);
8091 if (uentry_isStatic (ue))
8093 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
8097 if (context_inIterDef ())
8099 /* should check if it is yield */
8100 uentry_setUsed (ue, loc);
8107 exprNode_mergeUSs (ret, e);
8111 exprNode exprNode_iter (/*@observer@*/ uentry name,
8112 /*@only@*/ exprNodeList alist,
8113 /*@only@*/ exprNode body,
8114 /*@observer@*/ uentry end)
8119 llassert (uentry_isValid (name));
8121 uentry_setUsed (name, exprNode_loc (body));
8123 ret = exprNode_createPartialCopy (body);
8124 iname = uentry_getName (name);
8126 if (uentry_isInvalid (end))
8129 message ("Iter %s not balanced with end_%s", iname, iname));
8133 cstring ename = uentry_getName (end);
8135 if (!cstring_equalPrefix (ename, "end_"))
8137 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
8138 iname, iname, ename));
8142 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
8145 message ("Iter %s not balanced with end_%s: %s",
8146 iname, iname, ename));
8150 cstring_free (ename);
8153 context_exitIterClause (body);
8155 ret->kind = XPR_ITER;
8156 ret->edata = exprData_makeIter (name, alist, body, end);
8158 if (uentry_isIter (name))
8160 (void) checkArgsReal (name, body,
8161 uentry_getParams (name), alist, TRUE, ret);
8164 cstring_free (iname);
8170 exprNode_iterNewId (/*@only@*/ cstring s)
8172 exprNode e = exprNode_new ();
8173 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
8175 llassert (processingIterVars ());
8177 e->loc = context_getSaveLocation ();
8179 if (fileloc_isUndefined (e->loc))
8181 fileloc_free (e->loc);
8182 e->loc = fileloc_copy (g_currentloc);
8185 e->uses = sRefSet_new ();
8186 e->sets = sRefSet_new ();
8187 e->msets = sRefSet_new ();
8189 e->val = multiVal_unknown ();
8190 e->guards = guardSet_new ();
8192 e->isJumpPoint = FALSE;
8193 e->exitCode = XK_NEVERESCAPE;
8195 /*> missing fields, detected by lclint <*/
8196 e->canBreak = FALSE;
8197 e->mustBreak = FALSE;
8198 e->etext = cstring_undefined;
8200 if (uentry_isYield (ue))
8202 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
8203 fileloc_copy (e->loc),
8207 uue = usymtab_supEntrySrefReturn (uue);
8209 sr = uentry_getSref (uue);
8210 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
8211 sr = uentry_getSref (uue);
8212 sRef_setDefined (sr, e->loc);
8214 e->typ = uentry_getType (uue);
8216 e->edata = exprData_makeId (uue);
8217 uentry_setUsed (uue, g_currentloc);
8223 sRef_setGlobalScope ();
8224 uue = uentry_makeVariableLoc (s, ctype_unknown);
8226 e->typ = ctype_unknown;
8227 e->edata = exprData_makeId (uue);
8229 uentry_setUsed (uue, e->loc);
8230 uentry_setHasNameError (uue);
8232 if (context_getFlag (FLG_REPEATUNRECOG))
8234 uentry_markOwned (uue);
8238 usymtab_supGlobalEntry (uue);
8241 sRef_clearGlobalScope ();
8243 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
8250 exprNode_defineConstraints(e);
8255 exprNode_iterExpr (/*@returned@*/ exprNode e)
8257 if (!processingIterVars ())
8259 llcontbuglit ("checkIterParam: not in iter");
8263 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
8266 if (exprNode_isDefined (e))
8268 if (fileloc_isDefined (e->loc))
8272 message ("Yield parameter is not simple identifier: %s",
8273 exprNode_unparse (e)),
8280 message ("Yield parameter is not simple identifier: %s",
8281 exprNode_unparse (e)),
8291 exprNode_iterId (/*@observer@*/ uentry c)
8295 llassert (processingIterVars ());
8297 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
8300 if (uentry_isYield (ue))
8302 ctype ct = uentry_getType (ue);
8303 exprNode e = exprNode_createPlain (ct);
8304 cstring name = uentry_getName (c);
8305 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
8307 uentry_setUsed (ue, g_currentloc);
8308 uentry_setHasNameError (ue);
8310 cstring_free (name);
8313 e->edata = exprData_makeId (le);
8314 e->loc = context_getSaveLocation ();
8315 e->sref = uentry_getSref (le);
8317 usymtab_supEntrySref (le);
8319 if (!context_inHeader ())
8323 message ("Yield parameter shadows local declaration: %q",
8324 uentry_getName (c)),
8325 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
8327 uentry_showWhereDeclared (c);
8334 return (exprNode_fromIdentifierAux (c));
8337 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
8339 exprNode ret = exprNode_create (ctype_unknown);
8341 ret->kind = XPR_ITERCALL;
8342 ret->edata = exprData_makeIterCall (name, alist);
8344 if (uentry_isIter (name))
8346 uentryList params = uentry_getParams (name);
8348 if (context_inIterDef ()
8349 && uentryList_size (params) == exprNodeList_size (alist))
8353 exprNodeList_elements (alist, arg)
8355 uentry parg = uentryList_getN (params, i);
8357 if (uentry_isYield (parg))
8359 uentry ue = exprNode_getUentry (arg);
8361 if (uentry_isValid (ue))
8368 } end_exprNodeList_elements;
8371 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
8372 checkUnspecCall (ret, params, alist);
8378 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
8380 if (exprNode_isDefined (e))
8383 if (e->sref == defref) /*@noaccess sRef@*/
8386 e->sref = sRef_makeUnknown ();
8387 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
8398 return sRef_undefined;
8402 /*@observer@*/ cstring
8403 exprNode_unparseFirst (exprNode e)
8405 if (exprNode_isDefined (e))
8409 if (e->kind == XPR_STMTLIST
8410 || e->kind == XPR_COMMA || e->kind == XPR_COND)
8412 exprNode first = exprData_getPairA (e->edata);
8414 if (exprNode_isDefined (first))
8416 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
8420 return (cstring_makeLiteralTemp ("..."));
8424 ret = cstring_elide (exprNode_unparse (e), 20);
8425 cstring_markOwned (ret);
8431 return cstring_makeLiteralTemp ("<error>");
8435 /*@observer@*/ cstring
8436 exprNode_unparse (/*@temp@*/ exprNode e)
8438 if (exprNode_isError (e))
8440 return cstring_makeLiteralTemp ("<error>");
8443 if (cstring_isDefined (e->etext))
8449 cstring ret = exprNode_doUnparse (e);
8451 /*@-modifies@*/ /* benevolent */
8458 /*@observer@*/ fileloc
8459 exprNode_loc (exprNode e)
8461 if (exprNode_isError (e))
8463 return (g_currentloc);
8472 ** executes exprNode e
8473 ** recursively rexecutes as though in original parse using
8474 ** information in e->edata
8477 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
8479 exprNodeList ret = exprNodeList_new ();
8481 exprNodeList_elements (e, current)
8483 exprNodeList_addh (ret, exprNode_effect (current));
8484 } end_exprNodeList_elements;
8489 static /*@only@*/ exprNode exprNode_effect (exprNode e)
8490 /*@globals internalState@*/
8492 bool innerEffect = inEffect;
8498 context_clearJustPopped ();
8500 if (exprNode_isError (e))
8502 ret = exprNode_undefined;
8507 ** Turn off expose and dependent transfer checking.
8508 ** Need to pass exposed internal nodes,
8509 ** [ copying would be a waste! ]
8510 ** [ Actually, I think I wasted a lot more time than its worth ]
8511 ** [ trying to do this. ]
8515 /*@-observertrans@*/
8516 /*@-dependenttrans@*/
8523 ret = exprNode_addParens (exprData_getUopTok (data),
8524 exprNode_effect (exprData_getUopNode (data)));
8527 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
8528 exprNode_effect (exprData_getOpB (data)),
8529 exprData_getOpTok (data));
8532 ret = exprNode_undefined;
8535 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
8536 exprNodeList_effect (exprData_getArgs (data)));
8549 cstring id = exprData_getId (data);
8550 uentry ue = usymtab_lookupSafe (id);
8552 ret = exprNode_fromIdentifierAux (ue);
8553 ret->loc = fileloc_update (ret->loc, e->loc);
8560 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
8561 exprNode_effect (exprData_getPairB (data)));
8564 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
8565 exprNode_effect (exprData_getOpB (data)),
8566 exprData_getOpTok (data));
8570 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
8571 exprData_getUopTok (data));
8574 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
8575 exprData_getUopTok (data));
8587 ret = exprNode_vaArg (exprData_getCastTok (data),
8588 exprNode_effect (exprData_getCastNode (data)),
8589 exprData_getCastType (data));
8593 ret = exprNode_cast (exprData_getCastTok (data),
8594 exprNode_effect (exprData_getCastNode (data)),
8595 exprData_getCastType (data));
8598 ret = exprNode_iterStart (exprData_getIterCallIter (data),
8600 (exprData_getIterCallArgs (data)));
8604 ret = exprNode_iter (exprData_getIterSname (data),
8605 exprNodeList_effect (exprData_getIterAlist (data)),
8606 exprNode_effect (exprData_getIterBody (data)),
8607 exprData_getIterEname (data));
8611 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
8612 exprNode_effect (exprData_getPairB (data)));
8616 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
8617 exprNode_effect (exprData_getTripleTest (data)),
8618 exprNode_effect (exprData_getTripleInc (data)));
8622 ret = exprNode_createTok (exprData_getTok (data));
8626 ret = exprNode_goto (exprData_getLiteral (data));
8627 ret->loc = fileloc_update (ret->loc, e->loc);
8631 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
8635 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
8639 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
8642 case XPR_NULLRETURN:
8643 ret = exprNode_nullReturn (exprData_getTok (data));
8647 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
8648 exprNode_effect (exprData_getPairB (data)));
8652 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
8653 exprNode_effect (exprData_getTripleTrue (data)),
8654 exprNode_effect (exprData_getTripleFalse (data)));
8657 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
8658 exprNode_effect (exprData_getPairB (data)));
8662 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
8663 exprNode_effect (exprData_getTripleTrue (data)),
8664 exprNode_effect (exprData_getTripleFalse (data)));
8667 ret = exprNode_whilePred (exprData_getSingle (data));
8671 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
8672 exprNode_effect (exprData_getPairB (data)));
8676 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
8677 exprNode_effect (exprData_getPairB (data)));
8681 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
8685 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
8686 exprData_getUopTok (data));
8690 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
8691 exprNode_effect (exprData_getPairB (data)));
8696 ret = exprNode_caseMarker
8697 (exprNode_effect (exprData_getSingle (data)),
8703 ret = exprNode_createTok (exprData_getTok (data));
8707 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
8708 exprNode_effect (exprData_getPairB (data)));
8712 ret = exprNode_makeInitialization
8713 (exprData_getInitId (data),
8714 exprNode_effect (exprData_getInitNode (data)));
8718 ret = exprNode_fieldAccessAux
8719 (exprNode_effect (exprData_getFieldNode (data)),
8720 exprNode_loc (exprData_getFieldNode (data)),
8721 cstring_copy (exprData_getFieldName (data)));
8725 ret = exprNode_arrowAccessAux
8726 (exprNode_effect (exprData_getFieldNode (data)),
8727 exprNode_loc (exprData_getFieldNode (data)),
8728 cstring_copy (exprData_getFieldName (data)));
8731 case XPR_STRINGLITERAL:
8745 /*@=observertrans@*/
8747 /*@=dependenttrans@*/
8758 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8763 if (exprNode_isError (e))
8765 return cstring_undefined;
8773 ret = exprNode_rootVarName (exprData_getUopNode (data));
8776 ret = exprNode_rootVarName (exprData_getOpA (data));
8780 ret = exprData_getId (data);
8783 ret = idDecl_getName (exprData_getInitId (data));
8808 case XPR_NULLRETURN:
8830 case XPR_STRINGLITERAL:
8831 ret = cstring_undefined;
8838 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8843 if (exprNode_isError (e))
8845 static /*@only@*/ cstring error = cstring_undefined;
8847 if (!cstring_isDefined (error))
8849 error = cstring_makeLiteral ("<error>");
8860 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8863 ret = message ("%s %s %s",
8864 exprNode_unparse (exprData_getOpA (data)),
8865 lltok_unparse (exprData_getOpTok (data)),
8866 exprNode_unparse (exprData_getOpB (data)));
8869 ret = message ("%s(%q)",
8870 exprNode_unparse (exprData_getFcn (data)),
8871 exprNodeList_unparse (exprData_getArgs (data)));
8874 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8877 ret = cstring_undefined;
8880 ret = message ("%s:", exprData_getId (data));
8884 ret = cstring_copy (exprData_getId (data));
8887 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8888 exprNode_unparse (exprData_getPairB (data)));
8891 ret = message ("<body>");
8894 ret = message ("%s %s %s",
8895 exprNode_unparse (exprData_getOpA (data)),
8896 lltok_unparse (exprData_getOpTok (data)),
8897 exprNode_unparse (exprData_getOpB (data)));
8901 ret = message ("%s%s",
8902 lltok_unparse (exprData_getUopTok (data)),
8903 exprNode_unparse (exprData_getUopNode (data)));
8907 ret = message ("%s%s",
8908 exprNode_unparse (exprData_getUopNode (data)),
8909 lltok_unparse (exprData_getUopTok (data)));
8913 ret = message ("offsetof(%s,%q)",
8914 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8915 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8919 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8923 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8927 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8931 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8935 ret = message ("va_arg(%s, %q)",
8936 exprNode_unparse (exprData_getCastNode (data)),
8937 qtype_unparse (exprData_getCastType (data)));
8941 ret = message ("%q(%q)",
8942 uentry_getName (exprData_getIterCallIter (data)),
8943 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8946 ret = message ("%q(%q) %s %q",
8947 uentry_getName (exprData_getIterSname (data)),
8948 exprNodeList_unparse (exprData_getIterAlist (data)),
8949 exprNode_unparse (exprData_getIterBody (data)),
8950 uentry_getName (exprData_getIterEname (data)));
8953 ret = message ("(%q)%s",
8954 qtype_unparse (exprData_getCastType (data)),
8955 exprNode_unparse (exprData_getCastNode (data)));
8959 ret = message ("%s %s",
8960 exprNode_unparse (exprData_getPairA (data)),
8961 exprNode_unparse (exprData_getPairB (data)));
8965 ret = message ("for (%s; %s; %s)",
8966 exprNode_unparse (exprData_getTripleInit (data)),
8967 exprNode_unparse (exprData_getTripleTest (data)),
8968 exprNode_unparse (exprData_getTripleInc (data)));
8972 ret = message ("goto %s", exprData_getLiteral (data));
8976 ret = cstring_makeLiteral ("continue");
8980 ret = cstring_makeLiteral ("break");
8984 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
8987 case XPR_NULLRETURN:
8988 ret = cstring_makeLiteral ("return");
8992 ret = message ("%s, %s",
8993 exprNode_unparse (exprData_getPairA (data)),
8994 exprNode_unparse (exprData_getPairB (data)));
8998 ret = message ("%s ? %s : %s",
8999 exprNode_unparse (exprData_getTriplePred (data)),
9000 exprNode_unparse (exprData_getTripleTrue (data)),
9001 exprNode_unparse (exprData_getTripleFalse (data)));
9004 ret = message ("if (%s) %s",
9005 exprNode_unparse (exprData_getPairA (data)),
9006 exprNode_unparse (exprData_getPairB (data)));
9010 ret = message ("if (%s) %s else %s",
9011 exprNode_unparse (exprData_getTriplePred (data)),
9012 exprNode_unparse (exprData_getTripleTrue (data)),
9013 exprNode_unparse (exprData_getTripleFalse (data)));
9016 ret = message ("while (%s) %s",
9017 exprNode_unparse (exprData_getPairA (data)),
9018 exprNode_unparse (exprData_getPairB (data)));
9022 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
9026 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
9030 ret = message ("do { %s } while (%s)",
9031 exprNode_unparse (exprData_getPairB (data)),
9032 exprNode_unparse (exprData_getPairA (data)));
9036 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
9040 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
9044 ret = message ("%s; %s",
9045 exprNode_unparse (exprData_getPairA (data)),
9046 exprNode_unparse (exprData_getPairB (data)));
9051 ret = cstring_makeLiteral ("default:");
9055 ret = message ("switch (%s) %s",
9056 exprNode_unparse (exprData_getPairA (data)),
9057 exprNode_unparse (exprData_getPairB (data)));
9062 ret = message ("case %s:",
9063 exprNode_unparse (exprData_getSingle (data)));
9067 if (exprNode_isError (exprData_getInitNode (data)))
9069 ret = message ("%q", idDecl_unparseC (exprData_getInitId (data)));
9073 ret = message ("%q = %s",
9074 idDecl_unparseC (exprData_getInitId (data)),
9075 exprNode_unparse (exprData_getInitNode (data)));
9080 ret = message ("%s.%s",
9081 exprNode_unparse (exprData_getFieldNode (data)),
9082 exprData_getFieldName (data));
9086 ret = message ("%s->%s",
9087 exprNode_unparse (exprData_getFieldNode (data)),
9088 exprData_getFieldName (data));
9091 case XPR_STRINGLITERAL:
9092 ret = message ("\"%s\"", exprData_getLiteral (data));
9096 ret = cstring_copy (exprData_getLiteral (data));
9100 ret = cstring_makeLiteral ("<node>");
9108 exprNode_isInitializer (exprNode e)
9110 return (exprNode_isDefined (e)
9111 && e->kind == XPR_INIT);
9115 exprNode_isCharLit (exprNode e)
9117 if (exprNode_isDefined (e))
9119 return (multiVal_isChar (exprNode_getValue (e)));
9128 exprNode_isNumLit (exprNode e)
9130 if (exprNode_isDefined (e))
9132 return (multiVal_isInt (exprNode_getValue (e)));
9141 exprNode_isFalseConstant (exprNode e)
9143 if (exprNode_isDefined (e))
9145 cstring s = exprNode_rootVarName (e);
9147 if (cstring_equal (s, context_getFalseName ()))
9157 exprNode_matchLiteral (ctype expected, exprNode e)
9159 if (exprNode_isDefined (e))
9161 multiVal m = exprNode_getValue (e);
9163 if (multiVal_isDefined (m))
9165 if (multiVal_isInt (m))
9167 long int val = multiVal_forceInt (m);
9169 if (ctype_isDirectBool (ctype_realishType (expected)))
9173 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
9181 if (ctype_isRealInt (expected))
9184 ** unsigned <- [ constant >= 0 is okay ]
9187 if (ctype_isUnsigned (expected))
9196 ** No checks on sizes of integers...maybe add
9200 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
9201 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
9202 bool_unparse (ctype_isInt (exprNode_getType (e)))));
9204 if (context_getFlag (FLG_NUMLITERAL)
9205 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
9211 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
9215 else if (ctype_isChar (expected))
9219 else if (ctype_isArrayPtr (expected))
9223 else if (ctype_isAnyFloat (expected))
9225 return (context_getFlag (FLG_NUMLITERAL));
9232 else if (multiVal_isDouble (m))
9234 if (ctype_isAnyFloat (expected))
9239 else if (multiVal_isChar (m))
9241 char val = multiVal_forceChar (m);
9243 if (ctype_isChar (expected))
9245 if (ctype_isUnsigned (expected) && ((int)val) < 0)
9266 exprNode_matchType (ctype expected, exprNode e)
9270 if (!exprNode_isDefined (e)) return TRUE;
9272 actual = ctype_realishType (exprNode_getType (e));
9274 if (ctype_match (ctype_realishType (expected), actual))
9279 llassert (!exprNode_isError (e));
9280 return (exprNode_matchLiteral (expected, e));
9284 exprNode_matchTypes (exprNode e1, exprNode e2)
9289 if (!exprNode_isDefined (e1)) return TRUE;
9290 if (!exprNode_isDefined (e2)) return TRUE;
9293 ** realish type --- keep bools, bools
9296 t1 = ctype_realishType (exprNode_getType (e1));
9297 t2 = ctype_realishType (exprNode_getType (e2));
9299 if (ctype_match (t1, t2))
9304 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
9312 exprNode_matchArgType (ctype ct, exprNode e)
9316 if (!exprNode_isDefined (e))
9321 et = ctype_realType (exprNode_getType (e));
9323 if (ctype_matchArg (ct, et)) return TRUE;
9325 llassert (!exprNode_isError (e));
9326 return (exprNode_matchLiteral (ct, e));
9329 static /*@only@*/ exprNodeSList
9330 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
9332 if (exprNode_isDefined (e))
9334 if (e->kind == XPR_STMTLIST)
9336 return (exprNodeSList_append
9337 (exprNode_flatten (exprData_getPairA (e->edata)),
9338 exprNode_flatten (exprData_getPairB (e->edata))));
9340 else if (e->kind == XPR_BLOCK)
9342 return (exprNode_flatten (exprData_getSingle (e->edata)));
9346 return (exprNodeSList_singleton (e));
9350 return exprNodeSList_new ();
9353 static /*@exposed@*/ exprNode
9354 exprNode_lastStatement (/*@returned@*/ exprNode e)
9356 if (exprNode_isDefined (e))
9358 if (e->kind == XPR_STMTLIST)
9360 exprNode b = exprData_getPairB (e->edata);
9362 if (exprNode_isDefined (b))
9364 return exprNode_lastStatement (b);
9368 return exprNode_lastStatement (exprData_getPairA (e->edata));
9371 else if (e->kind == XPR_BLOCK)
9373 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
9381 return exprNode_undefined;
9384 static /*@exposed@*/ exprNode
9385 exprNode_firstStatement (/*@returned@*/ exprNode e)
9387 if (exprNode_isDefined (e))
9389 if (e->kind == XPR_STMTLIST)
9391 exprNode b = exprData_getPairA (e->edata);
9393 if (exprNode_isDefined (b))
9395 return exprNode_firstStatement (b);
9399 return exprNode_firstStatement (exprData_getPairB (e->edata));
9402 else if (e->kind == XPR_BLOCK)
9404 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
9412 return exprNode_undefined;
9416 exprNode_mergeUSs (exprNode res, exprNode other)
9418 if (exprNode_isDefined (res) && exprNode_isDefined (other))
9420 res->msets = sRefSet_union (res->msets, other->msets);
9421 res->sets = sRefSet_union (res->sets, other->sets);
9422 res->uses = sRefSet_union (res->uses, other->uses);
9427 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
9429 if (exprNode_isDefined (res))
9431 if (exprNode_isDefined (other1))
9433 res->sets = sRefSet_union (res->sets, other1->sets);
9434 res->msets = sRefSet_union (res->msets, other1->msets);
9435 res->uses = sRefSet_union (res->uses, other1->uses);
9437 if (exprNode_isDefined (other2))
9439 res->sets = sRefSet_union (res->sets, other2->sets);
9440 res->msets = sRefSet_union (res->msets, other2->msets);
9441 res->uses = sRefSet_union (res->uses, other2->uses);
9449 ** Reports errors is s is not defined.
9453 exprNode_addUse (exprNode e, /*@exposed@*/ sRef s)
9455 if (exprNode_isDefined (e))
9457 e->uses = sRefSet_insert (e->uses, s);
9462 exprNode_checkUse (exprNode e, /*@exposed@*/ sRef s, fileloc loc)
9464 if (sRef_isKnown (s) && !sRef_isConst (s))
9467 ** need to check all outer types are useable
9470 DPRINTF (("Check use: %s / %s",
9471 exprNode_unparse (e), sRef_unparse (s)));
9473 exprNode_addUse (e, s);
9475 if (!context_inProtectVars ())
9478 ** only report the deepest error
9481 sRef errorRef = sRef_undefined;
9482 sRef lastRef = sRef_undefined;
9483 bool deadRef = FALSE;
9484 bool unuseable = FALSE;
9485 bool errorMaybe = FALSE;
9487 while (sRef_isValid (s) && sRef_isKnown (s))
9489 ynm readable = sRef_isReadable (s);
9491 DPRINTF (("Readable: %s / %s",
9492 sRef_unparseFull (s), ynm_unparse (readable)));
9494 if (!(ynm_toBoolStrict (readable)))
9496 if (ynm_isMaybe (readable))
9500 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
9501 deadRef = sRef_isPossiblyDead (errorRef);
9502 unuseable = sRef_isUnuseable (errorRef);
9509 deadRef = sRef_isDead (errorRef);
9510 unuseable = sRef_isUnuseable (errorRef);
9514 if (!sRef_isPartial (s))
9516 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
9517 sRef_setDefined (s, fileloc_undefined);
9521 s = sRef_getBaseSafe (s);
9524 if (sRef_isValid (errorRef))
9526 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
9527 && sRef_isPointer (errorRef))
9534 if (sRef_isThroughArrayFetch (errorRef))
9537 (FLG_STRICTUSERELEASED,
9538 message ("%q %q may be used after being released",
9539 sRef_unparseKindNamePlain (errorRef),
9540 sRef_unparse (errorRef)),
9543 sRef_showRefKilled (errorRef);
9545 if (sRef_isKept (errorRef))
9547 sRef_clearAliasState (errorRef, loc);
9553 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
9557 message ("%q %q %qused after being released",
9558 sRef_unparseKindNamePlain (errorRef),
9559 sRef_unparse (errorRef),
9560 cstring_makeLiteral (errorMaybe
9564 sRef_showRefKilled (errorRef);
9566 if (sRef_isKept (errorRef))
9568 sRef_clearAliasState (errorRef, loc);
9577 message ("%q %q%qused in inconsistent state",
9578 sRef_unparseKindName (errorRef),
9579 sRef_unparseOpt (errorRef),
9580 cstring_makeLiteral (errorMaybe ? "may be " : "")),
9583 sRef_showStateInconsistent (errorRef);
9588 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
9592 message ("%q %q%qused before definition",
9593 sRef_unparseKindName (errorRef),
9594 sRef_unparseOpt (errorRef),
9595 cstring_makeLiteral (errorMaybe ? "may be " : "")),
9598 DPRINTF (("Error: %s", sRef_unparseFull (errorRef)));
9601 sRef_setDefined (errorRef, loc);
9603 if (sRef_isAddress (errorRef))
9605 sRef_setDefined (sRef_getRootBase (errorRef), loc);
9607 } /* end is error */
9615 checkSafeUse (exprNode e, /*@exposed@*/ sRef s)
9617 if (exprNode_isDefined (e) && sRef_isKnown (s))
9619 e->uses = sRefSet_insert (e->uses, s);
9624 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
9626 if (exprNode_isDefined (e))
9628 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
9633 exprNode_checkSet (exprNode e, /*@exposed@*/ sRef s)
9635 sRef defines = sRef_undefined;
9637 if (sRef_isValid (s) && !sRef_isNothing (s))
9639 uentry ue = sRef_getBaseUentry (s);
9641 if (uentry_isValid (ue))
9643 uentry_setLset (ue);
9646 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9648 voptgenerror (FLG_USEDEF,
9649 message ("Attempt to set unuseable storage: %q",
9654 if (sRef_isMeaningful (s))
9657 if (sRef_isDead (s))
9659 sRef base = sRef_getBaseSafe (s);
9661 if (sRef_isValid (base)
9662 && sRef_isDead (base))
9664 sRef_setPartial (s, exprNode_loc (e));
9667 defines = s; /* okay - modifies for only param */
9669 else if (sRef_isPartial (s))
9671 sRef eref = exprNode_getSref (e);
9673 if (!sRef_isPartial (eref))
9676 ** should do something different here???
9679 sRef_setDefinedComplete (eref, exprNode_loc (e));
9683 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
9686 if (sRef_isMeaningful (eref))
9695 else if (sRef_isAllocated (s))
9697 sRef eref = exprNode_getSref (e);
9700 if (!sRef_isAllocated (eref))
9702 sRef_setDefinedComplete (eref, exprNode_loc (e));
9706 sRef base = sRef_getBaseSafe (eref);
9708 if (sRef_isValid (base))
9710 sRef_setPdefined (base, exprNode_loc (e));
9718 sRef_setDefinedNCComplete (s, exprNode_loc (e));
9723 else /* not meaningful...but still need to insert it */
9729 if (exprNode_isDefined (e) && sRef_isValid (defines))
9731 e->sets = sRefSet_insert (e->sets, defines);
9736 exprNode_checkMSet (exprNode e, /*@exposed@*/ sRef s)
9738 if (sRef_isValid (s) && !sRef_isNothing (s))
9740 uentry ue = sRef_getBaseUentry (s);
9742 if (uentry_isValid (ue))
9744 uentry_setLset (ue);
9747 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9749 voptgenerror (FLG_USEDEF,
9750 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9754 if (sRef_isMeaningful (s))
9756 sRef_setDefinedComplete (s, exprNode_loc (e));
9759 if (exprNode_isDefined (e))
9761 e->msets = sRefSet_insert (e->msets, s);
9767 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9769 checkAnyCall (fcn, cstring_undefined, params, args,
9770 FALSE, sRefSet_undefined, FALSE, 0);
9774 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9775 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9779 if (uentry_isYield (ucurrent))
9781 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9782 exprNode_checkSet (current, current->sref);
9786 if (uentry_isSefParam (ucurrent))
9788 sRefSet sets = current->sets;
9789 sRef ref = exprNode_getSref (current);
9791 if (sRef_isMacroParamRef (ref))
9793 uentry ue = sRef_getUentry (ref);
9795 if (!uentry_isSefParam (ue))
9800 ("Parameter %d to %s is declared sef, but "
9801 "the argument is a macro parameter declared "
9803 argno, exprNode_unparse (fcn),
9804 exprNode_unparse (current)),
9805 exprNode_loc (current));
9809 if (!sRefSet_isEmpty (sets))
9811 sRefSet reported = sRefSet_undefined;
9813 sRefSet_realElements (current->sets, el)
9815 if (sRefSet_isSameNameMember (reported, el))
9817 ; /* don't report again */
9821 if (sRef_isUnconstrained (el))
9826 ("Parameter %d to %s is declared sef, but "
9827 "the argument calls unconstrained function %s "
9828 "(no guarantee it will not modify something): %s",
9829 argno, exprNode_unparse (fcn),
9830 sRef_unconstrainedName (el),
9831 exprNode_unparse (current)),
9832 exprNode_loc (current));
9839 ("Parameter %d to %s is declared sef, but "
9840 "the argument may modify %q: %s",
9841 argno, exprNode_unparse (fcn),
9843 exprNode_unparse (current)),
9844 exprNode_loc (current));
9847 } end_sRefSet_realElements;
9851 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9852 exprNode_mergeUSs (fcn, current);
9857 checkAnyCall (/*@dependent@*/ exprNode fcn,
9858 /*@dependent@*/ cstring fname,
9861 bool hasMods, sRefSet mods,
9866 int nargs = exprNodeList_size (args);
9871 ** concat all args ud's to f, add each arg sref as a use unless
9872 ** it was specified as "out", in which case it is a def.
9875 uentryList_reset (pn);
9880 ** if paramn is only or unique, no other arg may alias argn
9883 exprNodeList_elements (args, current)
9887 if (exprNode_isDefined (current))
9889 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9891 uentry ucurrent = uentryList_current (pn);
9893 if (specialArgs == 0
9894 || (paramno < specialArgs))
9896 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9898 if (context_maybeSet (FLG_ALIASUNIQUE))
9900 if (uentry_isOnly (ucurrent)
9901 || uentry_isUnique (ucurrent))
9903 checkUniqueParams (fcn, current, args,
9909 else /* uentry is undefined */
9911 if (specialArgs == 0)
9913 exprNode_checkUseParam (current);
9916 exprNode_mergeUSs (fcn, current);
9919 uentryList_advanceSafe (pn);
9920 } end_exprNodeList_elements;
9926 sRefSet_allElements (mods, s)
9929 sRef rb = sRef_getRootBase (s);
9931 if (sRef_isFileOrGlobalScope (rb))
9933 context_usedGlobal (rb);
9936 fb = sRef_fixBaseParam (s, args);
9938 if (!sRef_isMacroParamRef (fb))
9940 if (sRef_isNothing (fb))
9946 if (sRef_isValid (fb))
9948 uentry ue = sRef_getBaseUentry (s);
9950 if (uentry_isValid (ue))
9952 uentry_setLset (ue);
9956 fcn->sets = sRefSet_insert (fcn->sets, fb);
9959 sRef_clearDerivedComplete (s);
9960 } end_sRefSet_allElements;
9966 if (context_hasMods ())
9968 if (context_maybeSet (FLG_MODUNCON))
9972 message ("Undetected modification possible "
9973 "from call to unconstrained function %s: %s",
9975 exprNode_unparse (fcn)),
9976 exprNode_loc (fcn));
9981 if (context_maybeSet (FLG_MODUNCONNOMODS)
9982 && !(context_inIterDef () || context_inIterEnd ()))
9985 (FLG_MODUNCONNOMODS,
9986 message ("Undetected modification possible "
9987 "from call to unconstrained function %s: %s",
9989 exprNode_unparse (fcn)),
9990 exprNode_loc (fcn));
9994 exprNode_checkSetAny (fcn, fname);
9998 void exprNode_checkUseParam (exprNode current)
10000 if (exprNode_isDefined (current))
10002 exprNode_checkUse (current, current->sref, current->loc);
10007 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
10008 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10013 if (!ctype_match (tr1, tr2))
10015 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
10016 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
10022 (void) gentypeerror
10024 message ("Incompatible types for %s (%s, %s): %s %s %s",
10025 lltok_unparse (op),
10026 ctype_unparse (te1),
10027 ctype_unparse (te2),
10028 exprNode_unparse (e1), lltok_unparse (op),
10029 exprNode_unparse (e2)),
10032 ret = ctype_unknown;
10036 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
10038 ret = ctype_resolveNumerics (tr1, tr2);
10040 else if (!context_msgStrictOps ())
10042 if (ctype_isPointer (tr1))
10044 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
10048 else if (ctype_isInt (tr2))
10054 ret = ctype_unknown;
10057 else if (ctype_isPointer (tr2))
10059 if (ctype_isPointer (tr1))
10063 else if (ctype_isInt (tr1))
10069 ret = ctype_unknown;
10074 ret = ctype_resolveNumerics (tr1, tr2);
10079 int opid = lltok_getTok (op);
10080 bool comparop = (opid == EQ_OP || opid == NE_OP
10081 || opid == TLT || opid == TGT
10082 || opid == LE_OP || opid == GE_OP);
10084 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
10087 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
10088 || (ctype_isBool (tr1) && ctype_isBool (tr2))
10089 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
10095 if (ctype_sameName (te1, te2))
10099 message ("Operands of %s are non-numeric (%t): %s %s %s",
10100 lltok_unparse (op), te1,
10101 exprNode_unparse (e1), lltok_unparse (op),
10102 exprNode_unparse (e2)),
10109 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
10110 lltok_unparse (op), te1, te2,
10111 exprNode_unparse (e1), lltok_unparse (op),
10112 exprNode_unparse (e2)),
10117 else if (!ctype_isNumeric (tr1))
10121 message ("Right operand of %s is non-numeric (%t): %s %s %s",
10122 lltok_unparse (op), te1,
10123 exprNode_unparse (e1), lltok_unparse (op),
10124 exprNode_unparse (e2)),
10129 if (!ctype_isNumeric (tr2))
10133 message ("Left operand of %s is non-numeric (%t): %s %s %s",
10134 lltok_unparse (op), te2,
10135 exprNode_unparse (e1), lltok_unparse (op),
10136 exprNode_unparse (e2)),
10141 ret = ctype_unknown;
10149 abstractOpError (ctype tr1, ctype tr2, lltok op,
10150 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10151 fileloc loc1, fileloc loc2)
10153 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
10155 if (ctype_match (tr1, tr2))
10159 message ("Operands of %s are abstract type (%t): %s %s %s",
10160 lltok_unparse (op), tr1,
10161 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10168 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
10169 lltok_unparse (op), tr1, tr2,
10170 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10174 else if (ctype_isRealAbstract (tr1))
10178 message ("Left operand of %s is abstract type (%t): %s %s %s",
10179 lltok_unparse (op), tr1,
10180 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10185 if (ctype_isRealAbstract (tr2))
10189 message ("Right operand of %s is abstract type (%t): %s %s %s",
10190 lltok_unparse (op), tr2,
10191 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10200 ** requies e1 and e2 and not error exprNode's.
10204 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
10205 ** the rep of the abstract type is exposed.
10207 ** The order is very important:
10209 ** check rep expose (move into check transfer)
10215 ** This isn't really a sensible procedure, but the indententation
10216 ** was getting too deep.
10220 checkOneRepExpose (sRef ysr, sRef base,
10221 /*@notnull@*/ exprNode e1,
10222 /*@notnull@*/ exprNode e2, ctype ct,
10225 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
10226 || sRef_isOwned (ysr)
10227 || sRef_isExposed (ysr)))
10229 if (sRef_isAnyParam (base) && !sRef_isExposed (base)
10230 && !sRef_isObserver (base)) /* evans 2001-07-11: added isObserver */
10233 if (sRef_isIReference (ysr))
10235 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10240 ("Assignment of mutable component of parameter %q "
10241 "to component of abstract "
10242 "type %s exposes rep: %s = %s",
10243 sRef_unparse (base),
10244 ctype_unparse (ct),
10245 exprNode_unparse (e1), exprNode_unparse (e2)),
10253 ("Assignment of mutable component of parameter %q "
10254 "(through alias %q) to component of abstract "
10255 "type %s exposes rep: %s = %s",
10256 sRef_unparse (base),
10257 sRef_unparse (e2->sref),
10258 ctype_unparse (ct),
10259 exprNode_unparse (e1), exprNode_unparse (e2)),
10265 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10269 message ("Assignment of mutable parameter %q "
10270 "to component of abstract type %s "
10271 "exposes rep: %s = %s",
10272 sRef_unparse (base),
10273 ctype_unparse (ct),
10274 exprNode_unparse (e1),
10275 exprNode_unparse (e2)),
10282 message ("Assignment of mutable parameter %q "
10283 "(through alias %q) to "
10284 "component of abstract type %s exposes "
10286 sRef_unparse (base),
10287 sRef_unparse (e2->sref),
10288 ctype_unparse (ct),
10289 exprNode_unparse (e1),
10290 exprNode_unparse (e2)),
10296 if (sRef_isFileOrGlobalScope (s2b))
10298 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10302 message ("Assignment of global %q "
10304 "abstract type %s exposes rep: %s = %s",
10305 sRef_unparse (base),
10306 ctype_unparse (ct),
10307 exprNode_unparse (e1), exprNode_unparse (e2)),
10314 message ("Assignment of global %q (through alias %q) "
10316 "abstract type %s exposes rep: %s = %s",
10317 sRef_unparse (base),
10318 sRef_unparse (e2->sref),
10319 ctype_unparse (ct),
10320 exprNode_unparse (e1), exprNode_unparse (e2)),
10328 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
10330 if (ctype_isRealFunction (exprNode_getType (e1))
10331 && !ctype_isRealPointer (exprNode_getType (e1)))
10335 message ("Invalid left-hand side of assignment (function type %s): %s",
10336 ctype_unparse (exprNode_getType (e1)),
10337 exprNode_unparse (e1)),
10341 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
10343 ctype t2 = exprNode_getType (e2);
10344 sRef sr = sRef_getRootBase (e1->sref);
10345 ctype ct = sRef_getType (sr);
10347 if (ctype_isAbstract (t2)
10348 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
10350 /* it is immutable, okay to reference */
10351 goto donerepexpose;
10354 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
10356 sRef s2b = sRef_getRootBase (e2->sref);
10357 sRef s1 = e1->sref;
10358 sRef s1b = sRef_getRootBase (s1);
10361 aliases = usymtab_canAlias (e2->sref);
10363 if (!sRef_similar (s2b, s1b)
10364 && !sRef_isExposed (s1)
10365 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
10367 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
10368 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
10369 && !sRef_isExposed (s2b))
10371 if (sRef_isIReference (e2->sref))
10376 ("Assignment of mutable component of parameter %q "
10377 "to component of abstract type %s exposes rep: %s = %s",
10378 sRef_unparse (s2b),
10379 ctype_unparse (ct),
10380 exprNode_unparse (e1), exprNode_unparse (e2)),
10387 message ("Assignment of mutable parameter %q to "
10388 "component of abstract type %s exposes rep: %s = %s",
10389 sRef_unparse (s2b),
10390 ctype_unparse (ct),
10391 exprNode_unparse (e1), exprNode_unparse (e2)),
10396 if (sRef_isFileOrGlobalScope (s2b))
10400 message ("Assignment of global %q to component of "
10401 "abstract type %s exposes rep: %s = %s",
10402 sRef_unparse (s2b),
10403 ctype_unparse (ct),
10404 exprNode_unparse (e1), exprNode_unparse (e2)),
10408 sRefSet_realElements (aliases, ysr)
10410 sRef base = sRef_getRootBase (ysr);
10412 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
10413 || sRef_sameName (base, s1b))
10415 ; /* error already reported or same sref */
10419 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
10421 } end_sRefSet_realElements;
10423 sRefSet_free (aliases);
10430 ** function variables don't really work...
10433 if (!ctype_isFunction (ctype_realType (e2->typ)))
10437 DPRINTF (("Check init: %s / %s",
10438 exprNode_unparse (e1), exprNode_unparse (e2)));
10439 checkInitTransfer (e1, e2);
10443 checkAssignTransfer (e1, e2);
10448 sRef fref = e2->sref;
10450 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
10451 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
10453 /* Need to typecheck the annotation on the parameters */
10455 if (ctype_isRealFunction (e1->typ)) {
10456 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
10457 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
10459 if (!uentryList_isMissingParams (e1p)
10460 && !uentryList_isMissingParams (e2p)
10461 && uentryList_size (e1p) > 0) {
10462 if (uentryList_size (e1p) == uentryList_size (e2p)) {
10465 uentryList_elements (e1p, el1) {
10468 el2 = uentryList_getN (e2p, n);
10470 uentry_checkMatchParam (el1, el2, n, e2);
10471 } end_uentryList_elements;
10477 if (isInit && sRef_isFileOrGlobalScope (e1->sref))
10483 DPRINTF (("Update aliases: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
10484 updateAliases (e1, e2);
10489 checkMacroParen (exprNode e)
10491 if (exprNode_isError (e) || e->kind == XPR_CAST)
10497 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
10501 message ("Macro parameter used without parentheses: %s",
10502 exprNode_unparse (e)),
10509 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
10513 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
10517 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
10524 ** if e2 is a parameter or global derived location which
10525 ** can be modified (that is, e2 is a mutable abstract type,
10526 ** or a derived pointer), then e1 can alias e2.
10528 ** e1 can alias everything which e2 can alias.
10530 ** Also, if e1 is guarded, remove from guard sets!
10533 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
10535 if (!context_inProtectVars ())
10538 ** depends on types of e1 and e2
10541 sRef s1 = e1->sref;
10542 sRef s2 = e2->sref;
10543 ctype t1 = exprNode_getType (e1);
10545 /* handle pointer sRefs, record fields, arrays, etc... */
10547 if (!ctype_isRealSU (t1))
10549 DPRINTF (("Copying real! %s", ctype_unparse (t1)));
10550 sRef_copyRealDerivedComplete (s1, s2);
10555 ** Fields should alias
10558 DPRINTF (("Not COPYING!: %s", ctype_unparse (t1)));
10561 if (ctype_isMutable (t1) && sRef_isKnown (s1))
10563 usymtab_clearAlias (s1);
10564 usymtab_addMustAlias (s1, s2);
10565 DPRINTF (("Add must alias: %s / %s", sRef_unparse (s1), sRef_unparse (s2)));
10569 DPRINTF (("Not mutable: %s", ctype_unparse (t1)));
10572 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
10574 usymtab_unguard (s1);
10579 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
10581 if (exprNode_isDefined (e))
10583 e->loc = fileloc_update (e->loc, loc);
10587 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
10593 static void checkUniqueParams (exprNode fcn,
10594 /*@notnull@*/ exprNode current,
10596 int paramno, uentry ucurrent)
10599 sRef thisref = exprNode_getSref (current);
10602 ** Check if any argument could match this argument.
10605 exprNodeList_elements (args, icurrent)
10609 if (iparamno != paramno)
10611 sRef sr = exprNode_getSref (icurrent);
10613 if (sRef_similarRelaxed (thisref, sr))
10615 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
10620 ("Parameter %d (%s) to function %s is declared %s but "
10621 "is aliased by parameter %d (%s)",
10623 exprNode_unparse (current),
10624 exprNode_unparse (fcn),
10625 alkind_unparse (uentry_getAliasKind (ucurrent)),
10626 iparamno, exprNode_unparse (icurrent)),
10632 sRefSet aliases = usymtab_canAlias (sr);
10634 sRefSet_allElements (aliases, asr)
10636 if (ctype_isUnknown (sRef_getType (thisref)))
10638 sRef_setType (thisref, uentry_getType (ucurrent));
10641 if (sRef_similarRelaxed (thisref, asr))
10643 if (sRef_isExternal (asr))
10645 if (sRef_isLocalState (thisref))
10651 sRef base = sRef_getRootBase (asr);
10653 if (!sRef_similar (sRef_getBase (asr), thisref))
10655 if (sRef_isUnique (base) || sRef_isOnly (base)
10656 || sRef_isKept (base)
10657 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
10658 || (sRef_isAddress (thisref)
10659 && sRef_isLocalVar (sRef_getRootBase (thisref))))
10661 ; /* okay, no error */
10666 (FLG_MAYALIASUNIQUE,
10668 ("Parameter %d (%s) to function %s is declared %s but "
10669 "may be aliased externally by parameter %d (%s)",
10671 exprNode_unparse (current),
10672 exprNode_unparse (fcn),
10673 alkind_unparse (uentry_getAliasKind (ucurrent)),
10674 iparamno, exprNode_unparse (icurrent)),
10685 ("Parameter %d (%s) to function %s is declared %s but "
10686 "is aliased externally by parameter %d (%s) through "
10689 exprNode_unparse (current),
10690 exprNode_unparse (fcn),
10691 alkind_unparse (uentry_getAliasKind (ucurrent)),
10692 iparamno, exprNode_unparse (icurrent),
10693 sRef_unparse (asr)),
10697 } end_sRefSet_allElements;
10698 sRefSet_free (aliases);
10701 } end_exprNodeList_elements;
10704 long exprNode_getLongValue (exprNode e) {
10707 if (exprNode_hasValue (e)
10708 && multiVal_isInt (exprNode_getValue (e)))
10710 value = multiVal_forceInt (exprNode_getValue (e));
10720 /*@observer@*/ fileloc exprNode_getfileloc (exprNode p_e)
10722 if (exprNode_isDefined (p_e) )
10723 return ( p_e->loc );
10725 return fileloc_undefined;
10728 /*@only@*/ fileloc exprNode_getNextSequencePoint (exprNode e)
10731 ** Returns the location of the sequence point following e.
10733 ** Only works for statements (for now).
10736 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
10737 lltok t = exprData_getUopTok (e->edata);
10738 return fileloc_copy(lltok_getLoc (t));
10740 /* drl possible problem : warning fix
10741 llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
10743 return fileloc_undefined;
10747 exprNode exprNode_createNew(ctype c)
10751 ret = exprNode_createPlain (c);
10756 bool exprNode_isInitBlock (exprNode e)
10758 return (exprNode_isDefined(e) && e->kind == XPR_INITBLOCK);