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 DPRINTF (("Array fetch: %s / %s",
1090 exprNode_unparse (e1), exprNode_unparse (e2)));
1092 if (exprNode_isError (e1))
1095 return (exprNode_makeError ());
1101 ctype carr = exprNode_getType (e1);
1102 ctype crarr = ctype_realType (carr);
1105 ** this sets up funny aliasing, that leads to spurious
1106 ** lclint errors. Hence, the i2 comments.
1109 /* evans 2001-09-09 added ctype_isKnown so there is no swap when e1 type is unknown */
1110 if (ctype_isKnown (crarr)
1111 && !ctype_isRealArray (crarr)
1112 && ctype_isRealNumeric (crarr)
1113 && !exprNode_isError (e2)
1114 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1119 carr = exprNode_getType (arr);
1120 crarr = ctype_realType (carr);
1128 DPRINTF (("arr: %s", exprNode_unparse (arr)));
1130 if (sRef_possiblyNull (arr->sref))
1132 if (!usymtab_isGuarded (arr->sref))
1134 if (optgenerror (FLG_NULLDEREF,
1135 message ("Index of %s pointer %q: %s",
1136 sRef_nullMessage (arr->sref),
1137 sRef_unparse (arr->sref),
1138 exprNode_unparse (arr)),
1141 DPRINTF (("ref: %s", sRef_unparseFull (arr->sref)));
1142 sRef_showNullInfo (arr->sref);
1144 /* suppress future messages */
1145 sRef_setNullError (arr->sref);
1150 if (exprNode_isError (ind))
1152 if ((ctype_isArrayPtr (crarr)
1153 && !ctype_isFunction (crarr))
1154 || ctype_isUnknown (carr))
1156 exprNode ret = exprNode_createPartialCopy (arr);
1158 if (ctype_isKnown (carr))
1160 ret->typ = ctype_baseArrayPtr (crarr);
1164 ret->typ = ctype_unknown;
1167 ret->sref = sRef_makeArrayFetch (arr->sref);
1169 ret->kind = XPR_FETCH;
1172 ** Because of funny aliasing (when arr and ind are
1173 ** flipped) spurious errors would be reported here.
1176 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1177 checkSafeUse (ret, arr->sref);
1182 voptgenerror (FLG_TYPE,
1183 message ("Array fetch from non-array (%t): %s[%s]", carr,
1184 exprNode_unparse (e1), exprNode_unparse (e2)),
1186 exprNode_free (arr);
1187 return (exprNode_makeError ());
1192 if (!ctype_isForceRealInt (&(ind->typ)))
1194 ctype rt = ctype_realType (ind->typ);
1196 if (ctype_isChar (rt))
1200 message ("Array fetch using non-integer, %t: %s[%s]",
1202 exprNode_unparse (e1), exprNode_unparse (e2)),
1205 else if (ctype_isEnum (rt))
1209 message ("Array fetch using non-integer, %t: %s[%s]",
1211 exprNode_unparse (e1), exprNode_unparse (e2)),
1218 message ("Array fetch using non-integer, %t: %s[%s]",
1220 exprNode_unparse (e1), exprNode_unparse (e2)),
1224 multiVal_free (ind->val);
1225 ind->val = multiVal_unknown ();
1228 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1230 exprNode ret = exprNode_createSemiCopy (arr);
1231 multiVal m = exprNode_getValue (ind);
1233 ret->typ = ctype_baseArrayPtr (crarr);
1234 ret->kind = XPR_FETCH;
1236 if (multiVal_isInt (m))
1238 int i = (int) multiVal_forceInt (m);
1240 if (sRef_isValid (arr->sref)) {
1241 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1243 ret->sref = sRef_undefined;
1248 ret->sref = sRef_makeArrayFetch (arr->sref);
1251 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1252 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1253 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1255 /* (see comment on spurious errors above) */
1256 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1258 exprNode_checkUse (ret, ind->sref, ind->loc);
1259 exprNode_checkUse (ret, arr->sref, arr->loc);
1265 if (ctype_isUnknown (carr))
1267 exprNode ret = exprNode_createPartialCopy (arr);
1269 ret->kind = XPR_FETCH;
1270 ret->typ = ctype_unknown;
1271 ret->sets = sRefSet_union (ret->sets, ind->sets);
1272 ret->msets = sRefSet_union (ret->msets, ind->msets);
1273 ret->uses = sRefSet_union (ret->uses, ind->uses);
1275 /* (see comment on spurious errors above) */
1276 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1278 exprNode_checkUse (ret, ind->sref, ind->loc);
1279 exprNode_checkUse (ret, arr->sref, arr->loc);
1286 message ("Array fetch from non-array (%t): %s[%s]", carr,
1287 exprNode_unparse (e1), exprNode_unparse (e2)),
1290 exprNode_free (arr);
1291 exprNode_free (ind);
1293 return (exprNode_makeError ());
1303 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1304 exprNodeList args, exprNode ret)
1306 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1310 ** checkPrintfArgs --- checks arguments for printf-like functions
1311 ** Arguments before ... have already been checked.
1312 ** The argument before the ... is a char *.
1313 ** argno is the format string argument.
1317 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1318 exprNodeList args, exprNode ret, int argno)
1321 ** the last argument before the elips is the format string
1326 int nargs = exprNodeList_size (args);
1327 uentryList params = uentry_getParams (fcn);
1331 ** These should be ensured by checkSpecialFunction
1334 llassert (uentryList_size (params) == argno + 1);
1335 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1337 a = exprNodeList_getN (args, argno - 1);
1338 formatloc = fileloc_copy (exprNode_loc (a));
1340 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1341 && exprNode_knownStringValue (a))
1343 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1344 char *code = format;
1347 nargs = exprNodeList_size (args);
1349 while ((code = strchr (code, '%')) != NULL)
1351 char *origcode = code;
1352 cstring codetext = cstring_newEmpty ();
1353 char key = *(++code);
1354 ctype modtype = ctype_int;
1355 bool modified = FALSE;
1357 fileloc_addColumn (formatloc, code - ocode);
1359 codetext = cstring_appendChar (codetext, key);
1362 while (isFlagKey (key))
1365 codetext = cstring_appendChar (codetext, key);
1366 fileloc_incColumn (formatloc);
1369 if (key == 'm') /* skipped in syslog */
1374 /* ignore field width */
1375 while (isdigit ((int) key) != 0)
1378 codetext = cstring_appendChar (codetext, key);
1379 fileloc_incColumn (formatloc);
1382 /* ignore precision */
1386 codetext = cstring_appendChar (codetext, key);
1387 fileloc_incColumn (formatloc);
1390 ** In printf, '*' means: read the next arg as an int for the
1391 ** field width. This seems to be missing from my copy of the
1392 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1393 ** later) but never does.
1398 ; /* don't do anything --- handle later */
1402 while (isdigit ((int) key) != 0)
1405 codetext = cstring_appendChar (codetext, key);
1406 fileloc_incColumn (formatloc);
1413 modtype = ctype_sint; /* short */
1415 codetext = cstring_appendChar (codetext, key);
1416 fileloc_incColumn (formatloc);
1418 else if (key == 'l' || key == 'L')
1420 modtype = ctype_lint; /* long */
1422 codetext = cstring_appendChar (codetext, key);
1423 fileloc_incColumn (formatloc);
1425 if (key == 'l' || key == 'L') {
1426 modtype = ctype_llint; /* long long */
1428 codetext = cstring_appendChar (codetext, key);
1429 fileloc_incColumn (formatloc);
1437 /* now, key = type of conversion to apply */
1439 fileloc_incColumn (formatloc);
1447 message ("No argument corresponding to %q format "
1448 "code %d (%%%s): \"%s\"",
1449 uentry_getName (fcn),
1451 cstring_fromChars (format)),
1454 if (fileloc_isDefined (formatloc)
1455 && context_getFlag (FLG_SHOWCOL))
1457 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1465 a = exprNodeList_getN (args, i);
1468 if (!exprNode_isError (a))
1474 case '*': /* int argument for fieldwidth */
1475 expecttype = ctype_int;
1476 *(--code) = '%'; /* convert it for next code */
1477 fileloc_subColumn (formatloc, 1);
1478 /*@switchbreak@*/ break;
1481 expecttype = ctype_combine (ctype_uint, modtype);
1482 /*@switchbreak@*/ break;
1484 case 'i': /* int argument */
1486 expecttype = ctype_combine (ctype_int, modtype);
1487 /*@switchbreak@*/ break;
1489 case 'x': /* unsigned int */
1491 expecttype = ctype_combine (ctype_uint, modtype);
1493 /*@switchbreak@*/ break;
1499 case 'f': /* double */
1500 expecttype = ctype_combine (ctype_double, modtype);
1501 /*@switchbreak@*/ break;
1503 case 'c': /* int converted to char (check its a char?) */
1504 expecttype = ctype_makeConj (ctype_char, ctype_uchar);
1505 /*@switchbreak@*/ break;
1507 case 's': /* string */
1508 expecttype = ctype_string;
1509 /*@switchbreak@*/ break;
1512 while (((key = *(++code)) != ']')
1515 codetext = cstring_appendChar (codetext, key);
1516 fileloc_incColumn (formatloc);
1522 (message ("Bad character set format: %s",
1523 cstring_fromChars (origcode)));
1526 expecttype = ctype_string;
1527 /*@switchbreak@*/ break;
1529 case 'p': /* pointer */
1530 expecttype = ctype_makePointer (ctype_void);
1531 uentry_setDefState (regArg, SS_RELDEF); /* need not be defined */
1532 sRef_setPosNull (uentry_getSref (regArg), fileloc_undefined); /* could be null */
1533 /*@switchbreak@*/ break;
1535 case 'n': /* pointer to int, modified by call! */
1536 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1538 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1539 /*@switchbreak@*/ break;
1541 case 'm': /* in a syslog, it doesn't consume an argument */
1542 /* should check we're really doing syslog */
1544 /*@switchbreak@*/ break;
1548 expecttype = ctype_unknown;
1552 message ("Unrecognized format code: %s",
1553 cstring_fromChars (origcode)),
1554 fileloc_isDefined (formatloc)
1555 ? formatloc : g_currentloc);
1557 /*@switchbreak@*/ break;
1560 if (!(exprNode_matchArgType (expecttype, a)))
1562 if (ctype_isVoidPointer (expecttype)
1563 && ctype_isRealAbstract (a->typ)
1564 && (context_getFlag (FLG_ABSTVOIDP)))
1570 if (llgenformattypeerror
1571 (expecttype, exprNode_undefined,
1573 message ("Format argument %d to %q (%%%s) expects "
1576 uentry_getName (fcn),
1579 a->typ, exprNode_unparse (a)),
1582 if (fileloc_isDefined (formatloc)
1583 && context_getFlag (FLG_SHOWCOL))
1586 (cstring_makeLiteral
1587 ("Corresponding format code"),
1594 uentry_setType (regArg, expecttype);
1595 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1597 if (ctype_equal (expecttype, ctype_string))
1599 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1602 uentry_setType (regArg, ctype_unknown);
1603 uentry_fixupSref (regArg);
1607 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1618 cstring_free (codetext);
1623 voptgenerror (FLG_TYPE,
1624 message ("Format string for %q has %d arg%&, given %d",
1625 uentry_getName (fcn), i - argno, nargs - argno),
1631 /* no checking possible for compile-time unknown format strings */
1632 if (exprNode_isDefined (a))
1636 message ("Format string parameter to %s is not a compile-time constant: %s",
1637 exprNode_unparse (f),
1638 exprNode_unparse (a)),
1643 fileloc_free (formatloc);
1647 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1648 exprNodeList args, exprNode ret, int argno)
1652 int nargs = exprNodeList_size (args);
1653 uentryList params = uentry_getParams (fcn);
1657 ** These should be ensured by checkSpecialFunction
1660 llassert (uentryList_size (params) == argno + 1);
1661 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1663 a = exprNodeList_getN (args, argno - 1);
1664 formatloc = fileloc_copy (exprNode_loc (a));
1666 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1667 && exprNode_knownStringValue (a))
1669 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1670 char *code = format;
1673 nargs = exprNodeList_size (args);
1675 while ((code = strchr (code, '%')) != NULL)
1677 char *origcode = code;
1678 char key = *(++code);
1679 cstring codetext = cstring_newEmpty ();
1680 ctype modtype = ctype_int;
1681 char modifier = '\0';
1682 bool modified = TRUE;
1683 bool ignore = FALSE;
1685 codetext = cstring_appendChar (codetext, key);
1686 fileloc_addColumn (formatloc, code - ocode);
1689 ** this is based on ANSI standard library description of fscanf
1690 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1693 /* '*' suppresses assignment (does not need match argument) */
1698 codetext = cstring_appendChar (codetext, key);
1701 fileloc_incColumn (formatloc);
1704 /* ignore field width */
1705 while (isdigit ((int) key) != 0)
1708 codetext = cstring_appendChar (codetext, key);
1709 fileloc_incColumn (formatloc);
1714 modtype = ctype_sint; /* short */
1716 codetext = cstring_appendChar (codetext, key);
1717 fileloc_incColumn (formatloc);
1719 else if (key == 'l' || key == 'L')
1721 modtype = ctype_lint; /* long */
1725 codetext = cstring_appendChar (codetext, key);
1727 fileloc_incColumn (formatloc);
1729 if (key == 'l' || key == 'L') {
1730 modtype = ctype_llint; /* long long */
1732 codetext = cstring_appendChar (codetext, key);
1733 fileloc_incColumn (formatloc);
1741 /* now, key = type of conversion to apply */
1743 fileloc_incColumn (formatloc);
1757 message ("No argument corresponding to %q format "
1758 "code %d (%%%s): \"%s\"",
1759 uentry_getName (fcn),
1761 cstring_fromChars (format)),
1764 if (fileloc_isDefined (formatloc)
1765 && context_getFlag (FLG_SHOWCOL))
1768 (cstring_makeLiteral ("Corresponding format code"),
1776 a = exprNodeList_getN (args, i);
1779 if (!exprNode_isError (a))
1785 case '*': /* int argument for fieldwidth */
1786 expecttype = ctype_makePointer (ctype_int);
1787 *(--code) = '%'; /* convert it for next code */
1788 fileloc_subColumn (formatloc, 1);
1789 /*@switchbreak@*/ break;
1792 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1793 /*@switchbreak@*/ break;
1798 case 'X': /* unsigned int */
1799 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1800 /*@switchbreak@*/ break;
1807 /* printf is double, scanf is float! */
1809 if (modifier == 'l')
1811 expecttype = ctype_makePointer (ctype_double);
1813 else if (modifier == 'L')
1815 expecttype = ctype_makePointer (ctype_ldouble);
1819 llassert (modifier == '\0');
1820 expecttype = ctype_makePointer (ctype_float);
1822 /*@switchbreak@*/ break;
1824 case 'c': /* int converted to char (check its a char?) */
1825 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1826 /*@switchbreak@*/ break;
1828 case 's': /* string */
1829 expecttype = ctype_string;
1830 /*@switchbreak@*/ break;
1834 while (((key = *(++code)) != ']')
1837 codetext = cstring_appendChar (codetext, key);
1838 fileloc_incColumn (formatloc);
1844 (message ("Bad character set format: %s",
1845 cstring_fromChars (origcode)));
1848 expecttype = ctype_string;
1849 /*@switchbreak@*/ break;
1852 case 'p': /* pointer */
1855 message ("Format code should not be used in scanf: %s",
1856 cstring_fromChars (origcode)),
1857 fileloc_isDefined (formatloc)
1858 ? formatloc : g_currentloc);
1860 expecttype = ctype_unknown;
1861 /*@switchbreak@*/ break;
1863 case 'n': /* pointer to int, modified by call! */
1864 expecttype = ctype_makePointer (ctype_int);
1865 /*@switchbreak@*/ break;
1868 expecttype = ctype_unknown;
1872 message ("Unrecognized format code: %s",
1873 cstring_fromChars (origcode)),
1874 fileloc_isDefined (formatloc)
1875 ? formatloc : g_currentloc);
1877 /*@switchbreak@*/ break;
1880 if (!(exprNode_matchArgType (expecttype, a)))
1882 if (ctype_isVoidPointer (expecttype)
1883 && ctype_isRealAbstract (a->typ)
1884 && (context_getFlag (FLG_ABSTVOIDP)))
1890 if (llgenformattypeerror
1891 (expecttype, exprNode_undefined,
1893 message ("Format argument %d to %q (%%%s) expects "
1896 uentry_getName (fcn),
1897 codetext, expecttype,
1898 a->typ, exprNode_unparse (a)),
1901 if (fileloc_isDefined (formatloc)
1902 && context_getFlag (FLG_SHOWCOL))
1905 (cstring_makeLiteral
1906 ("Corresponding format code"),
1913 uentry_setType (outArg, expecttype);
1914 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
1915 uentry_setType (outArg, ctype_unknown);
1916 uentry_fixupSref (outArg);
1920 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1925 /* a->sref = defref; */
1932 cstring_free (codetext);
1937 voptgenerror (FLG_TYPE,
1938 message ("Format string for %q has %d arg%&, given %d",
1939 uentry_getName (fcn), i - argno, nargs - argno),
1945 /* no checking possible for compile-time unknown format strings */
1948 fileloc_free (formatloc);
1952 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
1955 /*@unused@*/ int argno)
1958 ** the last argument before the elips is the format string
1961 int nargs = exprNodeList_size (args);
1966 a = exprNodeList_getN (args, argno - 1);
1967 formatloc = fileloc_copy (exprNode_loc (a));
1969 if (ctype_isUnknown (cstringType)) {
1970 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
1972 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
1976 if (ctype_isUnknown (ctypeType)) {
1977 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
1979 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
1983 if (ctype_isUnknown (filelocType)) {
1984 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
1986 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
1990 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1991 && exprNode_knownStringValue (a))
1993 cstring format = multiVal_forceString (exprNode_getValue (a));
1994 char *code = cstring_toCharsSafe (format);
1997 nargs = exprNodeList_size (args);
1999 while ((code = strchr (code, '%')) != NULL)
2001 char *origcode = code;
2002 char key = *(++code);
2003 cstring codetext = cstring_newEmpty ();
2004 bool isOnly = FALSE;
2006 codetext = cstring_appendChar (codetext, key);
2008 fileloc_addColumn (formatloc, code - ocode);
2010 while (key >= '0' && key <= '9')
2013 codetext = cstring_appendChar (codetext, key);
2014 fileloc_incColumn (formatloc);
2018 fileloc_incColumn (formatloc);
2022 if (key == '&') /* plural marker */
2031 message ("Message missing format arg %d (%%%s): \"%s\"",
2032 i + 1, codetext, format),
2038 a = exprNodeList_getN (args, i);
2042 if (!exprNode_isError (a))
2046 /*@-loopswitchbreak@*/
2052 expecttype = ctype_char; break;
2054 expecttype = cstringType; break;
2056 expecttype = cstringType; isOnly = TRUE; break;
2058 expecttype = cstringType; isOnly = TRUE; break;
2059 case 'd': expecttype = ctype_int; break;
2060 case 'u': expecttype = ctype_uint; break;
2061 case 'w': expecttype = ctype_ulint; break;
2062 case 'f': expecttype = ctype_float; break;
2063 case 'b': expecttype = ctype_bool; break;
2064 case 't': expecttype = ctypeType; break;
2065 case 'l': expecttype = filelocType; break;
2066 case '&': /* a wee bit of a hack methinks */
2067 expecttype = ctype_int;
2069 case 'r': expecttype = ctype_bool; break;
2071 expecttype = ctype_unknown;
2074 message ("Unrecognized format code: %s",
2075 cstring_fromChars (origcode)),
2076 fileloc_isDefined (formatloc)
2077 ? formatloc : g_currentloc);
2080 /*@=loopswitchbreak@*/
2082 if (!(exprNode_matchArgType (expecttype, a)))
2084 if (ctype_isVoidPointer (expecttype)
2085 && ctype_isRealAbstract (a->typ)
2086 && (context_getFlag (FLG_ABSTVOIDP)))
2092 if (llgenformattypeerror
2093 (expecttype, exprNode_undefined,
2095 message ("Format argument %d to %q (%%%s) expects "
2098 uentry_getName (fcn),
2099 codetext, expecttype,
2100 a->typ, exprNode_unparse (a)),
2103 if (fileloc_isDefined (formatloc)
2104 && context_getFlag (FLG_SHOWCOL))
2107 (cstring_makeLiteral
2108 ("Corresponding format code"),
2115 if (ctype_equal (expecttype, cstringType))
2119 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
2120 uentry_fixupSref (csOnlyArg);
2124 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2125 uentry_fixupSref (csArg);
2130 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2131 uentry_fixupSref (regArg);
2137 cstring_free (codetext);
2142 voptgenerror (FLG_TYPE,
2143 message ("Format string for %q has %d arg%&, given %d",
2144 uentry_getName (fcn), i - argno, nargs -argno),
2150 /* no checking possible for compile-time unknown format strings */
2153 fileloc_free (formatloc);
2157 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2158 /*@notnull@*/ exprNode e2,
2164 bool hadUncon = FALSE;
2166 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e1->sref)) &&
2167 sRefSet_hasUnconstrained (sets2))
2170 (FLG_EVALORDERUNCON,
2172 ("Expression may have undefined behavior (%q used in right operand "
2173 "may set global variable %q used in left operand): %s %s %s",
2174 sRefSet_unparseUnconstrained (sets2),
2175 sRef_unparse (sRef_getRootBase (e1->sref)),
2176 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2180 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e2->sref)) &&
2181 sRefSet_hasUnconstrained (sets1))
2184 (FLG_EVALORDERUNCON,
2186 ("Expression has undefined behavior (%q used in left operand "
2187 "may set global variable %q used in right operand): %s %s %s",
2188 sRefSet_unparseUnconstrained (sets1),
2189 sRef_unparse (e2->sref),
2190 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2194 sRefSet_realElements (e1->uses, sr)
2196 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2201 ("Expression has undefined behavior (left operand uses %q, "
2202 "modified by right operand): %s %s %s",
2204 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2207 } end_sRefSet_realElements;
2209 sRefSet_realElements (sets1, sr)
2211 if (sRef_isMeaningful (sr))
2213 if (sRef_same (sr, e2->sref))
2218 ("Expression has undefined behavior (value of right operand "
2219 "modified by left operand): %s %s %s",
2220 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2223 else if (sRefSet_member (e2->uses, sr))
2228 ("Expression has undefined behavior (left operand modifies %q, "
2229 "used by right operand): %s %s %s",
2231 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2236 if (sRefSet_member (sets2, sr))
2238 if (sRef_isUnconstrained (sr))
2246 hadUncon = optgenerror
2247 (FLG_EVALORDERUNCON,
2249 ("Expression may have undefined behavior. Left operand "
2250 "calls %q; right operand calls %q. The unconstrained "
2251 "functions may modify global state used by "
2252 "the other operand): %s %s %s",
2253 sRefSet_unparseUnconstrained (sets1),
2254 sRefSet_unparseUnconstrained (sets2),
2255 exprNode_unparse (e1), lltok_unparse (op),
2256 exprNode_unparse (e2)),
2265 ("Expression has undefined behavior (both "
2266 "operands modify %q): %s %s %s",
2268 exprNode_unparse (e1),
2269 lltok_unparse (op), exprNode_unparse (e2)),
2275 } end_sRefSet_realElements;
2278 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2280 bool hasError = FALSE;
2282 if (exprNode_isError (e1) || exprNode_isError (e2))
2287 if (sRefSet_member (e2->sets, e1->sref))
2289 if (e2->kind == XPR_CALL)
2295 hasError = optgenerror
2297 message ("Expression has undefined behavior "
2298 "(value of left operand %s is modified "
2299 "by right operand %s): %s %s %s",
2300 exprNode_unparse (e1),
2301 exprNode_unparse (e2),
2302 exprNode_unparse (e1), lltok_unparse (op),
2303 exprNode_unparse (e2)),
2308 if (context_getFlag (FLG_EVALORDERUNCON))
2310 if (sRefSet_member (e2->msets, e1->sref))
2312 if (e2->kind == XPR_CALL)
2318 hasError = optgenerror
2321 ("Expression has undefined behavior (value of left "
2322 "operand may be modified by right operand): %s %s %s",
2323 exprNode_unparse (e1), lltok_unparse (op),
2324 exprNode_unparse (e2)),
2332 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2334 if (context_maybeSet (FLG_EVALORDERUNCON))
2336 checkExpressionDefinedAux (e1, e2, e1->msets,
2337 e2->msets, op, FLG_EVALORDERUNCON);
2342 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2345 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2346 exprNodeList args, bool isIter, exprNode ret)
2350 if (!exprNode_isError (f))
2352 if (!uentryList_isMissingParams (cl))
2354 int nargs = exprNodeList_size (args);
2355 int expectargs = uentryList_size (cl);
2359 if (expectargs == 0)
2367 message ("Iter %q invoked with %d args, "
2369 uentry_getName (fcn),
2377 message ("Function %s called with %d args, "
2379 exprNode_unparse (f), nargs),
2386 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2388 exprNodeList_reset (args);
2390 uentryList_elements (cl, current)
2392 ctype ct = uentry_getType (current);
2395 if (ctype_isElips (ct))
2398 ** do special checking for printf/scanf library functions
2400 ** this is kludgey code, just for handling the special case
2404 if (uentry_isPrintfLike (fcn))
2406 checkPrintfArgs (f, fcn, args, ret, i);
2409 else if (uentry_isScanfLike (fcn))
2411 checkScanfArgs (f, fcn, args, ret, i);
2414 else if (uentry_isMessageLike (fcn))
2416 checkMessageArgs (f, fcn, args, i);
2421 llassert (!uentry_isSpecialFunction (fcn));
2424 nargs = expectargs; /* avoid errors */
2429 if (i >= nargs) break;
2431 a = exprNodeList_current (args);
2432 exprNodeList_advance (args);
2436 if (exprNode_isError (a))
2443 probably necessary? I'm not sure about this one
2444 checkMacroParen (a);
2447 f->guards = guardSet_union (f->guards, a->guards);
2449 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2451 if (!(exprNode_matchArgType (ct, a)))
2453 DPRINTF (("Args mismatch!"));
2455 if (ctype_isVoidPointer (ct)
2456 && (ctype_isPointer (a->typ)
2457 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2462 ("Pointer to abstract type (%t) used "
2464 "(arg %d to %q): %s",
2466 uentry_getName (fcn),
2467 exprNode_unparse (a)),
2475 (ct, exprNode_undefined,
2478 ("Iter %q expects arg %d to "
2479 "be %t gets %t: %s",
2480 uentry_getName (fcn),
2481 i, ct, a->typ, exprNode_unparse (a)),
2492 ("Function %q expects arg %d to be %t gets %t: %s",
2493 uentry_getName (fcn),
2494 i, ct, a->typ, exprNode_unparse (a)),
2497 DPRINTF (("Types: %s / %s",
2499 ctype_unparse (a->typ)));
2503 ** Clear null marker for abstract types.
2504 ** (It is not revealed, so suppress future messages.)
2507 if (ctype_isAbstract (a->typ))
2509 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2516 } end_uentryList_elements ;
2519 if (expectargs != nargs) /* note: not != since we may have ... */
2521 if (ctype_isElips (last))
2525 message ("Function %s called with %d args, expects at least %d",
2526 exprNode_unparse (f),
2527 nargs, expectargs - 1),
2536 message ("Iter %q invoked with %d args, expects %d",
2537 uentry_getName (fcn), nargs, expectargs),
2544 message ("Function %s called with %d args, expects %d",
2545 exprNode_unparse (f),
2558 ** Check for undefined code sequences in function arguments:
2560 ** one parameter sets something used by another parameter
2561 ** one parameter sets something set by another parameter
2565 checkSequencingOne (exprNode f, exprNodeList args,
2566 /*@notnull@*/ exprNode el, int argno)
2569 ** Do second loop, iff +undefunspec
2573 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2575 for (checkloop = 0; checkloop < numloops; checkloop++)
2581 thissets = el->sets;
2585 llassert (checkloop == 1);
2586 thissets = el->msets;
2589 sRefSet_realElements (thissets, thisset)
2593 /*@access exprNodeList@*/
2594 for (j = 0; j < args->nelements; j++)
2596 exprNode jl = args->elements[j];
2597 int thisargno = j + 1;
2599 if (thisargno != argno && exprNode_isDefined (jl))
2601 sRefSet otheruses = jl->uses;
2603 if (sRef_isFileOrGlobalScope (sRef_getRootBase (jl->sref)) &&
2604 sRefSet_hasUnconstrained (thissets))
2607 (FLG_EVALORDERUNCON,
2610 ("%q used in argument %d may set "
2611 "global variable %q used by argument %d: %s(%q)",
2612 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2615 sRef_unparse (sRef_getRootBase (jl->sref)),
2617 exprNode_unparse (f), exprNodeList_unparse (args)),
2621 if (sRefSet_member (otheruses, thisset))
2623 if (sRef_isUnconstrained (thisset))
2626 (FLG_EVALORDERUNCON,
2628 ("Unconstrained functions used in arguments %d (%q) "
2629 "and %d (%s) may modify "
2630 "or use global state in undefined way: %s(%q)",
2632 sRefSet_unparseUnconstrainedPlain (otheruses),
2634 sRef_unconstrainedName (thisset),
2635 exprNode_unparse (f),
2636 exprNodeList_unparse (args)),
2644 ("Argument %d modifies %q, used by argument %d "
2645 "(order of evaluation of actual parameters is "
2646 "undefined): %s(%q)",
2647 argno, sRef_unparse (thisset), thisargno,
2648 exprNode_unparse (f), exprNodeList_unparse (args)),
2654 sRefSet othersets = jl->sets;
2656 if (sRefSet_member (othersets, thisset))
2658 if (sRef_isUnconstrained (thisset))
2661 (FLG_EVALORDERUNCON,
2663 ("Unconstrained functions used in "
2664 "arguments %d (%q) and %d (%s) may modify "
2665 "or use global state in undefined way: %s(%q)",
2667 sRefSet_unparseUnconstrainedPlain (othersets),
2669 sRef_unconstrainedName (thisset),
2670 exprNode_unparse (f), exprNodeList_unparse (args)),
2678 ("Argument %d modifies %q, set by argument %d (order of"
2679 " evaluation of actual parameters is undefined): %s(%q)",
2680 argno, sRef_unparse (thisset), thisargno,
2681 exprNode_unparse (f), exprNodeList_unparse (args)),
2688 /*@noaccess exprNodeList@*/
2689 } end_sRefSet_realElements;
2694 checkSequencing (exprNode f, exprNodeList args)
2696 if (exprNodeList_size (args) > 1)
2701 /*@access exprNodeList*/
2703 for (i = 0; i < args->nelements; i++)
2705 el = args->elements[i];
2707 if (!exprNode_isError (el))
2709 checkSequencingOne (f, args, el, i + 1);
2712 /*@noaccess exprNodeList*/
2717 ** requires le = exprNode_getUentry (f)
2721 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2722 uentry le, exprNodeList args,
2723 /*@notnull@*/ exprNode ret, int specialArgs)
2725 bool isSpec = FALSE;
2726 bool hasMods = FALSE;
2728 globSet usesGlobs = globSet_undefined;
2729 sRefSet mods = sRefSet_undefined;
2730 bool freshMods = FALSE;
2731 uentryList params = uentryList_undefined;
2733 DPRINTF (("Check glob mods: %s", exprNode_unparse (ret)));
2736 ** check globals and modifies
2741 if (!uentry_isValid (le))
2743 ctype fr = ctype_realType (f->typ);
2745 if (ctype_isFunction (fr))
2747 params = ctype_argsFunction (fr);
2751 params = uentryList_missingParams;
2754 if (!context_getFlag (FLG_MODNOMODS)
2755 && !context_getFlag (FLG_GLOBUNSPEC))
2757 checkUnspecCall (f, params, args);
2763 fname = uentry_rawName (le);
2767 if (uentry_isFunction (le))
2769 params = uentry_getParams (le);
2770 mods = uentry_getMods (le);
2771 hasMods = uentry_hasMods (le);
2772 usesGlobs = uentry_getGlobs (le);
2773 isSpec = uentry_isSpecified (le);
2775 else /* not a function */
2777 ctype ct = ctype_realType (uentry_getType (le));
2779 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2780 ("checkModGlobs: uentry not a function: %s",
2781 uentry_unparse (le)));
2783 params = ctype_argsFunction (ct);
2784 return; /*@32 ! remove this? */
2793 globSet_allElements (usesGlobs, el)
2795 if (sRef_isValid (el))
2797 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2799 context_usedGlobal (el);
2800 exprNode_checkUse (f, el, f->loc);
2802 if (context_checkInternalUse ())
2804 if (!context_globAccess (el))
2806 if (sRef_isSystemState (el)
2807 && !context_getFlag (FLG_MODFILESYSTEM))
2816 ("Called procedure %s may access %q, but "
2817 "globals list does not include globals %s",
2818 exprNode_unparse (f),
2820 cstring_makeLiteralTemp (sRef_isInternalState (el)
2828 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2834 uentry gle = sRef_getUentry (el);
2835 sRef sr = sRef_updateSref (el);
2837 if (sRef_isUndefGlob (el))
2839 sRef_setDefined (sr, f->loc);
2840 exprNode_checkSet (f, sr);
2848 if (sRef_isAllocated (el))
2850 exprNode_checkSet (f, sr);
2854 if (sRef_isStateUndefined (sr))
2859 ("%s %q used by function undefined before call: %s",
2860 sRef_getScopeName (sr),
2862 exprNode_unparse (f)),
2864 sRef_setDefined (sr, f->loc);
2866 exprNode_checkUse (f, sr, f->loc);
2869 checkGlobUse (gle, TRUE, f);
2872 if (sRef_isKilledGlob (el))
2874 sRef_kill (sr, f->loc);
2875 context_usedGlobal (sr);
2879 } end_globSet_allElements;
2885 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
2887 sRefSet smods = sRefSet_undefined;
2890 ** NEED to check for modifies anything
2894 ** check each sRef that called function modifies (ml), is
2900 sRefSet_allElements (mods, s) /* s is something which may be modified */
2902 DPRINTF (("Check modify: %s", sRef_unparse (s)));
2904 if (sRef_isKindSpecial (s))
2906 if (sRef_isSpecInternalState (s))
2908 if (context_getFlag (FLG_MODINTERNALSTRICT))
2910 exprNode_checkCallModifyVal (s, args, f, ret);
2914 sRefSet mmods = context_modList ();
2916 sRefSet_allElements (mmods, el)
2918 if (sRef_isInternalState (el))
2920 sRef_setModified (el);
2922 } end_sRefSet_allElements ;
2927 exprNode_checkCallModifyVal (s, args, f, ret);
2932 sRef rb = sRef_getRootBase (s);
2934 if (sRef_isFileOrGlobalScope (rb))
2936 context_usedGlobal (rb);
2939 if (sRef_isFileStatic (s)
2940 && !fileId_equal (fileloc_fileId (f->loc),
2941 fileloc_fileId (uentry_whereDefined (le))))
2943 smods = sRefSet_insert (smods, s);
2947 exprNode_checkCallModifyVal (s, args, f, ret);
2950 } end_sRefSet_allElements;
2955 ** Static elements in modifies set can have nasty consequences.
2956 ** (I think...have not been able to reproduce a possible bug.)
2959 if (!sRefSet_isDefined (smods))
2961 mods = sRefSet_newCopy (mods);
2964 sRefSet_allElements (smods, el)
2966 bool res = sRefSet_delete (mods, el);
2969 } end_sRefSet_allElements;
2971 sRefSet_free (smods);
2976 else if (sRefSet_isDefined (mods))
2977 { /* just check observers */
2980 sRefSet_allElements (mods, s) /* s is something which may be modified */
2982 sRef rb = sRef_getRootBase (s);
2986 if (sRef_isParam (rb))
2988 sRef b = sRef_fixBaseParam (s, args);
2990 if (sRef_isObserver (b))
2992 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
2996 message ("Function call may modify observer%q: %s",
2997 sRef_unparsePreOpt (b), exprNode_unparse (e)),
3000 sRef_showExpInfo (b);
3004 } end_sRefSet_allElements;
3008 if (!hasMods) /* no specified modifications */
3010 if (context_getFlag (FLG_MODOBSERVERUNCON))
3012 exprNodeList_elements (args, e)
3014 if (exprNode_isDefined (e))
3016 sRef s = exprNode_getSref (e);
3018 if (sRef_isObserver (s)
3019 && ctype_isMutable (sRef_getType (s)))
3022 (FLG_MODOBSERVERUNCON,
3024 ("Call to unconstrained function %s may modify observer%q: %s",
3025 exprNode_unparse (f),
3026 sRef_unparsePreOpt (s), exprNode_unparse (e)),
3029 sRef_showExpInfo (s);
3033 } end_exprNodeList_elements;
3038 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
3040 ret->uses = sRefSet_union (ret->uses, f->uses);
3041 ret->sets = sRefSet_union (ret->sets, f->sets);
3042 ret->msets = sRefSet_union (ret->msets, f->msets);
3047 ** Spurious errors reported, because lclint can't tell
3048 ** mods must be fresh if freshMods is true.
3051 /*@i@*/ sRefSet_free (mods);
3057 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
3059 if (uentry_isVar (glob))
3061 if (context_inFunctionLike ())
3063 sRef sr = uentry_getSref (glob);
3065 context_usedGlobal (sr);
3067 if (context_checkGlobUse (glob))
3069 if (!context_globAccess (sr))
3075 message ("Called procedure %s may access %s %q",
3076 exprNode_unparse (e),
3077 sRef_unparseScope (sr),
3078 uentry_getName (glob)),
3085 message ("Undocumented use of %s %s",
3086 sRef_unparseScope (sr),
3087 exprNode_unparse (e)),
3096 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
3101 reflectEnsuresClause (exprNode ret, uentry le, exprNode f, exprNodeList args)
3103 DPRINTF (("Reflect ensures clause: %s(%s) / %s / %s",
3104 exprNode_unparse (f), exprNodeList_unparse (args),
3105 uentry_unparseFull (le),
3106 stateClauseList_unparse (uentry_getStateClauseList (le))));
3108 if (uentry_isValid (le) && uentry_isFunction (le))
3110 stateClauseList sclauses = uentry_getStateClauseList (le);
3112 if (stateClauseList_isDefined (sclauses))
3114 DPRINTF (("Reflect ensures: %s / %s / %s",
3115 uentry_unparse (le),
3116 exprNode_unparse (f), exprNodeList_unparse (args)));
3118 stateClauseList_elements (sclauses, cl)
3120 if (stateClause_hasEnsures (cl))
3122 /* Same in usymtab.c:1904 */
3123 if (stateClause_setsMetaState (cl))
3125 qual q = stateClause_getMetaQual (cl);
3126 annotationInfo ainfo = qual_getAnnotationInfo (q);
3127 metaStateInfo minfo = annotationInfo_getState (ainfo);
3128 cstring key = metaStateInfo_getName (minfo);
3129 int mvalue = annotationInfo_getValue (ainfo);
3131 sRefSet osrs = sRefSet_undefined;
3134 if (stateClause_isGlobal (cl))
3136 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3141 srs = stateClause_getRefs (cl);
3144 DPRINTF (("Reflect ensures clause: %s", stateClause_unparse (cl)));
3147 DPRINTF (("Sets meta state! %s", stateClause_unparse (cl)));
3149 sRefSet_elements (srs, sel)
3153 if (sRef_isResult (sRef_getRootBase (sel)))
3155 s = exprNode_getSref (ret);
3159 s = sRef_fixBaseParam (sel, args);
3162 DPRINTF (("Reflecting state clause on: %s / %s",
3163 sRef_unparse (sel), sRef_unparse (s)));
3165 sRef_setMetaStateValueComplete (s, key, mvalue, exprNode_loc (f));
3166 } end_sRefSet_elements;
3168 sRefSet_free (osrs);
3172 sRefSet srs = stateClause_getRefs (cl);
3173 sRefModVal modf = stateClause_getEnsuresFunction (cl);
3174 int eparam = stateClause_getStateParameter (cl);
3176 DPRINTF (("Reflect after clause: %s / %s",
3177 stateClause_unparse (cl),
3178 sRefSet_unparse (srs)));
3180 sRefSet_elements (srs, sel)
3184 DPRINTF (("elements: %s", sRef_unparse (sel)));
3185 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3187 if (sRef_isResult (sRef_getRootBase (sel)))
3189 DPRINTF (("Fix base: %s / %s",
3190 sRef_unparse (sel), sRef_unparse (exprNode_getSref (ret))));
3191 s = sRef_fixBase (sel, exprNode_getSref (ret));
3192 DPRINTF (("==> %s", sRef_unparseFull (s)));
3196 s = sRef_fixBaseParam (sel, args);
3199 DPRINTF (("elements: %s", sRef_unparse (s)));
3200 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3202 DPRINTF (("Reflecting state clause on: %s / %s",
3203 sRef_unparseFull (sel), sRef_unparseFull (s)));
3205 /* evans 2001-08-24 - added aliasSetCompleteParam */
3206 sRef_aliasSetCompleteParam (modf, s, eparam, exprNode_loc (f));
3208 DPRINTF (("After reflecting state clause on: %s / %s",
3209 sRef_unparseFull (sel), sRef_unparseFull (s)));
3210 } end_sRefSet_elements;
3213 } end_stateClauseList_elements ;
3216 DPRINTF (("Here: %s / %s",
3217 uentry_unparseFull (le),
3218 bool_unparse (uentry_hasMetaStateEnsures (le))));
3220 if (uentry_hasMetaStateEnsures (le))
3222 fileloc loc = exprNode_loc (f);
3224 metaStateConstraintList mscl = uentry_getMetaStateEnsures (le);
3226 metaStateConstraintList_elements (mscl, msc)
3228 metaStateSpecifier msspec = metaStateConstraint_getSpecifier (msc);
3229 metaStateInfo msinfo = metaStateSpecifier_getMetaStateInfo (msspec);
3230 metaStateExpression msexpr = metaStateConstraint_getExpression (msc);
3231 cstring key = metaStateInfo_getName (msinfo);
3232 sRef mlsr = metaStateSpecifier_getSref (msspec);
3234 sRef lastref = sRef_undefined;
3235 stateValue sval = stateValue_undefined;
3237 DPRINTF (("Meta state constraint for %s: %s", uentry_unparse (le),
3238 metaStateConstraint_unparse (msc)));
3239 DPRINTF (("Matches left: %s", sRef_unparseDebug (mlsr)));
3241 if (sRef_isResult (sRef_getRootBase (mlsr)))
3243 s = exprNode_getSref (ret);
3247 s = sRef_fixBaseParam (mlsr, args);
3250 DPRINTF (("Setting state: %s", sRef_unparseFull (s)));
3252 while (metaStateExpression_isDefined (msexpr))
3254 metaStateSpecifier ms = metaStateExpression_getSpecifier (msexpr);
3255 metaStateInfo msi = metaStateSpecifier_getMetaStateInfo (ms);
3258 DPRINTF (("Check expression: %s", metaStateExpression_unparse (msexpr)));
3260 if (metaStateExpression_isMerge (msexpr))
3262 msexpr = metaStateExpression_getRest (msexpr);
3266 msexpr = metaStateExpression_undefined;
3269 if (metaStateInfo_isDefined (msi))
3271 /* Must match lhs state */
3272 llassert (metaStateInfo_equal (msinfo, msi));
3275 if (metaStateSpecifier_isElipsis (ms))
3278 ** For elipsis, we need to merge all the relevant elipsis parameters
3282 uentryList params = uentry_getParams (le);
3283 int paramno = uentryList_size (params) - 1;
3285 if (!uentry_isElipsisMarker (uentryList_getN (params, paramno)))
3289 message ("Ensures clauses uses ... for function without ... in parameter list: %q",
3290 uentry_getName (le)),
3291 uentry_whereLast (le));
3292 /*@innerbreak@*/ break;
3295 while (paramno < exprNodeList_size (args))
3297 exprNode arg = exprNodeList_getN (args, paramno);
3298 fs = exprNode_getSref (arg);
3299 DPRINTF (("Merge arg: %s", exprNode_unparse (arg)));
3301 /* cut and pasted... gack*/
3302 if (stateValue_isDefined (sval))
3304 /* Use combination table to merge old state value with new one: */
3305 stateValue tval = sRef_getMetaStateValue (fs, key);
3307 if (stateValue_isDefined (tval))
3309 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3310 cstring msg = cstring_undefined;
3311 int nval = stateCombinationTable_lookup (sctable,
3312 stateValue_getValue (sval),
3313 stateValue_getValue (tval),
3315 DPRINTF (("Combining: %s + %s -> %d",
3316 stateValue_unparseValue (sval, msinfo),
3317 stateValue_unparseValue (tval, msinfo),
3320 if (nval == stateValue_error)
3325 ("Attributes merged in ensures clause in states that "
3326 "cannot be combined (%q is %q, %q is %q)%q",
3327 sRef_unparse (lastref),
3328 stateValue_unparseValue (sval, msinfo),
3330 stateValue_unparseValue (tval, msinfo),
3331 cstring_isDefined (msg) ?
3332 message (": %s", msg) : cstring_undefined),
3335 sRef_showMetaStateInfo (fs, key);
3339 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3340 loc = exprNode_loc (arg);
3344 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3349 sval = sRef_getMetaStateValue (fs, key);
3354 if (stateValue_isError (sval))
3356 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3365 msr = metaStateSpecifier_getSref (ms);
3368 llassert (sRef_isParam (sRef_getRootBase (msr)));
3369 fs = sRef_fixBaseParam (msr, args);
3371 if (stateValue_isDefined (sval))
3373 /* Use combination table to merge old state value with new one: */
3374 stateValue tval = sRef_getMetaStateValue (fs, key);
3376 if (stateValue_isDefined (tval))
3378 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3379 cstring msg = cstring_undefined;
3380 int nval = stateCombinationTable_lookup (sctable,
3381 stateValue_getValue (sval),
3382 stateValue_getValue (tval),
3384 DPRINTF (("Combining: %s + %s -> %d",
3385 stateValue_unparseValue (sval, msinfo),
3386 stateValue_unparseValue (tval, msinfo),
3389 if (nval == stateValue_error)
3394 ("Attributes merged in ensures clause in states that "
3395 "cannot be combined (%q is %q, %q is %q)%q",
3396 sRef_unparse (lastref),
3397 stateValue_unparseValue (sval, msinfo),
3399 stateValue_unparseValue (tval, msinfo),
3400 cstring_isDefined (msg)
3401 ? message (": %s", msg) : cstring_undefined),
3404 sRef_showMetaStateInfo (fs, key);
3408 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3412 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3417 sval = sRef_getMetaStateValue (fs, key);
3422 if (stateValue_isError (sval))
3424 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3429 DPRINTF (("Setting: %s:%s <- %s", sRef_unparse (s), key, stateValue_unparse (sval)));
3431 if (stateValue_isDefined (sval))
3433 sRef_setMetaStateValueComplete (s, key, stateValue_getValue (sval), loc);
3437 DPRINTF (("Undefined state: %s", cstring_toCharsSafe (sRef_unparse (s))));
3439 } end_metaStateConstraintList_elements ;
3441 metaStateConstraintList_free (mscl);
3447 checkRequiresClause (uentry le, exprNode f, exprNodeList args)
3449 DPRINTF (("Check requires clause: %s(%s) / %s / %s",
3450 exprNode_unparse (f), exprNodeList_unparse (args),
3451 uentry_unparseFull (le),
3452 stateClauseList_unparse (uentry_getStateClauseList (le))));
3454 if (uentry_isValid (le) && uentry_isFunction (le))
3456 stateClauseList sclauses = uentry_getStateClauseList (le);
3458 if (stateClauseList_isDefined (sclauses))
3460 DPRINTF (("Check requires: %s / %s / %s",
3461 uentry_unparse (le),
3462 exprNode_unparse (f), exprNodeList_unparse (args)));
3464 stateClauseList_elements (sclauses, cl)
3466 DPRINTF (("Check clause: %s / %s",
3467 stateClause_unparse (cl),
3468 bool_unparse (stateClause_hasRequires (cl))));
3470 if (stateClause_hasRequires (cl))
3472 sRefSet osrs = sRefSet_undefined;
3475 if (stateClause_isGlobal (cl))
3477 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3482 srs = stateClause_getRefs (cl);
3485 DPRINTF (("Refs: %s", sRefSet_unparse (srs)));
3487 if (stateClause_setsMetaState (cl))
3489 qual q = stateClause_getMetaQual (cl);
3490 annotationInfo ainfo = qual_getAnnotationInfo (q);
3491 metaStateInfo minfo = annotationInfo_getState (ainfo);
3492 cstring key = metaStateInfo_getName (minfo);
3493 int mvalue = annotationInfo_getValue (ainfo);
3495 DPRINTF (("Requires meta state! %s = %d", key, mvalue));
3497 sRefSet_elements (srs, sel)
3499 sRef s = sRef_fixBaseParam (sel, args);
3501 if (sRef_isResult (sRef_getRootBase (sel)))
3507 DPRINTF (("Checking state clause on: %s / %s / %s = %d",
3508 sRef_unparseFull (sel), sRef_unparseFull (s),
3511 if (!sRef_checkMetaStateValue (s, key, mvalue))
3513 DPRINTF (("HERE: %s", sRef_unparse (s)));
3517 ("Requires clause of called function %q not satisfied%q (state is %q): %q",
3518 uentry_getName (le),
3519 sRef_isGlobalMarker (s)
3521 : message (" by %q", sRef_unparse (s)),
3522 stateValue_unparseValue (sRef_getMetaStateValue (s, key),
3524 stateClause_unparse (cl)),
3527 sRef_showAliasInfo (s);
3531 DPRINTF (("Error supressed!"));
3532 DPRINTF (("Loc: %s", fileloc_unparse (exprNode_loc (f))));
3533 DPRINTF (("Context supress: %s",
3534 bool_unparse (context_suppressFlagMsg (FLG_STATETRANSFER, exprNode_loc (f)))));
3538 } end_sRefSet_elements;
3542 sRefModVal modf = stateClause_getRequiresBodyFunction (cl);
3543 int eparam = stateClause_getStateParameter (cl);
3545 DPRINTF (("Reflect after clause: %s / %s",
3546 stateClause_unparse (cl),
3547 sRefSet_unparse (srs)));
3549 sRefSet_elements (srs, sel)
3553 DPRINTF (("elements: %s", sRef_unparse (sel)));
3554 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3556 s = sRef_fixBaseParam (sel, args);
3558 DPRINTF (("elements: %s", sRef_unparse (s)));
3559 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3561 if (sRef_isResult (sRef_getRootBase (sel)))
3563 ; /*@i423 what do we do about results */
3567 DPRINTF (("Reflecting state clause on: %s / %s",
3568 sRef_unparse (sel), sRef_unparse (s)));
3570 modf (s, eparam, exprNode_loc (f));
3572 } end_sRefSet_elements;
3575 sRefSet_free (osrs);
3577 } end_stateClauseList_elements ;
3582 static /*@only@*/ exprNode
3583 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
3584 ctype t, /*@keep@*/ exprNodeList args)
3586 /* requires f is a non-error exprNode, with type function */
3587 cstring fname = exprNode_unparse (f);
3588 uentry le = exprNode_getUentry (f);
3589 exprNode ret = exprNode_createPartialCopy (f);
3594 DPRINTF (("Call: %s %s",exprNode_unparse (f), exprNodeList_unparse (args)));
3596 ret->typ = ctype_getReturnType (t);
3597 ret->kind = XPR_CALL;
3599 ret->edata = exprData_makeCall (f, args);
3602 ** Order of these steps is very important!
3604 ** Must check for argument dependencies before messing up uses and sets.
3607 if (context_getFlag (FLG_EVALORDER))
3609 exprNodeList_elements (args, current)
3611 if (exprNode_isDefined (current))
3613 exprNode_addUse (current, current->sref);
3615 } end_exprNodeList_elements;
3617 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3619 checkSequencing (f, args);
3622 exprNodeList_elements (args, current)
3624 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3626 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3628 } end_exprNodeList_elements ;
3631 special = checkArgs (le, f, t, args, ret);
3632 checkGlobMods (f, le, args, ret, special);
3633 checkRequiresClause (le, f, args);
3636 if (uentry_isValid (le)
3637 && (uentry_isFunction (le)
3638 || (uentry_isVariable (le)
3639 && ctype_isFunction (uentry_getType (le)))))
3641 exitkind exk = uentry_getExitCode (le);
3643 /* f->typ is already set to the return type */
3645 DPRINTF (("Function: %s", uentry_unparseFull (le)));
3646 ret->sref = uentry_returnedRef (le, args);
3647 DPRINTF (("Returned: %s / %s",
3648 uentry_unparseFull (le),
3649 sRef_unparseFull (ret->sref)));
3651 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3653 qual nullPred = uentry_nullPred (le);
3655 if (qual_isTrueNull (nullPred))
3657 exprNode arg = exprNodeList_head (args);
3659 if (exprNode_isDefined (arg))
3661 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3664 else if (qual_isFalseNull (nullPred))
3666 exprNode arg = exprNodeList_head (args);
3668 if (exprNode_isDefined (arg))
3670 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3675 llassert (qual_isUnknown (nullPred));
3679 if (exitkind_isConditionalExit (exk))
3683 ** if (arg0) then { exit! } else { ; }
3685 ** if (arg0) then { ; } else { exit! }
3690 llassert (!exprNodeList_isEmpty (args));
3691 firstArg = exprNodeList_head (args);
3693 if (exprNode_isDefined (firstArg)
3694 && !guardSet_isEmpty (firstArg->guards))
3696 usymtab_trueBranch (guardSet_undefined);
3697 usymtab_altBranch (guardSet_undefined);
3699 if (exitkind_isTrueExit (exk))
3701 usymtab_popBranches (firstArg,
3702 exprNode_makeMustExit (),
3704 TRUE, TRUEEXITCLAUSE);
3708 usymtab_popBranches (firstArg,
3710 exprNode_makeMustExit (),
3711 TRUE, FALSEEXITCLAUSE);
3715 ret->exitCode = XK_MAYEXIT;
3717 else if (exitkind_mustExit (exk))
3719 ret->exitCode = XK_MUSTEXIT;
3721 else if (exitkind_couldExit (exk))
3723 ret->exitCode = XK_MAYEXIT;
3730 if (cstring_equalLit (fname, "exit"))
3732 if (exprNodeList_size (args) == 1)
3734 exprNode arg = exprNodeList_head (args);
3736 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3738 long int val = multiVal_forceInt (exprNode_getValue (arg));
3745 ("Argument to exit has implementation defined behavior: %s",
3746 exprNode_unparse (arg)),
3747 exprNode_loc (arg));
3756 exprNode_checkSetAny (ret, uentry_rawName (le));
3759 DPRINTF (("Before reflect: %s", sRef_unparseFull (ret->sref)));
3760 DPRINTF (("Reflect: %s", uentry_unparseFull (le)));
3761 reflectEnsuresClause (ret, le, f, args);
3768 ** this is yucky! should keep the uentry as part of exprNode!
3771 uentry exprNode_getUentry (exprNode e)
3773 if (exprNode_isError (e))
3775 return uentry_undefined;
3779 cstring s = exprNode_rootVarName (e);
3780 uentry ue = usymtab_lookupSafe (s);
3787 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3789 exprNode ret = exprNode_createPlain (ctype_unknown);
3791 ret->kind = XPR_INITBLOCK;
3792 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3793 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3799 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3805 if (exprNode_isUndefined (f))
3808 exprNodeList_free (args);
3809 return exprNode_undefined;
3812 t = exprNode_getType (f);
3814 if (sRef_isLocalVar (f->sref))
3816 exprNode_checkUse (f, f->sref, f->loc);
3818 if (sRef_possiblyNull (f->sref))
3820 if (!usymtab_isGuarded (f->sref))
3822 if (optgenerror (FLG_NULLDEREF,
3823 message ("Function call using %s pointer %q",
3824 sRef_nullMessage (f->sref),
3825 sRef_unparse (f->sref)),
3828 sRef_showNullInfo (f->sref);
3829 sRef_setNullError (f->sref);
3837 if (ctype_isRealFunction (t))
3839 exprNode ret = functionCallSafe (f, t, args);
3843 else if (ctype_isUnknown (t))
3845 exprNode ret = exprNode_createPartialCopy (f);
3851 exprNodeList_elements (args, current)
3853 if (exprNode_isDefined (current))
3855 exprNode_checkUse (ret, current->sref, ret->loc);
3858 ** also, anything derivable from current->sref may be used
3861 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3862 exprNode_mergeUSs (ret, current);
3864 } end_exprNodeList_elements;
3866 ret->edata = exprData_makeCall (f, args);
3867 ret->kind = XPR_CALL;
3869 tstring = cstring_copy (exprNode_unparse (f));
3871 cstring_markOwned (tstring);
3872 exprNode_checkSetAny (ret, tstring);
3878 voptgenerror (FLG_TYPE,
3879 message ("Call to non-function (type %t): %s", t,
3880 exprNode_unparse (f)),
3883 exprNodeList_free (args);
3885 return (exprNode_makeError ());
3890 exprNode_fieldAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
3891 /*@only@*/ cstring f)
3893 exprNode ret = exprNode_createPartialCopy (s);
3895 ret->kind = XPR_FACCESS;
3897 if (exprNode_isError (s))
3899 ret->edata = exprData_makeField (s, f);
3904 ctype t = exprNode_getType (s);
3905 ctype tr = ctype_realType (t);
3907 checkMacroParen (s);
3909 ret->edata = exprData_makeField (s, f);
3911 if (ctype_isStructorUnion (tr))
3913 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
3915 if (uentry_isUndefined (tf))
3917 voptgenerror (FLG_TYPE,
3918 message ("Access non-existent field %s of %t: %s", f, t,
3919 exprNode_unparse (ret)),
3921 /*! cstring_free (f); */ /* evans 2001-03-25 self-detect */
3926 uentry_setUsed (tf, exprNode_loc (ret));
3928 ret->typ = uentry_getType (tf);
3929 checkSafeUse (ret, s->sref);
3931 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
3932 /*!? exprNode_free (s); */ /* evans 2001-03-25 self-detect */
3936 else /* isStructorUnion */
3938 if (ctype_isRealAbstract (tr))
3942 message ("Access field of abstract type (%t): %s.%s",
3943 t, exprNode_unparse (s), f),
3945 ret->typ = ctype_unknown;
3949 if (ctype_isKnown (tr))
3954 ("Access field of non-struct or union (%t): %s.%s",
3955 t, exprNode_unparse (s), f),
3958 ret->typ = ctype_unknown;
3962 cstring sn = cstring_copy (f);
3964 checkSafeUse (ret, s->sref);
3965 cstring_markOwned (sn);
3966 ret->sref = sRef_makeField (s->sref, sn);
3978 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ lltok dot,
3979 /*@only@*/ cstring f)
3981 exprNode res = exprNode_fieldAccessAux (s, lltok_getLoc (dot), f);
3982 lltok_release (dot);
3987 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
3989 exprNode ret = exprNode_createPartialCopy (e);
3991 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
3992 ret->kind = XPR_PARENS;
3993 ret->edata = exprData_makeUop (e, lpar);
3995 if (!exprNode_isError (e))
3997 ret->exitCode = e->exitCode;
3998 ret->canBreak = e->canBreak;
3999 ret->mustBreak = e->mustBreak;
4000 ret->isJumpPoint = e->isJumpPoint;
4001 ret->sref = e->sref;
4008 exprNode_arrowAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
4009 /*@only@*/ cstring f)
4011 exprNode ret = exprNode_createPartialCopy (s);
4013 ret->edata = exprData_makeField (s, f);
4014 ret->kind = XPR_ARROW;
4016 if (exprNode_isError (s))
4022 ctype t = exprNode_getType (s);
4023 ctype tr = ctype_realType (t);
4025 checkMacroParen (s);
4027 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
4029 if (ctype_isRealPointer (tr))
4031 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
4033 if (ctype_isStructorUnion (b))
4035 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4037 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
4039 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
4043 message ("Arrow access from %s pointer%q: %s",
4044 sRef_nullMessage (s->sref),
4045 sRef_unparsePreOpt (s->sref),
4046 exprNode_unparse (ret)),
4049 sRef_showNullInfo (s->sref);
4050 sRef_setNullError (s->sref);
4055 if (uentry_isUndefined (fentry))
4059 message ("Access non-existent field %s of %t: %s",
4060 f, t, exprNode_unparse (ret)),
4062 ret->typ = ctype_unknown;
4068 ** was safeUse: shouldn't be safe!
4071 ** rec must be defined,
4072 ** *rec must be allocated
4073 ** rec->field need only be defined it if is an rvalue
4076 uentry_setUsed (fentry, exprNode_loc (ret));
4077 ret->typ = uentry_getType (fentry);
4079 exprNode_checkUse (ret, s->sref, s->loc);
4081 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
4082 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4086 else /* Pointer to something that is not a struct or union*/
4088 if (ctype_isRealAbstract (tr))
4090 ctype xrt = ctype_forceRealType (tr);
4094 message ("Arrow access field of abstract type (%t): %s->%s",
4095 t, exprNode_unparse (s), f),
4099 ** Set the state correctly, as if the abstraction is broken.
4102 if (ctype_isRealPointer (xrt) &&
4103 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
4104 ctype_isStructorUnion (b)))
4106 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4107 ret->typ = uentry_getType (fentry);
4108 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4112 ret->typ = ctype_unknown;
4113 ret->sref = sRef_undefined;
4116 else /* not a struct, union or abstract */
4118 if (ctype_isUnknown (tr)) {
4119 cstring sn = cstring_copy (f);
4121 DPRINTF (("Here: %s", exprNode_unparse (s)));
4123 exprNode_checkUse (ret, s->sref, s->loc);
4124 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4126 cstring_markOwned (sn);
4127 ret->sref = sRef_makeArrow (s->sref, sn);
4129 ret->kind = XPR_ARROW;
4134 message ("Arrow access field of non-struct or union "
4135 "pointer (%t): %s->%s",
4136 t, exprNode_unparse (s), f),
4139 ret->typ = ctype_unknown;
4140 ret->sref = sRef_undefined;
4145 else /* its not a pointer */
4147 if (!ctype_isUnknown (tr))
4151 message ("Arrow access of non-pointer (%t): %s->%s",
4152 t, exprNode_unparse (s), f),
4155 ret->typ = ctype_unknown;
4156 ret->sref = sRef_undefined;
4160 cstring sn = cstring_copy (f);
4162 DPRINTF (("Here: %s", exprNode_unparse (s)));
4164 exprNode_checkUse (ret, s->sref, s->loc);
4165 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4167 cstring_markOwned (sn);
4168 ret->sref = sRef_makeArrow (s->sref, sn);
4170 ret->kind = XPR_ARROW;
4181 exprNode_arrowAccess (/*@only@*/ exprNode s,
4182 /*@only@*/ lltok arrow,
4183 /*@only@*/ cstring f)
4185 exprNode res = exprNode_arrowAccessAux (s, lltok_getLoc (arrow), f);
4186 lltok_release (arrow);
4191 ** only postOp's in C: i++ and i--
4195 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4197 /* check modification also */
4198 /* cstring opname = lltok_unparse (op);*/
4200 exprNode ret = exprNode_createPartialCopy (e);
4202 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4203 ret->kind = XPR_POSTOP;
4204 ret->edata = exprData_makeUop (e, op);
4206 if (!exprNode_isDefined (e))
4211 checkMacroParen (e);
4213 exprNode_checkUse (ret, e->sref, e->loc);
4214 exprNode_checkSet (ret, e->sref);
4216 t = exprNode_getType (e);
4218 if (sRef_isUnsafe (e->sref))
4220 voptgenerror (FLG_MACROPARAMS,
4221 message ("Operand of %s is macro parameter (non-functional): %s%s",
4222 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
4224 sRef_makeSafe (e->sref);
4225 sRef_makeSafe (ret->sref);
4228 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
4234 if (ctype_isRealAbstract (t))
4238 message ("Operand of %s is abstract type (%t): %s",
4239 lltok_unparse (op), t, exprNode_unparse (e)),
4246 message ("Operand of %s is non-numeric (%t): %s",
4247 lltok_unparse (op), t, exprNode_unparse (e)),
4250 ret->typ = ctype_unknown;
4253 /* if (ctype_isZero (t)) e->typ = ctype_int; */
4255 exprNode_checkModify (e, ret);
4257 /* added 7/11/2000 D.L */
4259 /*DRL 6/8/01 I decided to disable all LCLint Warning here since the code
4260 probably needs a rewrite any way */
4265 /* updateEnvironmentForPostOp (e); */
4267 /* start modifications */
4268 /* added by Seejo on 4/16/2000 */
4270 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4272 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4274 ret->sref = sRef_copy (e->sref);
4277 if (lltok_getTok (op) == INC_OP) {
4278 if (sRef_getSize(e->sref) > 0) {
4280 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4282 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4283 /* Assumption: there is only 1 \0 in the buffer */
4284 /* This will not be correct if there are 2 \0's in the buffer */
4285 sRef_setNotNullTerminatedState(ret->sref);
4286 sRef_resetLen(ret->sref);
4288 sRef_setNullTerminatedState(ret->sref);
4289 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4291 if (sRef_isNullTerminated (ret->sref))
4292 printf ("ret->sref is Null Terminated\n");
4293 else if (sRef_isPossiblyNullTerminated (ret->sref))
4294 printf ("ret->sref is Possibly Null Terminated\n");
4295 else if (sRef_isNotNullTerminated (ret->sref))
4296 printf ("ret->sref is Not Null Terminated\n");
4301 if (lltok_getTok (op) == DEC_OP) {
4302 if (sRef_getSize(e->sref) >= 0) {
4303 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4304 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4309 /* end modifications */
4315 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4317 bool checkMod = FALSE;
4319 int opid = lltok_getTok (op);
4320 exprNode ret = exprNode_createSemiCopy (e);
4322 exprNode_copySets (ret, e);
4324 multiVal_free (ret->val);
4325 ret->val = multiVal_undefined;
4326 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4327 ret->kind = XPR_PREOP;
4328 ret->edata = exprData_makeUop (e, op);
4330 if (exprNode_isError (e))
4335 checkMacroParen (e);
4337 te = exprNode_getType (e);
4338 tr = ctype_realType (te);
4340 if (opid != TAMPERSAND)
4342 exprNode_checkUse (ret, e->sref, e->loc);
4344 if (ctype_isRealAbstract (tr)
4345 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
4347 if (optgenerror (FLG_ABSTRACT,
4348 message ("Operand of %s is abstract type (%t): %s",
4349 lltok_unparse (op), tr,
4350 exprNode_unparse (ret)),
4353 tr = te = ctype_unknown;
4354 ret->typ = ctype_unknown;
4355 sRef_setNullError (e->sref);
4363 case DEC_OP: /* should also check modification! */
4364 if (sRef_isMacroParamRef (e->sref))
4368 message ("Operand of %s is macro parameter (non-functional): %s",
4369 lltok_unparse (op), exprNode_unparse (ret)),
4374 exprNode_checkSet (ret, e->sref);
4377 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
4382 if (context_msgStrictOps ())
4386 message ("Operand of %s is non-numeric (%t): %s",
4387 lltok_unparse (op), te, exprNode_unparse (ret)),
4390 ret->typ = ctype_int;
4393 /* start modifications */
4394 /* added by Seejo on 4/16/2000 */
4396 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4398 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4400 ret->sref = sRef_copy (e->sref);
4403 if (lltok_getTok (op) == INC_OP) {
4404 if (sRef_getSize(e->sref) > 0) {
4406 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4408 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4409 /* Assumption: there is only 1 \0 in the buffer */
4410 /* This will not be correct if there are 2 \0's in the buffer */
4411 sRef_setNotNullTerminatedState(ret->sref);
4412 sRef_resetLen (ret->sref);
4414 sRef_setNullTerminatedState(ret->sref);
4415 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4421 if (lltok_getTok (op) == DEC_OP) {
4422 if (sRef_getSize(e->sref) >= 0) {
4423 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4424 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4429 /* end modifications */
4436 if (ctype_isForceRealNumeric (&tr))
4440 ret->val = multiVal_invert (exprNode_getValue (e));
4444 ret->val = multiVal_copy (exprNode_getValue (e));
4449 if (context_msgStrictOps ())
4453 message ("Operand of %s is non-numeric (%t): %s",
4454 lltok_unparse (op), te, exprNode_unparse (ret)),
4458 ret->typ = ctype_int;
4462 case TEXCL: /* maybe this should be restricted */
4463 guardSet_flip (ret->guards);
4465 if (ctype_isRealBool (te) || ctype_isUnknown (te))
4471 if (ctype_isRealPointer (tr))
4473 if (sRef_isKnown (e->sref))
4475 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
4479 (FLG_BOOLOPS, FLG_PTRNEGATE,
4480 message ("Operand of %s is non-boolean (%t): %s",
4481 lltok_unparse (op), te, exprNode_unparse (ret)),
4488 message ("Operand of %s is non-boolean (%t): %s",
4489 lltok_unparse (op), te, exprNode_unparse (ret)),
4493 ret->typ = ctype_bool;
4498 if (ctype_isForceRealInt (&tr))
4503 if (context_msgStrictOps ())
4507 message ("Operand of %s is non-integer (%t): %s",
4508 lltok_unparse (op), te, exprNode_unparse (ret)),
4512 if (ctype_isInt (e->typ))
4518 ret->typ = ctype_int;
4524 ret->typ = ctype_makePointer (e->typ);
4526 if (sRef_isKnown (e->sref))
4528 ret->sref = sRef_makeAddress (e->sref);
4535 if (ctype_isAP (tr))
4537 ret->typ = ctype_baseArrayPtr (e->typ);
4541 if (ctype_isKnown (te))
4543 if (ctype_isFunction (te))
4549 message ("Dereference of function type (%t): %s",
4550 te, exprNode_unparse (ret)),
4555 voptgenerror (FLG_TYPE,
4556 message ("Dereference of non-pointer (%t): %s",
4557 te, exprNode_unparse (ret)),
4559 ret->typ = ctype_unknown;
4564 ret->typ = ctype_unknown;
4569 if (sRef_isKnown (e->sref))
4571 if (sRef_possiblyNull (e->sref))
4573 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
4577 message ("Dereference of %s pointer %q: %s",
4578 sRef_nullMessage (e->sref),
4579 sRef_unparse (e->sref),
4580 exprNode_unparse (ret)),
4583 sRef_showNullInfo (e->sref);
4584 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
4589 ret->sref = sRef_makePointer (e->sref);
4594 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
4599 exprNode_checkModify (e, ret);
4606 ** any reason to disallow sizeof (abstract type) ?
4610 ** used by both sizeof
4614 ctype sizeof_resultType (void)
4616 static ctype sizet = ctype_unknown;
4618 if (ctype_isUnknown (sizet))
4620 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
4622 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
4626 sizet = ctype_ulint;
4633 exprNode_sizeofType (/*@only@*/ qtype qt)
4635 exprNode ret = exprNode_create (sizeof_resultType ());
4636 ctype ct = qtype_getType (qt);
4638 ret->kind = XPR_SIZEOFT;
4639 ret->edata = exprData_makeSizeofType (qt);
4641 voptgenerror (FLG_SIZEOFTYPE,
4642 message ("Parameter to sizeof is type %s: %s",
4644 exprNode_unparse (ret)),
4651 exprNode_alignofType (/*@only@*/ qtype qt)
4653 exprNode ret = exprNode_create (sizeof_resultType ());
4654 ctype ct = qtype_getType (qt);
4656 ret->kind = XPR_ALIGNOFT;
4657 ret->edata = exprData_makeSizeofType (qt);
4659 voptgenerror (FLG_SIZEOFTYPE,
4660 message ("Parameter to alignof is type %s: %s",
4662 exprNode_unparse (ret)),
4668 exprNode exprNode_offsetof (qtype qt, cstringList s)
4670 exprNode ret = exprNode_create (sizeof_resultType ());
4671 ctype ct = qtype_getType (qt);
4673 ret->kind = XPR_OFFSETOF;
4674 ret->edata = exprData_makeOffsetof (qt, s);
4676 if (!ctype_isRealSU (ct))
4678 voptgenerror (FLG_TYPE,
4679 message ("First parameter to offsetof is not a "
4680 "struct or union type (type %s): %s",
4682 exprNode_unparse (ret)),
4689 cstringList_elements (s, el) {
4693 if (ctype_isUndefined (lt))
4697 else if (!ctype_isRealSU (lt))
4699 voptgenerror (FLG_TYPE,
4700 message ("Inner offsetof type is not a "
4701 "struct or union type (type %s before field %s): %s",
4702 ctype_unparse (lt), el,
4703 exprNode_unparse (ret)),
4709 fields = ctype_getFields (ctype_realType (lt));
4710 fld = uentryList_lookupField (fields, el);
4711 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4713 if (uentry_isUndefined (fld))
4715 if (ctype_equal (lt, ct)) {
4716 voptgenerror (FLG_TYPE,
4717 message ("Field %s in offsetof is not the "
4718 "name of a field of %s: %s",
4721 exprNode_unparse (ret)),
4724 voptgenerror (FLG_TYPE,
4725 message ("Deep field %s in offsetof is not the "
4726 "name of a field of %s: %s",
4729 exprNode_unparse (ret)),
4735 lt = uentry_getType (fld);
4738 } end_cstringList_elements;
4740 /* Should report error if its a bit field - behavior is undefined! */
4747 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4751 if (exprNode_isUndefined (e))
4753 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4754 ret->edata = exprData_makeSingle (e);
4755 ret->typ = sizeof_resultType ();
4756 ret->kind = XPR_SIZEOF;
4760 uentry u = exprNode_getUentry (e);
4762 ret = exprNode_createPartialCopy (e);
4763 ret->edata = exprData_makeSingle (e);
4765 ret->typ = sizeof_resultType ();
4766 ret->kind = XPR_SIZEOF;
4768 if (uentry_isValid (u)
4769 && uentry_isRefParam (u)
4770 && ctype_isRealArray (uentry_getType (u)))
4773 (FLG_SIZEOFFORMALARRAY,
4774 message ("Parameter to sizeof is an array-type function parameter: %s",
4775 exprNode_unparse (ret)),
4781 ** sizeof (x) doesn't "really" use x
4788 exprNode_alignofExpr (/*@only@*/ exprNode e)
4792 if (exprNode_isUndefined (e))
4794 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4798 ret = exprNode_createPartialCopy (e);
4801 ret->edata = exprData_makeSingle (e);
4802 ret->typ = sizeof_resultType ();
4803 ret->kind = XPR_ALIGNOF;
4806 ** sizeof (x) doesn't "really" use x
4813 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4819 if (exprNode_isError (e))
4822 lltok_release (tok);
4823 return exprNode_undefined;
4826 checkMacroParen (e);
4828 c = qtype_getType (q);
4829 t = exprNode_getType (e);
4831 ret = exprNode_createPartialCopy (e);
4833 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
4835 ret->kind = XPR_CAST;
4836 ret->edata = exprData_makeCast (tok, e, q);
4838 if (ctype_isRealSU (ctype_getBaseType (sRef_getType (e->sref))))
4841 ** This is a bit of a hack to avoid a problem
4842 ** when the code does,
4843 ** (some other struct) x
4848 ret->sref = sRef_copy (e->sref);
4849 usymtab_addForceMustAlias (ret->sref, e->sref);
4850 sRef_setTypeFull (ret->sref, c);
4851 DPRINTF (("Cast: %s -> %s", sRef_unparseFull (e->sref),
4852 sRef_unparseFull (ret->sref)));
4856 ret->sref = e->sref;
4857 sRef_setTypeFull (ret->sref, c);
4858 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
4865 ** void * <-> abstract * (if FLG_ABSTVOIDP)
4866 ** abstract * <-> void * (if FLG_ABSTVOIDP)
4869 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
4873 else if (ctype_isRealAP (c)) /* casting to array or pointer */
4875 ctype bc = ctype_getBaseType (c);
4876 ctype bt = ctype_getBaseType (t);
4877 ctype rt = ctype_realType (t);
4879 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
4880 && (ctype_isArrayPtr (rt)
4881 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4885 message ("Cast from function pointer type (%t) to "
4886 "non-function pointer (%t): %s",
4887 c, t, exprNode_unparse (ret)),
4891 if (!ctype_isFunction (ctype_baseArrayPtr (c))
4892 && (ctype_isArrayPtr (rt)
4893 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4897 message ("Cast from non-function pointer type (%t) to "
4898 "function pointer (%t): %s",
4899 c, t, exprNode_unparse (ret)),
4903 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
4904 !(ctype_isRealAbstract (bc)
4905 && context_hasAccess (ctype_typeId (bc))))
4907 ; /* okay to cast zero */
4911 if (ctype_isRealAbstract (bc)
4912 && !context_hasAccess (ctype_typeId (bc)))
4914 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
4918 message ("Cast to underlying abstract type %t: %s",
4919 c, exprNode_unparse (ret)),
4926 message ("Cast to underlying abstract type %t: %s",
4927 c, exprNode_unparse (ret)),
4932 if (ctype_isRealAbstract (bt)
4933 && !context_hasAccess (ctype_typeId (bt)))
4935 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
4939 message ("Cast from underlying abstract type %t: %s",
4940 t, exprNode_unparse (ret)),
4947 message ("Cast from underlying abstract type %t: %s",
4948 t, exprNode_unparse (ret)),
4956 ctype bt = ctype_realType (ctype_getBaseType (t));
4957 ctype bc = ctype_realType (ctype_getBaseType (c));
4959 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
4961 if (ctype_match (c, t))
4963 if (ctype_equal (c, t))
4967 message ("Redundant cast involving abstract type %t: %s",
4968 bt, exprNode_unparse (ret)),
4976 message ("Cast from abstract type %t: %s",
4977 bt, exprNode_unparse (ret)),
4982 if (ctype_isAbstract (bc)
4983 && !context_hasAccess (ctype_typeId (bc)))
4985 if (ctype_match (c, t))
4991 DPRINTF (("No access to: %s / %d",
4992 ctype_unparse (bc), ctype_typeId (bc)));
4993 DPRINTF (("Context %s %s",
4994 bool_unparse (context_inFunctionLike ()),
4995 context_unparse ()));
4998 message ("Cast to abstract type %t: %s", bc,
4999 exprNode_unparse (ret)),
5005 if (ctype_isAbstract (c))
5007 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
5009 /* okay, cast exposed to abstract */
5010 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
5014 if (ctype_isVisiblySharable (t)
5015 && sRef_isExternallyVisible (e->sref)
5016 && !(ctype_isAbstract (t)
5017 && context_hasAccess (ctype_typeId (t))))
5021 message ("Cast to abstract type from externally visible "
5022 "mutable storage exposes rep of %s: %s",
5024 exprNode_unparse (e)),
5034 evaluationOrderUndefined (lltok op)
5036 int opid = lltok_getTok (op);
5038 return (opid != AND_OP && opid != OR_OP);
5041 static bool checkIntegral (/*@notnull@*/ exprNode e1,
5042 /*@notnull@*/ exprNode e2,
5043 /*@notnull@*/ exprNode ret,
5048 ctype te1 = exprNode_getType (e1);
5049 ctype te2 = exprNode_getType (e2);
5051 ctype tr1 = ctype_realishType (te1);
5052 ctype tr2 = ctype_realishType (te2);
5054 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
5060 if (context_msgStrictOps ())
5062 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
5064 if (ctype_sameName (te1, te2))
5068 message ("Operands of %s are non-integer (%t): %s",
5069 lltok_unparse (op), te1,
5070 exprNode_unparse (ret)),
5077 message ("Operands of %s are non-integers (%t, %t): %s",
5078 lltok_unparse (op), te1, te2,
5079 exprNode_unparse (ret)),
5083 else if (!ctype_isInt (tr1))
5087 message ("Left operand of %s is non-integer (%t): %s",
5088 lltok_unparse (op), te1, exprNode_unparse (ret)),
5092 /* !ctype_isInt (te2) */
5096 message ("Right operand of %s is non-integer (%t): %s",
5097 lltok_unparse (op), te2, exprNode_unparse (ret)),
5107 ** returns exprNode representing e1 op e2
5109 ** uses msg if there are errors
5110 ** can be used for both assignment ops and regular ops
5115 static /*@only@*/ /*@notnull@*/ exprNode
5116 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
5117 /*@keep@*/ lltok op)
5119 ctype te1, te2, tr1, tr2, tret;
5120 int opid = lltok_getTok (op);
5121 bool hasError = FALSE;
5124 if (exprNode_isError (e1))
5126 ret = exprNode_createPartialNVCopy (e2);
5130 ret = exprNode_createPartialNVCopy (e1);
5133 ret->val = multiVal_undefined;
5135 ret->edata = exprData_makeOp (e1, e2, op);
5137 if (exprNode_isError (e1) || exprNode_isError (e2))
5139 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5140 || opid == EQ_OP || opid == NE_OP
5141 || opid == AND_OP || opid == OR_OP)
5143 ret->typ = ctype_bool;
5146 if (exprNode_isDefined (e1))
5148 exprNode_checkUse (ret, e1->sref, e1->loc);
5151 if (exprNode_isDefined (e2))
5153 exprNode_mergeUSs (ret, e2);
5154 exprNode_checkUse (ret, e2->sref, e2->loc);
5160 tret = ctype_unknown;
5161 te1 = exprNode_getType (e1);
5162 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
5164 te2 = exprNode_getType (e2);
5166 tr1 = ctype_realishType (te1);
5167 tr2 = ctype_realishType (te2);
5171 ret->guards = guardSet_or (ret->guards, e2->guards);
5173 else if (opid == AND_OP)
5175 ret->guards = guardSet_and (ret->guards, e2->guards);
5182 if (opid == EQ_OP || opid == NE_OP)
5184 exprNode temp1 = e1, temp2 = e2;
5186 /* could do NULL == x */
5188 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
5190 temp1 = e2; temp2 = e1;
5193 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
5195 reflectNullTest (temp1, (opid == NE_OP));
5196 guardSet_free (ret->guards);
5197 ret->guards = guardSet_copy (temp1->guards);
5201 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5202 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
5207 if (anyAbstract (tr1, tr2) &&
5208 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
5209 (opid == AND_OP || opid == OR_OP
5210 || opid == EQ_OP || opid == NE_OP))))
5212 abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc);
5214 else if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
5216 /* unknown types, no comparisons possible */
5222 case TMULT: /* multiplication and division: */
5224 case MUL_ASSIGN: /* numeric, numeric -> numeric */
5225 case DIV_ASSIGN: /* */
5227 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5230 case TPLUS: /* addition and subtraction: */
5231 case TMINUS: /* pointer, int -> pointer */
5232 case SUB_ASSIGN: /* int, pointer -> pointer */
5233 case ADD_ASSIGN: /* numeric, numeric -> numeric */
5235 tr1 = ctype_fixArrayPtr (tr1);
5237 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
5238 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
5242 if (context_msgPointerArith ())
5246 message ("Pointer arithmetic (%t, %t): %s",
5247 te1, te2, exprNode_unparse (ret)),
5252 ** Swap terms so e1 is always the pointer
5255 if (ctype_isRealPointer (tr1))
5261 exprNode_swap (e1, e2);
5265 if (sRef_possiblyNull (e1->sref)
5266 && !usymtab_isGuarded (e1->sref))
5269 (FLG_NULLPOINTERARITH,
5270 message ("Pointer arithmetic involving possibly "
5271 "null pointer %s: %s",
5272 exprNode_unparse (e1),
5273 exprNode_unparse (ret)),
5277 ret->sref = sRef_copy (e1->sref);
5279 /* start modifications */
5280 /* added by Seejo on 4/16/2000 */
5282 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5284 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
5287 added ugly fixed to stop
5288 program from crashing on point + int +int
5289 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
5291 if (!multiVal_isInt (e2->val) )
5295 val = (int) multiVal_forceInt (e2->val);
5297 /* Operator : + or += */
5298 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5299 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
5300 val should not result in a
5301 size < 0 (size = 0 is ok !) */
5303 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
5305 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
5306 sRef_setNotNullTerminatedState(ret->sref);
5307 sRef_resetLen (ret->sref);
5309 sRef_setNullTerminatedState(ret->sref);
5310 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
5315 /* Operator : - or -= */
5316 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5317 if (sRef_getSize(e1->sref) >= 0) {
5318 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
5319 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
5324 /* end modifications */
5326 sRef_setNullError (ret->sref);
5329 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5330 ** since is points to storage that should not be deallocated
5331 ** through this pointer.
5334 if (sRef_isOnly (ret->sref)
5335 || sRef_isFresh (ret->sref))
5337 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5342 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
5343 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
5345 if (context_msgPointerArith ())
5349 message ("Pointer arithmetic (%t, %t): %s",
5350 te1, te2, exprNode_unparse (ret)),
5354 if (sRef_possiblyNull (e1->sref)
5355 && !usymtab_isGuarded (e1->sref))
5358 (FLG_NULLPOINTERARITH,
5359 message ("Pointer arithmetic involving possibly "
5360 "null pointer %s: %s",
5361 exprNode_unparse (e2),
5362 exprNode_unparse (ret)),
5366 ret->sref = sRef_copy (e2->sref);
5368 /* start modifications */
5369 /* added by Seejo on 4/16/2000 */
5371 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5374 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
5375 int val = (int) multiVal_forceInt (e1->val);
5377 /* Operator : + or += */
5378 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5379 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
5380 val should not result in a
5381 size < 0 (size = 0 is ok !) */
5383 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
5385 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
5386 sRef_setNotNullTerminatedState(ret->sref);
5387 sRef_resetLen (ret->sref);
5389 sRef_setNullTerminatedState(ret->sref);
5390 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
5395 /* Operator : - or -= */
5396 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5397 if (sRef_getSize(e2->sref) >= 0) {
5398 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
5399 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
5404 /* end modifications */
5406 sRef_setNullError (ret->sref);
5409 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5410 ** since is points to storage that should not be deallocated
5411 ** through this pointer.
5414 if (sRef_isOnly (ret->sref)
5415 || sRef_isFresh (ret->sref)) {
5416 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5420 ret->sref = e2->sref;
5424 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5429 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
5433 case TAMPERSAND: /* bitwise & */
5435 case TCIRC: /* ^ (XOR) */
5440 bool reported = FALSE;
5441 flagcode code = FLG_BITWISEOPS;
5443 if (opid == LEFT_OP || opid == LEFT_ASSIGN
5444 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
5445 code = FLG_SHIFTSIGNED;
5448 if (!ctype_isUnsigned (tr1))
5450 if (exprNode_isNonNegative (e1)) {
5453 reported = optgenerror
5455 message ("Left operand of %s is not unsigned value (%t): %s",
5456 lltok_unparse (op), te1,
5457 exprNode_unparse (ret)),
5467 /* right need not be signed for shifts */
5468 if (code != FLG_SHIFTSIGNED
5469 && !ctype_isUnsigned (tr2))
5471 if (!exprNode_isNonNegative (e2)) {
5472 reported = optgenerror
5474 message ("Right operand of %s is not unsigned value (%t): %s",
5475 lltok_unparse (op), te2,
5476 exprNode_unparse (ret)),
5484 if (!checkIntegral (e1, e2, ret, op)) {
5485 te1 = ctype_unknown;
5489 DPRINTF (("Set: %s", ctype_unparse (te1)));
5492 ** tret is the widest type of te1 and te2
5495 tret = ctype_widest (te1, te2);
5500 if (checkIntegral (e1, e2, ret, op)) {
5503 tret = ctype_unknown;
5508 case TLT: /* comparisons */
5509 case TGT: /* numeric, numeric -> bool */
5510 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
5511 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
5514 bool fepsilon = FALSE;
5516 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
5521 if (opid == TLT || opid == TGT)
5523 uentry ue1 = exprNode_getUentry (e1);
5524 uentry ue2 = exprNode_getUentry (e2);
5527 ** FLT_EPSILON, etc. really is a variable, not
5531 if (uentry_isVariable (ue1))
5533 cstring uname = uentry_rawName (ue1);
5535 if (cstring_equalLit (uname, "FLT_EPSILON")
5536 || cstring_equalLit (uname, "DBL_EPSILON")
5537 || cstring_equalLit (uname, "LDBL_EPSILON"))
5543 if (uentry_isVariable (ue2))
5545 cstring uname = uentry_rawName (ue2);
5547 if (cstring_equalLit (uname, "FLT_EPSILON")
5548 || cstring_equalLit (uname, "DBL_EPSILON")
5549 || cstring_equalLit (uname, "LDBL_EPSILON"))
5558 ; /* Don't complain. */
5564 message ("Dangerous comparison involving %s types: %s",
5565 ctype_unparse (rtype),
5566 exprNode_unparse (ret)),
5575 ** Types should match.
5578 if (!exprNode_matchTypes (e1, e2))
5580 hasError = gentypeerror
5582 message ("Operands of %s have incompatible types (%t, %t): %s",
5583 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5589 || (ctype_isForceRealNumeric (&tr1)
5590 && ctype_isForceRealNumeric (&tr2)) ||
5591 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
5597 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
5598 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
5602 message ("Comparison of pointer and numeric (%t, %t): %s",
5603 te1, te2, exprNode_unparse (ret)),
5608 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5613 /* certain comparisons on unsigned's and zero look suspicious */
5615 if (opid == TLT || opid == LE_OP || opid == GE_OP)
5617 if ((ctype_isUnsigned (tr1) && exprNode_isZero (e2))
5618 || (ctype_isUnsigned (tr2) && exprNode_isZero (e1)))
5621 (FLG_UNSIGNEDCOMPARE,
5622 message ("Comparison of unsigned value involving zero: %s",
5623 exprNode_unparse (ret)),
5628 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
5630 if ((opid == EQ_OP || opid == NE_OP) &&
5631 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
5634 ** is one a variable?
5637 if (uentry_isVariable (exprNode_getUentry (e1))
5638 || uentry_isVariable (exprNode_getUentry (e2)))
5641 ** comparisons with FALSE are okay
5644 if (exprNode_isFalseConstant (e1)
5645 || exprNode_isFalseConstant (e2))
5654 ("Use of %q with %s variables (risks inconsistency because "
5655 "of multiple true values): %s",
5656 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
5657 context_printBoolName (), exprNode_unparse (ret)),
5664 case AND_OP: /* bool, bool -> bool */
5667 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
5673 if (context_maybeSet (FLG_BOOLOPS))
5675 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
5677 if (ctype_sameName (te1, te2))
5681 message ("Operands of %s are non-boolean (%t): %s",
5682 lltok_unparse (op), te1,
5683 exprNode_unparse (ret)),
5691 ("Operands of %s are non-booleans (%t, %t): %s",
5692 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5696 else if (!ctype_isRealBool (te1))
5700 message ("Left operand of %s is non-boolean (%t): %s",
5701 lltok_unparse (op), te1, exprNode_unparse (ret)),
5704 else if (!ctype_isRealBool (te2))
5708 message ("Right operand of %s is non-boolean (%t): %s",
5709 lltok_unparse (op), te2, exprNode_unparse (ret)),
5722 (cstring_makeLiteral
5723 ("There has been a problem in the parser. This is believed to result "
5724 "from a problem with bison v. 1.25. Please try rebuidling LCLint "
5725 "using the pre-compiled grammar files by commenting out the "
5726 "BISON= line in the top-level Makefile."));
5731 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5734 exprNode_checkUse (ret, e1->sref, e1->loc);
5735 exprNode_mergeUSs (ret, e2);
5736 exprNode_checkUse (ret, e2->sref, e2->loc);
5742 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5743 /*@only@*/ lltok op)
5747 checkMacroParen (e1);
5748 checkMacroParen (e2);
5750 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5752 checkExpressionDefined (e1, e2, op);
5755 ret = exprNode_makeOp (e1, e2, op);
5760 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5763 ** This is somewhat bogus!
5765 ** Assigning to a nested observer in a non-observer datatype
5766 ** should not produce an error.
5769 sRef ref = exprNode_getSref (e1);
5771 DPRINTF (("Check assign mod: %s",
5772 sRef_unparseFull (ref)));
5774 if (sRef_isObserver (ref)
5775 || ((sRef_isFileStatic (ref) || sRef_isFileOrGlobalScope (ref))
5776 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5778 sRef base = sRef_getBase (ref);
5780 if (sRef_isValid (base) && sRef_isObserver (base))
5782 exprNode_checkModify (e1, ret);
5786 exprNode_checkModifyVal (e1, ret);
5791 exprNode_checkModify (e1, ret);
5796 exprNode_assign (/*@only@*/ exprNode e1,
5797 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5799 bool isalloc = FALSE;
5800 bool isjustalloc = FALSE;
5803 DPRINTF (("%s [%s] <- %s [%s]",
5804 exprNode_unparse (e1),
5805 ctype_unparse (e1->typ),
5806 exprNode_unparse (e2),
5807 ctype_unparse (e2->typ)));
5809 if (lltok_getTok (op) != TASSIGN)
5811 ret = exprNode_makeOp (e1, e2, op);
5815 ret = exprNode_createPartialCopy (e1);
5816 ret->kind = XPR_ASSIGN;
5817 ret->edata = exprData_makeOp (e1, e2, op);
5819 if (!exprNode_isError (e2))
5821 ret->sets = sRefSet_union (ret->sets, e2->sets);
5822 ret->msets = sRefSet_union (ret->msets, e2->msets);
5823 ret->uses = sRefSet_union (ret->uses, e2->uses);
5827 checkExpressionDefined (e1, e2, op);
5829 if (exprNode_isError (e1))
5831 if (!exprNode_isError (e2))
5833 ret->loc = fileloc_update (ret->loc, e2->loc);
5837 ret->loc = fileloc_update (ret->loc, g_currentloc);
5841 if (!exprNode_isError (e2))
5843 checkMacroParen (e2);
5846 if (exprNode_isDefined (e1))
5848 if (sRef_isMacroParamRef (e1->sref))
5850 if (context_inIterDef ())
5852 uentry ue = sRef_getUentry (e1->sref);
5854 if (uentry_isYield (ue))
5860 if (fileloc_isDefined (e1->loc))
5864 message ("Assignment to non-yield iter parameter: %q",
5865 sRef_unparse (e1->sref)),
5872 message ("Assignment to non-yield iter parameter: %q",
5873 sRef_unparse (e1->sref)),
5880 if (fileloc_isDefined (e1->loc))
5884 message ("Assignment to macro parameter: %q",
5885 sRef_unparse (e1->sref)),
5892 message ("Assignment to macro parameter: %q",
5893 sRef_unparse (e1->sref)),
5897 exprNode_checkAssignMod (e1, ret); /* evans 2001-07-22 */
5902 exprNode_checkAssignMod (e1, ret);
5905 if (exprNode_isDefined (e2))
5907 if (lltok_getTok (op) == TASSIGN)
5909 ctype te1 = exprNode_getType (e1);
5910 ctype te2 = exprNode_getType (e2);
5912 if (!ctype_forceMatch (te1, te2))
5914 if (exprNode_matchLiteral (te1, e2))
5922 message ("Assignment of %t to %t: %s %s %s",
5923 te2, te1, exprNode_unparse (e1),
5925 exprNode_unparse (e2)),
5931 exprNode_mergeUSs (ret, e2);
5932 exprNode_checkUse (ret, e2->sref, e2->loc);
5934 doAssign (e1, e2, FALSE);
5935 ret->sref = e1->sref;
5939 if (exprNode_isDefined (e2))
5941 exprNode_mergeUSs (ret, e2);
5942 exprNode_checkUse (ret, e2->sref, e2->loc);
5946 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5948 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5951 isjustalloc = sRef_isJustAllocated (e1->sref);
5952 isalloc = sRef_isAllocated (e1->sref);
5954 if (sRef_isField (e1->sref))
5956 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5958 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5960 exprNode_checkUse (ret, root, e1->loc);
5966 ** be careful! this defines e1->sref.
5969 /* evans 2001-07-22: removed if (!sRef_isMacroParamRef (e1->sref)) */
5971 DPRINTF (("Setting: %s -> %s", exprNode_unparse (ret), sRef_unparse (e1->sref)));
5972 exprNode_checkSet (ret, e1->sref);
5976 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5977 ? e2->loc : e1->loc);
5983 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5992 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5993 /*@keep@*/ exprNode elseclause)
5997 if (!exprNode_isError (pred))
5999 ret = exprNode_createPartialCopy (pred);
6000 checkMacroParen (pred);
6001 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
6003 if (!exprNode_isError (ifclause))
6005 checkMacroParen (ifclause); /* update macro counts! */
6007 if (!exprNode_isError (elseclause))
6009 checkMacroParen (elseclause);
6011 if (!exprNode_matchTypes (ifclause, elseclause))
6014 (exprNode_getType (ifclause),
6016 exprNode_getType (elseclause),
6018 message ("Conditional clauses are not of same type: "
6020 exprNode_unparse (ifclause),
6021 exprNode_getType (ifclause),
6022 exprNode_unparse (elseclause),
6023 exprNode_getType (elseclause)),
6026 ret->sref = sRef_undefined;
6027 ret->typ = ctype_unknown;
6032 /* for now...should merge the states */
6033 ret->sref = ifclause->sref;
6034 ret->typ = ifclause->typ;
6036 if (exprNode_isNullValue (ifclause))
6038 ret->typ = elseclause->typ;
6042 exprNode_checkUse (ret, pred->sref, pred->loc);
6043 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6044 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6046 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6051 ret->typ = ifclause->typ;
6053 exprNode_checkUse (pred, pred->sref, pred->loc);
6054 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6056 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
6061 if (!exprNode_isError (elseclause))
6063 ret->typ = elseclause->typ;
6065 exprNode_checkUse (pred, pred->sref, pred->loc);
6066 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6068 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6072 else /* pred is error */
6074 if (!exprNode_isError (ifclause))
6076 ret = exprNode_createSemiCopy (ifclause);
6078 checkMacroParen (ifclause); /* update macro counts! */
6080 if (!exprNode_isError (elseclause))
6082 checkMacroParen (elseclause);
6084 ret->typ = ifclause->typ;
6086 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
6089 (exprNode_getType (ifclause),
6091 exprNode_getType (elseclause),
6093 message ("Conditional clauses are not of same type: "
6095 exprNode_unparse (ifclause),
6096 exprNode_getType (ifclause),
6097 exprNode_unparse (elseclause),
6098 exprNode_getType (elseclause)),
6101 ret->typ = ctype_unknown;
6105 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6106 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6108 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6111 else if (!exprNode_isError (elseclause)) /* pred, if errors */
6113 ret = exprNode_createSemiCopy (ifclause);
6115 ret->typ = elseclause->typ;
6116 checkMacroParen (elseclause);
6118 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6119 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6121 else /* all errors! */
6123 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6127 ret->kind = XPR_COND;
6128 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
6130 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
6132 exprNode_combineControl (ret, ifclause, elseclause);
6139 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
6141 ctype totype = qtype_getType (qt);
6143 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
6147 ** check use of va_arg : <valist>, type -> type
6150 if (exprNode_isError (arg))
6155 targ = exprNode_getType (arg);
6158 ** arg should have be a pointer
6161 if (!ctype_isUA (targ) ||
6162 (!usymId_equal (ctype_typeId (targ),
6163 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
6167 message ("First argument to va_arg is not a va_list (type %t): %s",
6168 targ, exprNode_unparse (arg)),
6172 exprNode_checkSet (ret, arg->sref);
6176 ** return type is totype
6180 ret->kind = XPR_VAARG;
6181 ret->edata = exprData_makeCast (tok, arg, qt);
6186 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
6188 exprNode ret = exprNode_createPlain (ctype_undefined);
6189 ret->kind = XPR_LABEL;
6190 ret->edata = exprData_makeLiteral (label);
6191 ret->isJumpPoint = TRUE;
6193 return (ret); /* for now, ignore label */
6196 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
6198 if (exprNode_isDefined (stmt))
6200 stmt->isJumpPoint = TRUE;
6202 /* This prevent stray no return path errors, etc. */
6203 stmt->exitCode = XK_MUSTEXIT;
6209 bool exprNode_isDefaultMarker (exprNode e)
6211 if (exprNode_isDefined (e))
6213 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
6219 bool exprNode_isCaseMarker (exprNode e)
6221 if (exprNode_isDefined (e))
6223 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
6229 bool exprNode_isLabelMarker (exprNode e)
6231 if (exprNode_isDefined (e))
6233 return (e->kind == XPR_LABEL);
6239 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
6241 exprNode ret = exprNode_createPartialCopy (test);
6243 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6245 if (exprNode_isError (test)) {
6249 exprNode_checkUse (ret, test->sref, test->loc);
6251 usymtab_setExitCode (ret->exitCode);
6255 usymtab_setMustBreak ();
6258 ret->edata = exprData_makeSingle (test);
6259 ret->isJumpPoint = TRUE;
6265 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
6267 exprNode ret = exprNode_createPartialCopy (test);
6269 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6270 ret->edata = exprData_makePair (test, stmt);
6271 ret->isJumpPoint = TRUE;
6273 if (exprNode_isError (test))
6278 exprNode_checkUse (ret, test->sref, test->loc);
6280 if (exprNode_isError (stmt))
6285 exprNode_mergeUSs (ret, stmt);
6287 ret->exitCode = stmt->exitCode;
6288 ret->mustBreak = stmt->mustBreak;
6289 ret->canBreak = stmt->canBreak;
6291 usymtab_setExitCode (ret->exitCode);
6295 usymtab_setMustBreak ();
6302 /*@notnull@*/ /*@only@*/ exprNode
6303 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
6305 exprNode ret = exprNode_createTok (def);
6307 ret->isJumpPoint = TRUE;
6308 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
6313 exprNode_mayEscape (exprNode e)
6315 if (exprNode_isDefined (e))
6317 return exitkind_couldEscape (e->exitCode);
6323 exprNode_mustBreak (exprNode e)
6325 if (exprNode_isDefined (e))
6327 return e->mustBreak;
6333 exprNode_mustEscape (exprNode e)
6335 if (exprNode_isDefined (e))
6337 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
6344 exprNode_errorEscape (exprNode e)
6346 if (exprNode_isDefined (e))
6348 return exitkind_isError (e->exitCode);
6354 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
6356 exprNode ret = exprNode_createPartialCopy (e1);
6358 DPRINTF (("Concat: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6360 ret->edata = exprData_makePair (e1, e2);
6361 ret->kind = XPR_STMTLIST;
6363 if (exprNode_isDefined (e1))
6365 ret->isJumpPoint = e1->isJumpPoint;
6366 ret->canBreak = e1->canBreak;
6370 if (exprNode_isDefined (e2))
6372 ret->loc = fileloc_update (ret->loc, e2->loc);
6376 if (exprNode_isDefined (e2))
6378 ret->exitCode = e2->exitCode;
6379 ret->mustBreak = e2->mustBreak;
6380 if (e2->canBreak) ret->canBreak = TRUE;
6384 ** if e1 must return, then e2 is unreachable!
6387 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
6389 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
6390 && !(e2->isJumpPoint))
6392 if (context_getFlag (FLG_UNREACHABLE))
6396 if (e2->kind == XPR_STMT)
6398 nr = exprData_getUopNode (e2->edata);
6401 if ((nr->kind == XPR_TOK
6402 && lltok_isSemi (exprData_getTok (nr->edata))))
6404 /* okay to have unreachable ";" */
6405 ret->exitCode = XK_MUSTEXIT;
6406 ret->canBreak = TRUE;
6410 if (optgenerror (FLG_UNREACHABLE,
6411 message ("Unreachable code: %s",
6412 exprNode_unparseFirst (nr)),
6415 ret->isJumpPoint = TRUE;
6416 ret->mustBreak = FALSE;
6417 ret->exitCode = XK_ERROR;
6418 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
6422 ret->exitCode = XK_MUSTEXIT;
6423 ret->canBreak = TRUE;
6431 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
6434 ** We want a warning anytime we have:
6436 ** yyy; <<<- no break or return
6440 exprNode lastStmt = exprNode_lastStatement (e1);
6442 if (exprNode_isDefined (lastStmt)
6443 && !exprNode_mustEscape (lastStmt)
6444 && !exprNode_mustBreak (lastStmt)
6445 && !exprNode_isCaseMarker (lastStmt)
6446 && !exprNode_isDefaultMarker (lastStmt)
6447 && !exprNode_isLabelMarker (lastStmt))
6449 voptgenerror (FLG_CASEBREAK,
6451 ("Fall through case (no preceeding break)"),
6458 exprNode_mergeUSs (ret, e2);
6460 usymtab_setExitCode (ret->exitCode);
6464 usymtab_setMustBreak ();
6470 exprNode exprNode_createTok (/*@only@*/ lltok t)
6472 exprNode ret; /*@i23 if on same line, bad things happen...!@*/
6473 ret = exprNode_create (ctype_unknown);
6474 ret->kind = XPR_TOK;
6475 ret->edata = exprData_makeTok (t);
6479 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6481 if (!exprNode_isError (e))
6483 exprNode_checkStatement(e);
6486 return (exprNode_statementError (e, t));
6489 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6491 exprNode ret = exprNode_createPartialCopy (e);
6493 if (!exprNode_isError (e))
6495 if (e->kind != XPR_ASSIGN)
6497 exprNode_checkUse (ret, e->sref, e->loc);
6500 ret->exitCode = e->exitCode;
6501 ret->canBreak = e->canBreak;
6502 ret->mustBreak = e->mustBreak;
6505 ret->edata = exprData_makeUop (e, t);
6506 ret->kind = XPR_STMT;
6511 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
6513 if (!exprNode_isError (e))
6515 if (e->kind != XPR_ASSIGN)
6517 exprNode_checkUse (e, e->sref, e->loc);
6524 void exprNode_produceGuards (exprNode pred)
6526 if (!exprNode_isError (pred))
6528 if (ctype_isRealPointer (pred->typ))
6530 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
6533 exprNode_checkUse (pred, pred->sref, pred->loc);
6534 exprNode_resetSref (pred);
6538 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
6540 exprNode ret = exprNode_createPartialCopy (e);
6542 if (!exprNode_isError (e))
6544 ret->exitCode = e->exitCode;
6545 ret->canBreak = e->canBreak;
6546 ret->mustBreak = e->mustBreak;
6549 ret->edata = exprData_makeSingle (e);
6550 ret->kind = XPR_BLOCK;
6554 bool exprNode_isBlock (exprNode e)
6556 return (exprNode_isDefined (e)
6557 && ((e)->kind == XPR_BLOCK));
6560 bool exprNode_isAssign (exprNode e)
6562 if (exprNode_isDefined (e))
6564 return (e->kind == XPR_ASSIGN);
6570 bool exprNode_isEmptyStatement (exprNode e)
6572 return (exprNode_isDefined (e)
6573 && (e->kind == XPR_TOK)
6574 && (lltok_isSemi (exprData_getTok (e->edata))));
6577 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
6580 bool emptyErr = FALSE;
6582 if (context_maybeSet (FLG_IFEMPTY))
6584 if (exprNode_isEmptyStatement (tclause))
6586 emptyErr = optgenerror (FLG_IFEMPTY,
6588 ("Body of if statement is empty"),
6589 exprNode_loc (tclause));
6593 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
6595 if (exprNode_isDefined (tclause)
6596 && !exprNode_isBlock (tclause))
6598 voptgenerror (FLG_IFBLOCK,
6600 ("Body of if statement is not a block: %s",
6601 exprNode_unparse (tclause)),
6602 exprNode_loc (tclause));
6606 if (exprNode_isError (pred))
6608 if (exprNode_isError (tclause))
6610 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6614 ret = exprNode_createPartialCopy (tclause);
6619 if (exprNode_mustEscape (pred))
6623 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6624 exprNode_loc (pred));
6627 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6628 exprNode_checkUse (pred, pred->sref, pred->loc);
6630 if (!exprNode_isError (tclause))
6632 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
6635 ret = exprNode_createPartialCopy (pred);
6639 ret->edata = exprData_makePair (pred, tclause);
6641 ret->exitCode = XK_UNKNOWN;
6643 if (exprNode_isDefined (tclause))
6645 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
6646 ret->canBreak = tclause->canBreak;
6647 ret->sets = sRefSet_union (ret->sets, tclause->sets);
6648 ret->msets = sRefSet_union (ret->msets, tclause->msets);
6649 ret->uses = sRefSet_union (ret->uses, tclause->uses);
6652 ret->mustBreak = FALSE;
6657 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
6658 /*@only@*/ exprNode tclause,
6659 /*@only@*/ exprNode eclause)
6662 bool tEmptyErr = FALSE;
6663 bool eEmptyErr = FALSE;
6665 if (context_maybeSet (FLG_IFEMPTY))
6667 if (exprNode_isEmptyStatement (tclause))
6669 tEmptyErr = optgenerror
6672 ("Body of if clause of if statement is empty"),
6673 exprNode_loc (tclause));
6676 if (exprNode_isEmptyStatement (eclause))
6678 eEmptyErr = optgenerror
6681 ("Body of else clause of if statement is empty"),
6682 exprNode_loc (eclause));
6686 if (context_maybeSet (FLG_IFBLOCK))
6689 && exprNode_isDefined (tclause)
6690 && !exprNode_isBlock (tclause))
6692 voptgenerror (FLG_IFBLOCK,
6694 ("Body of if clause of if statement is not a block: %s",
6695 exprNode_unparse (tclause)),
6696 exprNode_loc (tclause));
6700 && exprNode_isDefined (eclause)
6701 && !exprNode_isBlock (eclause)
6702 && !(eclause->kind == XPR_IF)
6703 && !(eclause->kind == XPR_IFELSE))
6708 ("Body of else clause of if statement is not a block: %s",
6709 exprNode_unparse (eclause)),
6710 exprNode_loc (eclause));
6714 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6716 if (exprNode_isDefined (eclause)
6717 && (eclause->kind == XPR_IF))
6719 voptgenerror (FLG_ELSEIFCOMPLETE,
6720 message ("Incomplete else if logic (no final else): %s",
6721 exprNode_unparse (eclause)),
6722 exprNode_loc (eclause));
6726 if (exprNode_isError (pred))
6728 if (exprNode_isError (tclause))
6730 if (exprNode_isError (eclause))
6732 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6736 ret = exprNode_createPartialCopy (eclause);
6741 ret = exprNode_createPartialCopy (tclause);
6744 else /* pred is okay */
6746 ret = exprNode_createPartialCopy (pred);
6748 if (exprNode_mustEscape (pred))
6752 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6753 exprNode_loc (pred));
6756 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6757 exprNode_checkUse (ret, pred->sref, pred->loc);
6759 exprNode_mergeCondUSs (ret, tclause, eclause);
6762 ret->kind = XPR_IFELSE;
6763 ret->edata = exprData_makeCond (pred, tclause, eclause);
6765 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6767 exprNode_combineControl (ret, tclause, eclause);
6768 ret->loc = fileloc_update (ret->loc, eclause->loc);
6775 ** *allpaths <- TRUE iff all executions paths must go through the switch
6779 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6781 exprNodeSList el = exprNode_flatten (e);
6782 bool mustReturn = TRUE; /* find a branch that doesn't */
6783 bool thisReturn = FALSE;
6784 bool hasDefault = FALSE;
6785 bool hasAllMembers = FALSE;
6786 bool inSwitch = FALSE;
6787 bool isEnumSwitch = FALSE;
6788 bool canBreak = FALSE;
6789 bool fallThrough = FALSE;
6790 ctype ct = ctype_unknown;
6791 enumNameSList usedEnums;
6794 if (exprNode_isDefined (test))
6799 ttype = ctype_realType (ct);
6801 if (ctype_isEnum (ttype))
6803 isEnumSwitch = TRUE;
6804 enums = ctype_elist (ttype);
6805 usedEnums = enumNameSList_new ();
6809 exprNodeSList_elements (el, current)
6811 if (exprNode_isDefined (current))
6813 switch (current->kind)
6821 message ("Duplicate default cases in switch"),
6822 exprNode_loc (current));
6827 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6835 exprNode st = exprData_getSingle (current->edata);
6836 uentry ue = exprNode_getUentry (st);
6838 if (uentry_isValid (ue))
6840 cstring cname = uentry_rawName (ue);
6842 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6844 if (enumNameSList_member
6845 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6849 message ("Duplicate case in switch: %s",
6855 enumNameSList_addh (usedEnums, cname);
6862 message ("Case in switch not %s member: %s",
6863 ctype_unparse (ct), cname),
6870 if (inSwitch && !fallThrough)
6872 if (!thisReturn || canBreak)
6882 /*@switchbreak@*/ break;
6884 thisReturn = thisReturn || exprNode_mustEscape (current);
6885 canBreak = canBreak || current->canBreak;
6886 if (canBreak) fallThrough = FALSE;
6889 } end_exprNodeSList_elements;
6891 if (inSwitch) /* check the last one! */
6893 if (!thisReturn || canBreak)
6902 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6903 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6905 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6907 voptgenerror (FLG_MISSCASE,
6908 message ("Missing case%s in switch: %q",
6909 cstring_makeLiteralTemp
6910 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6911 enumNameSList_unparse (unused)),
6914 enumNameSList_free (unused);
6918 hasAllMembers = TRUE;
6922 enumNameSList_free (usedEnums);
6926 *allpaths = hasDefault;
6929 exprNodeSList_free (el);
6930 return ((hasDefault || hasAllMembers) && mustReturn);
6933 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6935 exprNode ret = exprNode_createPartialCopy (e);
6938 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6940 ret->kind = XPR_SWITCH;
6941 ret->edata = exprData_makePair (e, s);
6943 if (!exprNode_isError (s))
6945 exprNode fs = exprNode_firstStatement (s);
6946 ret->loc = fileloc_update (ret->loc, s->loc);
6948 if (exprNode_isUndefined (fs)
6949 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6950 || exprNode_isDefaultMarker (fs)) {
6953 voptgenerror (FLG_FIRSTCASE,
6955 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6960 if (!exprNode_isError (e))
6962 if (checkSwitchExpr (e, s, &allpaths))
6964 ret->exitCode = XK_MUSTRETURN;
6968 ret->exitCode = e->exitCode;
6971 ret->canBreak = e->canBreak;
6972 ret->mustBreak = e->mustBreak;
6976 ** exprNode.c:3883,32: Variable allpaths used before definition
6983 DPRINTF (("Context exit switch!"));
6984 context_exitSwitch (ret, allpaths);
6985 DPRINTF (("Context exit switch done!"));
6990 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6991 /*@notnull@*/ exprNode body)
6993 sRefSet tuses = test->uses;
6995 if (!sRefSet_isEmpty (test->uses))
6997 sRefSet sets = sRefSet_newCopy (body->sets);
6998 bool hasError = TRUE;
6999 bool innerState = FALSE;
7000 sRefSet tuncon = sRefSet_undefined;
7002 sets = sRefSet_union (sets, test->sets);
7003 sets = sRefSet_union (sets, body->msets);
7004 sets = sRefSet_union (sets, test->msets);
7006 sRefSet_allElements (tuses, el)
7008 if (sRef_isUnconstrained (el))
7010 tuncon = sRefSet_insert (tuncon, el);
7014 if (sRefSet_member (sets, el))
7021 if (sRef_isInternalState (el)
7022 || sRef_isFileStatic (sRef_getRootBase (el)))
7026 } end_sRefSet_allElements ;
7030 sRefSet suncon = sRefSet_undefined;
7031 bool sinner = FALSE;
7033 sRefSet_allElements (sets, el)
7035 if (sRef_isUnconstrained (el))
7037 suncon = sRefSet_insert (suncon, el);
7039 else if (sRef_isInternalState (el))
7047 } end_sRefSet_allElements ;
7049 if (sinner && innerState)
7053 else if (sRefSet_isEmpty (tuncon)
7054 && sRefSet_isEmpty (suncon))
7059 ("Suspected infinite loop. No value used in loop test (%q) "
7060 "is modified by test or loop body.",
7061 sRefSet_unparsePlain (tuses)),
7066 if (sRefSet_isEmpty (tuncon))
7070 message ("Suspected infinite loop. No condition values "
7071 "modified. Modification possible through "
7072 "unconstrained calls: %q",
7073 sRefSet_unparsePlain (suncon)),
7080 message ("Suspected infinite loop. No condition values "
7081 "modified. Possible undetected dependency through "
7082 "unconstrained calls in loop test: %q",
7083 sRefSet_unparsePlain (tuncon)),
7089 sRefSet_free (sets);
7093 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
7096 bool emptyErr = FALSE;
7098 if (context_maybeSet (FLG_WHILEEMPTY))
7100 if (exprNode_isEmptyStatement (b))
7102 emptyErr = optgenerror
7105 ("Body of while statement is empty"),
7110 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
7112 if (exprNode_isDefined (b)
7113 && !exprNode_isBlock (b))
7115 if (context_inIterDef ()
7116 && (b->kind == XPR_STMTLIST
7117 || b->kind == XPR_TOK))
7123 voptgenerror (FLG_WHILEBLOCK,
7125 ("Body of while statement is not a block: %s",
7126 exprNode_unparse (b)),
7132 if (exprNode_isError (t))
7134 if (exprNode_isError (b))
7136 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7140 ret = exprNode_createPartialCopy (b);
7147 ret = exprNode_createPartialCopy (t);
7149 llassert (t->kind == XPR_WHILEPRED);
7151 test = exprData_getSingle (t->edata);
7153 if (!exprNode_isError (b) && exprNode_isDefined (test))
7155 if (context_maybeSet (FLG_INFLOOPS)
7156 || context_maybeSet (FLG_INFLOOPSUNCON))
7159 ** check that some variable in the predicate is set by the body
7160 ** if the predicate uses any variables
7163 checkInfiniteLoop (test, b);
7166 exprNode_mergeUSs (ret, b);
7168 if (exprNode_isDefined (b))
7170 ret->exitCode = exitkind_makeConditional (b->exitCode);
7175 ret->edata = exprData_makePair (t, b);
7176 ret->kind = XPR_WHILE;
7178 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
7182 message ("Predicate always exits: %s", exprNode_unparse (t)),
7186 ret->exitCode = XK_NEVERESCAPE;
7189 ** If loop is infinite, and there is no break inside,
7190 ** exit code is never reach.
7193 if (exprNode_knownIntValue (t))
7195 if (!exprNode_isZero (t))
7197 if (exprNode_isDefined (b))
7201 /* Really, it means never reached. */
7202 ret->exitCode = XK_MUSTEXIT;
7212 ret->canBreak = FALSE;
7213 ret->mustBreak = FALSE;
7219 ** do { b } while (t);
7221 ** note: body passed as first argument
7224 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
7228 if (exprNode_isError (t))
7230 if (exprNode_isError (b))
7232 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7236 ret = exprNode_createPartialCopy (b);
7238 ret->exitCode = exitkind_makeConditional (b->exitCode);
7239 exprNode_checkUse (ret, b->sref, b->loc);
7240 ret->exitCode = b->exitCode;
7241 ret->canBreak = b->canBreak;
7242 ret->mustBreak = b->mustBreak;
7247 ret = exprNode_createPartialCopy (t);
7248 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
7250 if (!exprNode_isError (b))
7253 ** forgot the copy's --- why wasn't this detected??
7256 ret->sets = sRefSet_copyInto (ret->sets, b->sets);
7257 ret->msets = sRefSet_copyInto (ret->msets, b->msets);
7258 ret->uses = sRefSet_copyInto (ret->uses, b->uses);
7260 /* left this out --- causes and aliasing bug (infinite loop)
7261 should be detected?? */
7263 exprNode_checkUse (ret, b->sref, b->loc);
7264 exprNode_mergeUSs (ret, t);
7265 exprNode_checkUse (ret, t->sref, t->loc);
7267 ret->exitCode = b->exitCode;
7268 ret->canBreak = b->canBreak;
7269 ret->mustBreak = b->mustBreak;
7273 context_exitDoWhileClause (t);
7275 ret->kind = XPR_DOWHILE;
7276 ret->edata = exprData_makePair (t, b);
7280 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
7283 bool emptyErr = FALSE;
7285 if (context_maybeSet (FLG_FOREMPTY))
7287 if (exprNode_isEmptyStatement (body))
7289 emptyErr = optgenerror
7292 ("Body of for statement is empty"),
7293 exprNode_loc (body));
7297 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
7299 if (exprNode_isDefined (body)
7300 && !exprNode_isBlock (body))
7302 if (context_inIterDef ()
7303 && (body->kind == XPR_STMTLIST
7304 || body->kind == XPR_TOK))
7310 voptgenerror (FLG_FORBLOCK,
7312 ("Body of for statement is not a block: %s",
7313 exprNode_unparse (body)),
7314 exprNode_loc (body));
7320 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
7323 if (exprNode_isError (body))
7325 ret = exprNode_createPartialCopy (inc);
7329 ret = exprNode_createPartialCopy (body);
7331 ret->exitCode = exitkind_makeConditional (body->exitCode);
7333 exprNode_mergeUSs (inc, body);
7335 if (exprNode_isDefined (inc))
7339 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
7342 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
7343 exprNode_freeShallow (tmp);
7345 context_clearMessageAnnote ();
7346 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
7348 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
7349 exprNode_freeShallow (tmp);
7351 context_clearMessageAnnote ();
7353 ret->uses = sRefSet_copyInto (ret->uses, inc->uses);
7354 ret->sets = sRefSet_copyInto (ret->sets, inc->sets);
7355 ret->msets = sRefSet_copyInto (ret->msets, inc->msets);
7359 ret->kind = XPR_FOR;
7360 ret->edata = exprData_makePair (inc, body);
7362 if (exprNode_isDefined (inc)) {
7363 exprNode test = exprData_getTripleTest (inc->edata);
7365 if (exprNode_isUndefined (test)) {
7366 if (exprNode_isDefined (body)) {
7367 if (!body->canBreak) {
7368 /* Really, it means never reached. */
7369 ret->exitCode = XK_MUSTEXIT;
7379 ** for (init; test; inc)
7382 ** while (test) { body; inc; }
7384 ** Now: check use of init (may set vars for test)
7385 ** check use of test
7389 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
7393 if (exprNode_isError (pred)) return guardSet_undefined;
7395 llassert (pred->kind == XPR_FORPRED);
7397 test = exprData_getTripleTest (pred->edata);
7399 if (!exprNode_isError (test))
7401 return (test->guards);
7404 return guardSet_undefined;
7407 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
7409 exprNode ret = exprNode_createSemiCopy (test);
7411 if (exprNode_isDefined (test))
7413 exprNode_copySets (ret, test);
7414 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
7415 exprNode_checkUse (ret, test->sref, test->loc);
7417 exprNode_produceGuards (test);
7419 ret->guards = guardSet_copy (test->guards);
7422 ret->edata = exprData_makeSingle (test);
7423 ret->kind = XPR_WHILEPRED;
7427 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
7428 /*@only@*/ exprNode inc)
7433 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
7436 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
7438 if (!exprNode_isError (inc))
7440 ret = exprNode_createPartialCopy (inc);
7444 if (!exprNode_isError (init))
7446 ret = exprNode_createPartialCopy (init);
7448 else if (!exprNode_isError (test))
7450 ret = exprNode_createPartialCopy (test);
7454 ret = exprNode_createUnknown ();
7458 exprNode_mergeUSs (ret, init);
7460 if (exprNode_isDefined (init))
7462 exprNode_checkUse (ret, init->sref, init->loc);
7465 exprNode_mergeUSs (ret, test);
7467 if (exprNode_isDefined (test))
7469 exprNode_checkUse (ret, test->sref, test->loc);
7472 ret->kind = XPR_FORPRED;
7473 ret->edata = exprData_makeFor (init, test, inc);
7477 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
7479 exprNode ret = exprNode_createUnknown ();
7481 if (context_inMacro ())
7483 voptgenerror (FLG_MACROSTMT,
7484 message ("Macro %s uses goto (not functional)",
7485 context_inFunctionName ()),
7489 ret->kind = XPR_GOTO;
7490 ret->edata = exprData_makeLiteral (label);
7491 ret->mustBreak = TRUE;
7492 ret->exitCode = XK_GOTO;
7493 ret->canBreak = TRUE;
7497 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
7499 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7501 ret->kind = XPR_CONTINUE;
7502 ret->edata = exprData_makeTok (l);
7503 ret->canBreak = TRUE;
7504 ret->mustBreak = TRUE;
7506 if (qcontinue == QSAFEBREAK)
7510 else if (qcontinue == QINNERCONTINUE)
7512 if (!context_inDeepLoop ())
7515 (FLG_LOOPLOOPCONTINUE,
7516 cstring_makeLiteral ("Continue statement marked with innercontinue "
7517 "is not inside a nested loop"),
7518 exprNode_loc (ret));
7521 else if (qcontinue == BADTOK)
7523 if (context_inDeepLoop ())
7526 (FLG_LOOPLOOPCONTINUE,
7527 cstring_makeLiteral ("Continue statement in nested loop"),
7528 exprNode_loc (ret));
7533 llbuglit ("exprNode_continue: bad qcontinue");
7539 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
7541 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7542 clause breakClause = context_breakClause ();
7544 ret->kind = XPR_BREAK;
7545 ret->edata = exprData_makeTok (l);
7546 ret->canBreak = TRUE;
7547 ret->mustBreak = TRUE;
7549 if (breakClause == NOCLAUSE)
7553 cstring_makeLiteral ("Break not inside while, for or switch statement"),
7554 exprNode_loc (ret));
7558 if (bqual != BADTOK)
7565 if (breakClause == SWITCHCLAUSE)
7567 if (!context_inDeepSwitch ())
7569 voptgenerror (FLG_SYNTAX,
7571 ("Break preceded by innerbreak is not in a deep switch"),
7572 exprNode_loc (ret));
7577 if (!context_inDeepLoop ())
7579 voptgenerror (FLG_SYNTAX,
7581 ("Break preceded by innerbreak is not in a deep loop"),
7582 exprNode_loc (ret));
7587 if (breakClause == SWITCHCLAUSE)
7589 voptgenerror (FLG_SYNTAX,
7591 ("Break preceded by loopbreak is breaking a switch"),
7592 exprNode_loc (ret));
7596 if (breakClause != SWITCHCLAUSE)
7600 message ("Break preceded by switchbreak is breaking %s",
7601 cstring_makeLiteralTemp
7602 ((breakClause == WHILECLAUSE
7603 || breakClause == DOWHILECLAUSE) ? "a while loop"
7604 : (breakClause == FORCLAUSE) ? "a for loop"
7605 : (breakClause == ITERCLAUSE) ? "an iterator"
7607 exprNode_loc (ret));
7615 if (breakClause == SWITCHCLAUSE)
7617 clause nextBreakClause = context_nextBreakClause ();
7619 switch (nextBreakClause)
7621 case NOCLAUSE: break;
7627 (FLG_LOOPSWITCHBREAK,
7628 cstring_makeLiteral ("Break statement in switch inside loop"),
7629 exprNode_loc (ret));
7633 (FLG_SWITCHSWITCHBREAK,
7634 cstring_makeLiteral ("Break statement in switch inside switch"),
7635 exprNode_loc (ret));
7642 if (context_inDeepLoop ())
7646 cstring_makeLiteral ("Break statement in nested loop"),
7647 exprNode_loc (ret));
7651 if (context_inDeepLoopSwitch ())
7654 (FLG_SWITCHLOOPBREAK,
7655 cstring_makeLiteral ("Break statement in loop inside switch"),
7656 exprNode_loc (ret));
7666 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
7668 fileloc loc = lltok_getLoc (t);
7669 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
7671 context_returnFunction ();
7672 exprChecks_checkNullReturn (loc);
7674 ret->kind = XPR_NULLRETURN;
7675 ret->edata = exprData_makeTok (t);
7676 ret->exitCode = XK_MUSTRETURN;
7680 exprNode exprNode_return (/*@only@*/ exprNode e)
7684 if (exprNode_isError (e))
7686 ret = exprNode_createUnknown ();
7690 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7692 exprNode_checkUse (ret, e->sref, e->loc);
7693 exprNode_checkReturn (e);
7696 context_returnFunction ();
7697 ret->kind = XPR_RETURN;
7698 ret->edata = exprData_makeSingle (e);
7699 ret->exitCode = XK_MUSTRETURN;
7704 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7708 if (exprNode_isError (e1))
7710 if (exprNode_isError (e2))
7712 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7716 ret = exprNode_createPartialCopy (e2);
7717 exprNode_checkUse (ret, e2->sref, e2->loc);
7718 ret->sref = e2->sref;
7723 ret = exprNode_createPartialCopy (e1);
7725 exprNode_checkUse (ret, e1->sref, e1->loc);
7727 if (!exprNode_isError (e2))
7729 exprNode_mergeUSs (ret, e2);
7730 exprNode_checkUse (ret, e2->sref, e2->loc);
7731 ret->sref = e2->sref;
7735 ret->kind = XPR_COMMA;
7736 ret->edata = exprData_makePair (e1, e2);
7738 if (exprNode_isDefined (e1))
7740 if (exprNode_isDefined (e2))
7744 if (exprNode_mustEscape (e1) || e1->mustBreak)
7748 message ("Second clause of comma expression is unreachable: %s",
7749 exprNode_unparse (e2)),
7753 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7754 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7755 ret->canBreak = e1->canBreak || e2->canBreak;
7759 if (exprNode_mustEscape (e1) || e1->mustBreak)
7763 message ("Second clause of comma expression is unreachable: %s",
7764 exprNode_unparse (e2)),
7768 ret->exitCode = e1->exitCode;
7769 ret->canBreak = e1->canBreak;
7774 if (exprNode_isDefined (e2))
7776 ret->exitCode = e2->exitCode;
7777 ret->mustBreak = e2->mustBreak;
7778 ret->canBreak = e2->canBreak;
7785 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7787 ctype t1 = exprNode_getType (el);
7788 ctype t2 = exprNode_getType (val);
7789 bool hasError = FALSE;
7791 if (ctype_isUnknown (t1))
7793 voptgenerror (FLG_IMPTYPE,
7794 message ("Variable has unknown (implicitly int) type: %s",
7795 exprNode_unparse (el)),
7799 el->typ = ctype_int;
7802 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7804 exprNodeList vals = exprData_getArgs (val->edata);
7806 if (ctype_isRealAP (t1))
7811 /*@i423 check number of entries int a[3] = { 1, 2, 3, 4 } ; */
7813 exprNodeList_elements (vals, oneval)
7815 cstring istring = message ("%d", i);
7818 (exprNode_fakeCopy (el),
7819 exprNode_numLiteral (ctype_int, istring,
7820 fileloc_copy (el->loc), i));
7822 if (exprNode_isDefined (newel))
7824 if (exprNodeList_size (vals) == 1
7825 && ctype_isString (exprNode_getType (oneval))
7826 && ctype_isChar (exprNode_getType (newel)))
7828 exprNode_freeIniter (newel);
7832 if (exprNode_checkOneInit (newel, oneval))
7837 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7840 (message ("Additional initialization errors "
7841 "for %s not reported",
7842 exprNode_unparse (el)),
7844 exprNode_freeIniter (newel);
7849 exprNode_freeIniter (newel);
7854 exprNode_freeIniter (newel);
7859 cstring_free (istring);
7862 } end_exprNodeList_elements;
7865 else if (ctype_isStruct (ctype_realType (t1)))
7867 uentryList fields = ctype_getFields (t1);
7870 if (uentryList_size (fields) != exprNodeList_size (vals))
7872 if (uentryList_size (fields) > exprNodeList_size (vals))
7874 hasError = optgenerror
7876 message ("Initializer block for "
7877 "%s has %d field%&, but %s has %d field%&: %q",
7878 exprNode_unparse (el),
7879 exprNodeList_size (vals),
7881 uentryList_size (fields),
7882 exprNodeList_unparse (vals)),
7887 hasError = optgenerror
7889 message ("Initializer block for "
7890 "%s has %d field%&, but %s has %d field%&: %q",
7891 exprNode_unparse (el),
7892 exprNodeList_size (vals),
7894 uentryList_size (fields),
7895 exprNodeList_unparse (vals)),
7901 exprNodeList_elements (vals, oneval)
7903 uentry thisfield = uentryList_getN (fields, i);
7905 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
7907 uentry_getName (thisfield));
7909 if (exprNode_isDefined (newel))
7911 if (exprNode_checkOneInit (newel, oneval))
7916 exprNode_freeIniter (newel);
7920 } end_exprNodeList_elements;
7925 hasError = optgenerror
7927 message ("Initializer block used for "
7928 "%s where %t is expected: %s",
7929 exprNode_unparse (el), t1, exprNode_unparse (val)),
7935 if (exprNode_isDefined (val))
7937 doAssign (el, val, TRUE);
7939 if (!exprNode_matchType (t1, val))
7941 hasError = gentypeerror
7943 message ("Initial value of %s is type %t, "
7945 exprNode_unparse (el),
7946 t2, t1, exprNode_unparse (val)),
7956 exprNode_makeInitializationAux (/*@temp@*/ idDecl t)
7960 if (usymtab_exists (idDecl_observeId (t)))
7962 uentry ue = usymtab_lookup (idDecl_observeId (t));
7963 ret = exprNode_createId (ue);
7965 /*@i723 don't do this...but why? */
7967 ct = ctype_realishType (ret->typ);
7969 DPRINTF (("Type: %s", ctype_unparse (ret->typ)));
7971 if (ctype_isUnknown (ct))
7973 if (uentry_isAnyTag (ue))
7977 message ("%s used but not previously declared: %s",
7978 uentry_ekindName (ue),
7979 idDecl_getName (t)),
7987 message ("Variable has unknown (implicitly int) type: %s",
7988 idDecl_getName (t)),
8000 DPRINTF (("Unrecognized: %s", idDecl_unparse (t)));
8002 ue = uentry_makeUnrecognized (idDecl_observeId (t), fileloc_copy (g_currentloc));
8003 /*!! fileloc_copy (g_currentloc)); */
8004 /*@i32!!! should get error without this */
8005 ret = exprNode_fromIdentifierAux (ue);
8008 ** No error - this happens in old style declarations:
8012 message ("Unrecognized identifier in intializer: %s", idDecl_observeId (t)),
8019 exprData_free (ret->edata, ret->kind);
8020 ret->edata = exprData_undefined;
8022 ret->exitCode = XK_NEVERESCAPE;
8023 ret->mustBreak = FALSE;
8024 ret->kind = XPR_INIT;
8028 exprNode exprNode_makeEmptyInitialization (/*@only@*/ idDecl t)
8030 exprNode ret = exprNode_makeInitializationAux (t);
8031 llassert (ret->edata == exprData_undefined);
8032 ret->edata = exprData_makeInit (t, exprNode_undefined);
8036 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
8037 /*@only@*/ exprNode e)
8039 uentry ue = usymtab_lookup (idDecl_observeId (t));
8040 exprNode ret = exprNode_makeInitializationAux (t);
8041 fileloc loc = exprNode_loc (e);
8043 if (exprNode_isError (e))
8045 e = exprNode_createUnknown ();
8048 /* error: assume initializer is defined */
8049 sRef_setDefined (ret->sref, g_currentloc);
8053 ctype ct = ctype_realishType (ret->typ);
8058 ** was addSafeUse --- what's the problem?
8060 ** int x = 3, y = x ?
8063 exprData_free (ret->edata, ret->kind);
8064 ret->edata = exprData_makeInit (t, e);
8066 exprNode_checkUse (ret, e->sref, e->loc);
8068 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
8070 exprNode lhs = exprNode_createId (ue);
8073 ** static storage should be undefined before initializing
8076 if (uentry_isStatic (ue))
8078 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
8081 (void) exprNode_checkOneInit (lhs, e);
8083 if (uentry_isStatic (ue))
8085 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
8088 exprNode_free (lhs);
8092 if (!exprNode_matchType (ct, e))
8094 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
8101 (exprNode_getType (e), e, exprNode_getType (ret), ret,
8103 ("Variable %q initialized to type %t, expects %t: %s",
8104 uentry_getName (ue), exprNode_getType (e),
8105 exprNode_getType (ret),
8106 exprNode_unparse (e)),
8112 if (uentry_isStatic (ue))
8114 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
8117 doAssign (ret, e, TRUE);
8119 if (uentry_isStatic (ue))
8121 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
8125 if (context_inIterDef ())
8127 /* should check if it is yield */
8128 uentry_setUsed (ue, loc);
8135 exprNode_mergeUSs (ret, e);
8139 exprNode exprNode_iter (/*@observer@*/ uentry name,
8140 /*@only@*/ exprNodeList alist,
8141 /*@only@*/ exprNode body,
8142 /*@observer@*/ uentry end)
8147 llassert (uentry_isValid (name));
8149 uentry_setUsed (name, exprNode_loc (body));
8151 ret = exprNode_createPartialCopy (body);
8152 iname = uentry_getName (name);
8154 if (uentry_isInvalid (end))
8157 message ("Iter %s not balanced with end_%s", iname, iname));
8161 cstring ename = uentry_getName (end);
8163 if (!cstring_equalPrefixLit (ename, "end_"))
8165 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
8166 iname, iname, ename));
8170 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
8173 message ("Iter %s not balanced with end_%s: %s",
8174 iname, iname, ename));
8178 cstring_free (ename);
8181 context_exitIterClause (body);
8183 ret->kind = XPR_ITER;
8184 ret->edata = exprData_makeIter (name, alist, body, end);
8186 if (uentry_isIter (name))
8188 (void) checkArgsReal (name, body,
8189 uentry_getParams (name), alist, TRUE, ret);
8192 cstring_free (iname);
8198 exprNode_iterNewId (/*@only@*/ cstring s)
8200 exprNode e = exprNode_new ();
8201 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
8203 llassert (processingIterVars ());
8205 e->loc = context_getSaveLocation ();
8207 if (fileloc_isUndefined (e->loc))
8209 fileloc_free (e->loc);
8210 e->loc = fileloc_copy (g_currentloc);
8213 e->uses = sRefSet_new ();
8214 e->sets = sRefSet_new ();
8215 e->msets = sRefSet_new ();
8217 e->val = multiVal_unknown ();
8218 e->guards = guardSet_new ();
8220 e->isJumpPoint = FALSE;
8221 e->exitCode = XK_NEVERESCAPE;
8223 /*> missing fields, detected by lclint <*/
8224 e->canBreak = FALSE;
8225 e->mustBreak = FALSE;
8226 e->etext = cstring_undefined;
8228 if (uentry_isYield (ue))
8230 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
8231 fileloc_copy (e->loc),
8235 uue = usymtab_supEntrySrefReturn (uue);
8237 sr = uentry_getSref (uue);
8238 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
8239 sr = uentry_getSref (uue);
8240 sRef_setDefined (sr, e->loc);
8242 e->typ = uentry_getType (uue);
8244 e->edata = exprData_makeId (uue);
8245 uentry_setUsed (uue, g_currentloc);
8251 sRef_setGlobalScope ();
8252 uue = uentry_makeVariableLoc (s, ctype_unknown);
8254 e->typ = ctype_unknown;
8255 e->edata = exprData_makeId (uue);
8257 uentry_setUsed (uue, e->loc);
8258 uentry_setHasNameError (uue);
8260 if (context_getFlag (FLG_REPEATUNRECOG))
8262 uentry_markOwned (uue);
8266 usymtab_supGlobalEntry (uue);
8269 sRef_clearGlobalScope ();
8271 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
8278 exprNode_defineConstraints(e);
8283 exprNode_iterExpr (/*@returned@*/ exprNode e)
8285 if (!processingIterVars ())
8287 llcontbuglit ("checkIterParam: not in iter");
8291 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
8294 if (exprNode_isDefined (e))
8296 if (fileloc_isDefined (e->loc))
8300 message ("Yield parameter is not simple identifier: %s",
8301 exprNode_unparse (e)),
8308 message ("Yield parameter is not simple identifier: %s",
8309 exprNode_unparse (e)),
8319 exprNode_iterId (/*@observer@*/ uentry c)
8323 llassert (processingIterVars ());
8325 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
8328 if (uentry_isYield (ue))
8330 ctype ct = uentry_getType (ue);
8331 exprNode e = exprNode_createPlain (ct);
8332 cstring name = uentry_getName (c);
8333 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
8335 uentry_setUsed (ue, g_currentloc);
8336 uentry_setHasNameError (ue);
8338 cstring_free (name);
8341 e->edata = exprData_makeId (le);
8342 e->loc = context_getSaveLocation ();
8343 e->sref = uentry_getSref (le);
8345 usymtab_supEntrySref (le);
8347 if (!context_inHeader ())
8351 message ("Yield parameter shadows local declaration: %q",
8352 uentry_getName (c)),
8353 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
8355 uentry_showWhereDeclared (c);
8362 return (exprNode_fromIdentifierAux (c));
8365 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
8367 exprNode ret = exprNode_create (ctype_unknown);
8369 ret->kind = XPR_ITERCALL;
8370 ret->edata = exprData_makeIterCall (name, alist);
8372 if (uentry_isIter (name))
8374 uentryList params = uentry_getParams (name);
8376 if (context_inIterDef ()
8377 && uentryList_size (params) == exprNodeList_size (alist))
8381 exprNodeList_elements (alist, arg)
8383 uentry parg = uentryList_getN (params, i);
8385 if (uentry_isYield (parg))
8387 uentry ue = exprNode_getUentry (arg);
8389 if (uentry_isValid (ue))
8396 } end_exprNodeList_elements;
8399 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
8400 checkUnspecCall (ret, params, alist);
8406 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
8408 if (exprNode_isDefined (e))
8411 if (e->sref == defref) /*@noaccess sRef@*/
8414 e->sref = sRef_makeUnknown ();
8415 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
8426 return sRef_undefined;
8430 /*@observer@*/ cstring
8431 exprNode_unparseFirst (exprNode e)
8433 if (exprNode_isDefined (e))
8437 if (e->kind == XPR_STMTLIST
8438 || e->kind == XPR_COMMA || e->kind == XPR_COND)
8440 exprNode first = exprData_getPairA (e->edata);
8442 if (exprNode_isDefined (first))
8444 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
8448 return (cstring_makeLiteralTemp ("..."));
8452 ret = cstring_elide (exprNode_unparse (e), 20);
8453 cstring_markOwned (ret);
8459 return cstring_makeLiteralTemp ("<error>");
8463 /*@observer@*/ cstring
8464 exprNode_unparse (/*@temp@*/ exprNode e)
8466 if (exprNode_isError (e))
8468 return cstring_makeLiteralTemp ("<error>");
8471 if (cstring_isDefined (e->etext))
8477 cstring ret = exprNode_doUnparse (e);
8479 /*@-modifies@*/ /* benevolent */
8486 /*@observer@*/ fileloc
8487 exprNode_loc (exprNode e)
8489 if (exprNode_isError (e))
8491 return (g_currentloc);
8500 ** executes exprNode e
8501 ** recursively rexecutes as though in original parse using
8502 ** information in e->edata
8505 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
8507 exprNodeList ret = exprNodeList_new ();
8509 exprNodeList_elements (e, current)
8511 exprNodeList_addh (ret, exprNode_effect (current));
8512 } end_exprNodeList_elements;
8517 static /*@only@*/ exprNode exprNode_effect (exprNode e)
8518 /*@globals internalState@*/
8520 bool innerEffect = inEffect;
8526 context_clearJustPopped ();
8528 if (exprNode_isError (e))
8530 ret = exprNode_undefined;
8535 ** Turn off expose and dependent transfer checking.
8536 ** Need to pass exposed internal nodes,
8537 ** [ copying would be a waste! ]
8538 ** [ Actually, I think I wasted a lot more time than its worth ]
8539 ** [ trying to do this. ]
8543 /*@-observertrans@*/
8544 /*@-dependenttrans@*/
8551 ret = exprNode_addParens (exprData_getUopTok (data),
8552 exprNode_effect (exprData_getUopNode (data)));
8555 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
8556 exprNode_effect (exprData_getOpB (data)),
8557 exprData_getOpTok (data));
8560 ret = exprNode_undefined;
8563 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
8564 exprNodeList_effect (exprData_getArgs (data)));
8577 cstring id = exprData_getId (data);
8578 uentry ue = usymtab_lookupSafe (id);
8580 ret = exprNode_fromIdentifierAux (ue);
8581 ret->loc = fileloc_update (ret->loc, e->loc);
8588 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
8589 exprNode_effect (exprData_getPairB (data)));
8592 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
8593 exprNode_effect (exprData_getOpB (data)),
8594 exprData_getOpTok (data));
8598 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
8599 exprData_getUopTok (data));
8602 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
8603 exprData_getUopTok (data));
8615 ret = exprNode_vaArg (exprData_getCastTok (data),
8616 exprNode_effect (exprData_getCastNode (data)),
8617 exprData_getCastType (data));
8621 ret = exprNode_cast (exprData_getCastTok (data),
8622 exprNode_effect (exprData_getCastNode (data)),
8623 exprData_getCastType (data));
8626 ret = exprNode_iterStart (exprData_getIterCallIter (data),
8628 (exprData_getIterCallArgs (data)));
8632 ret = exprNode_iter (exprData_getIterSname (data),
8633 exprNodeList_effect (exprData_getIterAlist (data)),
8634 exprNode_effect (exprData_getIterBody (data)),
8635 exprData_getIterEname (data));
8639 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
8640 exprNode_effect (exprData_getPairB (data)));
8644 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
8645 exprNode_effect (exprData_getTripleTest (data)),
8646 exprNode_effect (exprData_getTripleInc (data)));
8650 ret = exprNode_createTok (exprData_getTok (data));
8654 ret = exprNode_goto (exprData_getLiteral (data));
8655 ret->loc = fileloc_update (ret->loc, e->loc);
8659 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
8663 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
8667 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
8670 case XPR_NULLRETURN:
8671 ret = exprNode_nullReturn (exprData_getTok (data));
8675 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
8676 exprNode_effect (exprData_getPairB (data)));
8680 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
8681 exprNode_effect (exprData_getTripleTrue (data)),
8682 exprNode_effect (exprData_getTripleFalse (data)));
8685 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
8686 exprNode_effect (exprData_getPairB (data)));
8690 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
8691 exprNode_effect (exprData_getTripleTrue (data)),
8692 exprNode_effect (exprData_getTripleFalse (data)));
8695 ret = exprNode_whilePred (exprData_getSingle (data));
8699 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
8700 exprNode_effect (exprData_getPairB (data)));
8704 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
8705 exprNode_effect (exprData_getPairB (data)));
8709 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
8713 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
8714 exprData_getUopTok (data));
8718 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
8719 exprNode_effect (exprData_getPairB (data)));
8724 ret = exprNode_caseMarker
8725 (exprNode_effect (exprData_getSingle (data)),
8731 ret = exprNode_createTok (exprData_getTok (data));
8735 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
8736 exprNode_effect (exprData_getPairB (data)));
8740 ret = exprNode_makeInitialization
8741 (exprData_getInitId (data),
8742 exprNode_effect (exprData_getInitNode (data)));
8746 ret = exprNode_fieldAccessAux
8747 (exprNode_effect (exprData_getFieldNode (data)),
8748 exprNode_loc (exprData_getFieldNode (data)),
8749 cstring_copy (exprData_getFieldName (data)));
8753 ret = exprNode_arrowAccessAux
8754 (exprNode_effect (exprData_getFieldNode (data)),
8755 exprNode_loc (exprData_getFieldNode (data)),
8756 cstring_copy (exprData_getFieldName (data)));
8759 case XPR_STRINGLITERAL:
8773 /*@=observertrans@*/
8775 /*@=dependenttrans@*/
8786 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8791 if (exprNode_isError (e))
8793 return cstring_undefined;
8801 ret = exprNode_rootVarName (exprData_getUopNode (data));
8804 ret = exprNode_rootVarName (exprData_getOpA (data));
8808 ret = exprData_getId (data);
8811 ret = idDecl_getName (exprData_getInitId (data));
8836 case XPR_NULLRETURN:
8858 case XPR_STRINGLITERAL:
8859 ret = cstring_undefined;
8866 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8871 if (exprNode_isError (e))
8873 static /*@only@*/ cstring error = cstring_undefined;
8875 if (!cstring_isDefined (error))
8877 error = cstring_makeLiteral ("<error>");
8888 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8891 ret = message ("%s %s %s",
8892 exprNode_unparse (exprData_getOpA (data)),
8893 lltok_unparse (exprData_getOpTok (data)),
8894 exprNode_unparse (exprData_getOpB (data)));
8897 ret = message ("%s(%q)",
8898 exprNode_unparse (exprData_getFcn (data)),
8899 exprNodeList_unparse (exprData_getArgs (data)));
8902 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8905 ret = cstring_undefined;
8908 ret = message ("%s:", exprData_getId (data));
8912 ret = cstring_copy (exprData_getId (data));
8915 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8916 exprNode_unparse (exprData_getPairB (data)));
8919 ret = message ("<body>");
8922 ret = message ("%s %s %s",
8923 exprNode_unparse (exprData_getOpA (data)),
8924 lltok_unparse (exprData_getOpTok (data)),
8925 exprNode_unparse (exprData_getOpB (data)));
8929 ret = message ("%s%s",
8930 lltok_unparse (exprData_getUopTok (data)),
8931 exprNode_unparse (exprData_getUopNode (data)));
8935 ret = message ("%s%s",
8936 exprNode_unparse (exprData_getUopNode (data)),
8937 lltok_unparse (exprData_getUopTok (data)));
8941 ret = message ("offsetof(%s,%q)",
8942 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8943 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8947 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8951 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8955 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8959 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8963 ret = message ("va_arg(%s, %q)",
8964 exprNode_unparse (exprData_getCastNode (data)),
8965 qtype_unparse (exprData_getCastType (data)));
8969 ret = message ("%q(%q)",
8970 uentry_getName (exprData_getIterCallIter (data)),
8971 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8974 ret = message ("%q(%q) %s %q",
8975 uentry_getName (exprData_getIterSname (data)),
8976 exprNodeList_unparse (exprData_getIterAlist (data)),
8977 exprNode_unparse (exprData_getIterBody (data)),
8978 uentry_getName (exprData_getIterEname (data)));
8981 ret = message ("(%q)%s",
8982 qtype_unparse (exprData_getCastType (data)),
8983 exprNode_unparse (exprData_getCastNode (data)));
8987 ret = message ("%s %s",
8988 exprNode_unparse (exprData_getPairA (data)),
8989 exprNode_unparse (exprData_getPairB (data)));
8993 ret = message ("for (%s; %s; %s)",
8994 exprNode_unparse (exprData_getTripleInit (data)),
8995 exprNode_unparse (exprData_getTripleTest (data)),
8996 exprNode_unparse (exprData_getTripleInc (data)));
9000 ret = message ("goto %s", exprData_getLiteral (data));
9004 ret = cstring_makeLiteral ("continue");
9008 ret = cstring_makeLiteral ("break");
9012 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
9015 case XPR_NULLRETURN:
9016 ret = cstring_makeLiteral ("return");
9020 ret = message ("%s, %s",
9021 exprNode_unparse (exprData_getPairA (data)),
9022 exprNode_unparse (exprData_getPairB (data)));
9026 ret = message ("%s ? %s : %s",
9027 exprNode_unparse (exprData_getTriplePred (data)),
9028 exprNode_unparse (exprData_getTripleTrue (data)),
9029 exprNode_unparse (exprData_getTripleFalse (data)));
9032 ret = message ("if (%s) %s",
9033 exprNode_unparse (exprData_getPairA (data)),
9034 exprNode_unparse (exprData_getPairB (data)));
9038 ret = message ("if (%s) %s else %s",
9039 exprNode_unparse (exprData_getTriplePred (data)),
9040 exprNode_unparse (exprData_getTripleTrue (data)),
9041 exprNode_unparse (exprData_getTripleFalse (data)));
9044 ret = message ("while (%s) %s",
9045 exprNode_unparse (exprData_getPairA (data)),
9046 exprNode_unparse (exprData_getPairB (data)));
9050 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
9054 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
9058 ret = message ("do { %s } while (%s)",
9059 exprNode_unparse (exprData_getPairB (data)),
9060 exprNode_unparse (exprData_getPairA (data)));
9064 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
9068 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
9072 ret = message ("%s; %s",
9073 exprNode_unparse (exprData_getPairA (data)),
9074 exprNode_unparse (exprData_getPairB (data)));
9079 ret = cstring_makeLiteral ("default:");
9083 ret = message ("switch (%s) %s",
9084 exprNode_unparse (exprData_getPairA (data)),
9085 exprNode_unparse (exprData_getPairB (data)));
9090 ret = message ("case %s:",
9091 exprNode_unparse (exprData_getSingle (data)));
9095 if (exprNode_isError (exprData_getInitNode (data)))
9097 ret = message ("%q", idDecl_unparseC (exprData_getInitId (data)));
9101 ret = message ("%q = %s",
9102 idDecl_unparseC (exprData_getInitId (data)),
9103 exprNode_unparse (exprData_getInitNode (data)));
9108 ret = message ("%s.%s",
9109 exprNode_unparse (exprData_getFieldNode (data)),
9110 exprData_getFieldName (data));
9114 ret = message ("%s->%s",
9115 exprNode_unparse (exprData_getFieldNode (data)),
9116 exprData_getFieldName (data));
9119 case XPR_STRINGLITERAL:
9120 ret = message ("\"%s\"", exprData_getLiteral (data));
9124 ret = cstring_copy (exprData_getLiteral (data));
9128 ret = cstring_makeLiteral ("<node>");
9136 exprNode_isInitializer (exprNode e)
9138 return (exprNode_isDefined (e)
9139 && e->kind == XPR_INIT);
9143 exprNode_isCharLit (exprNode e)
9145 if (exprNode_isDefined (e))
9147 return (multiVal_isChar (exprNode_getValue (e)));
9156 exprNode_isNumLit (exprNode e)
9158 if (exprNode_isDefined (e))
9160 return (multiVal_isInt (exprNode_getValue (e)));
9169 exprNode_isFalseConstant (exprNode e)
9171 if (exprNode_isDefined (e))
9173 cstring s = exprNode_rootVarName (e);
9175 if (cstring_equal (s, context_getFalseName ()))
9185 exprNode_matchLiteral (ctype expected, exprNode e)
9187 if (exprNode_isDefined (e))
9189 multiVal m = exprNode_getValue (e);
9191 if (multiVal_isDefined (m))
9193 if (multiVal_isInt (m))
9195 long int val = multiVal_forceInt (m);
9197 if (ctype_isDirectBool (ctype_realishType (expected)))
9201 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
9209 if (ctype_isRealInt (expected))
9212 ** unsigned <- [ constant >= 0 is okay ]
9215 if (ctype_isUnsigned (expected))
9224 ** No checks on sizes of integers...maybe add
9228 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
9229 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
9230 bool_unparse (ctype_isInt (exprNode_getType (e)))));
9232 if (context_getFlag (FLG_NUMLITERAL)
9233 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
9239 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
9243 else if (ctype_isChar (expected))
9247 else if (ctype_isArrayPtr (expected))
9251 else if (ctype_isAnyFloat (expected))
9253 return (context_getFlag (FLG_NUMLITERAL));
9260 else if (multiVal_isDouble (m))
9262 if (ctype_isAnyFloat (expected))
9267 else if (multiVal_isChar (m))
9269 char val = multiVal_forceChar (m);
9271 if (ctype_isChar (expected))
9273 if (ctype_isUnsigned (expected) && ((int)val) < 0)
9294 exprNode_matchType (ctype expected, exprNode e)
9298 if (!exprNode_isDefined (e)) return TRUE;
9300 actual = ctype_realishType (exprNode_getType (e));
9302 if (ctype_match (ctype_realishType (expected), actual))
9307 llassert (!exprNode_isError (e));
9308 return (exprNode_matchLiteral (expected, e));
9312 exprNode_matchTypes (exprNode e1, exprNode e2)
9317 if (!exprNode_isDefined (e1)) return TRUE;
9318 if (!exprNode_isDefined (e2)) return TRUE;
9321 ** realish type --- keep bools, bools
9324 t1 = ctype_realishType (exprNode_getType (e1));
9325 t2 = ctype_realishType (exprNode_getType (e2));
9327 if (ctype_match (t1, t2))
9332 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
9340 exprNode_matchArgType (ctype ct, exprNode e)
9344 if (!exprNode_isDefined (e))
9349 et = ctype_realType (exprNode_getType (e));
9351 if (ctype_matchArg (ct, et)) return TRUE;
9353 llassert (!exprNode_isError (e));
9354 return (exprNode_matchLiteral (ct, e));
9357 static /*@only@*/ exprNodeSList
9358 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
9360 if (exprNode_isDefined (e))
9362 if (e->kind == XPR_STMTLIST)
9364 return (exprNodeSList_append
9365 (exprNode_flatten (exprData_getPairA (e->edata)),
9366 exprNode_flatten (exprData_getPairB (e->edata))));
9368 else if (e->kind == XPR_BLOCK)
9370 return (exprNode_flatten (exprData_getSingle (e->edata)));
9374 return (exprNodeSList_singleton (e));
9378 return exprNodeSList_new ();
9381 static /*@exposed@*/ exprNode
9382 exprNode_lastStatement (/*@returned@*/ exprNode e)
9384 if (exprNode_isDefined (e))
9386 if (e->kind == XPR_STMTLIST)
9388 exprNode b = exprData_getPairB (e->edata);
9390 if (exprNode_isDefined (b))
9392 return exprNode_lastStatement (b);
9396 return exprNode_lastStatement (exprData_getPairA (e->edata));
9399 else if (e->kind == XPR_BLOCK)
9401 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
9409 return exprNode_undefined;
9412 static /*@exposed@*/ exprNode
9413 exprNode_firstStatement (/*@returned@*/ exprNode e)
9415 if (exprNode_isDefined (e))
9417 if (e->kind == XPR_STMTLIST)
9419 exprNode b = exprData_getPairA (e->edata);
9421 if (exprNode_isDefined (b))
9423 return exprNode_firstStatement (b);
9427 return exprNode_firstStatement (exprData_getPairB (e->edata));
9430 else if (e->kind == XPR_BLOCK)
9432 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
9440 return exprNode_undefined;
9444 exprNode_mergeUSs (exprNode res, exprNode other)
9446 if (exprNode_isDefined (res) && exprNode_isDefined (other))
9448 res->msets = sRefSet_union (res->msets, other->msets);
9449 res->sets = sRefSet_union (res->sets, other->sets);
9450 res->uses = sRefSet_union (res->uses, other->uses);
9455 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
9457 if (exprNode_isDefined (res))
9459 if (exprNode_isDefined (other1))
9461 res->sets = sRefSet_union (res->sets, other1->sets);
9462 res->msets = sRefSet_union (res->msets, other1->msets);
9463 res->uses = sRefSet_union (res->uses, other1->uses);
9465 if (exprNode_isDefined (other2))
9467 res->sets = sRefSet_union (res->sets, other2->sets);
9468 res->msets = sRefSet_union (res->msets, other2->msets);
9469 res->uses = sRefSet_union (res->uses, other2->uses);
9477 ** Reports errors is s is not defined.
9481 exprNode_addUse (exprNode e, /*@exposed@*/ sRef s)
9483 if (exprNode_isDefined (e))
9485 e->uses = sRefSet_insert (e->uses, s);
9490 exprNode_checkUse (exprNode e, /*@exposed@*/ sRef s, fileloc loc)
9492 if (sRef_isKnown (s) && !sRef_isConst (s))
9495 ** need to check all outer types are useable
9498 DPRINTF (("Check use: %s / %s",
9499 exprNode_unparse (e), sRef_unparse (s)));
9501 exprNode_addUse (e, s);
9503 if (!context_inProtectVars ())
9506 ** only report the deepest error
9509 sRef errorRef = sRef_undefined;
9510 sRef lastRef = sRef_undefined;
9511 bool deadRef = FALSE;
9512 bool unuseable = FALSE;
9513 bool errorMaybe = FALSE;
9515 while (sRef_isValid (s) && sRef_isKnown (s))
9517 ynm readable = sRef_isReadable (s);
9519 DPRINTF (("Readable: %s / %s",
9520 sRef_unparseFull (s), ynm_unparse (readable)));
9522 if (!(ynm_toBoolStrict (readable)))
9524 if (ynm_isMaybe (readable))
9528 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
9529 deadRef = sRef_isPossiblyDead (errorRef);
9530 unuseable = sRef_isUnuseable (errorRef);
9537 deadRef = sRef_isDead (errorRef);
9538 unuseable = sRef_isUnuseable (errorRef);
9542 if (!sRef_isPartial (s))
9544 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
9545 sRef_setDefined (s, fileloc_undefined);
9549 s = sRef_getBaseSafe (s);
9552 if (sRef_isValid (errorRef))
9554 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
9555 && sRef_isPointer (errorRef))
9562 if (sRef_isThroughArrayFetch (errorRef))
9565 (FLG_STRICTUSERELEASED,
9566 message ("%q %q may be used after being released",
9567 sRef_unparseKindNamePlain (errorRef),
9568 sRef_unparse (errorRef)),
9571 sRef_showRefKilled (errorRef);
9573 if (sRef_isKept (errorRef))
9575 sRef_clearAliasState (errorRef, loc);
9581 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
9585 message ("%q %q %qused after being released",
9586 sRef_unparseKindNamePlain (errorRef),
9587 sRef_unparse (errorRef),
9588 cstring_makeLiteral (errorMaybe
9592 sRef_showRefKilled (errorRef);
9594 if (sRef_isKept (errorRef))
9596 sRef_clearAliasState (errorRef, loc);
9605 message ("%q %q%qused in inconsistent state",
9606 sRef_unparseKindName (errorRef),
9607 sRef_unparseOpt (errorRef),
9608 cstring_makeLiteral (errorMaybe ? "may be " : "")),
9611 sRef_showStateInconsistent (errorRef);
9616 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
9620 message ("%q %q%qused before definition",
9621 sRef_unparseKindName (errorRef),
9622 sRef_unparseOpt (errorRef),
9623 cstring_makeLiteral (errorMaybe ? "may be " : "")),
9626 DPRINTF (("Error: %s", sRef_unparseFull (errorRef)));
9629 sRef_setDefined (errorRef, loc);
9631 if (sRef_isAddress (errorRef))
9633 sRef_setDefined (sRef_getRootBase (errorRef), loc);
9635 } /* end is error */
9643 checkSafeUse (exprNode e, /*@exposed@*/ sRef s)
9645 if (exprNode_isDefined (e) && sRef_isKnown (s))
9647 e->uses = sRefSet_insert (e->uses, s);
9652 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
9654 if (exprNode_isDefined (e))
9656 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
9661 exprNode_checkSet (exprNode e, /*@exposed@*/ sRef s)
9663 sRef defines = sRef_undefined;
9665 if (sRef_isValid (s) && !sRef_isNothing (s))
9667 uentry ue = sRef_getBaseUentry (s);
9669 if (uentry_isValid (ue))
9671 uentry_setLset (ue);
9674 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9676 voptgenerror (FLG_USEDEF,
9677 message ("Attempt to set unuseable storage: %q",
9682 if (sRef_isMeaningful (s))
9684 if (sRef_isDead (s))
9686 sRef base = sRef_getBaseSafe (s);
9688 if (sRef_isValid (base)
9689 && sRef_isDead (base))
9691 sRef_setPartial (s, exprNode_loc (e));
9694 defines = s; /* okay - modifies for only param */
9696 else if (sRef_isPartial (s))
9698 sRef eref = exprNode_getSref (e);
9700 if (!sRef_isPartial (eref))
9703 ** should do something different here???
9706 sRef_setDefinedComplete (eref, exprNode_loc (e));
9710 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
9713 if (sRef_isMeaningful (eref))
9722 else if (sRef_isAllocated (s))
9724 sRef eref = exprNode_getSref (e);
9727 if (!sRef_isAllocated (eref))
9729 sRef_setDefinedComplete (eref, exprNode_loc (e));
9733 sRef base = sRef_getBaseSafe (eref);
9735 if (sRef_isValid (base))
9737 sRef_setPdefined (base, exprNode_loc (e));
9745 sRef_setDefinedNCComplete (s, exprNode_loc (e));
9750 else /* not meaningful...but still need to insert it */
9756 if (exprNode_isDefined (e) && sRef_isValid (defines))
9758 e->sets = sRefSet_insert (e->sets, defines);
9763 exprNode_checkMSet (exprNode e, /*@exposed@*/ sRef s)
9765 if (sRef_isValid (s) && !sRef_isNothing (s))
9767 uentry ue = sRef_getBaseUentry (s);
9769 if (uentry_isValid (ue))
9771 uentry_setLset (ue);
9774 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9776 voptgenerror (FLG_USEDEF,
9777 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9781 if (sRef_isMeaningful (s))
9783 sRef_setDefinedComplete (s, exprNode_loc (e));
9786 if (exprNode_isDefined (e))
9788 e->msets = sRefSet_insert (e->msets, s);
9794 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9796 checkAnyCall (fcn, cstring_undefined, params, args,
9797 FALSE, sRefSet_undefined, FALSE, 0);
9801 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9802 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9806 if (uentry_isYield (ucurrent))
9808 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9809 exprNode_checkSet (current, current->sref);
9813 if (uentry_isSefParam (ucurrent))
9815 sRefSet sets = current->sets;
9816 sRef ref = exprNode_getSref (current);
9818 if (sRef_isMacroParamRef (ref))
9820 uentry ue = sRef_getUentry (ref);
9822 if (!uentry_isSefParam (ue))
9827 ("Parameter %d to %s is declared sef, but "
9828 "the argument is a macro parameter declared "
9830 argno, exprNode_unparse (fcn),
9831 exprNode_unparse (current)),
9832 exprNode_loc (current));
9836 if (!sRefSet_isEmpty (sets))
9838 sRefSet reported = sRefSet_undefined;
9840 sRefSet_realElements (current->sets, el)
9842 if (sRefSet_isSameNameMember (reported, el))
9844 ; /* don't report again */
9848 if (sRef_isUnconstrained (el))
9853 ("Parameter %d to %s is declared sef, but "
9854 "the argument calls unconstrained function %s "
9855 "(no guarantee it will not modify something): %s",
9856 argno, exprNode_unparse (fcn),
9857 sRef_unconstrainedName (el),
9858 exprNode_unparse (current)),
9859 exprNode_loc (current));
9866 ("Parameter %d to %s is declared sef, but "
9867 "the argument may modify %q: %s",
9868 argno, exprNode_unparse (fcn),
9870 exprNode_unparse (current)),
9871 exprNode_loc (current));
9874 } end_sRefSet_realElements;
9878 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9879 exprNode_mergeUSs (fcn, current);
9884 checkAnyCall (/*@dependent@*/ exprNode fcn,
9885 /*@dependent@*/ cstring fname,
9888 bool hasMods, sRefSet mods,
9893 int nargs = exprNodeList_size (args);
9898 ** concat all args ud's to f, add each arg sref as a use unless
9899 ** it was specified as "out", in which case it is a def.
9902 uentryList_reset (pn);
9907 ** if paramn is only or unique, no other arg may alias argn
9910 exprNodeList_elements (args, current)
9914 if (exprNode_isDefined (current))
9916 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9918 uentry ucurrent = uentryList_current (pn);
9920 if (specialArgs == 0
9921 || (paramno < specialArgs))
9923 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9925 if (context_maybeSet (FLG_ALIASUNIQUE))
9927 if (uentry_isOnly (ucurrent)
9928 || uentry_isUnique (ucurrent))
9930 checkUniqueParams (fcn, current, args,
9936 else /* uentry is undefined */
9938 if (specialArgs == 0)
9940 exprNode_checkUseParam (current);
9943 exprNode_mergeUSs (fcn, current);
9946 uentryList_advanceSafe (pn);
9947 } end_exprNodeList_elements;
9953 sRefSet_allElements (mods, s)
9956 sRef rb = sRef_getRootBase (s);
9958 if (sRef_isFileOrGlobalScope (rb))
9960 context_usedGlobal (rb);
9963 fb = sRef_fixBaseParam (s, args);
9965 if (!sRef_isMacroParamRef (fb))
9967 if (sRef_isNothing (fb))
9973 if (sRef_isValid (fb))
9975 uentry ue = sRef_getBaseUentry (s);
9977 if (uentry_isValid (ue))
9979 uentry_setLset (ue);
9983 fcn->sets = sRefSet_insert (fcn->sets, fb);
9986 sRef_clearDerivedComplete (s);
9987 } end_sRefSet_allElements;
9993 if (context_hasMods ())
9995 if (context_maybeSet (FLG_MODUNCON))
9999 message ("Undetected modification possible "
10000 "from call to unconstrained function %s: %s",
10002 exprNode_unparse (fcn)),
10003 exprNode_loc (fcn));
10008 if (context_maybeSet (FLG_MODUNCONNOMODS)
10009 && !(context_inIterDef () || context_inIterEnd ()))
10012 (FLG_MODUNCONNOMODS,
10013 message ("Undetected modification possible "
10014 "from call to unconstrained function %s: %s",
10016 exprNode_unparse (fcn)),
10017 exprNode_loc (fcn));
10021 exprNode_checkSetAny (fcn, fname);
10025 void exprNode_checkUseParam (exprNode current)
10027 if (exprNode_isDefined (current))
10029 exprNode_checkUse (current, current->sref, current->loc);
10034 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
10035 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10040 if (!ctype_match (tr1, tr2))
10042 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
10043 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
10049 (void) gentypeerror
10051 message ("Incompatible types for %s (%s, %s): %s %s %s",
10052 lltok_unparse (op),
10053 ctype_unparse (te1),
10054 ctype_unparse (te2),
10055 exprNode_unparse (e1), lltok_unparse (op),
10056 exprNode_unparse (e2)),
10059 ret = ctype_unknown;
10063 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
10065 ret = ctype_resolveNumerics (tr1, tr2);
10067 else if (!context_msgStrictOps ())
10069 if (ctype_isPointer (tr1))
10071 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
10075 else if (ctype_isInt (tr2))
10081 ret = ctype_unknown;
10084 else if (ctype_isPointer (tr2))
10086 if (ctype_isPointer (tr1))
10090 else if (ctype_isInt (tr1))
10096 ret = ctype_unknown;
10101 ret = ctype_resolveNumerics (tr1, tr2);
10106 int opid = lltok_getTok (op);
10107 bool comparop = (opid == EQ_OP || opid == NE_OP
10108 || opid == TLT || opid == TGT
10109 || opid == LE_OP || opid == GE_OP);
10111 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
10114 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
10115 || (ctype_isBool (tr1) && ctype_isBool (tr2))
10116 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
10122 if (ctype_sameName (te1, te2))
10126 message ("Operands of %s are non-numeric (%t): %s %s %s",
10127 lltok_unparse (op), te1,
10128 exprNode_unparse (e1), lltok_unparse (op),
10129 exprNode_unparse (e2)),
10136 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
10137 lltok_unparse (op), te1, te2,
10138 exprNode_unparse (e1), lltok_unparse (op),
10139 exprNode_unparse (e2)),
10144 else if (!ctype_isNumeric (tr1))
10148 message ("Right operand of %s is non-numeric (%t): %s %s %s",
10149 lltok_unparse (op), te1,
10150 exprNode_unparse (e1), lltok_unparse (op),
10151 exprNode_unparse (e2)),
10156 if (!ctype_isNumeric (tr2))
10160 message ("Left operand of %s is non-numeric (%t): %s %s %s",
10161 lltok_unparse (op), te2,
10162 exprNode_unparse (e1), lltok_unparse (op),
10163 exprNode_unparse (e2)),
10168 ret = ctype_unknown;
10176 abstractOpError (ctype tr1, ctype tr2, lltok op,
10177 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10178 fileloc loc1, fileloc loc2)
10180 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
10182 if (ctype_match (tr1, tr2))
10186 message ("Operands of %s are abstract type (%t): %s %s %s",
10187 lltok_unparse (op), tr1,
10188 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10195 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
10196 lltok_unparse (op), tr1, tr2,
10197 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10201 else if (ctype_isRealAbstract (tr1))
10205 message ("Left operand of %s is abstract type (%t): %s %s %s",
10206 lltok_unparse (op), tr1,
10207 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10212 if (ctype_isRealAbstract (tr2))
10216 message ("Right operand of %s is abstract type (%t): %s %s %s",
10217 lltok_unparse (op), tr2,
10218 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10227 ** requies e1 and e2 and not error exprNode's.
10231 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
10232 ** the rep of the abstract type is exposed.
10234 ** The order is very important:
10236 ** check rep expose (move into check transfer)
10242 ** This isn't really a sensible procedure, but the indententation
10243 ** was getting too deep.
10247 checkOneRepExpose (sRef ysr, sRef base,
10248 /*@notnull@*/ exprNode e1,
10249 /*@notnull@*/ exprNode e2, ctype ct,
10252 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
10253 || sRef_isOwned (ysr)
10254 || sRef_isExposed (ysr)))
10256 if (sRef_isAnyParam (base) && !sRef_isExposed (base)
10257 && !sRef_isObserver (base)) /* evans 2001-07-11: added isObserver */
10260 if (sRef_isIReference (ysr))
10262 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10267 ("Assignment of mutable component of parameter %q "
10268 "to component of abstract "
10269 "type %s exposes rep: %s = %s",
10270 sRef_unparse (base),
10271 ctype_unparse (ct),
10272 exprNode_unparse (e1), exprNode_unparse (e2)),
10280 ("Assignment of mutable component of parameter %q "
10281 "(through alias %q) to component of abstract "
10282 "type %s exposes rep: %s = %s",
10283 sRef_unparse (base),
10284 sRef_unparse (e2->sref),
10285 ctype_unparse (ct),
10286 exprNode_unparse (e1), exprNode_unparse (e2)),
10292 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10296 message ("Assignment of mutable parameter %q "
10297 "to component of abstract type %s "
10298 "exposes rep: %s = %s",
10299 sRef_unparse (base),
10300 ctype_unparse (ct),
10301 exprNode_unparse (e1),
10302 exprNode_unparse (e2)),
10309 message ("Assignment of mutable parameter %q "
10310 "(through alias %q) to "
10311 "component of abstract type %s exposes "
10313 sRef_unparse (base),
10314 sRef_unparse (e2->sref),
10315 ctype_unparse (ct),
10316 exprNode_unparse (e1),
10317 exprNode_unparse (e2)),
10323 if (sRef_isFileOrGlobalScope (s2b))
10325 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10329 message ("Assignment of global %q "
10331 "abstract type %s exposes rep: %s = %s",
10332 sRef_unparse (base),
10333 ctype_unparse (ct),
10334 exprNode_unparse (e1), exprNode_unparse (e2)),
10341 message ("Assignment of global %q (through alias %q) "
10343 "abstract type %s exposes rep: %s = %s",
10344 sRef_unparse (base),
10345 sRef_unparse (e2->sref),
10346 ctype_unparse (ct),
10347 exprNode_unparse (e1), exprNode_unparse (e2)),
10355 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
10357 if (ctype_isRealFunction (exprNode_getType (e1))
10358 && !ctype_isRealPointer (exprNode_getType (e1)))
10362 message ("Invalid left-hand side of assignment (function type %s): %s",
10363 ctype_unparse (exprNode_getType (e1)),
10364 exprNode_unparse (e1)),
10368 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
10370 ctype t2 = exprNode_getType (e2);
10371 sRef sr = sRef_getRootBase (e1->sref);
10372 ctype ct = sRef_getType (sr);
10374 if (ctype_isAbstract (t2)
10375 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
10377 /* it is immutable, okay to reference */
10378 goto donerepexpose;
10381 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
10383 sRef s2b = sRef_getRootBase (e2->sref);
10384 sRef s1 = e1->sref;
10385 sRef s1b = sRef_getRootBase (s1);
10388 aliases = usymtab_canAlias (e2->sref);
10390 if (!sRef_similar (s2b, s1b)
10391 && !sRef_isExposed (s1)
10392 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
10394 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
10395 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
10396 && !sRef_isExposed (s2b))
10398 if (sRef_isIReference (e2->sref))
10403 ("Assignment of mutable component of parameter %q "
10404 "to component of abstract type %s exposes rep: %s = %s",
10405 sRef_unparse (s2b),
10406 ctype_unparse (ct),
10407 exprNode_unparse (e1), exprNode_unparse (e2)),
10414 message ("Assignment of mutable parameter %q to "
10415 "component of abstract type %s exposes rep: %s = %s",
10416 sRef_unparse (s2b),
10417 ctype_unparse (ct),
10418 exprNode_unparse (e1), exprNode_unparse (e2)),
10423 if (sRef_isFileOrGlobalScope (s2b))
10427 message ("Assignment of global %q to component of "
10428 "abstract type %s exposes rep: %s = %s",
10429 sRef_unparse (s2b),
10430 ctype_unparse (ct),
10431 exprNode_unparse (e1), exprNode_unparse (e2)),
10435 sRefSet_realElements (aliases, ysr)
10437 sRef base = sRef_getRootBase (ysr);
10439 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
10440 || sRef_sameName (base, s1b))
10442 ; /* error already reported or same sref */
10446 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
10448 } end_sRefSet_realElements;
10450 sRefSet_free (aliases);
10457 ** function variables don't really work...
10460 if (!ctype_isFunction (ctype_realType (e2->typ)))
10464 DPRINTF (("Check init: %s / %s",
10465 exprNode_unparse (e1), exprNode_unparse (e2)));
10466 checkInitTransfer (e1, e2);
10470 checkAssignTransfer (e1, e2);
10475 sRef fref = e2->sref;
10477 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
10478 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
10480 /* Need to typecheck the annotation on the parameters */
10482 if (ctype_isRealFunction (e1->typ)) {
10483 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
10484 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
10486 if (!uentryList_isMissingParams (e1p)
10487 && !uentryList_isMissingParams (e2p)
10488 && uentryList_size (e1p) > 0) {
10489 if (uentryList_size (e1p) == uentryList_size (e2p)) {
10492 uentryList_elements (e1p, el1) {
10495 el2 = uentryList_getN (e2p, n);
10497 uentry_checkMatchParam (el1, el2, n, e2);
10498 } end_uentryList_elements;
10504 if (isInit && sRef_isFileOrGlobalScope (e1->sref))
10510 DPRINTF (("Update aliases: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
10511 updateAliases (e1, e2);
10516 checkMacroParen (exprNode e)
10518 if (exprNode_isError (e) || e->kind == XPR_CAST)
10524 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
10528 message ("Macro parameter used without parentheses: %s",
10529 exprNode_unparse (e)),
10536 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
10540 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
10544 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
10551 ** if e2 is a parameter or global derived location which
10552 ** can be modified (that is, e2 is a mutable abstract type,
10553 ** or a derived pointer), then e1 can alias e2.
10555 ** e1 can alias everything which e2 can alias.
10557 ** Also, if e1 is guarded, remove from guard sets!
10560 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
10562 if (!context_inProtectVars ())
10565 ** depends on types of e1 and e2
10568 sRef s1 = e1->sref;
10569 sRef s2 = e2->sref;
10570 ctype t1 = exprNode_getType (e1);
10572 /* handle pointer sRefs, record fields, arrays, etc... */
10574 if (!ctype_isRealSU (t1))
10576 DPRINTF (("Copying real! %s", ctype_unparse (t1)));
10577 sRef_copyRealDerivedComplete (s1, s2);
10582 ** Fields should alias
10585 DPRINTF (("Not COPYING!: %s", ctype_unparse (t1)));
10588 if (ctype_isMutable (t1) && sRef_isKnown (s1))
10590 usymtab_clearAlias (s1);
10591 usymtab_addMustAlias (s1, s2);
10592 DPRINTF (("Add must alias: %s / %s", sRef_unparse (s1), sRef_unparse (s2)));
10596 DPRINTF (("Not mutable: %s", ctype_unparse (t1)));
10599 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
10601 usymtab_unguard (s1);
10606 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
10608 if (exprNode_isDefined (e))
10610 e->loc = fileloc_update (e->loc, loc);
10614 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
10620 static void checkUniqueParams (exprNode fcn,
10621 /*@notnull@*/ exprNode current,
10623 int paramno, uentry ucurrent)
10626 sRef thisref = exprNode_getSref (current);
10629 ** Check if any argument could match this argument.
10632 exprNodeList_elements (args, icurrent)
10636 if (iparamno != paramno)
10638 sRef sr = exprNode_getSref (icurrent);
10640 if (sRef_similarRelaxed (thisref, sr))
10642 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
10647 ("Parameter %d (%s) to function %s is declared %s but "
10648 "is aliased by parameter %d (%s)",
10650 exprNode_unparse (current),
10651 exprNode_unparse (fcn),
10652 alkind_unparse (uentry_getAliasKind (ucurrent)),
10653 iparamno, exprNode_unparse (icurrent)),
10659 sRefSet aliases = usymtab_canAlias (sr);
10661 sRefSet_allElements (aliases, asr)
10663 if (ctype_isUnknown (sRef_getType (thisref)))
10665 sRef_setType (thisref, uentry_getType (ucurrent));
10668 if (sRef_similarRelaxed (thisref, asr))
10670 if (sRef_isExternal (asr))
10672 if (sRef_isLocalState (thisref))
10678 sRef base = sRef_getRootBase (asr);
10680 if (!sRef_similar (sRef_getBase (asr), thisref))
10682 if (sRef_isUnique (base) || sRef_isOnly (base)
10683 || sRef_isKept (base)
10684 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
10685 || (sRef_isAddress (thisref)
10686 && sRef_isLocalVar (sRef_getRootBase (thisref))))
10688 ; /* okay, no error */
10693 (FLG_MAYALIASUNIQUE,
10695 ("Parameter %d (%s) to function %s is declared %s but "
10696 "may be aliased externally by parameter %d (%s)",
10698 exprNode_unparse (current),
10699 exprNode_unparse (fcn),
10700 alkind_unparse (uentry_getAliasKind (ucurrent)),
10701 iparamno, exprNode_unparse (icurrent)),
10712 ("Parameter %d (%s) to function %s is declared %s but "
10713 "is aliased externally by parameter %d (%s) through "
10716 exprNode_unparse (current),
10717 exprNode_unparse (fcn),
10718 alkind_unparse (uentry_getAliasKind (ucurrent)),
10719 iparamno, exprNode_unparse (icurrent),
10720 sRef_unparse (asr)),
10724 } end_sRefSet_allElements;
10725 sRefSet_free (aliases);
10728 } end_exprNodeList_elements;
10731 long exprNode_getLongValue (exprNode e) {
10734 if (exprNode_hasValue (e)
10735 && multiVal_isInt (exprNode_getValue (e)))
10737 value = multiVal_forceInt (exprNode_getValue (e));
10747 /*@observer@*/ fileloc exprNode_getfileloc (exprNode p_e)
10749 if (exprNode_isDefined (p_e) )
10750 return ( p_e->loc );
10752 return fileloc_undefined;
10755 /*@only@*/ fileloc exprNode_getNextSequencePoint (exprNode e)
10758 ** Returns the location of the sequence point following e.
10760 ** Only works for statements (for now).
10763 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
10764 lltok t = exprData_getUopTok (e->edata);
10765 return fileloc_copy(lltok_getLoc (t));
10767 /* drl possible problem : warning fix
10768 llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
10770 return fileloc_undefined;
10774 exprNode exprNode_createNew(ctype c)
10778 ret = exprNode_createPlain (c);
10783 bool exprNode_isInitBlock (exprNode e)
10785 return (exprNode_isDefined(e) && e->kind == XPR_INITBLOCK);