2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
28 # include <ctype.h> /* for isdigit */
29 # include "lclintMacros.nf"
31 # include "cgrammar.h"
32 # include "cgrammar_tokens.h"
34 # include "exprChecks.h"
35 # include "transferChecks.h"
36 # include "exprNodeSList.h"
38 static bool exprNode_isEmptyStatement (exprNode p_e);
39 static /*@exposed@*/ exprNode exprNode_firstStatement (/*@returned@*/ exprNode p_e);
40 static bool exprNode_isFalseConstant (exprNode p_e) /*@*/ ;
41 static bool exprNode_isBlock (exprNode p_e);
42 static void checkGlobUse (uentry p_glob, bool p_isCall, /*@notnull@*/ exprNode p_e);
43 static void exprNode_addUse (exprNode p_e, /*@exposed@*/ sRef p_s);
44 static bool exprNode_matchArgType (ctype p_ct, exprNode p_e);
45 static exprNode exprNode_fakeCopy (exprNode p_e) /*@*/ ;
46 static exprNode exprNode_statementError (/*@only@*/ exprNode p_e, /*@only@*/ lltok p_t);
47 static bool exprNode_matchTypes (exprNode p_e1, exprNode p_e2);
48 static void checkUniqueParams (exprNode p_fcn,
49 /*@notnull@*/ exprNode p_current, exprNodeList p_args,
50 int p_paramno, uentry p_ucurrent);
51 static void updateAliases (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2);
52 static void abstractOpError (ctype p_tr1, ctype p_tr2, lltok p_op,
53 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2,
54 fileloc p_loc1, fileloc p_loc2);
55 static ctype checkNumerics (ctype p_tr1, ctype p_tr2, ctype p_te1, ctype p_te2,
56 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, lltok p_op);
57 static void doAssign (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, bool p_isInit);
58 static void checkSafeUse (exprNode p_e, /*@exposed@*/ sRef p_s);
59 static void reflectNullTest (/*@notnull@*/ exprNode p_e, bool p_isnull);
60 static void checkMacroParen (exprNode p_e);
61 static exprNodeSList exprNode_flatten (/*@dependent@*/ exprNode p_e);
62 static void exprNode_checkSetAny (exprNode p_e, /*@dependent@*/ cstring p_name);
63 static void exprNode_checkUse (exprNode p_e, /*@exposed@*/ sRef p_s, fileloc p_loc);
64 static void exprNode_mergeUSs (exprNode p_res, exprNode p_other);
65 static void exprNode_mergeCondUSs (exprNode p_res, exprNode p_other1, exprNode p_other2);
66 static /*@only@*/ /*@notnull@*/ exprNode exprNode_fromIdentifierAux (/*@observer@*/ uentry p_c);
67 static void checkAnyCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn,
68 /*@dependent@*/ cstring p_fname,
69 uentryList p_pn, exprNodeList p_args,
70 bool p_hasMods, sRefSet p_mods, bool p_isSpec,
72 static void checkOneArg (uentry p_ucurrent, /*@notnull@*/ exprNode p_current,
73 /*@dependent@*/ exprNode p_fcn, bool p_isSpec, int p_argno, int p_totargs);
75 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn, uentryList p_params, exprNodeList p_args);
77 static /*@only@*/ exprNode exprNode_effect (exprNode p_e)
78 /*@globals internalState@*/ ;
79 static /*@only@*/ cstring exprNode_doUnparse (exprNode p_e);
80 static /*@observer@*/ cstring exprNode_rootVarName (exprNode p_e);
81 static /*@exposed@*/ exprNode
82 exprNode_lastStatement (/*@returned@*/ exprNode p_e);
84 static /*@null@*/ sRef defref = sRef_undefined;
85 static /*@only@*/ exprNode mustExitNode = exprNode_undefined;
87 static int checkArgsReal (uentry p_fcn, /*@dependent@*/ exprNode p_f,
89 exprNodeList p_args, bool p_isIter, exprNode p_ret);
91 static bool inEffect = FALSE;
92 static int nowalloc = 0;
93 static int totalloc = 0;
94 static int maxalloc = 0;
96 static /*@only@*/ uentry regArg;
97 static /*@only@*/ uentry outArg;
98 static /*@only@*/ uentry outStringArg;
99 static /*@exposed@*/ sRef stdinRef;
100 static /*@exposed@*/ sRef stdoutRef;
101 static /*@only@*/ uentry csArg;
102 static /*@only@*/ uentry csOnlyArg;
103 static ctype cstringType;
104 static ctype ctypeType;
105 static ctype filelocType;
106 static bool initMod = FALSE;
108 /*@function void exprNode_swap (sef exprNode, sef exprNode)@*/
110 # define exprNode_swap(e1,e2) do { exprNode m_tmp = (e1); (e1) = (e2); (e2) = m_tmp; } while (FALSE)
113 static void exprNode_defineConstraints(/*@sef@*/ /*@special@*/ /*@notnull@*/ exprNode e)
114 /*@defines e->requiresConstraints, e->ensuresConstraints,
115 e->trueEnsuresConstraints, e->falseEnsuresConstraints @*/
117 e->requiresConstraints = constraintList_makeNew ();
118 e->ensuresConstraints = constraintList_makeNew ();
119 e->trueEnsuresConstraints = constraintList_makeNew ();
120 e->falseEnsuresConstraints = constraintList_makeNew ();
124 ** must occur after library has been read
127 void exprNode_initMod (void)
128 /*@globals undef regArg, undef outArg, undef outStringArg,
129 undef csOnlyArg, undef csArg;
136 cstringType = ctype_unknown;
137 ctypeType = ctype_unknown;
138 filelocType = ctype_unknown;
140 defref = sRef_undefined;
142 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
144 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
147 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
149 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
152 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
154 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
157 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdin")))
159 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdin"));
161 else /* define stdin */
163 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdin"),
165 fileloc_getBuiltin (),
167 uentry_setHasNameError (ue);
168 ue = usymtab_supGlobalEntryReturn (ue);
171 stdinRef = sRef_makePointer (uentry_getSref (ue));
173 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdout")))
175 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdout"));
179 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdout"),
181 fileloc_getBuiltin (),
183 uentry_setHasNameError (ue);
184 ue = usymtab_supGlobalEntryReturn (ue);
187 stdoutRef = sRef_makePointer (uentry_getSref (ue));
189 tmp = idDecl_create (cstring_undefined, qtype_create (ctype_unknown));
191 regArg = uentry_makeParam (tmp, PARAMUNKNOWN);
194 qtype_addQual (qtype_create (ctype_makePointer (ctype_unknown)),
197 outArg = uentry_makeParam (tmp, PARAMUNKNOWN);
199 idDecl_setTyp (tmp, qtype_addQual (qtype_create (ctype_string),
202 outStringArg = uentry_makeParam (tmp, PARAMUNKNOWN);
204 idDecl_setTyp (tmp, qtype_addQual (qtype_addQual (qtype_create (cstringType),
206 qual_createNull ()));
208 csOnlyArg = uentry_makeParam (tmp, PARAMUNKNOWN);
210 idDecl_setTyp (tmp, qtype_addQual (qtype_create (cstringType), qual_createNull ()));
211 csArg = uentry_makeParam (tmp, PARAMUNKNOWN);
217 exprNode_destroyMod (void)
218 /*@globals killed regArg, killed outArg, killed outStringArg,
219 killed mustExitNode, initMod @*/
223 uentry_free (regArg);
224 uentry_free (outArg);
225 uentry_free (outStringArg);
227 exprNode_free (mustExitNode);
234 static void exprNode_resetSref (/*@notnull@*/ exprNode e)
239 exprNode exprNode_fakeCopy (exprNode e)
241 /*@-temptrans@*/ /*@-retalias@*/
243 /*@=temptrans@*/ /*@=retalias@*/
246 static bool isFlagKey (char key)
248 return (key == '-' || key == '+' || key == ' ' || key == '#');
251 static void exprNode_combineControl (/*@notnull@*/ exprNode ret,
252 /*@notnull@*/ exprNode ifclause,
253 /*@notnull@*/ exprNode elseclause)
255 ret->canBreak = ifclause->canBreak || elseclause->canBreak;
258 (ifclause->mustBreak || exprNode_mustEscape (ifclause))
259 && (elseclause->mustBreak || exprNode_mustEscape (elseclause));
261 ret->exitCode = exitkind_combine (ifclause->exitCode,
262 elseclause->exitCode);
267 ** For exprNode's returned by exprNode_effect.
270 static bool shallowKind (exprKind kind)
272 return (kind == XPR_STRINGLITERAL
273 || kind == XPR_NUMLIT
276 || kind == XPR_NODE);
280 exprNode_freeIniter (/*@only@*/ exprNode e)
282 if (!exprNode_isError (e))
288 ** Its a fake copy, don't free the field->rec and field->field
293 sfree (e->edata->field);
299 exprNode_free (e->edata->op->b);
300 /*@-compdestroy@*/ sfree (e->edata->op); /*@=compdestroy@*/
304 llbug (message ("other: %s", exprNode_unparse (e)));
307 multiVal_free (e->val);
308 cstring_free (e->etext);
309 fileloc_free (e->loc);
310 sRefSet_free (e->uses);
311 sRefSet_free (e->sets);
312 sRefSet_free (e->msets);
313 guardSet_free (e->guards);
315 constraintList_free(e->requiresConstraints);
316 constraintList_free(e->ensuresConstraints);
317 constraintList_free(e->trueEnsuresConstraints);
318 constraintList_free(e->falseEnsuresConstraints);
320 e->requiresConstraints = NULL;
321 e->ensuresConstraints = NULL;
322 e->trueEnsuresConstraints = NULL;
323 e->falseEnsuresConstraints = NULL;
330 exprNode_freeShallow (/*@only@*/ exprNode e)
332 if (!exprNode_isError (e))
334 if (shallowKind (e->kind))
341 if (e->kind == XPR_EMPTY
342 || e->kind == XPR_BODY
343 || e->kind == XPR_STRINGLITERAL
344 || e->kind == XPR_NUMLIT
345 || e->kind == XPR_NODE
346 || e->kind == XPR_OFFSETOF
347 || e->kind == XPR_ALIGNOFT
348 || e->kind == XPR_ALIGNOF
349 || e->kind == XPR_SIZEOFT
350 || e->kind == XPR_SIZEOF)
352 /* don't free anything */
356 /* multiVal_free (e->val); */
357 cstring_free (e->etext);
358 fileloc_free (e->loc);
359 sRefSet_free (e->uses);
360 sRefSet_free (e->sets);
361 sRefSet_free (e->msets);
362 guardSet_free (e->guards);
363 exprData_freeShallow (e->edata, e->kind);
365 /*@-compdestroy@*/ sfree (e); /*@=compdestroy@*/
374 exprNode_free (exprNode e)
376 if (!exprNode_isError (e))
380 multiVal_free (e->val);
381 cstring_free (e->etext);
382 fileloc_free (e->loc);
383 sRefSet_free (e->uses);
384 sRefSet_free (e->sets);
385 sRefSet_free (e->msets);
386 guardSet_free (e->guards);
387 exprData_free (e->edata, e->kind);
389 constraintList_free(e->requiresConstraints);
390 constraintList_free(e->ensuresConstraints);
391 constraintList_free(e->trueEnsuresConstraints);
392 constraintList_free(e->falseEnsuresConstraints);
394 e->requiresConstraints = NULL;
395 e->ensuresConstraints = NULL;
396 e->trueEnsuresConstraints = NULL;
397 e->falseEnsuresConstraints = NULL;
407 exprNode_makeError ()
409 return exprNode_undefined;
412 static /*@out@*/ /*@only@*/ /*@notnull@*/ exprNode
415 exprNode ret = (exprNode) dmalloc (sizeof (*ret));
416 /* static int lastexpnodes = 0; */
421 if (nowalloc > maxalloc)
429 static /*@notnull@*/ /*@special@*/ exprNode
430 exprNode_createPlain (ctype c)
432 /*@ensures isnull result->edata, result->loc, result->val, result->guards,
433 result->uses, result->sets, result->msets, result->etext @*/
436 exprNode e = exprNode_new ();
440 e->val = multiVal_undefined;
442 e->etext = cstring_undefined;
443 e->loc = fileloc_undefined;
444 e->guards = guardSet_undefined;
445 e->uses = sRefSet_undefined;
446 e->sets = sRefSet_undefined;
447 e->msets = sRefSet_undefined;
448 e->edata = exprData_undefined;
449 e->exitCode = XK_NEVERESCAPE;
451 e->mustBreak = FALSE;
452 e->isJumpPoint = FALSE;
454 exprNode_defineConstraints(e);
459 /*@observer@*/ exprNode exprNode_makeMustExit (void)
461 if (exprNode_isUndefined (mustExitNode))
463 mustExitNode = exprNode_createPlain (ctype_unknown);
464 mustExitNode->exitCode = XK_MUSTEXIT;
471 static /*@notnull@*/ /*@special@*/ exprNode exprNode_create (ctype c)
473 /*@post:isnull result->edata, result->guards, result->val,
474 result->uses, result->sets, result->msets@*/
477 exprNode e = exprNode_createPlain (c);
478 e->loc = fileloc_copy (g_currentloc);
482 static /*@notnull@*/ /*@special@*/ exprNode exprNode_createUnknown (void)
484 /*@post:isnull result->edata, result->guards,
485 result->uses, result->sets, result->msets@*/
488 return (exprNode_create (ctype_unknown));
491 static /*@notnull@*/ /*@special@*/ exprNode
492 exprNode_createLoc (ctype c, /*@keep@*/ fileloc loc)
494 /*@post:isnull result->edata, result->guards, result->val,
495 result->uses, result->sets, result->msets@*/
498 exprNode e = exprNode_createPlain (c);
504 exprNode_copySets (/*@special@*/ /*@notnull@*/ exprNode ret, exprNode e)
505 /*@defines ret->guards, ret->uses, ret->sets, ret->msets@*/
507 if (exprNode_isDefined (e))
509 ret->guards = guardSet_copy (e->guards);
510 ret->uses = sRefSet_newCopy (e->uses);
511 ret->sets = sRefSet_newCopy (e->sets);
512 ret->msets = sRefSet_newCopy (e->msets);
516 ret->guards = guardSet_undefined;
517 ret->uses = sRefSet_undefined;
518 ret->sets = sRefSet_undefined;
519 ret->msets = sRefSet_undefined;
523 static /*@notnull@*/ /*@special@*/ exprNode
524 exprNode_createPartialLocCopy (exprNode e, /*@only@*/ fileloc loc)
526 /*@post:isnull result->edata, result->etext@*/
529 exprNode ret = exprNode_new ();
531 if (exprNode_isError (e))
533 ret->typ = ctype_unknown;
534 ret->val = multiVal_undefined;
536 ret->guards = guardSet_undefined;
537 ret->uses = sRefSet_undefined;
538 ret->sets = sRefSet_undefined;
539 ret->msets = sRefSet_undefined;
544 ret->val = multiVal_copy (e->val);
546 ret->guards = guardSet_copy (e->guards);
547 ret->uses = sRefSet_newCopy (e->uses);
548 ret->sets = sRefSet_newCopy (e->sets);
549 ret->msets = sRefSet_newCopy (e->msets);
552 ret->kind = XPR_EMPTY;
554 ret->etext = cstring_undefined;
555 ret->exitCode = XK_NEVERESCAPE;
556 ret->canBreak = FALSE;
557 ret->mustBreak = FALSE;
558 ret->isJumpPoint = FALSE;
559 ret->edata = exprData_undefined;
561 exprNode_defineConstraints(ret);
567 static /*@notnull@*/ /*@special@*/ exprNode
568 exprNode_createPartialCopy (exprNode e)
570 /*@post:isnull result->edata, result->etext@*/
573 return (exprNode_createPartialLocCopy (e, fileloc_copy (exprNode_loc (e))));
576 static /*@notnull@*/ /*@special@*/ exprNode
577 exprNode_createPartialNVCopy (exprNode e)
579 /*@post:isnull result->edata, result->etext, result->val @*/
582 exprNode ret = exprNode_new ();
584 if (exprNode_isError (e))
586 ret->typ = ctype_unknown;
587 ret->loc = fileloc_undefined;
588 ret->guards = guardSet_undefined;
589 ret->uses = sRefSet_undefined;
590 ret->sets = sRefSet_undefined;
591 ret->msets = sRefSet_undefined;
596 ret->loc = fileloc_copy (e->loc);
597 ret->guards = guardSet_copy (e->guards);
598 ret->uses = sRefSet_newCopy (e->uses);
599 ret->sets = sRefSet_newCopy (e->sets);
600 ret->msets = sRefSet_newCopy (e->msets);
603 ret->val = multiVal_undefined;
604 ret->kind = XPR_EMPTY;
606 ret->etext = cstring_undefined;
607 ret->exitCode = XK_NEVERESCAPE;
608 ret->canBreak = FALSE;
609 ret->mustBreak = FALSE;
610 ret->isJumpPoint = FALSE;
611 ret->edata = exprData_undefined;
613 exprNode_defineConstraints(ret);
618 static /*@notnull@*/ /*@special@*/ exprNode
619 exprNode_createSemiCopy (exprNode e)
621 /*@post:isnull result->edata, result->etext, result->sets,
622 result->msets, result->uses, result->guards@*/
625 if (exprNode_isError (e))
627 return exprNode_createPlain (ctype_unknown);
631 exprNode ret = exprNode_new ();
634 ret->val = multiVal_copy (e->val);
635 ret->loc = fileloc_copy (e->loc);
636 ret->guards = guardSet_undefined;
637 ret->uses = sRefSet_undefined;
638 ret->sets = sRefSet_undefined;
639 ret->msets = sRefSet_undefined;
641 ret->kind = XPR_EMPTY;
643 ret->etext = cstring_undefined;
644 ret->exitCode = XK_NEVERESCAPE;
645 ret->canBreak = FALSE;
646 ret->mustBreak = FALSE;
647 ret->isJumpPoint = FALSE;
648 ret->edata = exprData_undefined;
650 exprNode_defineConstraints(ret);
657 exprNode_isNullValue (exprNode e)
659 if (exprNode_isDefined (e))
661 multiVal m = exprNode_getValue (e);
663 if (multiVal_isInt (m))
665 return (multiVal_forceInt (m) == 0);
673 exprNode_isUnknownConstant (/*@notnull@*/ exprNode e)
675 while (e->kind == XPR_PARENS)
677 e = exprData_getUopNode (e->edata);
678 llassert (exprNode_isDefined (e));
681 if (e->kind == XPR_CONST)
683 multiVal m = exprNode_getValue (e);
685 if (multiVal_isUnknown (m))
695 exprNode_numLiteral (ctype c, /*@temp@*/ cstring t,
696 /*@only@*/ fileloc loc, long val)
698 exprNode e = exprNode_createLoc (c, loc);
700 e->kind = XPR_NUMLIT;
702 llassert (multiVal_isUndefined (e->val));
703 e->val = multiVal_makeInt (val);
704 e->edata = exprData_makeLiteral (cstring_copy (t));
708 e->sref = sRef_makeUnknown ();
709 sRef_setDefNull (e->sref, e->loc);
712 DPRINTF (("Num lit: %s / %s", exprNode_unparse (e), ctype_unparse (exprNode_getType (e))));
717 exprNode_charLiteral (char c, cstring text, /*@only@*/ fileloc loc)
719 exprNode e = exprNode_createLoc (ctype_char, loc);
721 if (context_getFlag (FLG_CHARINTLITERAL))
723 e->typ = ctype_makeConj (ctype_char, ctype_int);
726 e->kind = XPR_NUMLIT;
727 e->val = multiVal_makeChar (c);
729 e->edata = exprData_makeLiteral (cstring_copy (text));
734 exprNode_floatLiteral (double d, ctype ct, cstring text, /*@only@*/ fileloc loc)
736 exprNode e = exprNode_createLoc (ct, loc);
738 e->kind = XPR_NUMLIT;
739 e->val = multiVal_makeDouble (d);
740 e->edata = exprData_makeLiteral (cstring_copy (text));
744 multiVal exprNode_getValue (exprNode e)
746 while (exprNode_isInParens (e)) {
747 if (e->edata != NULL) {
748 e = exprData_getUopNode (e->edata);
754 if (exprNode_isDefined (e)) {
757 return multiVal_undefined;
762 exprNode_combineLiterals (exprNode e, exprNode rest)
766 /* Both must be string literals. */
768 if (exprNode_isUndefined (rest) || exprNode_isUndefined (e))
770 exprNode_free (rest);
774 if (!exprNode_isStringLiteral (e))
778 message ("Constant concatentation is ungrammatical: %s %s", exprNode_unparse (e),
779 exprNode_unparse (rest)),
781 exprNode_free (rest);
785 if (!exprNode_isStringLiteral (rest))
789 message ("Constant concatentation is ungrammatical: %s %s", exprNode_unparse (e), exprNode_unparse (rest)),
792 exprNode_free (rest);
796 ns = cstring_concat (multiVal_forceString (exprNode_getValue (e)),
797 multiVal_forceString (exprNode_getValue (rest)));
799 multiVal_free (e->val);
800 exprData_free (e->edata, e->kind);
801 e->edata = exprData_makeLiteral (cstring_copy (ns));
802 e->val = multiVal_makeString (ns);
803 exprNode_free (rest);
808 exprNode_rawStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
810 exprNode e = exprNode_createLoc (ctype_string, loc);
811 int len = cstring_length (t);
813 if (context_getFlag (FLG_STRINGLITERALLEN))
815 if (len > context_getValue (FLG_STRINGLITERALLEN))
817 voptgenerror (FLG_STRINGLITERALLEN,
819 ("String literal length (%d) exceeds maximum "
820 "length (%d): \"%s\"",
822 context_getValue (FLG_STRINGLITERALLEN),
828 e->kind = XPR_STRINGLITERAL;
829 e->val = multiVal_makeString (cstring_copy (t));
830 e->edata = exprData_makeLiteral (t);
831 e->sref = sRef_makeConst (ctype_string);
833 if (context_getFlag (FLG_READONLYSTRINGS))
835 sRef_setAliasKind (e->sref, AK_STATIC, fileloc_undefined);
836 sRef_setExKind (e->sref, XO_OBSERVER, loc);
840 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
843 return (e); /* s released */
847 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
849 int len = cstring_length (t) - 2;
850 char *ts = cstring_toCharsSafe (t);
851 char *s = cstring_toCharsSafe (cstring_create (len + 1));
853 llassert (*ts == '\"' && *(ts + len + 1) == '\"');
854 strncpy (s, ts+1, size_fromInt (len));
857 return exprNode_rawStringLiteral (cstring_fromCharsO (s), loc);
860 exprNode exprNode_fromUIO (cstring c)
862 fileloc loc = context_getSaveLocation ();
863 exprNode e = exprNode_createPlain (ctype_unknown);
867 if (fileloc_isUndefined (loc))
869 loc = fileloc_copy (g_currentloc);
872 e->loc = loc; /* save loc was mangled */
875 if (usymtab_exists (c))
877 uentry ue = usymtab_lookupEither (c);
879 if (uentry_isDatatype (ue)
880 && uentry_isSpecified (ue))
883 (message ("%q: Specified datatype %s used in code, but not defined. "
884 "(Cannot continue reasonably from this error.)",
885 fileloc_unparse (e->loc), c));
893 llassertprint (!usymtab_exists (c), ("Entry exists: %s", c));
896 ** was supercedeGlobalEntry...is this better?
899 if (!context_inIterEnd ())
901 if (context_inMacro ())
903 if (context_getFlag (FLG_UNRECOG))
907 message ("Unrecognized identifier in macro definition: %s", c), e->loc);
911 flagcode_recordSuppressed (FLG_UNRECOG);
917 (FLG_UNRECOG, message ("Unrecognized identifier: %s", c), e->loc);
921 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
923 /* No alias errors for unrecognized identifiers */
924 sRef_setAliasKind (e->sref, AK_ERROR, loc);
929 exprNode exprNode_createId (/*@observer@*/ uentry c)
931 if (uentry_isValid (c))
933 exprNode e = exprNode_new ();
935 e->typ = uentry_getType (c);
937 if (uentry_isFunction (c)
938 && !sRef_isLocalVar (uentry_getSref (c)))
940 e->sref = sRef_undefined;
944 e->sref = uentry_getSref (c);
947 if (sRef_isStateUnknown (e->sref) && uentry_isNonLocal (c))
949 sRef_setDefined (e->sref, fileloc_undefined);
953 ** yoikes! leaving this out was a heinous bug...that would have been
954 ** caught if i had lclint working first. gag!
957 e->etext = cstring_undefined;
959 if (uentry_isEitherConstant (c))
962 e->val = multiVal_copy (uentry_getConstantValue (c));
967 e->val = multiVal_unknown ();
970 e->edata = exprData_makeId (c);
971 e->loc = context_getSaveLocation ();
973 if (fileloc_isUndefined (e->loc))
975 fileloc_free (e->loc);
976 e->loc = fileloc_copy (g_currentloc);
979 e->guards = guardSet_new ();
980 e->sets = sRefSet_new ();
981 e->msets = sRefSet_new ();
982 e->uses = sRefSet_new ();
984 /*> missing fields, detected by lclint <*/
985 e->exitCode = XK_NEVERESCAPE;
986 e->isJumpPoint = FALSE;
988 e->mustBreak = FALSE;
990 exprNode_defineConstraints(e);
996 return exprNode_createUnknown ();
1000 /*@notnull@*/ exprNode
1001 exprNode_fromIdentifier (/*@observer@*/ uentry c)
1005 if (context_justPopped ()) /* watch out! c could be dead */
1007 uentry ce = usymtab_lookupSafe (LastIdentifier ());
1009 if (uentry_isValid (ce))
1015 llbuglit ("Looks like Aunt Millie forgot to walk to dog again.");
1019 ret = exprNode_fromIdentifierAux (c);
1024 static /*@only@*/ /*@notnull@*/ exprNode
1025 exprNode_fromIdentifierAux (/*@observer@*/ uentry c)
1027 exprNode e = exprNode_createId (c);
1030 uentry_setUsed (c, e->loc);
1032 if (uentry_isVar (c) && sRef_isFileOrGlobalScope (sr))
1034 checkGlobUse (c, FALSE, e);
1041 exprNode_isZero (exprNode e)
1043 if (exprNode_isDefined (e))
1045 multiVal m = exprNode_getValue (e);
1047 if (multiVal_isInt (m))
1049 return (multiVal_forceInt (m) == 0);
1057 exprNode_isNonNegative (exprNode e)
1059 if (exprNode_isDefined (e))
1061 multiVal m = exprNode_getValue (e);
1063 if (multiVal_isInt (m))
1065 return (multiVal_forceInt (m) >= 0);
1073 ** a[x] - uses a but NOT a[]
1074 ** result sref = a[] (set/use in assignment)
1076 ** The syntax x[a] is also legal in C, and has the same
1077 ** semantics. If ind is an array, and arr is an int, flip
1082 exprNode_arrayFetch (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
1085 ** error in arr, error propagates (no new messages)
1086 ** error in ind, assume valid and continue
1089 if (exprNode_isError (e1))
1092 return (exprNode_makeError ());
1098 ctype carr = exprNode_getType (e1);
1099 ctype crarr = ctype_realType (carr);
1102 ** this sets up funny aliasing, that leads to spurious
1103 ** lclint errors. Hence, the i2 comments.
1106 if (!ctype_isRealArray (crarr)
1107 && ctype_isRealNumeric (crarr)
1108 && !exprNode_isError (e2)
1109 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1114 carr = exprNode_getType (arr);
1115 crarr = ctype_realType (carr);
1123 if (sRef_possiblyNull (arr->sref))
1125 if (!usymtab_isGuarded (arr->sref))
1127 if (optgenerror (FLG_NULLDEREF,
1128 message ("Index of %s pointer %q: %s",
1129 sRef_nullMessage (arr->sref),
1130 sRef_unparse (arr->sref),
1131 exprNode_unparse (arr)),
1134 sRef_showNullInfo (arr->sref);
1136 /* suppress future messages */
1137 sRef_setNullError (arr->sref);
1142 if (exprNode_isError (ind))
1144 if ((ctype_isArrayPtr (crarr)
1145 && !ctype_isFunction (crarr))
1146 || ctype_isUnknown (carr))
1148 exprNode ret = exprNode_createPartialCopy (arr);
1150 if (ctype_isKnown (carr))
1152 ret->typ = ctype_baseArrayPtr (crarr);
1156 ret->typ = ctype_unknown;
1159 ret->sref = sRef_makeArrayFetch (arr->sref);
1161 ret->kind = XPR_FETCH;
1164 ** Because of funny aliasing (when arr and ind are
1165 ** flipped) spurious errors would be reported here.
1168 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1169 checkSafeUse (ret, arr->sref);
1174 voptgenerror (FLG_TYPE,
1175 message ("Array fetch from non-array (%t): %s[%s]", carr,
1176 exprNode_unparse (e1), exprNode_unparse (e2)),
1178 exprNode_free (arr);
1179 return (exprNode_makeError ());
1184 if (!ctype_isForceRealInt (&(ind->typ)))
1186 ctype rt = ctype_realType (ind->typ);
1188 if (ctype_isChar (rt))
1192 message ("Array fetch using non-integer, %t: %s[%s]",
1194 exprNode_unparse (e1), exprNode_unparse (e2)),
1197 else if (ctype_isEnum (rt))
1201 message ("Array fetch using non-integer, %t: %s[%s]",
1203 exprNode_unparse (e1), exprNode_unparse (e2)),
1210 message ("Array fetch using non-integer, %t: %s[%s]",
1212 exprNode_unparse (e1), exprNode_unparse (e2)),
1216 multiVal_free (ind->val);
1217 ind->val = multiVal_unknown ();
1220 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1222 exprNode ret = exprNode_createSemiCopy (arr);
1223 multiVal m = exprNode_getValue (ind);
1225 ret->typ = ctype_baseArrayPtr (crarr);
1226 ret->kind = XPR_FETCH;
1228 if (multiVal_isInt (m))
1230 int i = (int) multiVal_forceInt (m);
1232 if (sRef_isValid (arr->sref)) {
1233 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1235 ret->sref = sRef_undefined;
1240 ret->sref = sRef_makeArrayFetch (arr->sref);
1243 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1244 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1245 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1247 /* (see comment on spurious errors above) */
1248 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1250 exprNode_checkUse (ret, ind->sref, ind->loc);
1251 exprNode_checkUse (ret, arr->sref, arr->loc);
1257 if (ctype_isUnknown (carr))
1259 exprNode ret = exprNode_createPartialCopy (arr);
1261 ret->kind = XPR_FETCH;
1262 ret->typ = ctype_unknown;
1263 ret->sets = sRefSet_union (ret->sets, ind->sets);
1264 ret->msets = sRefSet_union (ret->msets, ind->msets);
1265 ret->uses = sRefSet_union (ret->uses, ind->uses);
1267 /* (see comment on spurious errors above) */
1268 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1270 exprNode_checkUse (ret, ind->sref, ind->loc);
1271 exprNode_checkUse (ret, arr->sref, arr->loc);
1278 message ("Array fetch from non-array (%t): %s[%s]", carr,
1279 exprNode_unparse (e1), exprNode_unparse (e2)),
1282 exprNode_free (arr);
1283 exprNode_free (ind);
1285 return (exprNode_makeError ());
1295 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1296 exprNodeList args, exprNode ret)
1298 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1302 ** checkPrintfArgs --- checks arguments for printf-like functions
1303 ** Arguments before ... have already been checked.
1304 ** The argument before the ... is a char *.
1305 ** argno is the format string argument.
1309 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1310 exprNodeList args, exprNode ret, int argno)
1313 ** the last argument before the elips is the format string
1318 int nargs = exprNodeList_size (args);
1319 uentryList params = uentry_getParams (fcn);
1323 ** These should be ensured by checkSpecialFunction
1326 llassert (uentryList_size (params) == argno + 1);
1327 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1329 a = exprNodeList_getN (args, argno - 1);
1330 formatloc = fileloc_copy (exprNode_loc (a));
1332 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1333 && exprNode_knownStringValue (a))
1335 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1336 char *code = format;
1339 nargs = exprNodeList_size (args);
1341 while ((code = strchr (code, '%')) != NULL)
1343 char *origcode = code;
1344 cstring codetext = cstring_newEmpty ();
1345 char key = *(++code);
1346 ctype modtype = ctype_int;
1347 bool modified = FALSE;
1349 fileloc_addColumn (formatloc, code - ocode);
1351 codetext = cstring_appendChar (codetext, key);
1354 while (isFlagKey (key))
1357 codetext = cstring_appendChar (codetext, key);
1358 fileloc_incColumn (formatloc);
1361 if (key == 'm') /* skipped in syslog */
1366 /* ignore field width */
1367 while (isdigit ((int) key) != 0)
1370 codetext = cstring_appendChar (codetext, key);
1371 fileloc_incColumn (formatloc);
1374 /* ignore precision */
1378 codetext = cstring_appendChar (codetext, key);
1379 fileloc_incColumn (formatloc);
1382 ** In printf, '*' means: read the next arg as an int for the
1383 ** field width. This seems to be missing from my copy of the
1384 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1385 ** later) but never does.
1390 ; /* don't do anything --- handle later */
1394 while (isdigit ((int) key) != 0)
1397 codetext = cstring_appendChar (codetext, key);
1398 fileloc_incColumn (formatloc);
1405 modtype = ctype_sint; /* short */
1407 codetext = cstring_appendChar (codetext, key);
1408 fileloc_incColumn (formatloc);
1410 else if (key == 'l' || key == 'L')
1412 modtype = ctype_lint; /* long */
1414 codetext = cstring_appendChar (codetext, key);
1415 fileloc_incColumn (formatloc);
1417 if (key == 'l' || key == 'L') {
1418 modtype = ctype_llint; /* long long */
1420 codetext = cstring_appendChar (codetext, key);
1421 fileloc_incColumn (formatloc);
1429 /* now, key = type of conversion to apply */
1431 fileloc_incColumn (formatloc);
1439 message ("No argument corresponding to %q format "
1440 "code %d (%%%s): \"%s\"",
1441 uentry_getName (fcn),
1443 cstring_fromChars (format)),
1446 if (fileloc_isDefined (formatloc)
1447 && context_getFlag (FLG_SHOWCOL))
1449 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1457 a = exprNodeList_getN (args, i);
1460 if (!exprNode_isError (a))
1466 case '*': /* int argument for fieldwidth */
1467 expecttype = ctype_int;
1468 *(--code) = '%'; /* convert it for next code */
1469 fileloc_subColumn (formatloc, 1);
1470 /*@switchbreak@*/ break;
1473 expecttype = ctype_combine (ctype_uint, modtype);
1474 /*@switchbreak@*/ break;
1476 case 'i': /* int argument */
1478 expecttype = ctype_combine (ctype_int, modtype);
1479 /*@switchbreak@*/ break;
1481 case 'x': /* unsigned int */
1483 expecttype = ctype_combine (ctype_uint, modtype);
1485 /*@switchbreak@*/ break;
1491 case 'f': /* double */
1492 expecttype = ctype_combine (ctype_double, modtype);
1493 /*@switchbreak@*/ break;
1495 case 'c': /* int converted to char (check its a char?) */
1496 expecttype = ctype_makeConj (ctype_char, ctype_uchar);
1497 /*@switchbreak@*/ break;
1499 case 's': /* string */
1500 expecttype = ctype_string;
1501 /*@switchbreak@*/ break;
1504 while (((key = *(++code)) != ']')
1507 codetext = cstring_appendChar (codetext, key);
1508 fileloc_incColumn (formatloc);
1514 (message ("Bad character set format: %s",
1515 cstring_fromChars (origcode)));
1518 expecttype = ctype_string;
1519 /*@switchbreak@*/ break;
1521 case 'p': /* pointer */
1522 expecttype = ctype_makePointer (ctype_void);
1523 uentry_setDefState (regArg, SS_RELDEF); /* need not be defined */
1524 sRef_setPosNull (uentry_getSref (regArg), fileloc_undefined); /* could be null */
1525 /*@switchbreak@*/ break;
1527 case 'n': /* pointer to int, modified by call! */
1528 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1530 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1531 /*@switchbreak@*/ break;
1533 case 'm': /* in a syslog, it doesn't consume an argument */
1534 /* should check we're really doing syslog */
1536 /*@switchbreak@*/ break;
1540 expecttype = ctype_unknown;
1544 message ("Unrecognized format code: %s",
1545 cstring_fromChars (origcode)),
1546 fileloc_isDefined (formatloc)
1547 ? formatloc : g_currentloc);
1549 /*@switchbreak@*/ break;
1552 if (!(exprNode_matchArgType (expecttype, a)))
1554 if (ctype_isVoidPointer (expecttype)
1555 && ctype_isRealAbstract (a->typ)
1556 && (context_getFlag (FLG_ABSTVOIDP)))
1562 if (llgenformattypeerror
1563 (expecttype, exprNode_undefined,
1565 message ("Format argument %d to %q (%%%s) expects "
1568 uentry_getName (fcn),
1571 a->typ, exprNode_unparse (a)),
1574 if (fileloc_isDefined (formatloc)
1575 && context_getFlag (FLG_SHOWCOL))
1578 (cstring_makeLiteral
1579 ("Corresponding format code"),
1586 uentry_setType (regArg, expecttype);
1587 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1589 if (ctype_equal (expecttype, ctype_string))
1591 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1594 uentry_setType (regArg, ctype_unknown);
1595 uentry_fixupSref (regArg);
1599 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1610 cstring_free (codetext);
1615 voptgenerror (FLG_TYPE,
1616 message ("Format string for %q has %d arg%&, given %d",
1617 uentry_getName (fcn), i - argno, nargs - argno),
1623 /* no checking possible for compile-time unknown format strings */
1624 if (exprNode_isDefined (a))
1628 message ("Format string parameter to %s is not a compile-time constant: %s",
1629 exprNode_unparse (f),
1630 exprNode_unparse (a)),
1635 fileloc_free (formatloc);
1639 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1640 exprNodeList args, exprNode ret, int argno)
1644 int nargs = exprNodeList_size (args);
1645 uentryList params = uentry_getParams (fcn);
1649 ** These should be ensured by checkSpecialFunction
1652 llassert (uentryList_size (params) == argno + 1);
1653 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1655 a = exprNodeList_getN (args, argno - 1);
1656 formatloc = fileloc_copy (exprNode_loc (a));
1658 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1659 && exprNode_knownStringValue (a))
1661 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1662 char *code = format;
1665 nargs = exprNodeList_size (args);
1667 while ((code = strchr (code, '%')) != NULL)
1669 char *origcode = code;
1670 char key = *(++code);
1671 cstring codetext = cstring_newEmpty ();
1672 ctype modtype = ctype_int;
1673 char modifier = '\0';
1674 bool modified = TRUE;
1675 bool ignore = FALSE;
1677 codetext = cstring_appendChar (codetext, key);
1678 fileloc_addColumn (formatloc, code - ocode);
1681 ** this is based on ANSI standard library description of fscanf
1682 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1685 /* '*' suppresses assignment (does not need match argument) */
1690 codetext = cstring_appendChar (codetext, key);
1693 fileloc_incColumn (formatloc);
1696 /* ignore field width */
1697 while (isdigit ((int) key) != 0)
1700 codetext = cstring_appendChar (codetext, key);
1701 fileloc_incColumn (formatloc);
1706 modtype = ctype_sint; /* short */
1708 codetext = cstring_appendChar (codetext, key);
1709 fileloc_incColumn (formatloc);
1711 else if (key == 'l' || key == 'L')
1713 modtype = ctype_lint; /* long */
1717 codetext = cstring_appendChar (codetext, key);
1719 fileloc_incColumn (formatloc);
1721 if (key == 'l' || key == 'L') {
1722 modtype = ctype_llint; /* long long */
1724 codetext = cstring_appendChar (codetext, key);
1725 fileloc_incColumn (formatloc);
1733 /* now, key = type of conversion to apply */
1735 fileloc_incColumn (formatloc);
1749 message ("No argument corresponding to %q format "
1750 "code %d (%%%s): \"%s\"",
1751 uentry_getName (fcn),
1753 cstring_fromChars (format)),
1756 if (fileloc_isDefined (formatloc)
1757 && context_getFlag (FLG_SHOWCOL))
1760 (cstring_makeLiteral ("Corresponding format code"),
1768 a = exprNodeList_getN (args, i);
1771 if (!exprNode_isError (a))
1777 case '*': /* int argument for fieldwidth */
1778 expecttype = ctype_makePointer (ctype_int);
1779 *(--code) = '%'; /* convert it for next code */
1780 fileloc_subColumn (formatloc, 1);
1781 /*@switchbreak@*/ break;
1784 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1785 /*@switchbreak@*/ break;
1790 case 'X': /* unsigned int */
1791 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1792 /*@switchbreak@*/ break;
1799 /* printf is double, scanf is float! */
1801 if (modifier == 'l')
1803 expecttype = ctype_makePointer (ctype_double);
1805 else if (modifier == 'L')
1807 expecttype = ctype_makePointer (ctype_ldouble);
1811 llassert (modifier == '\0');
1812 expecttype = ctype_makePointer (ctype_float);
1814 /*@switchbreak@*/ break;
1816 case 'c': /* int converted to char (check its a char?) */
1817 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1818 /*@switchbreak@*/ break;
1820 case 's': /* string */
1821 expecttype = ctype_string;
1822 /*@switchbreak@*/ break;
1826 while (((key = *(++code)) != ']')
1829 codetext = cstring_appendChar (codetext, key);
1830 fileloc_incColumn (formatloc);
1836 (message ("Bad character set format: %s",
1837 cstring_fromChars (origcode)));
1840 expecttype = ctype_string;
1841 /*@switchbreak@*/ break;
1844 case 'p': /* pointer */
1847 message ("Format code should not be used in scanf: %s",
1848 cstring_fromChars (origcode)),
1849 fileloc_isDefined (formatloc)
1850 ? formatloc : g_currentloc);
1852 expecttype = ctype_unknown;
1853 /*@switchbreak@*/ break;
1855 case 'n': /* pointer to int, modified by call! */
1856 expecttype = ctype_makePointer (ctype_int);
1857 /*@switchbreak@*/ break;
1860 expecttype = ctype_unknown;
1864 message ("Unrecognized format code: %s",
1865 cstring_fromChars (origcode)),
1866 fileloc_isDefined (formatloc)
1867 ? formatloc : g_currentloc);
1869 /*@switchbreak@*/ break;
1872 if (!(exprNode_matchArgType (expecttype, a)))
1874 if (ctype_isVoidPointer (expecttype)
1875 && ctype_isRealAbstract (a->typ)
1876 && (context_getFlag (FLG_ABSTVOIDP)))
1882 if (llgenformattypeerror
1883 (expecttype, exprNode_undefined,
1885 message ("Format argument %d to %q (%%%s) expects "
1888 uentry_getName (fcn),
1889 codetext, expecttype,
1890 a->typ, exprNode_unparse (a)),
1893 if (fileloc_isDefined (formatloc)
1894 && context_getFlag (FLG_SHOWCOL))
1897 (cstring_makeLiteral
1898 ("Corresponding format code"),
1905 uentry_setType (outArg, expecttype);
1906 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
1907 uentry_setType (outArg, ctype_unknown);
1908 uentry_fixupSref (outArg);
1912 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1917 /* a->sref = defref; */
1924 cstring_free (codetext);
1929 voptgenerror (FLG_TYPE,
1930 message ("Format string for %q has %d arg%&, given %d",
1931 uentry_getName (fcn), i - argno, nargs - argno),
1937 /* no checking possible for compile-time unknown format strings */
1940 fileloc_free (formatloc);
1944 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
1947 /*@unused@*/ int argno)
1950 ** the last argument before the elips is the format string
1953 int nargs = exprNodeList_size (args);
1958 a = exprNodeList_getN (args, argno - 1);
1959 formatloc = fileloc_copy (exprNode_loc (a));
1961 if (ctype_isUnknown (cstringType)) {
1962 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
1964 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
1968 if (ctype_isUnknown (ctypeType)) {
1969 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
1971 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
1975 if (ctype_isUnknown (filelocType)) {
1976 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
1978 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
1982 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1983 && exprNode_knownStringValue (a))
1985 cstring format = multiVal_forceString (exprNode_getValue (a));
1986 char *code = cstring_toCharsSafe (format);
1989 nargs = exprNodeList_size (args);
1991 while ((code = strchr (code, '%')) != NULL)
1993 char *origcode = code;
1994 char key = *(++code);
1995 cstring codetext = cstring_newEmpty ();
1996 bool isOnly = FALSE;
1998 codetext = cstring_appendChar (codetext, key);
2000 fileloc_addColumn (formatloc, code - ocode);
2002 while (key >= '0' && key <= '9')
2005 codetext = cstring_appendChar (codetext, key);
2006 fileloc_incColumn (formatloc);
2010 fileloc_incColumn (formatloc);
2014 if (key == '&') /* plural marker */
2023 message ("Message missing format arg %d (%%%s): \"%s\"",
2024 i + 1, codetext, format),
2030 a = exprNodeList_getN (args, i);
2034 if (!exprNode_isError (a))
2038 /*@-loopswitchbreak@*/
2044 expecttype = ctype_char; break;
2046 expecttype = cstringType; break;
2048 expecttype = cstringType; isOnly = TRUE; break;
2050 expecttype = cstringType; isOnly = TRUE; break;
2051 case 'd': expecttype = ctype_int; break;
2052 case 'u': expecttype = ctype_uint; break;
2053 case 'w': expecttype = ctype_ulint; break;
2054 case 'f': expecttype = ctype_float; break;
2055 case 'b': expecttype = ctype_bool; break;
2056 case 't': expecttype = ctypeType; break;
2057 case 'l': expecttype = filelocType; break;
2058 case '&': /* a wee bit of a hack methinks */
2059 expecttype = ctype_int;
2061 case 'r': expecttype = ctype_bool; break;
2063 expecttype = ctype_unknown;
2066 message ("Unrecognized format code: %s",
2067 cstring_fromChars (origcode)),
2068 fileloc_isDefined (formatloc)
2069 ? formatloc : g_currentloc);
2072 /*@=loopswitchbreak@*/
2074 if (!(exprNode_matchArgType (expecttype, a)))
2076 if (ctype_isVoidPointer (expecttype)
2077 && ctype_isRealAbstract (a->typ)
2078 && (context_getFlag (FLG_ABSTVOIDP)))
2084 if (llgenformattypeerror
2085 (expecttype, exprNode_undefined,
2087 message ("Format argument %d to %q (%%%s) expects "
2090 uentry_getName (fcn),
2091 codetext, expecttype,
2092 a->typ, exprNode_unparse (a)),
2095 if (fileloc_isDefined (formatloc)
2096 && context_getFlag (FLG_SHOWCOL))
2099 (cstring_makeLiteral
2100 ("Corresponding format code"),
2107 if (ctype_equal (expecttype, cstringType))
2111 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
2112 uentry_fixupSref (csOnlyArg);
2116 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2117 uentry_fixupSref (csArg);
2122 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2123 uentry_fixupSref (regArg);
2129 cstring_free (codetext);
2134 voptgenerror (FLG_TYPE,
2135 message ("Format string for %q has %d arg%&, given %d",
2136 uentry_getName (fcn), i - argno, nargs -argno),
2142 /* no checking possible for compile-time unknown format strings */
2145 fileloc_free (formatloc);
2149 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2150 /*@notnull@*/ exprNode e2,
2156 bool hadUncon = FALSE;
2158 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e1->sref)) &&
2159 sRefSet_hasUnconstrained (sets2))
2162 (FLG_EVALORDERUNCON,
2164 ("Expression may have undefined behavior (%q used in right operand "
2165 "may set global variable %q used in left operand): %s %s %s",
2166 sRefSet_unparseUnconstrained (sets2),
2167 sRef_unparse (sRef_getRootBase (e1->sref)),
2168 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2172 if (sRef_isFileOrGlobalScope (sRef_getRootBase (e2->sref)) &&
2173 sRefSet_hasUnconstrained (sets1))
2176 (FLG_EVALORDERUNCON,
2178 ("Expression has undefined behavior (%q used in left operand "
2179 "may set global variable %q used in right operand): %s %s %s",
2180 sRefSet_unparseUnconstrained (sets1),
2181 sRef_unparse (e2->sref),
2182 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2186 sRefSet_realElements (e1->uses, sr)
2188 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2193 ("Expression has undefined behavior (left operand uses %q, "
2194 "modified by right operand): %s %s %s",
2196 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2199 } end_sRefSet_realElements;
2201 sRefSet_realElements (sets1, sr)
2203 if (sRef_isMeaningful (sr))
2205 if (sRef_same (sr, e2->sref))
2210 ("Expression has undefined behavior (value of right operand "
2211 "modified by left operand): %s %s %s",
2212 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2215 else if (sRefSet_member (e2->uses, sr))
2220 ("Expression has undefined behavior (left operand modifies %q, "
2221 "used by right operand): %s %s %s",
2223 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2228 if (sRefSet_member (sets2, sr))
2230 if (sRef_isUnconstrained (sr))
2238 hadUncon = optgenerror
2239 (FLG_EVALORDERUNCON,
2241 ("Expression may have undefined behavior. Left operand "
2242 "calls %q; right operand calls %q. The unconstrained "
2243 "functions may modify global state used by "
2244 "the other operand): %s %s %s",
2245 sRefSet_unparseUnconstrained (sets1),
2246 sRefSet_unparseUnconstrained (sets2),
2247 exprNode_unparse (e1), lltok_unparse (op),
2248 exprNode_unparse (e2)),
2257 ("Expression has undefined behavior (both "
2258 "operands modify %q): %s %s %s",
2260 exprNode_unparse (e1),
2261 lltok_unparse (op), exprNode_unparse (e2)),
2267 } end_sRefSet_realElements;
2270 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2272 bool hasError = FALSE;
2274 if (exprNode_isError (e1) || exprNode_isError (e2))
2279 if (sRefSet_member (e2->sets, e1->sref))
2281 if (e2->kind == XPR_CALL)
2287 hasError = optgenerror
2289 message ("Expression has undefined behavior "
2290 "(value of left operand %s is modified "
2291 "by right operand %s): %s %s %s",
2292 exprNode_unparse (e1),
2293 exprNode_unparse (e2),
2294 exprNode_unparse (e1), lltok_unparse (op),
2295 exprNode_unparse (e2)),
2300 if (context_getFlag (FLG_EVALORDERUNCON))
2302 if (sRefSet_member (e2->msets, e1->sref))
2304 if (e2->kind == XPR_CALL)
2310 hasError = optgenerror
2313 ("Expression has undefined behavior (value of left "
2314 "operand may be modified by right operand): %s %s %s",
2315 exprNode_unparse (e1), lltok_unparse (op),
2316 exprNode_unparse (e2)),
2324 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2326 if (context_maybeSet (FLG_EVALORDERUNCON))
2328 checkExpressionDefinedAux (e1, e2, e1->msets,
2329 e2->msets, op, FLG_EVALORDERUNCON);
2334 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2337 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2338 exprNodeList args, bool isIter, exprNode ret)
2342 if (!exprNode_isError (f))
2344 if (!uentryList_isMissingParams (cl))
2346 int nargs = exprNodeList_size (args);
2347 int expectargs = uentryList_size (cl);
2351 if (expectargs == 0)
2359 message ("Iter %q invoked with %d args, "
2361 uentry_getName (fcn),
2369 message ("Function %s called with %d args, "
2371 exprNode_unparse (f), nargs),
2378 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2380 exprNodeList_reset (args);
2382 uentryList_elements (cl, current)
2384 ctype ct = uentry_getType (current);
2387 if (ctype_isElips (ct))
2390 ** do special checking for printf/scanf library functions
2392 ** this is kludgey code, just for handling the special case
2396 if (uentry_isPrintfLike (fcn))
2398 checkPrintfArgs (f, fcn, args, ret, i);
2401 else if (uentry_isScanfLike (fcn))
2403 checkScanfArgs (f, fcn, args, ret, i);
2406 else if (uentry_isMessageLike (fcn))
2408 checkMessageArgs (f, fcn, args, i);
2413 llassert (!uentry_isSpecialFunction (fcn));
2416 nargs = expectargs; /* avoid errors */
2421 if (i >= nargs) break;
2423 a = exprNodeList_current (args);
2424 exprNodeList_advance (args);
2428 if (exprNode_isError (a))
2435 probably necessary? I'm not sure about this one
2436 checkMacroParen (a);
2439 f->guards = guardSet_union (f->guards, a->guards);
2441 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2443 if (!(exprNode_matchArgType (ct, a)))
2445 DPRINTF (("Args mismatch!"));
2447 if (ctype_isVoidPointer (ct)
2448 && (ctype_isPointer (a->typ)
2449 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2454 ("Pointer to abstract type (%t) used "
2456 "(arg %d to %q): %s",
2458 uentry_getName (fcn),
2459 exprNode_unparse (a)),
2467 (ct, exprNode_undefined,
2470 ("Iter %q expects arg %d to "
2471 "be %t gets %t: %s",
2472 uentry_getName (fcn),
2473 i, ct, a->typ, exprNode_unparse (a)),
2484 ("Function %q expects arg %d to be %t gets %t: %s",
2485 uentry_getName (fcn),
2486 i, ct, a->typ, exprNode_unparse (a)),
2489 DPRINTF (("Types: %s / %s",
2491 ctype_unparse (a->typ)));
2495 ** Clear null marker for abstract types.
2496 ** (It is not revealed, so suppress future messages.)
2499 if (ctype_isAbstract (a->typ))
2501 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2508 } end_uentryList_elements ;
2511 if (expectargs != nargs) /* note: not != since we may have ... */
2513 if (ctype_isElips (last))
2517 message ("Function %s called with %d args, expects at least %d",
2518 exprNode_unparse (f),
2519 nargs, expectargs - 1),
2528 message ("Iter %q invoked with %d args, expects %d",
2529 uentry_getName (fcn), nargs, expectargs),
2536 message ("Function %s called with %d args, expects %d",
2537 exprNode_unparse (f),
2550 ** Check for undefined code sequences in function arguments:
2552 ** one parameter sets something used by another parameter
2553 ** one parameter sets something set by another parameter
2557 checkSequencingOne (exprNode f, exprNodeList args,
2558 /*@notnull@*/ exprNode el, int argno)
2561 ** Do second loop, iff +undefunspec
2565 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2567 for (checkloop = 0; checkloop < numloops; checkloop++)
2573 thissets = el->sets;
2577 llassert (checkloop == 1);
2578 thissets = el->msets;
2581 sRefSet_realElements (thissets, thisset)
2585 /*@access exprNodeList@*/
2586 for (j = 0; j < args->nelements; j++)
2588 exprNode jl = args->elements[j];
2589 int thisargno = j + 1;
2591 if (thisargno != argno && exprNode_isDefined (jl))
2593 sRefSet otheruses = jl->uses;
2595 if (sRef_isFileOrGlobalScope (sRef_getRootBase (jl->sref)) &&
2596 sRefSet_hasUnconstrained (thissets))
2599 (FLG_EVALORDERUNCON,
2602 ("%q used in argument %d may set "
2603 "global variable %q used by argument %d: %s(%q)",
2604 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2607 sRef_unparse (sRef_getRootBase (jl->sref)),
2609 exprNode_unparse (f), exprNodeList_unparse (args)),
2613 if (sRefSet_member (otheruses, thisset))
2615 if (sRef_isUnconstrained (thisset))
2618 (FLG_EVALORDERUNCON,
2620 ("Unconstrained functions used in arguments %d (%q) "
2621 "and %d (%s) may modify "
2622 "or use global state in undefined way: %s(%q)",
2624 sRefSet_unparseUnconstrainedPlain (otheruses),
2626 sRef_unconstrainedName (thisset),
2627 exprNode_unparse (f),
2628 exprNodeList_unparse (args)),
2636 ("Argument %d modifies %q, used by argument %d "
2637 "(order of evaluation of actual parameters is "
2638 "undefined): %s(%q)",
2639 argno, sRef_unparse (thisset), thisargno,
2640 exprNode_unparse (f), exprNodeList_unparse (args)),
2646 sRefSet othersets = jl->sets;
2648 if (sRefSet_member (othersets, thisset))
2650 if (sRef_isUnconstrained (thisset))
2653 (FLG_EVALORDERUNCON,
2655 ("Unconstrained functions used in "
2656 "arguments %d (%q) and %d (%s) may modify "
2657 "or use global state in undefined way: %s(%q)",
2659 sRefSet_unparseUnconstrainedPlain (othersets),
2661 sRef_unconstrainedName (thisset),
2662 exprNode_unparse (f), exprNodeList_unparse (args)),
2670 ("Argument %d modifies %q, set by argument %d (order of"
2671 " evaluation of actual parameters is undefined): %s(%q)",
2672 argno, sRef_unparse (thisset), thisargno,
2673 exprNode_unparse (f), exprNodeList_unparse (args)),
2680 /*@noaccess exprNodeList@*/
2681 } end_sRefSet_realElements;
2686 checkSequencing (exprNode f, exprNodeList args)
2688 if (exprNodeList_size (args) > 1)
2693 /*@access exprNodeList*/
2695 for (i = 0; i < args->nelements; i++)
2697 el = args->elements[i];
2699 if (!exprNode_isError (el))
2701 checkSequencingOne (f, args, el, i + 1);
2704 /*@noaccess exprNodeList*/
2709 ** requires le = exprNode_getUentry (f)
2713 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2714 uentry le, exprNodeList args,
2715 /*@notnull@*/ exprNode ret, int specialArgs)
2717 bool isSpec = FALSE;
2718 bool hasMods = FALSE;
2720 globSet usesGlobs = globSet_undefined;
2721 sRefSet mods = sRefSet_undefined;
2722 bool freshMods = FALSE;
2723 uentryList params = uentryList_undefined;
2725 DPRINTF (("Check glob mods: %s", exprNode_unparse (ret)));
2728 ** check globals and modifies
2733 if (!uentry_isValid (le))
2735 ctype fr = ctype_realType (f->typ);
2737 if (ctype_isFunction (fr))
2739 params = ctype_argsFunction (fr);
2743 params = uentryList_missingParams;
2746 if (!context_getFlag (FLG_MODNOMODS)
2747 && !context_getFlag (FLG_GLOBUNSPEC))
2749 checkUnspecCall (f, params, args);
2755 fname = uentry_rawName (le);
2759 if (uentry_isFunction (le))
2761 params = uentry_getParams (le);
2762 mods = uentry_getMods (le);
2763 hasMods = uentry_hasMods (le);
2764 usesGlobs = uentry_getGlobs (le);
2765 isSpec = uentry_isSpecified (le);
2767 else /* not a function */
2769 ctype ct = ctype_realType (uentry_getType (le));
2771 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2772 ("checkModGlobs: uentry not a function: %s",
2773 uentry_unparse (le)));
2775 params = ctype_argsFunction (ct);
2776 return; /*@32 ! remove this? */
2785 globSet_allElements (usesGlobs, el)
2787 if (sRef_isValid (el))
2789 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2791 context_usedGlobal (el);
2792 exprNode_checkUse (f, el, f->loc);
2794 if (context_checkInternalUse ())
2796 if (!context_globAccess (el))
2798 if (sRef_isSystemState (el)
2799 && !context_getFlag (FLG_MODFILESYSTEM))
2808 ("Called procedure %s may access %q, but "
2809 "globals list does not include globals %s",
2810 exprNode_unparse (f),
2812 cstring_makeLiteralTemp (sRef_isInternalState (el)
2820 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2826 uentry gle = sRef_getUentry (el);
2827 sRef sr = sRef_updateSref (el);
2829 if (sRef_isUndefGlob (el))
2831 sRef_setDefined (sr, f->loc);
2832 exprNode_checkSet (f, sr);
2840 if (sRef_isAllocated (el))
2842 exprNode_checkSet (f, sr);
2846 if (sRef_isStateUndefined (sr))
2851 ("%s %q used by function undefined before call: %s",
2852 sRef_getScopeName (sr),
2854 exprNode_unparse (f)),
2856 sRef_setDefined (sr, f->loc);
2858 exprNode_checkUse (f, sr, f->loc);
2861 checkGlobUse (gle, TRUE, f);
2864 if (sRef_isKilledGlob (el))
2866 sRef_kill (sr, f->loc);
2867 context_usedGlobal (sr);
2871 } end_globSet_allElements;
2877 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
2879 sRefSet smods = sRefSet_undefined;
2882 ** NEED to check for modifies anything
2886 ** check each sRef that called function modifies (ml), is
2892 sRefSet_allElements (mods, s) /* s is something which may be modified */
2894 DPRINTF (("Check modify: %s", sRef_unparse (s)));
2896 if (sRef_isKindSpecial (s))
2898 if (sRef_isSpecInternalState (s))
2900 if (context_getFlag (FLG_MODINTERNALSTRICT))
2902 exprNode_checkCallModifyVal (s, args, f, ret);
2906 sRefSet mmods = context_modList ();
2908 sRefSet_allElements (mmods, el)
2910 if (sRef_isInternalState (el))
2912 sRef_setModified (el);
2914 } end_sRefSet_allElements ;
2919 exprNode_checkCallModifyVal (s, args, f, ret);
2924 sRef rb = sRef_getRootBase (s);
2926 if (sRef_isFileOrGlobalScope (rb))
2928 context_usedGlobal (rb);
2931 if (sRef_isFileStatic (s)
2932 && !fileId_equal (fileloc_fileId (f->loc),
2933 fileloc_fileId (uentry_whereDefined (le))))
2935 smods = sRefSet_insert (smods, s);
2939 exprNode_checkCallModifyVal (s, args, f, ret);
2942 } end_sRefSet_allElements;
2947 ** Static elements in modifies set can have nasty consequences.
2948 ** (I think...have not been able to reproduce a possible bug.)
2951 if (!sRefSet_isDefined (smods))
2953 mods = sRefSet_newCopy (mods);
2956 sRefSet_allElements (smods, el)
2958 bool res = sRefSet_delete (mods, el);
2961 } end_sRefSet_allElements;
2963 sRefSet_free (smods);
2968 else if (sRefSet_isDefined (mods))
2969 { /* just check observers */
2972 sRefSet_allElements (mods, s) /* s is something which may be modified */
2974 sRef rb = sRef_getRootBase (s);
2978 if (sRef_isParam (rb))
2980 sRef b = sRef_fixBaseParam (s, args);
2982 if (sRef_isObserver (b))
2984 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
2988 message ("Function call may modify observer%q: %s",
2989 sRef_unparsePreOpt (b), exprNode_unparse (e)),
2992 sRef_showExpInfo (b);
2996 } end_sRefSet_allElements;
3000 if (!hasMods) /* no specified modifications */
3002 if (context_getFlag (FLG_MODOBSERVERUNCON))
3004 exprNodeList_elements (args, e)
3006 if (exprNode_isDefined (e))
3008 sRef s = exprNode_getSref (e);
3010 if (sRef_isObserver (s)
3011 && ctype_isMutable (sRef_getType (s)))
3014 (FLG_MODOBSERVERUNCON,
3016 ("Call to unconstrained function %s may modify observer%q: %s",
3017 exprNode_unparse (f),
3018 sRef_unparsePreOpt (s), exprNode_unparse (e)),
3021 sRef_showExpInfo (s);
3025 } end_exprNodeList_elements;
3030 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
3032 ret->uses = sRefSet_union (ret->uses, f->uses);
3033 ret->sets = sRefSet_union (ret->sets, f->sets);
3034 ret->msets = sRefSet_union (ret->msets, f->msets);
3039 ** Spurious errors reported, because lclint can't tell
3040 ** mods must be fresh if freshMods is true.
3043 /*@i@*/ sRefSet_free (mods);
3049 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
3051 if (uentry_isVar (glob))
3053 if (context_inFunctionLike ())
3055 sRef sr = uentry_getSref (glob);
3057 context_usedGlobal (sr);
3059 if (context_checkGlobUse (glob))
3061 if (!context_globAccess (sr))
3067 message ("Called procedure %s may access %s %q",
3068 exprNode_unparse (e),
3069 sRef_unparseScope (sr),
3070 uentry_getName (glob)),
3077 message ("Undocumented use of %s %s",
3078 sRef_unparseScope (sr),
3079 exprNode_unparse (e)),
3088 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
3093 reflectEnsuresClause (exprNode ret, uentry le, exprNode f, exprNodeList args)
3095 DPRINTF (("Reflect ensures clause: %s(%s) / %s / %s",
3096 exprNode_unparse (f), exprNodeList_unparse (args),
3097 uentry_unparseFull (le),
3098 stateClauseList_unparse (uentry_getStateClauseList (le))));
3100 if (uentry_isValid (le) && uentry_isFunction (le))
3102 stateClauseList sclauses = uentry_getStateClauseList (le);
3104 if (stateClauseList_isDefined (sclauses))
3106 DPRINTF (("Reflect ensures: %s / %s / %s",
3107 uentry_unparse (le),
3108 exprNode_unparse (f), exprNodeList_unparse (args)));
3110 stateClauseList_elements (sclauses, cl)
3112 if (stateClause_hasEnsures (cl))
3114 /* Same in usymtab.c:1904 */
3115 if (stateClause_setsMetaState (cl))
3117 qual q = stateClause_getMetaQual (cl);
3118 annotationInfo ainfo = qual_getAnnotationInfo (q);
3119 metaStateInfo minfo = annotationInfo_getState (ainfo);
3120 cstring key = metaStateInfo_getName (minfo);
3121 int mvalue = annotationInfo_getValue (ainfo);
3123 sRefSet osrs = sRefSet_undefined;
3126 if (stateClause_isGlobal (cl))
3128 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3133 srs = stateClause_getRefs (cl);
3136 DPRINTF (("Reflect ensures clause: %s", stateClause_unparse (cl)));
3139 DPRINTF (("Sets meta state! %s", stateClause_unparse (cl)));
3141 sRefSet_elements (srs, sel)
3145 if (sRef_isResult (sRef_getRootBase (sel)))
3147 s = exprNode_getSref (ret);
3151 s = sRef_fixBaseParam (sel, args);
3154 DPRINTF (("Reflecting state clause on: %s / %s",
3155 sRef_unparse (sel), sRef_unparse (s)));
3157 sRef_setMetaStateValueComplete (s, key, mvalue, exprNode_loc (f));
3158 } end_sRefSet_elements;
3160 sRefSet_free (osrs);
3164 sRefSet srs = stateClause_getRefs (cl);
3165 sRefModVal modf = stateClause_getEnsuresFunction (cl);
3166 int eparam = stateClause_getStateParameter (cl);
3168 DPRINTF (("Reflect after clause: %s / %s",
3169 stateClause_unparse (cl),
3170 sRefSet_unparse (srs)));
3172 sRefSet_elements (srs, sel)
3176 DPRINTF (("elements: %s", sRef_unparse (sel)));
3177 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3179 if (sRef_isResult (sRef_getRootBase (sel)))
3181 DPRINTF (("Fix base: %s / %s",
3182 sRef_unparse (sel), sRef_unparse (exprNode_getSref (ret))));
3183 s = sRef_fixBase (sel, exprNode_getSref (ret));
3184 DPRINTF (("==> %s", sRef_unparseFull (s)));
3188 s = sRef_fixBaseParam (sel, args);
3191 DPRINTF (("elements: %s", sRef_unparse (s)));
3192 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3194 DPRINTF (("Reflecting state clause on: %s / %s",
3195 sRef_unparseFull (sel), sRef_unparseFull (s)));
3197 /* evans 2001-08-24 - added aliasSetCompleteParam */
3198 sRef_aliasSetCompleteParam (modf, s, eparam, exprNode_loc (f));
3200 DPRINTF (("After reflecting state clause on: %s / %s",
3201 sRef_unparseFull (sel), sRef_unparseFull (s)));
3202 } end_sRefSet_elements;
3205 } end_stateClauseList_elements ;
3208 DPRINTF (("Here: %s / %s",
3209 uentry_unparseFull (le),
3210 bool_unparse (uentry_hasMetaStateEnsures (le))));
3212 if (uentry_hasMetaStateEnsures (le))
3214 fileloc loc = exprNode_loc (f);
3216 metaStateConstraintList mscl = uentry_getMetaStateEnsures (le);
3218 metaStateConstraintList_elements (mscl, msc)
3220 metaStateSpecifier msspec = metaStateConstraint_getSpecifier (msc);
3221 metaStateInfo msinfo = metaStateSpecifier_getMetaStateInfo (msspec);
3222 metaStateExpression msexpr = metaStateConstraint_getExpression (msc);
3223 cstring key = metaStateInfo_getName (msinfo);
3224 sRef mlsr = metaStateSpecifier_getSref (msspec);
3226 sRef lastref = sRef_undefined;
3227 stateValue sval = stateValue_undefined;
3229 DPRINTF (("Meta state constraint for %s: %s", uentry_unparse (le),
3230 metaStateConstraint_unparse (msc)));
3231 DPRINTF (("Matches left: %s", sRef_unparseDebug (mlsr)));
3233 if (sRef_isResult (sRef_getRootBase (mlsr)))
3235 s = exprNode_getSref (ret);
3239 s = sRef_fixBaseParam (mlsr, args);
3242 DPRINTF (("Setting state: %s", sRef_unparseFull (s)));
3244 while (metaStateExpression_isDefined (msexpr))
3246 metaStateSpecifier ms = metaStateExpression_getSpecifier (msexpr);
3247 metaStateInfo msi = metaStateSpecifier_getMetaStateInfo (ms);
3250 DPRINTF (("Check expression: %s", metaStateExpression_unparse (msexpr)));
3252 if (metaStateExpression_isMerge (msexpr))
3254 msexpr = metaStateExpression_getRest (msexpr);
3258 msexpr = metaStateExpression_undefined;
3261 if (metaStateInfo_isDefined (msi))
3263 /* Must match lhs state */
3264 llassert (metaStateInfo_equal (msinfo, msi));
3267 if (metaStateSpecifier_isElipsis (ms))
3270 ** For elipsis, we need to merge all the relevant elipsis parameters
3274 uentryList params = uentry_getParams (le);
3275 int paramno = uentryList_size (params) - 1;
3277 if (!uentry_isElipsisMarker (uentryList_getN (params, paramno)))
3281 message ("Ensures clauses uses ... for function without ... in parameter list: %q",
3282 uentry_getName (le)),
3283 uentry_whereLast (le));
3284 /*@innerbreak@*/ break;
3287 while (paramno < exprNodeList_size (args))
3289 exprNode arg = exprNodeList_getN (args, paramno);
3290 fs = exprNode_getSref (arg);
3291 DPRINTF (("Merge arg: %s", exprNode_unparse (arg)));
3293 /* cut and pasted... gack*/
3294 if (stateValue_isDefined (sval))
3296 /* Use combination table to merge old state value with new one: */
3297 stateValue tval = sRef_getMetaStateValue (fs, key);
3299 if (stateValue_isDefined (tval))
3301 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3302 cstring msg = cstring_undefined;
3303 int nval = stateCombinationTable_lookup (sctable,
3304 stateValue_getValue (sval),
3305 stateValue_getValue (tval),
3307 DPRINTF (("Combining: %s + %s -> %d",
3308 stateValue_unparseValue (sval, msinfo),
3309 stateValue_unparseValue (tval, msinfo),
3312 if (nval == stateValue_error)
3317 ("Attributes merged in ensures clause in states that "
3318 "cannot be combined (%q is %q, %q is %q)%q",
3319 sRef_unparse (lastref),
3320 stateValue_unparseValue (sval, msinfo),
3322 stateValue_unparseValue (tval, msinfo),
3323 cstring_isDefined (msg) ?
3324 message (": %s", msg) : cstring_undefined),
3327 sRef_showMetaStateInfo (fs, key);
3331 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3332 loc = exprNode_loc (arg);
3336 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3341 sval = sRef_getMetaStateValue (fs, key);
3346 if (stateValue_isError (sval))
3348 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3357 msr = metaStateSpecifier_getSref (ms);
3360 llassert (sRef_isParam (sRef_getRootBase (msr)));
3361 fs = sRef_fixBaseParam (msr, args);
3363 if (stateValue_isDefined (sval))
3365 /* Use combination table to merge old state value with new one: */
3366 stateValue tval = sRef_getMetaStateValue (fs, key);
3368 if (stateValue_isDefined (tval))
3370 stateCombinationTable sctable = metaStateInfo_getMergeTable (msinfo);
3371 cstring msg = cstring_undefined;
3372 int nval = stateCombinationTable_lookup (sctable,
3373 stateValue_getValue (sval),
3374 stateValue_getValue (tval),
3376 DPRINTF (("Combining: %s + %s -> %d",
3377 stateValue_unparseValue (sval, msinfo),
3378 stateValue_unparseValue (tval, msinfo),
3381 if (nval == stateValue_error)
3386 ("Attributes merged in ensures clause in states that "
3387 "cannot be combined (%q is %q, %q is %q)%q",
3388 sRef_unparse (lastref),
3389 stateValue_unparseValue (sval, msinfo),
3391 stateValue_unparseValue (tval, msinfo),
3392 cstring_isDefined (msg)
3393 ? message (": %s", msg) : cstring_undefined),
3396 sRef_showMetaStateInfo (fs, key);
3400 stateValue_updateValueLoc (sval, nval, fileloc_undefined);
3404 DPRINTF (("No value for: %s:%s", sRef_unparse (fs), key));
3409 sval = sRef_getMetaStateValue (fs, key);
3414 if (stateValue_isError (sval))
3416 /*@innerbreak@*/ break; /* Don't merge any more values if here was an error */
3421 DPRINTF (("Setting: %s:%s <- %s", sRef_unparse (s), key, stateValue_unparse (sval)));
3423 if (stateValue_isDefined (sval))
3425 sRef_setMetaStateValueComplete (s, key, stateValue_getValue (sval), loc);
3429 DPRINTF (("Undefined state: %s", cstring_toCharsSafe (sRef_unparse (s))));
3431 } end_metaStateConstraintList_elements ;
3433 metaStateConstraintList_free (mscl);
3439 checkRequiresClause (uentry le, exprNode f, exprNodeList args)
3441 DPRINTF (("Check requires clause: %s(%s) / %s / %s",
3442 exprNode_unparse (f), exprNodeList_unparse (args),
3443 uentry_unparseFull (le),
3444 stateClauseList_unparse (uentry_getStateClauseList (le))));
3446 if (uentry_isValid (le) && uentry_isFunction (le))
3448 stateClauseList sclauses = uentry_getStateClauseList (le);
3450 if (stateClauseList_isDefined (sclauses))
3452 DPRINTF (("Check requires: %s / %s / %s",
3453 uentry_unparse (le),
3454 exprNode_unparse (f), exprNodeList_unparse (args)));
3456 stateClauseList_elements (sclauses, cl)
3458 DPRINTF (("Check clause: %s / %s",
3459 stateClause_unparse (cl),
3460 bool_unparse (stateClause_hasRequires (cl))));
3462 if (stateClause_hasRequires (cl))
3464 sRefSet osrs = sRefSet_undefined;
3467 if (stateClause_isGlobal (cl))
3469 srs = sRefSet_single (usymtab_lookupGlobalMarker ());
3474 srs = stateClause_getRefs (cl);
3477 DPRINTF (("Refs: %s", sRefSet_unparse (srs)));
3479 if (stateClause_setsMetaState (cl))
3481 qual q = stateClause_getMetaQual (cl);
3482 annotationInfo ainfo = qual_getAnnotationInfo (q);
3483 metaStateInfo minfo = annotationInfo_getState (ainfo);
3484 cstring key = metaStateInfo_getName (minfo);
3485 int mvalue = annotationInfo_getValue (ainfo);
3487 DPRINTF (("Requires meta state! %s = %d", key, mvalue));
3489 sRefSet_elements (srs, sel)
3491 sRef s = sRef_fixBaseParam (sel, args);
3493 if (sRef_isResult (sRef_getRootBase (sel)))
3499 DPRINTF (("Checking state clause on: %s / %s / %s = %d",
3500 sRef_unparseFull (sel), sRef_unparseFull (s),
3503 if (!sRef_checkMetaStateValue (s, key, mvalue))
3505 DPRINTF (("HERE: %s", sRef_unparse (s)));
3509 ("Requires clause of called function %q not satisfied%q (state is %q): %q",
3510 uentry_getName (le),
3511 sRef_isGlobalMarker (s)
3513 : message (" by %q", sRef_unparse (s)),
3514 stateValue_unparseValue (sRef_getMetaStateValue (s, key),
3516 stateClause_unparse (cl)),
3519 sRef_showAliasInfo (s);
3523 DPRINTF (("Error supressed!"));
3524 DPRINTF (("Loc: %s", fileloc_unparse (exprNode_loc (f))));
3525 DPRINTF (("Context supress: %s",
3526 bool_unparse (context_suppressFlagMsg (FLG_STATETRANSFER, exprNode_loc (f)))));
3530 } end_sRefSet_elements;
3534 sRefModVal modf = stateClause_getRequiresBodyFunction (cl);
3535 int eparam = stateClause_getStateParameter (cl);
3537 DPRINTF (("Reflect after clause: %s / %s",
3538 stateClause_unparse (cl),
3539 sRefSet_unparse (srs)));
3541 sRefSet_elements (srs, sel)
3545 DPRINTF (("elements: %s", sRef_unparse (sel)));
3546 DPRINTF (("elements: %s", sRef_unparseFull (sel)));
3548 s = sRef_fixBaseParam (sel, args);
3550 DPRINTF (("elements: %s", sRef_unparse (s)));
3551 DPRINTF (("elements: %s", sRef_unparseFull (s)));
3553 if (sRef_isResult (sRef_getRootBase (sel)))
3555 ; /*@i423 what do we do about results */
3559 DPRINTF (("Reflecting state clause on: %s / %s",
3560 sRef_unparse (sel), sRef_unparse (s)));
3562 modf (s, eparam, exprNode_loc (f));
3564 } end_sRefSet_elements;
3567 sRefSet_free (osrs);
3569 } end_stateClauseList_elements ;
3574 static /*@only@*/ exprNode
3575 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
3576 ctype t, /*@keep@*/ exprNodeList args)
3578 /* requires f is a non-error exprNode, with type function */
3579 cstring fname = exprNode_unparse (f);
3580 uentry le = exprNode_getUentry (f);
3581 exprNode ret = exprNode_createPartialCopy (f);
3586 DPRINTF (("Call: %s %s",exprNode_unparse (f), exprNodeList_unparse (args)));
3588 ret->typ = ctype_getReturnType (t);
3589 ret->kind = XPR_CALL;
3591 ret->edata = exprData_makeCall (f, args);
3594 ** Order of these steps is very important!
3596 ** Must check for argument dependencies before messing up uses and sets.
3599 if (context_getFlag (FLG_EVALORDER))
3601 exprNodeList_elements (args, current)
3603 if (exprNode_isDefined (current))
3605 exprNode_addUse (current, current->sref);
3607 } end_exprNodeList_elements;
3609 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3611 checkSequencing (f, args);
3614 exprNodeList_elements (args, current)
3616 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3618 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3620 } end_exprNodeList_elements ;
3623 special = checkArgs (le, f, t, args, ret);
3624 checkGlobMods (f, le, args, ret, special);
3625 checkRequiresClause (le, f, args);
3628 if (uentry_isValid (le)
3629 && (uentry_isFunction (le)
3630 || (uentry_isVariable (le)
3631 && ctype_isFunction (uentry_getType (le)))))
3633 exitkind exk = uentry_getExitCode (le);
3635 /* f->typ is already set to the return type */
3637 DPRINTF (("Function: %s", uentry_unparseFull (le)));
3638 ret->sref = uentry_returnedRef (le, args);
3639 DPRINTF (("Returned: %s / %s",
3640 uentry_unparseFull (le),
3641 sRef_unparseFull (ret->sref)));
3643 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3645 qual nullPred = uentry_nullPred (le);
3647 if (qual_isTrueNull (nullPred))
3649 exprNode arg = exprNodeList_head (args);
3651 if (exprNode_isDefined (arg))
3653 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3656 else if (qual_isFalseNull (nullPred))
3658 exprNode arg = exprNodeList_head (args);
3660 if (exprNode_isDefined (arg))
3662 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3667 llassert (qual_isUnknown (nullPred));
3671 if (exitkind_isConditionalExit (exk))
3675 ** if (arg0) then { exit! } else { ; }
3677 ** if (arg0) then { ; } else { exit! }
3682 llassert (!exprNodeList_isEmpty (args));
3683 firstArg = exprNodeList_head (args);
3685 if (exprNode_isDefined (firstArg)
3686 && !guardSet_isEmpty (firstArg->guards))
3688 usymtab_trueBranch (guardSet_undefined);
3689 usymtab_altBranch (guardSet_undefined);
3691 if (exitkind_isTrueExit (exk))
3693 usymtab_popBranches (firstArg,
3694 exprNode_makeMustExit (),
3696 TRUE, TRUEEXITCLAUSE);
3700 usymtab_popBranches (firstArg,
3702 exprNode_makeMustExit (),
3703 TRUE, FALSEEXITCLAUSE);
3707 ret->exitCode = XK_MAYEXIT;
3709 else if (exitkind_mustExit (exk))
3711 ret->exitCode = XK_MUSTEXIT;
3713 else if (exitkind_couldExit (exk))
3715 ret->exitCode = XK_MAYEXIT;
3722 if (cstring_equalLit (fname, "exit"))
3724 if (exprNodeList_size (args) == 1)
3726 exprNode arg = exprNodeList_head (args);
3728 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3730 long int val = multiVal_forceInt (exprNode_getValue (arg));
3737 ("Argument to exit has implementation defined behavior: %s",
3738 exprNode_unparse (arg)),
3739 exprNode_loc (arg));
3748 exprNode_checkSetAny (ret, uentry_rawName (le));
3751 DPRINTF (("Before reflect: %s", sRef_unparseFull (ret->sref)));
3752 DPRINTF (("Reflect: %s", uentry_unparseFull (le)));
3753 reflectEnsuresClause (ret, le, f, args);
3760 ** this is yucky! should keep the uentry as part of exprNode!
3763 uentry exprNode_getUentry (exprNode e)
3765 if (exprNode_isError (e))
3767 return uentry_undefined;
3771 cstring s = exprNode_rootVarName (e);
3772 uentry ue = usymtab_lookupSafe (s);
3779 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3781 exprNode ret = exprNode_createPlain (ctype_unknown);
3783 ret->kind = XPR_INITBLOCK;
3784 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3785 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3791 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3797 if (exprNode_isUndefined (f))
3800 exprNodeList_free (args);
3801 return exprNode_undefined;
3804 t = exprNode_getType (f);
3806 if (sRef_isLocalVar (f->sref))
3808 exprNode_checkUse (f, f->sref, f->loc);
3810 if (sRef_possiblyNull (f->sref))
3812 if (!usymtab_isGuarded (f->sref))
3814 if (optgenerror (FLG_NULLDEREF,
3815 message ("Function call using %s pointer %q",
3816 sRef_nullMessage (f->sref),
3817 sRef_unparse (f->sref)),
3820 sRef_showNullInfo (f->sref);
3821 sRef_setNullError (f->sref);
3829 if (ctype_isRealFunction (t))
3831 exprNode ret = functionCallSafe (f, t, args);
3835 else if (ctype_isUnknown (t))
3837 exprNode ret = exprNode_createPartialCopy (f);
3843 exprNodeList_elements (args, current)
3845 if (exprNode_isDefined (current))
3847 exprNode_checkUse (ret, current->sref, ret->loc);
3850 ** also, anything derivable from current->sref may be used
3853 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3854 exprNode_mergeUSs (ret, current);
3856 } end_exprNodeList_elements;
3858 ret->edata = exprData_makeCall (f, args);
3859 ret->kind = XPR_CALL;
3861 tstring = cstring_copy (exprNode_unparse (f));
3863 cstring_markOwned (tstring);
3864 exprNode_checkSetAny (ret, tstring);
3870 voptgenerror (FLG_TYPE,
3871 message ("Call to non-function (type %t): %s", t,
3872 exprNode_unparse (f)),
3875 exprNodeList_free (args);
3877 return (exprNode_makeError ());
3882 exprNode_fieldAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
3883 /*@only@*/ cstring f)
3885 exprNode ret = exprNode_createPartialCopy (s);
3887 ret->kind = XPR_FACCESS;
3889 if (exprNode_isError (s))
3891 ret->edata = exprData_makeField (s, f);
3896 ctype t = exprNode_getType (s);
3897 ctype tr = ctype_realType (t);
3899 checkMacroParen (s);
3901 ret->edata = exprData_makeField (s, f);
3903 if (ctype_isStructorUnion (tr))
3905 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
3907 if (uentry_isUndefined (tf))
3909 voptgenerror (FLG_TYPE,
3910 message ("Access non-existent field %s of %t: %s", f, t,
3911 exprNode_unparse (ret)),
3913 /*! cstring_free (f); */ /* evans 2001-03-25 self-detect */
3918 uentry_setUsed (tf, exprNode_loc (ret));
3920 ret->typ = uentry_getType (tf);
3921 checkSafeUse (ret, s->sref);
3923 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
3924 /*!? exprNode_free (s); */ /* evans 2001-03-25 self-detect */
3928 else /* isStructorUnion */
3930 if (ctype_isRealAbstract (tr))
3934 message ("Access field of abstract type (%t): %s.%s",
3935 t, exprNode_unparse (s), f),
3937 ret->typ = ctype_unknown;
3941 if (ctype_isKnown (tr))
3946 ("Access field of non-struct or union (%t): %s.%s",
3947 t, exprNode_unparse (s), f),
3950 ret->typ = ctype_unknown;
3954 cstring sn = cstring_copy (f);
3956 checkSafeUse (ret, s->sref);
3957 cstring_markOwned (sn);
3958 ret->sref = sRef_makeField (s->sref, sn);
3970 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ lltok dot,
3971 /*@only@*/ cstring f)
3973 exprNode res = exprNode_fieldAccessAux (s, lltok_getLoc (dot), f);
3974 lltok_release (dot);
3979 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
3981 exprNode ret = exprNode_createPartialCopy (e);
3983 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
3984 ret->kind = XPR_PARENS;
3985 ret->edata = exprData_makeUop (e, lpar);
3987 if (!exprNode_isError (e))
3989 ret->exitCode = e->exitCode;
3990 ret->canBreak = e->canBreak;
3991 ret->mustBreak = e->mustBreak;
3992 ret->isJumpPoint = e->isJumpPoint;
3993 ret->sref = e->sref;
4000 exprNode_arrowAccessAux (/*@only@*/ exprNode s, /*@observer@*/ fileloc loc,
4001 /*@only@*/ cstring f)
4003 exprNode ret = exprNode_createPartialCopy (s);
4005 ret->edata = exprData_makeField (s, f);
4006 ret->kind = XPR_ARROW;
4008 if (exprNode_isError (s))
4014 ctype t = exprNode_getType (s);
4015 ctype tr = ctype_realType (t);
4017 checkMacroParen (s);
4019 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
4021 if (ctype_isRealPointer (tr))
4023 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
4025 if (ctype_isStructorUnion (b))
4027 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4029 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
4031 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
4035 message ("Arrow access from %s pointer%q: %s",
4036 sRef_nullMessage (s->sref),
4037 sRef_unparsePreOpt (s->sref),
4038 exprNode_unparse (ret)),
4041 sRef_showNullInfo (s->sref);
4042 sRef_setNullError (s->sref);
4047 if (uentry_isUndefined (fentry))
4051 message ("Access non-existent field %s of %t: %s",
4052 f, t, exprNode_unparse (ret)),
4054 ret->typ = ctype_unknown;
4060 ** was safeUse: shouldn't be safe!
4063 ** rec must be defined,
4064 ** *rec must be allocated
4065 ** rec->field need only be defined it if is an rvalue
4068 uentry_setUsed (fentry, exprNode_loc (ret));
4069 ret->typ = uentry_getType (fentry);
4071 exprNode_checkUse (ret, s->sref, s->loc);
4073 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
4074 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4078 else /* Pointer to something that is not a struct or union*/
4080 if (ctype_isRealAbstract (tr))
4082 ctype xrt = ctype_forceRealType (tr);
4086 message ("Arrow access field of abstract type (%t): %s->%s",
4087 t, exprNode_unparse (s), f),
4091 ** Set the state correctly, as if the abstraction is broken.
4094 if (ctype_isRealPointer (xrt) &&
4095 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
4096 ctype_isStructorUnion (b)))
4098 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
4099 ret->typ = uentry_getType (fentry);
4100 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
4104 ret->typ = ctype_unknown;
4105 ret->sref = sRef_undefined;
4108 else /* not a struct, union or abstract */
4110 if (ctype_isUnknown (tr)) {
4111 cstring sn = cstring_copy (f);
4113 DPRINTF (("Here: %s", exprNode_unparse (s)));
4115 exprNode_checkUse (ret, s->sref, s->loc);
4116 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4118 cstring_markOwned (sn);
4119 ret->sref = sRef_makeArrow (s->sref, sn);
4121 ret->kind = XPR_ARROW;
4126 message ("Arrow access field of non-struct or union "
4127 "pointer (%t): %s->%s",
4128 t, exprNode_unparse (s), f),
4131 ret->typ = ctype_unknown;
4132 ret->sref = sRef_undefined;
4137 else /* its not a pointer */
4139 if (!ctype_isUnknown (tr))
4143 message ("Arrow access of non-pointer (%t): %s->%s",
4144 t, exprNode_unparse (s), f),
4147 ret->typ = ctype_unknown;
4148 ret->sref = sRef_undefined;
4152 cstring sn = cstring_copy (f);
4154 DPRINTF (("Here: %s", exprNode_unparse (s)));
4156 exprNode_checkUse (ret, s->sref, s->loc);
4157 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
4159 cstring_markOwned (sn);
4160 ret->sref = sRef_makeArrow (s->sref, sn);
4162 ret->kind = XPR_ARROW;
4173 exprNode_arrowAccess (/*@only@*/ exprNode s,
4174 /*@only@*/ lltok arrow,
4175 /*@only@*/ cstring f)
4177 exprNode res = exprNode_arrowAccessAux (s, lltok_getLoc (arrow), f);
4178 lltok_release (arrow);
4183 ** only postOp's in C: i++ and i--
4187 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4189 /* check modification also */
4190 /* cstring opname = lltok_unparse (op);*/
4192 exprNode ret = exprNode_createPartialCopy (e);
4194 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4195 ret->kind = XPR_POSTOP;
4196 ret->edata = exprData_makeUop (e, op);
4198 if (!exprNode_isDefined (e))
4203 checkMacroParen (e);
4205 exprNode_checkUse (ret, e->sref, e->loc);
4206 exprNode_checkSet (ret, e->sref);
4208 t = exprNode_getType (e);
4210 if (sRef_isUnsafe (e->sref))
4212 voptgenerror (FLG_MACROPARAMS,
4213 message ("Operand of %s is macro parameter (non-functional): %s%s",
4214 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
4216 sRef_makeSafe (e->sref);
4217 sRef_makeSafe (ret->sref);
4220 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
4226 if (ctype_isRealAbstract (t))
4230 message ("Operand of %s is abstract type (%t): %s",
4231 lltok_unparse (op), t, exprNode_unparse (e)),
4238 message ("Operand of %s is non-numeric (%t): %s",
4239 lltok_unparse (op), t, exprNode_unparse (e)),
4242 ret->typ = ctype_unknown;
4245 /* if (ctype_isZero (t)) e->typ = ctype_int; */
4247 exprNode_checkModify (e, ret);
4249 /* added 7/11/2000 D.L */
4251 /*DRL 6/8/01 I decided to disable all LCLint Warning here since the code
4252 probably needs a rewrite any way */
4257 /* updateEnvironmentForPostOp (e); */
4259 /* start modifications */
4260 /* added by Seejo on 4/16/2000 */
4262 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4264 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4266 ret->sref = sRef_copy (e->sref);
4269 if (lltok_getTok (op) == INC_OP) {
4270 if (sRef_getSize(e->sref) > 0) {
4272 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4274 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4275 /* Assumption: there is only 1 \0 in the buffer */
4276 /* This will not be correct if there are 2 \0's in the buffer */
4277 sRef_setNotNullTerminatedState(ret->sref);
4278 sRef_resetLen(ret->sref);
4280 sRef_setNullTerminatedState(ret->sref);
4281 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4283 if (sRef_isNullTerminated (ret->sref))
4284 printf ("ret->sref is Null Terminated\n");
4285 else if (sRef_isPossiblyNullTerminated (ret->sref))
4286 printf ("ret->sref is Possibly Null Terminated\n");
4287 else if (sRef_isNotNullTerminated (ret->sref))
4288 printf ("ret->sref is Not Null Terminated\n");
4293 if (lltok_getTok (op) == DEC_OP) {
4294 if (sRef_getSize(e->sref) >= 0) {
4295 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4296 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4301 /* end modifications */
4307 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
4309 bool checkMod = FALSE;
4311 int opid = lltok_getTok (op);
4312 exprNode ret = exprNode_createSemiCopy (e);
4314 exprNode_copySets (ret, e);
4316 multiVal_free (ret->val);
4317 ret->val = multiVal_undefined;
4318 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
4319 ret->kind = XPR_PREOP;
4320 ret->edata = exprData_makeUop (e, op);
4322 if (exprNode_isError (e))
4327 checkMacroParen (e);
4329 te = exprNode_getType (e);
4330 tr = ctype_realType (te);
4332 if (opid != TAMPERSAND)
4334 exprNode_checkUse (ret, e->sref, e->loc);
4336 if (ctype_isRealAbstract (tr)
4337 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
4339 if (optgenerror (FLG_ABSTRACT,
4340 message ("Operand of %s is abstract type (%t): %s",
4341 lltok_unparse (op), tr,
4342 exprNode_unparse (ret)),
4345 tr = te = ctype_unknown;
4346 ret->typ = ctype_unknown;
4347 sRef_setNullError (e->sref);
4355 case DEC_OP: /* should also check modification! */
4356 if (sRef_isMacroParamRef (e->sref))
4360 message ("Operand of %s is macro parameter (non-functional): %s",
4361 lltok_unparse (op), exprNode_unparse (ret)),
4366 exprNode_checkSet (ret, e->sref);
4369 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
4374 if (context_msgStrictOps ())
4378 message ("Operand of %s is non-numeric (%t): %s",
4379 lltok_unparse (op), te, exprNode_unparse (ret)),
4382 ret->typ = ctype_int;
4385 /* start modifications */
4386 /* added by Seejo on 4/16/2000 */
4388 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4390 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
4392 ret->sref = sRef_copy (e->sref);
4395 if (lltok_getTok (op) == INC_OP) {
4396 if (sRef_getSize(e->sref) > 0) {
4398 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
4400 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
4401 /* Assumption: there is only 1 \0 in the buffer */
4402 /* This will not be correct if there are 2 \0's in the buffer */
4403 sRef_setNotNullTerminatedState(ret->sref);
4404 sRef_resetLen (ret->sref);
4406 sRef_setNullTerminatedState(ret->sref);
4407 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
4413 if (lltok_getTok (op) == DEC_OP) {
4414 if (sRef_getSize(e->sref) >= 0) {
4415 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
4416 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
4421 /* end modifications */
4428 if (ctype_isForceRealNumeric (&tr))
4432 ret->val = multiVal_invert (exprNode_getValue (e));
4436 ret->val = multiVal_copy (exprNode_getValue (e));
4441 if (context_msgStrictOps ())
4445 message ("Operand of %s is non-numeric (%t): %s",
4446 lltok_unparse (op), te, exprNode_unparse (ret)),
4450 ret->typ = ctype_int;
4454 case TEXCL: /* maybe this should be restricted */
4455 guardSet_flip (ret->guards);
4457 if (ctype_isRealBool (te) || ctype_isUnknown (te))
4463 if (ctype_isRealPointer (tr))
4465 if (sRef_isKnown (e->sref))
4467 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
4471 (FLG_BOOLOPS, FLG_PTRNEGATE,
4472 message ("Operand of %s is non-boolean (%t): %s",
4473 lltok_unparse (op), te, exprNode_unparse (ret)),
4480 message ("Operand of %s is non-boolean (%t): %s",
4481 lltok_unparse (op), te, exprNode_unparse (ret)),
4485 ret->typ = ctype_bool;
4490 if (ctype_isForceRealInt (&tr))
4495 if (context_msgStrictOps ())
4499 message ("Operand of %s is non-integer (%t): %s",
4500 lltok_unparse (op), te, exprNode_unparse (ret)),
4504 if (ctype_isInt (e->typ))
4510 ret->typ = ctype_int;
4516 ret->typ = ctype_makePointer (e->typ);
4518 if (sRef_isKnown (e->sref))
4520 ret->sref = sRef_makeAddress (e->sref);
4527 if (ctype_isAP (tr))
4529 ret->typ = ctype_baseArrayPtr (e->typ);
4533 if (ctype_isKnown (te))
4535 if (ctype_isFunction (te))
4541 message ("Dereference of function type (%t): %s",
4542 te, exprNode_unparse (ret)),
4547 voptgenerror (FLG_TYPE,
4548 message ("Dereference of non-pointer (%t): %s",
4549 te, exprNode_unparse (ret)),
4551 ret->typ = ctype_unknown;
4556 ret->typ = ctype_unknown;
4561 if (sRef_isKnown (e->sref))
4563 if (sRef_possiblyNull (e->sref))
4565 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
4569 message ("Dereference of %s pointer %q: %s",
4570 sRef_nullMessage (e->sref),
4571 sRef_unparse (e->sref),
4572 exprNode_unparse (ret)),
4575 sRef_showNullInfo (e->sref);
4576 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
4581 ret->sref = sRef_makePointer (e->sref);
4586 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
4591 exprNode_checkModify (e, ret);
4598 ** any reason to disallow sizeof (abstract type) ?
4602 ** used by both sizeof
4606 ctype sizeof_resultType (void)
4608 static ctype sizet = ctype_unknown;
4610 if (ctype_isUnknown (sizet))
4612 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
4614 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
4618 sizet = ctype_ulint;
4625 exprNode_sizeofType (/*@only@*/ qtype qt)
4627 exprNode ret = exprNode_create (sizeof_resultType ());
4628 ctype ct = qtype_getType (qt);
4630 ret->kind = XPR_SIZEOFT;
4631 ret->edata = exprData_makeSizeofType (qt);
4633 voptgenerror (FLG_SIZEOFTYPE,
4634 message ("Parameter to sizeof is type %s: %s",
4636 exprNode_unparse (ret)),
4643 exprNode_alignofType (/*@only@*/ qtype qt)
4645 exprNode ret = exprNode_create (sizeof_resultType ());
4646 ctype ct = qtype_getType (qt);
4648 ret->kind = XPR_ALIGNOFT;
4649 ret->edata = exprData_makeSizeofType (qt);
4651 voptgenerror (FLG_SIZEOFTYPE,
4652 message ("Parameter to alignof is type %s: %s",
4654 exprNode_unparse (ret)),
4660 exprNode exprNode_offsetof (qtype qt, cstringList s)
4662 exprNode ret = exprNode_create (sizeof_resultType ());
4663 ctype ct = qtype_getType (qt);
4665 ret->kind = XPR_OFFSETOF;
4666 ret->edata = exprData_makeOffsetof (qt, s);
4668 if (!ctype_isRealSU (ct))
4670 voptgenerror (FLG_TYPE,
4671 message ("First parameter to offsetof is not a "
4672 "struct or union type (type %s): %s",
4674 exprNode_unparse (ret)),
4681 cstringList_elements (s, el) {
4685 if (ctype_isUndefined (lt))
4689 else if (!ctype_isRealSU (lt))
4691 voptgenerror (FLG_TYPE,
4692 message ("Inner offsetof type is not a "
4693 "struct or union type (type %s before field %s): %s",
4694 ctype_unparse (lt), el,
4695 exprNode_unparse (ret)),
4701 fields = ctype_getFields (ctype_realType (lt));
4702 fld = uentryList_lookupField (fields, el);
4703 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4705 if (uentry_isUndefined (fld))
4707 if (ctype_equal (lt, ct)) {
4708 voptgenerror (FLG_TYPE,
4709 message ("Field %s in offsetof is not the "
4710 "name of a field of %s: %s",
4713 exprNode_unparse (ret)),
4716 voptgenerror (FLG_TYPE,
4717 message ("Deep field %s in offsetof is not the "
4718 "name of a field of %s: %s",
4721 exprNode_unparse (ret)),
4727 lt = uentry_getType (fld);
4730 } end_cstringList_elements;
4732 /* Should report error if its a bit field - behavior is undefined! */
4739 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4743 if (exprNode_isUndefined (e))
4745 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4746 ret->edata = exprData_makeSingle (e);
4747 ret->typ = sizeof_resultType ();
4748 ret->kind = XPR_SIZEOF;
4752 uentry u = exprNode_getUentry (e);
4754 ret = exprNode_createPartialCopy (e);
4755 ret->edata = exprData_makeSingle (e);
4757 ret->typ = sizeof_resultType ();
4758 ret->kind = XPR_SIZEOF;
4760 if (uentry_isValid (u)
4761 && uentry_isRefParam (u)
4762 && ctype_isRealArray (uentry_getType (u)))
4765 (FLG_SIZEOFFORMALARRAY,
4766 message ("Parameter to sizeof is an array-type function parameter: %s",
4767 exprNode_unparse (ret)),
4773 ** sizeof (x) doesn't "really" use x
4780 exprNode_alignofExpr (/*@only@*/ exprNode e)
4784 if (exprNode_isUndefined (e))
4786 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4790 ret = exprNode_createPartialCopy (e);
4793 ret->edata = exprData_makeSingle (e);
4794 ret->typ = sizeof_resultType ();
4795 ret->kind = XPR_ALIGNOF;
4798 ** sizeof (x) doesn't "really" use x
4805 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4811 if (exprNode_isError (e))
4814 lltok_release (tok);
4815 return exprNode_undefined;
4818 checkMacroParen (e);
4820 c = qtype_getType (q);
4821 t = exprNode_getType (e);
4823 ret = exprNode_createPartialCopy (e);
4825 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
4827 ret->kind = XPR_CAST;
4828 ret->edata = exprData_makeCast (tok, e, q);
4830 if (ctype_isRealSU (ctype_getBaseType (sRef_getType (e->sref))))
4833 ** This is a bit of a hack to avoid a problem
4834 ** when the code does,
4835 ** (some other struct) x
4840 ret->sref = sRef_copy (e->sref);
4841 usymtab_addForceMustAlias (ret->sref, e->sref);
4842 sRef_setTypeFull (ret->sref, c);
4843 DPRINTF (("Cast: %s -> %s", sRef_unparseFull (e->sref),
4844 sRef_unparseFull (ret->sref)));
4848 ret->sref = e->sref;
4849 sRef_setTypeFull (ret->sref, c);
4850 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
4857 ** void * <-> abstract * (if FLG_ABSTVOIDP)
4858 ** abstract * <-> void * (if FLG_ABSTVOIDP)
4861 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
4865 else if (ctype_isRealAP (c)) /* casting to array or pointer */
4867 ctype bc = ctype_getBaseType (c);
4868 ctype bt = ctype_getBaseType (t);
4869 ctype rt = ctype_realType (t);
4871 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
4872 && (ctype_isArrayPtr (rt)
4873 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4877 message ("Cast from function pointer type (%t) to "
4878 "non-function pointer (%t): %s",
4879 c, t, exprNode_unparse (ret)),
4883 if (!ctype_isFunction (ctype_baseArrayPtr (c))
4884 && (ctype_isArrayPtr (rt)
4885 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4889 message ("Cast from non-function pointer type (%t) to "
4890 "function pointer (%t): %s",
4891 c, t, exprNode_unparse (ret)),
4895 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
4896 !(ctype_isRealAbstract (bc)
4897 && context_hasAccess (ctype_typeId (bc))))
4899 ; /* okay to cast zero */
4903 if (ctype_isRealAbstract (bc)
4904 && !context_hasAccess (ctype_typeId (bc)))
4906 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
4910 message ("Cast to underlying abstract type %t: %s",
4911 c, exprNode_unparse (ret)),
4918 message ("Cast to underlying abstract type %t: %s",
4919 c, exprNode_unparse (ret)),
4924 if (ctype_isRealAbstract (bt)
4925 && !context_hasAccess (ctype_typeId (bt)))
4927 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
4931 message ("Cast from underlying abstract type %t: %s",
4932 t, exprNode_unparse (ret)),
4939 message ("Cast from underlying abstract type %t: %s",
4940 t, exprNode_unparse (ret)),
4948 ctype bt = ctype_realType (ctype_getBaseType (t));
4949 ctype bc = ctype_realType (ctype_getBaseType (c));
4951 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
4953 if (ctype_match (c, t))
4955 if (ctype_equal (c, t))
4959 message ("Redundant cast involving abstract type %t: %s",
4960 bt, exprNode_unparse (ret)),
4968 message ("Cast from abstract type %t: %s",
4969 bt, exprNode_unparse (ret)),
4974 if (ctype_isAbstract (bc)
4975 && !context_hasAccess (ctype_typeId (bc)))
4977 if (ctype_match (c, t))
4983 DPRINTF (("No access to: %s / %d",
4984 ctype_unparse (bc), ctype_typeId (bc)));
4985 DPRINTF (("Context %s %s",
4986 bool_unparse (context_inFunctionLike ()),
4987 context_unparse ()));
4990 message ("Cast to abstract type %t: %s", bc,
4991 exprNode_unparse (ret)),
4997 if (ctype_isAbstract (c))
4999 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
5001 /* okay, cast exposed to abstract */
5002 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
5006 if (ctype_isVisiblySharable (t)
5007 && sRef_isExternallyVisible (e->sref)
5008 && !(ctype_isAbstract (t)
5009 && context_hasAccess (ctype_typeId (t))))
5013 message ("Cast to abstract type from externally visible "
5014 "mutable storage exposes rep of %s: %s",
5016 exprNode_unparse (e)),
5026 evaluationOrderUndefined (lltok op)
5028 int opid = lltok_getTok (op);
5030 return (opid != AND_OP && opid != OR_OP);
5033 static bool checkIntegral (/*@notnull@*/ exprNode e1,
5034 /*@notnull@*/ exprNode e2,
5035 /*@notnull@*/ exprNode ret,
5040 ctype te1 = exprNode_getType (e1);
5041 ctype te2 = exprNode_getType (e2);
5043 ctype tr1 = ctype_realishType (te1);
5044 ctype tr2 = ctype_realishType (te2);
5046 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
5052 if (context_msgStrictOps ())
5054 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
5056 if (ctype_sameName (te1, te2))
5060 message ("Operands of %s are non-integer (%t): %s",
5061 lltok_unparse (op), te1,
5062 exprNode_unparse (ret)),
5069 message ("Operands of %s are non-integers (%t, %t): %s",
5070 lltok_unparse (op), te1, te2,
5071 exprNode_unparse (ret)),
5075 else if (!ctype_isInt (tr1))
5079 message ("Left operand of %s is non-integer (%t): %s",
5080 lltok_unparse (op), te1, exprNode_unparse (ret)),
5084 /* !ctype_isInt (te2) */
5088 message ("Right operand of %s is non-integer (%t): %s",
5089 lltok_unparse (op), te2, exprNode_unparse (ret)),
5099 ** returns exprNode representing e1 op e2
5101 ** uses msg if there are errors
5102 ** can be used for both assignment ops and regular ops
5107 static /*@only@*/ /*@notnull@*/ exprNode
5108 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
5109 /*@keep@*/ lltok op)
5111 ctype te1, te2, tr1, tr2, tret;
5112 int opid = lltok_getTok (op);
5113 bool hasError = FALSE;
5116 if (exprNode_isError (e1))
5118 ret = exprNode_createPartialNVCopy (e2);
5122 ret = exprNode_createPartialNVCopy (e1);
5125 ret->val = multiVal_undefined;
5127 ret->edata = exprData_makeOp (e1, e2, op);
5129 if (exprNode_isError (e1) || exprNode_isError (e2))
5131 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5132 || opid == EQ_OP || opid == NE_OP
5133 || opid == AND_OP || opid == OR_OP)
5135 ret->typ = ctype_bool;
5138 if (exprNode_isDefined (e1))
5140 exprNode_checkUse (ret, e1->sref, e1->loc);
5143 if (exprNode_isDefined (e2))
5145 exprNode_mergeUSs (ret, e2);
5146 exprNode_checkUse (ret, e2->sref, e2->loc);
5152 tret = ctype_unknown;
5153 te1 = exprNode_getType (e1);
5154 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
5156 te2 = exprNode_getType (e2);
5158 tr1 = ctype_realishType (te1);
5159 tr2 = ctype_realishType (te2);
5163 ret->guards = guardSet_or (ret->guards, e2->guards);
5165 else if (opid == AND_OP)
5167 ret->guards = guardSet_and (ret->guards, e2->guards);
5174 if (opid == EQ_OP || opid == NE_OP)
5176 exprNode temp1 = e1, temp2 = e2;
5178 /* could do NULL == x */
5180 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
5182 temp1 = e2; temp2 = e1;
5185 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
5187 reflectNullTest (temp1, (opid == NE_OP));
5188 guardSet_free (ret->guards);
5189 ret->guards = guardSet_copy (temp1->guards);
5193 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
5194 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
5199 if (anyAbstract (tr1, tr2) &&
5200 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
5201 (opid == AND_OP || opid == OR_OP
5202 || opid == EQ_OP || opid == NE_OP))))
5204 abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc);
5206 else if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
5208 /* unknown types, no comparisons possible */
5214 case TMULT: /* multiplication and division: */
5216 case MUL_ASSIGN: /* numeric, numeric -> numeric */
5217 case DIV_ASSIGN: /* */
5219 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5222 case TPLUS: /* addition and subtraction: */
5223 case TMINUS: /* pointer, int -> pointer */
5224 case SUB_ASSIGN: /* int, pointer -> pointer */
5225 case ADD_ASSIGN: /* numeric, numeric -> numeric */
5227 tr1 = ctype_fixArrayPtr (tr1);
5229 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
5230 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
5234 if (context_msgPointerArith ())
5238 message ("Pointer arithmetic (%t, %t): %s",
5239 te1, te2, exprNode_unparse (ret)),
5244 ** Swap terms so e1 is always the pointer
5247 if (ctype_isRealPointer (tr1))
5253 exprNode_swap (e1, e2);
5257 if (sRef_possiblyNull (e1->sref)
5258 && !usymtab_isGuarded (e1->sref))
5261 (FLG_NULLPOINTERARITH,
5262 message ("Pointer arithmetic involving possibly "
5263 "null pointer %s: %s",
5264 exprNode_unparse (e1),
5265 exprNode_unparse (ret)),
5269 ret->sref = sRef_copy (e1->sref);
5271 /* start modifications */
5272 /* added by Seejo on 4/16/2000 */
5274 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5276 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
5279 added ugly fixed to stop
5280 program from crashing on point + int +int
5281 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
5283 if (!multiVal_isInt (e2->val) )
5287 val = (int) multiVal_forceInt (e2->val);
5289 /* Operator : + or += */
5290 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5291 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
5292 val should not result in a
5293 size < 0 (size = 0 is ok !) */
5295 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
5297 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
5298 sRef_setNotNullTerminatedState(ret->sref);
5299 sRef_resetLen (ret->sref);
5301 sRef_setNullTerminatedState(ret->sref);
5302 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
5307 /* Operator : - or -= */
5308 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5309 if (sRef_getSize(e1->sref) >= 0) {
5310 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
5311 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
5316 /* end modifications */
5318 sRef_setNullError (ret->sref);
5321 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5322 ** since is points to storage that should not be deallocated
5323 ** through this pointer.
5326 if (sRef_isOnly (ret->sref)
5327 || sRef_isFresh (ret->sref))
5329 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5334 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
5335 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
5337 if (context_msgPointerArith ())
5341 message ("Pointer arithmetic (%t, %t): %s",
5342 te1, te2, exprNode_unparse (ret)),
5346 if (sRef_possiblyNull (e1->sref)
5347 && !usymtab_isGuarded (e1->sref))
5350 (FLG_NULLPOINTERARITH,
5351 message ("Pointer arithmetic involving possibly "
5352 "null pointer %s: %s",
5353 exprNode_unparse (e2),
5354 exprNode_unparse (ret)),
5358 ret->sref = sRef_copy (e2->sref);
5360 /* start modifications */
5361 /* added by Seejo on 4/16/2000 */
5363 /* Arithmetic operations on pointers wil modify the size/len/null terminated
5366 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
5367 int val = (int) multiVal_forceInt (e1->val);
5369 /* Operator : + or += */
5370 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
5371 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
5372 val should not result in a
5373 size < 0 (size = 0 is ok !) */
5375 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
5377 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
5378 sRef_setNotNullTerminatedState(ret->sref);
5379 sRef_resetLen (ret->sref);
5381 sRef_setNullTerminatedState(ret->sref);
5382 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
5387 /* Operator : - or -= */
5388 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
5389 if (sRef_getSize(e2->sref) >= 0) {
5390 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
5391 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
5396 /* end modifications */
5398 sRef_setNullError (ret->sref);
5401 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
5402 ** since is points to storage that should not be deallocated
5403 ** through this pointer.
5406 if (sRef_isOnly (ret->sref)
5407 || sRef_isFresh (ret->sref)) {
5408 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
5412 ret->sref = e2->sref;
5416 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5421 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
5425 case TAMPERSAND: /* bitwise & */
5427 case TCIRC: /* ^ (XOR) */
5432 bool reported = FALSE;
5433 flagcode code = FLG_BITWISEOPS;
5435 if (opid == LEFT_OP || opid == LEFT_ASSIGN
5436 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
5437 code = FLG_SHIFTSIGNED;
5440 if (!ctype_isUnsigned (tr1))
5442 if (exprNode_isNonNegative (e1)) {
5445 reported = optgenerror
5447 message ("Left operand of %s is not unsigned value (%t): %s",
5448 lltok_unparse (op), te1,
5449 exprNode_unparse (ret)),
5459 /* right need not be signed for shifts */
5460 if (code != FLG_SHIFTSIGNED
5461 && !ctype_isUnsigned (tr2))
5463 if (!exprNode_isNonNegative (e2)) {
5464 reported = optgenerror
5466 message ("Right operand of %s is not unsigned value (%t): %s",
5467 lltok_unparse (op), te2,
5468 exprNode_unparse (ret)),
5476 if (!checkIntegral (e1, e2, ret, op)) {
5477 te1 = ctype_unknown;
5481 DPRINTF (("Set: %s", ctype_unparse (te1)));
5484 ** tret is the widest type of te1 and te2
5487 tret = ctype_widest (te1, te2);
5492 if (checkIntegral (e1, e2, ret, op)) {
5495 tret = ctype_unknown;
5500 case TLT: /* comparisons */
5501 case TGT: /* numeric, numeric -> bool */
5502 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
5503 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
5506 bool fepsilon = FALSE;
5508 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
5513 if (opid == TLT || opid == TGT)
5515 uentry ue1 = exprNode_getUentry (e1);
5516 uentry ue2 = exprNode_getUentry (e2);
5519 ** FLT_EPSILON, etc. really is a variable, not
5523 if (uentry_isVariable (ue1))
5525 cstring uname = uentry_rawName (ue1);
5527 if (cstring_equalLit (uname, "FLT_EPSILON")
5528 || cstring_equalLit (uname, "DBL_EPSILON")
5529 || cstring_equalLit (uname, "LDBL_EPSILON"))
5535 if (uentry_isVariable (ue2))
5537 cstring uname = uentry_rawName (ue2);
5539 if (cstring_equalLit (uname, "FLT_EPSILON")
5540 || cstring_equalLit (uname, "DBL_EPSILON")
5541 || cstring_equalLit (uname, "LDBL_EPSILON"))
5550 ; /* Don't complain. */
5556 message ("Dangerous comparison involving %s types: %s",
5557 ctype_unparse (rtype),
5558 exprNode_unparse (ret)),
5567 ** Types should match.
5570 if (!exprNode_matchTypes (e1, e2))
5572 hasError = gentypeerror
5574 message ("Operands of %s have incompatible types (%t, %t): %s",
5575 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5581 || (ctype_isForceRealNumeric (&tr1)
5582 && ctype_isForceRealNumeric (&tr2)) ||
5583 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
5589 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
5590 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
5594 message ("Comparison of pointer and numeric (%t, %t): %s",
5595 te1, te2, exprNode_unparse (ret)),
5600 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
5605 /* certain comparisons on unsigned's and zero look suspicious */
5607 if (opid == TLT || opid == LE_OP || opid == GE_OP)
5609 if ((ctype_isUnsigned (tr1) && exprNode_isZero (e2))
5610 || (ctype_isUnsigned (tr2) && exprNode_isZero (e1)))
5613 (FLG_UNSIGNEDCOMPARE,
5614 message ("Comparison of unsigned value involving zero: %s",
5615 exprNode_unparse (ret)),
5620 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
5622 if ((opid == EQ_OP || opid == NE_OP) &&
5623 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
5626 ** is one a variable?
5629 if (uentry_isVariable (exprNode_getUentry (e1))
5630 || uentry_isVariable (exprNode_getUentry (e2)))
5633 ** comparisons with FALSE are okay
5636 if (exprNode_isFalseConstant (e1)
5637 || exprNode_isFalseConstant (e2))
5646 ("Use of %q with %s variables (risks inconsistency because "
5647 "of multiple true values): %s",
5648 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
5649 context_printBoolName (), exprNode_unparse (ret)),
5656 case AND_OP: /* bool, bool -> bool */
5659 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
5665 if (context_maybeSet (FLG_BOOLOPS))
5667 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
5669 if (ctype_sameName (te1, te2))
5673 message ("Operands of %s are non-boolean (%t): %s",
5674 lltok_unparse (op), te1,
5675 exprNode_unparse (ret)),
5683 ("Operands of %s are non-booleans (%t, %t): %s",
5684 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5688 else if (!ctype_isRealBool (te1))
5692 message ("Left operand of %s is non-boolean (%t): %s",
5693 lltok_unparse (op), te1, exprNode_unparse (ret)),
5696 else if (!ctype_isRealBool (te2))
5700 message ("Right operand of %s is non-boolean (%t): %s",
5701 lltok_unparse (op), te2, exprNode_unparse (ret)),
5714 (cstring_makeLiteral
5715 ("There has been a problem in the parser. This is believed to result "
5716 "from a problem with bison v. 1.25. Please try rebuidling LCLint "
5717 "using the pre-compiled grammar files by commenting out the "
5718 "BISON= line in the top-level Makefile."));
5723 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5726 exprNode_checkUse (ret, e1->sref, e1->loc);
5727 exprNode_mergeUSs (ret, e2);
5728 exprNode_checkUse (ret, e2->sref, e2->loc);
5734 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5735 /*@only@*/ lltok op)
5739 checkMacroParen (e1);
5740 checkMacroParen (e2);
5742 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5744 checkExpressionDefined (e1, e2, op);
5747 ret = exprNode_makeOp (e1, e2, op);
5752 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5755 ** This is somewhat bogus!
5757 ** Assigning to a nested observer in a non-observer datatype
5758 ** should not produce an error.
5761 sRef ref = exprNode_getSref (e1);
5763 DPRINTF (("Check assign mod: %s",
5764 sRef_unparseFull (ref)));
5766 if (sRef_isObserver (ref)
5767 || ((sRef_isFileStatic (ref) || sRef_isFileOrGlobalScope (ref))
5768 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5770 sRef base = sRef_getBase (ref);
5772 if (sRef_isValid (base) && sRef_isObserver (base))
5774 exprNode_checkModify (e1, ret);
5778 exprNode_checkModifyVal (e1, ret);
5783 exprNode_checkModify (e1, ret);
5788 exprNode_assign (/*@only@*/ exprNode e1,
5789 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5791 bool isalloc = FALSE;
5792 bool isjustalloc = FALSE;
5795 DPRINTF (("%s [%s] <- %s [%s]",
5796 exprNode_unparse (e1),
5797 ctype_unparse (e1->typ),
5798 exprNode_unparse (e2),
5799 ctype_unparse (e2->typ)));
5801 if (lltok_getTok (op) != TASSIGN)
5803 ret = exprNode_makeOp (e1, e2, op);
5807 ret = exprNode_createPartialCopy (e1);
5808 ret->kind = XPR_ASSIGN;
5809 ret->edata = exprData_makeOp (e1, e2, op);
5811 if (!exprNode_isError (e2))
5813 ret->sets = sRefSet_union (ret->sets, e2->sets);
5814 ret->msets = sRefSet_union (ret->msets, e2->msets);
5815 ret->uses = sRefSet_union (ret->uses, e2->uses);
5819 checkExpressionDefined (e1, e2, op);
5821 if (exprNode_isError (e1))
5823 if (!exprNode_isError (e2))
5825 ret->loc = fileloc_update (ret->loc, e2->loc);
5829 ret->loc = fileloc_update (ret->loc, g_currentloc);
5833 if (!exprNode_isError (e2))
5835 checkMacroParen (e2);
5838 if (exprNode_isDefined (e1))
5840 if (sRef_isMacroParamRef (e1->sref))
5842 if (context_inIterDef ())
5844 uentry ue = sRef_getUentry (e1->sref);
5846 if (uentry_isYield (ue))
5852 if (fileloc_isDefined (e1->loc))
5856 message ("Assignment to non-yield iter parameter: %q",
5857 sRef_unparse (e1->sref)),
5864 message ("Assignment to non-yield iter parameter: %q",
5865 sRef_unparse (e1->sref)),
5872 if (fileloc_isDefined (e1->loc))
5876 message ("Assignment to macro parameter: %q",
5877 sRef_unparse (e1->sref)),
5884 message ("Assignment to macro parameter: %q",
5885 sRef_unparse (e1->sref)),
5889 exprNode_checkAssignMod (e1, ret); /* evans 2001-07-22 */
5894 exprNode_checkAssignMod (e1, ret);
5897 if (exprNode_isDefined (e2))
5899 if (lltok_getTok (op) == TASSIGN)
5901 ctype te1 = exprNode_getType (e1);
5902 ctype te2 = exprNode_getType (e2);
5904 if (!ctype_forceMatch (te1, te2))
5906 if (exprNode_matchLiteral (te1, e2))
5914 message ("Assignment of %t to %t: %s %s %s",
5915 te2, te1, exprNode_unparse (e1),
5917 exprNode_unparse (e2)),
5923 exprNode_mergeUSs (ret, e2);
5924 exprNode_checkUse (ret, e2->sref, e2->loc);
5926 doAssign (e1, e2, FALSE);
5927 ret->sref = e1->sref;
5931 if (exprNode_isDefined (e2))
5933 exprNode_mergeUSs (ret, e2);
5934 exprNode_checkUse (ret, e2->sref, e2->loc);
5938 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5940 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5943 isjustalloc = sRef_isJustAllocated (e1->sref);
5944 isalloc = sRef_isAllocated (e1->sref);
5946 if (sRef_isField (e1->sref))
5948 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5950 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5952 exprNode_checkUse (ret, root, e1->loc);
5958 ** be careful! this defines e1->sref.
5961 /* evans 2001-07-22: removed if (!sRef_isMacroParamRef (e1->sref)) */
5963 DPRINTF (("Setting: %s -> %s", exprNode_unparse (ret), sRef_unparse (e1->sref)));
5964 exprNode_checkSet (ret, e1->sref);
5968 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5969 ? e2->loc : e1->loc);
5975 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5984 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5985 /*@keep@*/ exprNode elseclause)
5989 if (!exprNode_isError (pred))
5991 ret = exprNode_createPartialCopy (pred);
5992 checkMacroParen (pred);
5993 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
5995 if (!exprNode_isError (ifclause))
5997 checkMacroParen (ifclause); /* update macro counts! */
5999 if (!exprNode_isError (elseclause))
6001 checkMacroParen (elseclause);
6003 if (!exprNode_matchTypes (ifclause, elseclause))
6006 (exprNode_getType (ifclause),
6008 exprNode_getType (elseclause),
6010 message ("Conditional clauses are not of same type: "
6012 exprNode_unparse (ifclause),
6013 exprNode_getType (ifclause),
6014 exprNode_unparse (elseclause),
6015 exprNode_getType (elseclause)),
6018 ret->sref = sRef_undefined;
6019 ret->typ = ctype_unknown;
6024 /* for now...should merge the states */
6025 ret->sref = ifclause->sref;
6026 ret->typ = ifclause->typ;
6028 if (exprNode_isNullValue (ifclause))
6030 ret->typ = elseclause->typ;
6034 exprNode_checkUse (ret, pred->sref, pred->loc);
6035 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6036 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6038 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6043 ret->typ = ifclause->typ;
6045 exprNode_checkUse (pred, pred->sref, pred->loc);
6046 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6048 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
6053 if (!exprNode_isError (elseclause))
6055 ret->typ = elseclause->typ;
6057 exprNode_checkUse (pred, pred->sref, pred->loc);
6058 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6060 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6064 else /* pred is error */
6066 if (!exprNode_isError (ifclause))
6068 ret = exprNode_createSemiCopy (ifclause);
6070 checkMacroParen (ifclause); /* update macro counts! */
6072 if (!exprNode_isError (elseclause))
6074 checkMacroParen (elseclause);
6076 ret->typ = ifclause->typ;
6078 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
6081 (exprNode_getType (ifclause),
6083 exprNode_getType (elseclause),
6085 message ("Conditional clauses are not of same type: "
6087 exprNode_unparse (ifclause),
6088 exprNode_getType (ifclause),
6089 exprNode_unparse (elseclause),
6090 exprNode_getType (elseclause)),
6093 ret->typ = ctype_unknown;
6097 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
6098 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6100 exprNode_mergeCondUSs (ret, ifclause, elseclause);
6103 else if (!exprNode_isError (elseclause)) /* pred, if errors */
6105 ret = exprNode_createSemiCopy (ifclause);
6107 ret->typ = elseclause->typ;
6108 checkMacroParen (elseclause);
6110 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
6111 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
6113 else /* all errors! */
6115 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6119 ret->kind = XPR_COND;
6120 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
6122 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
6124 exprNode_combineControl (ret, ifclause, elseclause);
6131 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
6133 ctype totype = qtype_getType (qt);
6135 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
6139 ** check use of va_arg : <valist>, type -> type
6142 if (exprNode_isError (arg))
6147 targ = exprNode_getType (arg);
6150 ** arg should have be a pointer
6153 if (!ctype_isUA (targ) ||
6154 (!usymId_equal (ctype_typeId (targ),
6155 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
6159 message ("First argument to va_arg is not a va_list (type %t): %s",
6160 targ, exprNode_unparse (arg)),
6164 exprNode_checkSet (ret, arg->sref);
6168 ** return type is totype
6172 ret->kind = XPR_VAARG;
6173 ret->edata = exprData_makeCast (tok, arg, qt);
6178 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
6180 exprNode ret = exprNode_createPlain (ctype_undefined);
6181 ret->kind = XPR_LABEL;
6182 ret->edata = exprData_makeLiteral (label);
6183 ret->isJumpPoint = TRUE;
6185 return (ret); /* for now, ignore label */
6188 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
6190 if (exprNode_isDefined (stmt))
6192 stmt->isJumpPoint = TRUE;
6194 /* This prevent stray no return path errors, etc. */
6195 stmt->exitCode = XK_MUSTEXIT;
6201 bool exprNode_isDefaultMarker (exprNode e)
6203 if (exprNode_isDefined (e))
6205 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
6211 bool exprNode_isCaseMarker (exprNode e)
6213 if (exprNode_isDefined (e))
6215 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
6221 bool exprNode_isLabelMarker (exprNode e)
6223 if (exprNode_isDefined (e))
6225 return (e->kind == XPR_LABEL);
6231 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
6233 exprNode ret = exprNode_createPartialCopy (test);
6235 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6237 if (exprNode_isError (test)) {
6241 exprNode_checkUse (ret, test->sref, test->loc);
6243 usymtab_setExitCode (ret->exitCode);
6247 usymtab_setMustBreak ();
6250 ret->edata = exprData_makeSingle (test);
6251 ret->isJumpPoint = TRUE;
6257 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
6259 exprNode ret = exprNode_createPartialCopy (test);
6261 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
6262 ret->edata = exprData_makePair (test, stmt);
6263 ret->isJumpPoint = TRUE;
6265 if (exprNode_isError (test))
6270 exprNode_checkUse (ret, test->sref, test->loc);
6272 if (exprNode_isError (stmt))
6277 exprNode_mergeUSs (ret, stmt);
6279 ret->exitCode = stmt->exitCode;
6280 ret->mustBreak = stmt->mustBreak;
6281 ret->canBreak = stmt->canBreak;
6283 usymtab_setExitCode (ret->exitCode);
6287 usymtab_setMustBreak ();
6294 /*@notnull@*/ /*@only@*/ exprNode
6295 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
6297 exprNode ret = exprNode_createTok (def);
6299 ret->isJumpPoint = TRUE;
6300 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
6305 exprNode_mayEscape (exprNode e)
6307 if (exprNode_isDefined (e))
6309 return exitkind_couldEscape (e->exitCode);
6315 exprNode_mustBreak (exprNode e)
6317 if (exprNode_isDefined (e))
6319 return e->mustBreak;
6325 exprNode_mustEscape (exprNode e)
6327 if (exprNode_isDefined (e))
6329 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
6336 exprNode_errorEscape (exprNode e)
6338 if (exprNode_isDefined (e))
6340 return exitkind_isError (e->exitCode);
6346 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
6348 exprNode ret = exprNode_createPartialCopy (e1);
6350 DPRINTF (("Concat: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
6352 ret->edata = exprData_makePair (e1, e2);
6353 ret->kind = XPR_STMTLIST;
6355 if (exprNode_isDefined (e1))
6357 ret->isJumpPoint = e1->isJumpPoint;
6358 ret->canBreak = e1->canBreak;
6362 if (exprNode_isDefined (e2))
6364 ret->loc = fileloc_update (ret->loc, e2->loc);
6368 if (exprNode_isDefined (e2))
6370 ret->exitCode = e2->exitCode;
6371 ret->mustBreak = e2->mustBreak;
6372 if (e2->canBreak) ret->canBreak = TRUE;
6376 ** if e1 must return, then e2 is unreachable!
6379 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
6381 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
6382 && !(e2->isJumpPoint))
6384 if (context_getFlag (FLG_UNREACHABLE))
6388 if (e2->kind == XPR_STMT)
6390 nr = exprData_getUopNode (e2->edata);
6393 if ((nr->kind == XPR_TOK
6394 && lltok_isSemi (exprData_getTok (nr->edata))))
6396 /* okay to have unreachable ";" */
6397 ret->exitCode = XK_MUSTEXIT;
6398 ret->canBreak = TRUE;
6402 if (optgenerror (FLG_UNREACHABLE,
6403 message ("Unreachable code: %s",
6404 exprNode_unparseFirst (nr)),
6407 ret->isJumpPoint = TRUE;
6408 ret->mustBreak = FALSE;
6409 ret->exitCode = XK_ERROR;
6410 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
6414 ret->exitCode = XK_MUSTEXIT;
6415 ret->canBreak = TRUE;
6423 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
6426 ** We want a warning anytime we have:
6428 ** yyy; <<<- no break or return
6432 exprNode lastStmt = exprNode_lastStatement (e1);
6434 if (exprNode_isDefined (lastStmt)
6435 && !exprNode_mustEscape (lastStmt)
6436 && !exprNode_mustBreak (lastStmt)
6437 && !exprNode_isCaseMarker (lastStmt)
6438 && !exprNode_isDefaultMarker (lastStmt)
6439 && !exprNode_isLabelMarker (lastStmt))
6441 voptgenerror (FLG_CASEBREAK,
6443 ("Fall through case (no preceeding break)"),
6450 exprNode_mergeUSs (ret, e2);
6452 usymtab_setExitCode (ret->exitCode);
6456 usymtab_setMustBreak ();
6462 exprNode exprNode_createTok (/*@only@*/ lltok t)
6464 exprNode ret; /*@i23 if on same line, bad things happen...!@*/
6465 ret = exprNode_create (ctype_unknown);
6466 ret->kind = XPR_TOK;
6467 ret->edata = exprData_makeTok (t);
6471 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6473 if (!exprNode_isError (e))
6475 exprNode_checkStatement(e);
6478 return (exprNode_statementError (e, t));
6481 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
6483 exprNode ret = exprNode_createPartialCopy (e);
6485 if (!exprNode_isError (e))
6487 if (e->kind != XPR_ASSIGN)
6489 exprNode_checkUse (ret, e->sref, e->loc);
6492 ret->exitCode = e->exitCode;
6493 ret->canBreak = e->canBreak;
6494 ret->mustBreak = e->mustBreak;
6497 ret->edata = exprData_makeUop (e, t);
6498 ret->kind = XPR_STMT;
6503 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
6505 if (!exprNode_isError (e))
6507 if (e->kind != XPR_ASSIGN)
6509 exprNode_checkUse (e, e->sref, e->loc);
6516 void exprNode_produceGuards (exprNode pred)
6518 if (!exprNode_isError (pred))
6520 if (ctype_isRealPointer (pred->typ))
6522 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
6525 exprNode_checkUse (pred, pred->sref, pred->loc);
6526 exprNode_resetSref (pred);
6530 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
6532 exprNode ret = exprNode_createPartialCopy (e);
6534 if (!exprNode_isError (e))
6536 ret->exitCode = e->exitCode;
6537 ret->canBreak = e->canBreak;
6538 ret->mustBreak = e->mustBreak;
6541 ret->edata = exprData_makeSingle (e);
6542 ret->kind = XPR_BLOCK;
6546 bool exprNode_isBlock (exprNode e)
6548 return (exprNode_isDefined (e)
6549 && ((e)->kind == XPR_BLOCK));
6552 bool exprNode_isAssign (exprNode e)
6554 if (exprNode_isDefined (e))
6556 return (e->kind == XPR_ASSIGN);
6562 bool exprNode_isEmptyStatement (exprNode e)
6564 return (exprNode_isDefined (e)
6565 && (e->kind == XPR_TOK)
6566 && (lltok_isSemi (exprData_getTok (e->edata))));
6569 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
6572 bool emptyErr = FALSE;
6574 if (context_maybeSet (FLG_IFEMPTY))
6576 if (exprNode_isEmptyStatement (tclause))
6578 emptyErr = optgenerror (FLG_IFEMPTY,
6580 ("Body of if statement is empty"),
6581 exprNode_loc (tclause));
6585 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
6587 if (exprNode_isDefined (tclause)
6588 && !exprNode_isBlock (tclause))
6590 voptgenerror (FLG_IFBLOCK,
6592 ("Body of if statement is not a block: %s",
6593 exprNode_unparse (tclause)),
6594 exprNode_loc (tclause));
6598 if (exprNode_isError (pred))
6600 if (exprNode_isError (tclause))
6602 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6606 ret = exprNode_createPartialCopy (tclause);
6611 if (exprNode_mustEscape (pred))
6615 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6616 exprNode_loc (pred));
6619 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6620 exprNode_checkUse (pred, pred->sref, pred->loc);
6622 if (!exprNode_isError (tclause))
6624 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
6627 ret = exprNode_createPartialCopy (pred);
6631 ret->edata = exprData_makePair (pred, tclause);
6633 ret->exitCode = XK_UNKNOWN;
6635 if (exprNode_isDefined (tclause))
6637 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
6638 ret->canBreak = tclause->canBreak;
6639 ret->sets = sRefSet_union (ret->sets, tclause->sets);
6640 ret->msets = sRefSet_union (ret->msets, tclause->msets);
6641 ret->uses = sRefSet_union (ret->uses, tclause->uses);
6644 ret->mustBreak = FALSE;
6649 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
6650 /*@only@*/ exprNode tclause,
6651 /*@only@*/ exprNode eclause)
6654 bool tEmptyErr = FALSE;
6655 bool eEmptyErr = FALSE;
6657 if (context_maybeSet (FLG_IFEMPTY))
6659 if (exprNode_isEmptyStatement (tclause))
6661 tEmptyErr = optgenerror
6664 ("Body of if clause of if statement is empty"),
6665 exprNode_loc (tclause));
6668 if (exprNode_isEmptyStatement (eclause))
6670 eEmptyErr = optgenerror
6673 ("Body of else clause of if statement is empty"),
6674 exprNode_loc (eclause));
6678 if (context_maybeSet (FLG_IFBLOCK))
6681 && exprNode_isDefined (tclause)
6682 && !exprNode_isBlock (tclause))
6684 voptgenerror (FLG_IFBLOCK,
6686 ("Body of if clause of if statement is not a block: %s",
6687 exprNode_unparse (tclause)),
6688 exprNode_loc (tclause));
6692 && exprNode_isDefined (eclause)
6693 && !exprNode_isBlock (eclause)
6694 && !(eclause->kind == XPR_IF)
6695 && !(eclause->kind == XPR_IFELSE))
6700 ("Body of else clause of if statement is not a block: %s",
6701 exprNode_unparse (eclause)),
6702 exprNode_loc (eclause));
6706 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6708 if (exprNode_isDefined (eclause)
6709 && (eclause->kind == XPR_IF))
6711 voptgenerror (FLG_ELSEIFCOMPLETE,
6712 message ("Incomplete else if logic (no final else): %s",
6713 exprNode_unparse (eclause)),
6714 exprNode_loc (eclause));
6718 if (exprNode_isError (pred))
6720 if (exprNode_isError (tclause))
6722 if (exprNode_isError (eclause))
6724 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
6728 ret = exprNode_createPartialCopy (eclause);
6733 ret = exprNode_createPartialCopy (tclause);
6736 else /* pred is okay */
6738 ret = exprNode_createPartialCopy (pred);
6740 if (exprNode_mustEscape (pred))
6744 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6745 exprNode_loc (pred));
6748 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6749 exprNode_checkUse (ret, pred->sref, pred->loc);
6751 exprNode_mergeCondUSs (ret, tclause, eclause);
6754 ret->kind = XPR_IFELSE;
6755 ret->edata = exprData_makeCond (pred, tclause, eclause);
6757 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6759 exprNode_combineControl (ret, tclause, eclause);
6760 ret->loc = fileloc_update (ret->loc, eclause->loc);
6767 ** *allpaths <- TRUE iff all executions paths must go through the switch
6771 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6773 exprNodeSList el = exprNode_flatten (e);
6774 bool mustReturn = TRUE; /* find a branch that doesn't */
6775 bool thisReturn = FALSE;
6776 bool hasDefault = FALSE;
6777 bool hasAllMembers = FALSE;
6778 bool inSwitch = FALSE;
6779 bool isEnumSwitch = FALSE;
6780 bool canBreak = FALSE;
6781 bool fallThrough = FALSE;
6782 ctype ct = ctype_unknown;
6783 enumNameSList usedEnums;
6786 if (exprNode_isDefined (test))
6791 ttype = ctype_realType (ct);
6793 if (ctype_isEnum (ttype))
6795 isEnumSwitch = TRUE;
6796 enums = ctype_elist (ttype);
6797 usedEnums = enumNameSList_new ();
6801 exprNodeSList_elements (el, current)
6803 if (exprNode_isDefined (current))
6805 switch (current->kind)
6813 message ("Duplicate default cases in switch"),
6814 exprNode_loc (current));
6819 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6827 exprNode st = exprData_getSingle (current->edata);
6828 uentry ue = exprNode_getUentry (st);
6830 if (uentry_isValid (ue))
6832 cstring cname = uentry_rawName (ue);
6834 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6836 if (enumNameSList_member
6837 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6841 message ("Duplicate case in switch: %s",
6847 enumNameSList_addh (usedEnums, cname);
6854 message ("Case in switch not %s member: %s",
6855 ctype_unparse (ct), cname),
6862 if (inSwitch && !fallThrough)
6864 if (!thisReturn || canBreak)
6874 /*@switchbreak@*/ break;
6876 thisReturn = thisReturn || exprNode_mustEscape (current);
6877 canBreak = canBreak || current->canBreak;
6878 if (canBreak) fallThrough = FALSE;
6881 } end_exprNodeSList_elements;
6883 if (inSwitch) /* check the last one! */
6885 if (!thisReturn || canBreak)
6894 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6895 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6897 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6899 voptgenerror (FLG_MISSCASE,
6900 message ("Missing case%s in switch: %q",
6901 cstring_makeLiteralTemp
6902 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6903 enumNameSList_unparse (unused)),
6906 enumNameSList_free (unused);
6910 hasAllMembers = TRUE;
6914 enumNameSList_free (usedEnums);
6918 *allpaths = hasDefault;
6921 exprNodeSList_free (el);
6922 return ((hasDefault || hasAllMembers) && mustReturn);
6925 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6927 exprNode ret = exprNode_createPartialCopy (e);
6930 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6932 ret->kind = XPR_SWITCH;
6933 ret->edata = exprData_makePair (e, s);
6935 if (!exprNode_isError (s))
6937 exprNode fs = exprNode_firstStatement (s);
6938 ret->loc = fileloc_update (ret->loc, s->loc);
6940 if (exprNode_isUndefined (fs)
6941 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6942 || exprNode_isDefaultMarker (fs)) {
6945 voptgenerror (FLG_FIRSTCASE,
6947 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6952 if (!exprNode_isError (e))
6954 if (checkSwitchExpr (e, s, &allpaths))
6956 ret->exitCode = XK_MUSTRETURN;
6960 ret->exitCode = e->exitCode;
6963 ret->canBreak = e->canBreak;
6964 ret->mustBreak = e->mustBreak;
6968 ** exprNode.c:3883,32: Variable allpaths used before definition
6975 DPRINTF (("Context exit switch!"));
6976 context_exitSwitch (ret, allpaths);
6977 DPRINTF (("Context exit switch done!"));
6982 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6983 /*@notnull@*/ exprNode body)
6985 sRefSet tuses = test->uses;
6987 if (!sRefSet_isEmpty (test->uses))
6989 sRefSet sets = sRefSet_newCopy (body->sets);
6990 bool hasError = TRUE;
6991 bool innerState = FALSE;
6992 sRefSet tuncon = sRefSet_undefined;
6994 sets = sRefSet_union (sets, test->sets);
6995 sets = sRefSet_union (sets, body->msets);
6996 sets = sRefSet_union (sets, test->msets);
6998 sRefSet_allElements (tuses, el)
7000 if (sRef_isUnconstrained (el))
7002 tuncon = sRefSet_insert (tuncon, el);
7006 if (sRefSet_member (sets, el))
7013 if (sRef_isInternalState (el)
7014 || sRef_isFileStatic (sRef_getRootBase (el)))
7018 } end_sRefSet_allElements ;
7022 sRefSet suncon = sRefSet_undefined;
7023 bool sinner = FALSE;
7025 sRefSet_allElements (sets, el)
7027 if (sRef_isUnconstrained (el))
7029 suncon = sRefSet_insert (suncon, el);
7031 else if (sRef_isInternalState (el))
7039 } end_sRefSet_allElements ;
7041 if (sinner && innerState)
7045 else if (sRefSet_isEmpty (tuncon)
7046 && sRefSet_isEmpty (suncon))
7051 ("Suspected infinite loop. No value used in loop test (%q) "
7052 "is modified by test or loop body.",
7053 sRefSet_unparsePlain (tuses)),
7058 if (sRefSet_isEmpty (tuncon))
7062 message ("Suspected infinite loop. No condition values "
7063 "modified. Modification possible through "
7064 "unconstrained calls: %q",
7065 sRefSet_unparsePlain (suncon)),
7072 message ("Suspected infinite loop. No condition values "
7073 "modified. Possible undetected dependency through "
7074 "unconstrained calls in loop test: %q",
7075 sRefSet_unparsePlain (tuncon)),
7081 sRefSet_free (sets);
7085 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
7088 bool emptyErr = FALSE;
7090 if (context_maybeSet (FLG_WHILEEMPTY))
7092 if (exprNode_isEmptyStatement (b))
7094 emptyErr = optgenerror
7097 ("Body of while statement is empty"),
7102 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
7104 if (exprNode_isDefined (b)
7105 && !exprNode_isBlock (b))
7107 if (context_inIterDef ()
7108 && (b->kind == XPR_STMTLIST
7109 || b->kind == XPR_TOK))
7115 voptgenerror (FLG_WHILEBLOCK,
7117 ("Body of while statement is not a block: %s",
7118 exprNode_unparse (b)),
7124 if (exprNode_isError (t))
7126 if (exprNode_isError (b))
7128 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7132 ret = exprNode_createPartialCopy (b);
7139 ret = exprNode_createPartialCopy (t);
7141 llassert (t->kind == XPR_WHILEPRED);
7143 test = exprData_getSingle (t->edata);
7145 if (!exprNode_isError (b) && exprNode_isDefined (test))
7147 if (context_maybeSet (FLG_INFLOOPS)
7148 || context_maybeSet (FLG_INFLOOPSUNCON))
7151 ** check that some variable in the predicate is set by the body
7152 ** if the predicate uses any variables
7155 checkInfiniteLoop (test, b);
7158 exprNode_mergeUSs (ret, b);
7160 if (exprNode_isDefined (b))
7162 ret->exitCode = exitkind_makeConditional (b->exitCode);
7167 ret->edata = exprData_makePair (t, b);
7168 ret->kind = XPR_WHILE;
7170 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
7174 message ("Predicate always exits: %s", exprNode_unparse (t)),
7178 ret->exitCode = XK_NEVERESCAPE;
7181 ** If loop is infinite, and there is no break inside,
7182 ** exit code is never reach.
7185 if (exprNode_knownIntValue (t))
7187 if (!exprNode_isZero (t))
7189 if (exprNode_isDefined (b))
7193 /* Really, it means never reached. */
7194 ret->exitCode = XK_MUSTEXIT;
7204 ret->canBreak = FALSE;
7205 ret->mustBreak = FALSE;
7211 ** do { b } while (t);
7213 ** note: body passed as first argument
7216 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
7220 if (exprNode_isError (t))
7222 if (exprNode_isError (b))
7224 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7228 ret = exprNode_createPartialCopy (b);
7230 ret->exitCode = exitkind_makeConditional (b->exitCode);
7231 exprNode_checkUse (ret, b->sref, b->loc);
7232 ret->exitCode = b->exitCode;
7233 ret->canBreak = b->canBreak;
7234 ret->mustBreak = b->mustBreak;
7239 ret = exprNode_createPartialCopy (t);
7240 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
7242 if (!exprNode_isError (b))
7245 ** forgot the copy's --- why wasn't this detected??
7248 ret->sets = sRefSet_copyInto (ret->sets, b->sets);
7249 ret->msets = sRefSet_copyInto (ret->msets, b->msets);
7250 ret->uses = sRefSet_copyInto (ret->uses, b->uses);
7252 /* left this out --- causes and aliasing bug (infinite loop)
7253 should be detected?? */
7255 exprNode_checkUse (ret, b->sref, b->loc);
7256 exprNode_mergeUSs (ret, t);
7257 exprNode_checkUse (ret, t->sref, t->loc);
7259 ret->exitCode = b->exitCode;
7260 ret->canBreak = b->canBreak;
7261 ret->mustBreak = b->mustBreak;
7265 context_exitDoWhileClause (t);
7267 ret->kind = XPR_DOWHILE;
7268 ret->edata = exprData_makePair (t, b);
7272 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
7275 bool emptyErr = FALSE;
7277 if (context_maybeSet (FLG_FOREMPTY))
7279 if (exprNode_isEmptyStatement (body))
7281 emptyErr = optgenerror
7284 ("Body of for statement is empty"),
7285 exprNode_loc (body));
7289 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
7291 if (exprNode_isDefined (body)
7292 && !exprNode_isBlock (body))
7294 if (context_inIterDef ()
7295 && (body->kind == XPR_STMTLIST
7296 || body->kind == XPR_TOK))
7302 voptgenerror (FLG_FORBLOCK,
7304 ("Body of for statement is not a block: %s",
7305 exprNode_unparse (body)),
7306 exprNode_loc (body));
7312 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
7315 if (exprNode_isError (body))
7317 ret = exprNode_createPartialCopy (inc);
7321 ret = exprNode_createPartialCopy (body);
7323 ret->exitCode = exitkind_makeConditional (body->exitCode);
7325 exprNode_mergeUSs (inc, body);
7327 if (exprNode_isDefined (inc))
7331 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
7334 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
7335 exprNode_freeShallow (tmp);
7337 context_clearMessageAnnote ();
7338 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
7340 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
7341 exprNode_freeShallow (tmp);
7343 context_clearMessageAnnote ();
7345 ret->uses = sRefSet_copyInto (ret->uses, inc->uses);
7346 ret->sets = sRefSet_copyInto (ret->sets, inc->sets);
7347 ret->msets = sRefSet_copyInto (ret->msets, inc->msets);
7351 ret->kind = XPR_FOR;
7352 ret->edata = exprData_makePair (inc, body);
7354 if (exprNode_isDefined (inc)) {
7355 exprNode test = exprData_getTripleTest (inc->edata);
7357 if (exprNode_isUndefined (test)) {
7358 if (exprNode_isDefined (body)) {
7359 if (!body->canBreak) {
7360 /* Really, it means never reached. */
7361 ret->exitCode = XK_MUSTEXIT;
7371 ** for (init; test; inc)
7374 ** while (test) { body; inc; }
7376 ** Now: check use of init (may set vars for test)
7377 ** check use of test
7381 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
7385 if (exprNode_isError (pred)) return guardSet_undefined;
7387 llassert (pred->kind == XPR_FORPRED);
7389 test = exprData_getTripleTest (pred->edata);
7391 if (!exprNode_isError (test))
7393 return (test->guards);
7396 return guardSet_undefined;
7399 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
7401 exprNode ret = exprNode_createSemiCopy (test);
7403 if (exprNode_isDefined (test))
7405 exprNode_copySets (ret, test);
7406 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
7407 exprNode_checkUse (ret, test->sref, test->loc);
7409 exprNode_produceGuards (test);
7411 ret->guards = guardSet_copy (test->guards);
7414 ret->edata = exprData_makeSingle (test);
7415 ret->kind = XPR_WHILEPRED;
7419 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
7420 /*@only@*/ exprNode inc)
7425 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
7428 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
7430 if (!exprNode_isError (inc))
7432 ret = exprNode_createPartialCopy (inc);
7436 if (!exprNode_isError (init))
7438 ret = exprNode_createPartialCopy (init);
7440 else if (!exprNode_isError (test))
7442 ret = exprNode_createPartialCopy (test);
7446 ret = exprNode_createUnknown ();
7450 exprNode_mergeUSs (ret, init);
7452 if (exprNode_isDefined (init))
7454 exprNode_checkUse (ret, init->sref, init->loc);
7457 exprNode_mergeUSs (ret, test);
7459 if (exprNode_isDefined (test))
7461 exprNode_checkUse (ret, test->sref, test->loc);
7464 ret->kind = XPR_FORPRED;
7465 ret->edata = exprData_makeFor (init, test, inc);
7469 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
7471 exprNode ret = exprNode_createUnknown ();
7473 if (context_inMacro ())
7475 voptgenerror (FLG_MACROSTMT,
7476 message ("Macro %s uses goto (not functional)",
7477 context_inFunctionName ()),
7481 ret->kind = XPR_GOTO;
7482 ret->edata = exprData_makeLiteral (label);
7483 ret->mustBreak = TRUE;
7484 ret->exitCode = XK_GOTO;
7485 ret->canBreak = TRUE;
7489 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
7491 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7493 ret->kind = XPR_CONTINUE;
7494 ret->edata = exprData_makeTok (l);
7495 ret->canBreak = TRUE;
7496 ret->mustBreak = TRUE;
7498 if (qcontinue == QSAFEBREAK)
7502 else if (qcontinue == QINNERCONTINUE)
7504 if (!context_inDeepLoop ())
7507 (FLG_LOOPLOOPCONTINUE,
7508 cstring_makeLiteral ("Continue statement marked with innercontinue "
7509 "is not inside a nested loop"),
7510 exprNode_loc (ret));
7513 else if (qcontinue == BADTOK)
7515 if (context_inDeepLoop ())
7518 (FLG_LOOPLOOPCONTINUE,
7519 cstring_makeLiteral ("Continue statement in nested loop"),
7520 exprNode_loc (ret));
7525 llbuglit ("exprNode_continue: bad qcontinue");
7531 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
7533 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
7534 clause breakClause = context_breakClause ();
7536 ret->kind = XPR_BREAK;
7537 ret->edata = exprData_makeTok (l);
7538 ret->canBreak = TRUE;
7539 ret->mustBreak = TRUE;
7541 if (breakClause == NOCLAUSE)
7545 cstring_makeLiteral ("Break not inside while, for or switch statement"),
7546 exprNode_loc (ret));
7550 if (bqual != BADTOK)
7557 if (breakClause == SWITCHCLAUSE)
7559 if (!context_inDeepSwitch ())
7561 voptgenerror (FLG_SYNTAX,
7563 ("Break preceded by innerbreak is not in a deep switch"),
7564 exprNode_loc (ret));
7569 if (!context_inDeepLoop ())
7571 voptgenerror (FLG_SYNTAX,
7573 ("Break preceded by innerbreak is not in a deep loop"),
7574 exprNode_loc (ret));
7579 if (breakClause == SWITCHCLAUSE)
7581 voptgenerror (FLG_SYNTAX,
7583 ("Break preceded by loopbreak is breaking a switch"),
7584 exprNode_loc (ret));
7588 if (breakClause != SWITCHCLAUSE)
7592 message ("Break preceded by switchbreak is breaking %s",
7593 cstring_makeLiteralTemp
7594 ((breakClause == WHILECLAUSE
7595 || breakClause == DOWHILECLAUSE) ? "a while loop"
7596 : (breakClause == FORCLAUSE) ? "a for loop"
7597 : (breakClause == ITERCLAUSE) ? "an iterator"
7599 exprNode_loc (ret));
7607 if (breakClause == SWITCHCLAUSE)
7609 clause nextBreakClause = context_nextBreakClause ();
7611 switch (nextBreakClause)
7613 case NOCLAUSE: break;
7619 (FLG_LOOPSWITCHBREAK,
7620 cstring_makeLiteral ("Break statement in switch inside loop"),
7621 exprNode_loc (ret));
7625 (FLG_SWITCHSWITCHBREAK,
7626 cstring_makeLiteral ("Break statement in switch inside switch"),
7627 exprNode_loc (ret));
7634 if (context_inDeepLoop ())
7638 cstring_makeLiteral ("Break statement in nested loop"),
7639 exprNode_loc (ret));
7643 if (context_inDeepLoopSwitch ())
7646 (FLG_SWITCHLOOPBREAK,
7647 cstring_makeLiteral ("Break statement in loop inside switch"),
7648 exprNode_loc (ret));
7658 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
7660 fileloc loc = lltok_getLoc (t);
7661 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
7663 context_returnFunction ();
7664 exprChecks_checkNullReturn (loc);
7666 ret->kind = XPR_NULLRETURN;
7667 ret->edata = exprData_makeTok (t);
7668 ret->exitCode = XK_MUSTRETURN;
7672 exprNode exprNode_return (/*@only@*/ exprNode e)
7676 if (exprNode_isError (e))
7678 ret = exprNode_createUnknown ();
7682 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7684 exprNode_checkUse (ret, e->sref, e->loc);
7685 exprNode_checkReturn (e);
7688 context_returnFunction ();
7689 ret->kind = XPR_RETURN;
7690 ret->edata = exprData_makeSingle (e);
7691 ret->exitCode = XK_MUSTRETURN;
7696 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7700 if (exprNode_isError (e1))
7702 if (exprNode_isError (e2))
7704 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
7708 ret = exprNode_createPartialCopy (e2);
7709 exprNode_checkUse (ret, e2->sref, e2->loc);
7710 ret->sref = e2->sref;
7715 ret = exprNode_createPartialCopy (e1);
7717 exprNode_checkUse (ret, e1->sref, e1->loc);
7719 if (!exprNode_isError (e2))
7721 exprNode_mergeUSs (ret, e2);
7722 exprNode_checkUse (ret, e2->sref, e2->loc);
7723 ret->sref = e2->sref;
7727 ret->kind = XPR_COMMA;
7728 ret->edata = exprData_makePair (e1, e2);
7730 if (exprNode_isDefined (e1))
7732 if (exprNode_isDefined (e2))
7736 if (exprNode_mustEscape (e1) || e1->mustBreak)
7740 message ("Second clause of comma expression is unreachable: %s",
7741 exprNode_unparse (e2)),
7745 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7746 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7747 ret->canBreak = e1->canBreak || e2->canBreak;
7751 if (exprNode_mustEscape (e1) || e1->mustBreak)
7755 message ("Second clause of comma expression is unreachable: %s",
7756 exprNode_unparse (e2)),
7760 ret->exitCode = e1->exitCode;
7761 ret->canBreak = e1->canBreak;
7766 if (exprNode_isDefined (e2))
7768 ret->exitCode = e2->exitCode;
7769 ret->mustBreak = e2->mustBreak;
7770 ret->canBreak = e2->canBreak;
7777 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7779 ctype t1 = exprNode_getType (el);
7780 ctype t2 = exprNode_getType (val);
7781 bool hasError = FALSE;
7783 if (ctype_isUnknown (t1))
7785 voptgenerror (FLG_IMPTYPE,
7786 message ("Variable has unknown (implicitly int) type: %s",
7787 exprNode_unparse (el)),
7791 el->typ = ctype_int;
7794 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7796 exprNodeList vals = exprData_getArgs (val->edata);
7798 if (ctype_isRealAP (t1))
7803 /*@i423 check number of entries int a[3] = { 1, 2, 3, 4 } ; */
7805 exprNodeList_elements (vals, oneval)
7807 cstring istring = message ("%d", i);
7810 (exprNode_fakeCopy (el),
7811 exprNode_numLiteral (ctype_int, istring,
7812 fileloc_copy (el->loc), i));
7814 if (exprNode_isDefined (newel))
7816 if (exprNodeList_size (vals) == 1
7817 && ctype_isString (exprNode_getType (oneval))
7818 && ctype_isChar (exprNode_getType (newel)))
7820 exprNode_freeIniter (newel);
7824 if (exprNode_checkOneInit (newel, oneval))
7829 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7832 (message ("Additional initialization errors "
7833 "for %s not reported",
7834 exprNode_unparse (el)),
7836 exprNode_freeIniter (newel);
7841 exprNode_freeIniter (newel);
7846 exprNode_freeIniter (newel);
7851 cstring_free (istring);
7854 } end_exprNodeList_elements;
7857 else if (ctype_isStruct (ctype_realType (t1)))
7859 uentryList fields = ctype_getFields (t1);
7862 if (uentryList_size (fields) != exprNodeList_size (vals))
7864 if (uentryList_size (fields) > exprNodeList_size (vals))
7866 hasError = optgenerror
7868 message ("Initializer block for "
7869 "%s has %d field%&, but %s has %d field%&: %q",
7870 exprNode_unparse (el),
7871 exprNodeList_size (vals),
7873 uentryList_size (fields),
7874 exprNodeList_unparse (vals)),
7879 hasError = optgenerror
7881 message ("Initializer block for "
7882 "%s has %d field%&, but %s has %d field%&: %q",
7883 exprNode_unparse (el),
7884 exprNodeList_size (vals),
7886 uentryList_size (fields),
7887 exprNodeList_unparse (vals)),
7893 exprNodeList_elements (vals, oneval)
7895 uentry thisfield = uentryList_getN (fields, i);
7897 exprNode_fieldAccessAux (exprNode_fakeCopy (el),
7899 uentry_getName (thisfield));
7901 if (exprNode_isDefined (newel))
7903 if (exprNode_checkOneInit (newel, oneval))
7908 exprNode_freeIniter (newel);
7912 } end_exprNodeList_elements;
7917 hasError = optgenerror
7919 message ("Initializer block used for "
7920 "%s where %t is expected: %s",
7921 exprNode_unparse (el), t1, exprNode_unparse (val)),
7927 if (exprNode_isDefined (val))
7929 doAssign (el, val, TRUE);
7931 if (!exprNode_matchType (t1, val))
7933 hasError = gentypeerror
7935 message ("Initial value of %s is type %t, "
7937 exprNode_unparse (el),
7938 t2, t1, exprNode_unparse (val)),
7948 exprNode_makeInitializationAux (/*@temp@*/ idDecl t)
7952 if (usymtab_exists (idDecl_observeId (t)))
7954 uentry ue = usymtab_lookup (idDecl_observeId (t));
7955 ret = exprNode_createId (ue);
7957 /*@i723 don't do this...but why? */
7959 ct = ctype_realishType (ret->typ);
7961 DPRINTF (("Type: %s", ctype_unparse (ret->typ)));
7963 if (ctype_isUnknown (ct))
7965 if (uentry_isAnyTag (ue))
7969 message ("%s used but not previously declared: %s",
7970 uentry_ekindName (ue),
7971 idDecl_getName (t)),
7979 message ("Variable has unknown (implicitly int) type: %s",
7980 idDecl_getName (t)),
7992 DPRINTF (("Unrecognized: %s", idDecl_unparse (t)));
7994 ue = uentry_makeUnrecognized (idDecl_observeId (t), fileloc_copy (g_currentloc));
7995 /*!! fileloc_copy (g_currentloc)); */
7996 /*@i32!!! should get error without this */
7997 ret = exprNode_fromIdentifierAux (ue);
8000 ** No error - this happens in old style declarations:
8004 message ("Unrecognized identifier in intializer: %s", idDecl_observeId (t)),
8011 exprData_free (ret->edata, ret->kind);
8012 ret->edata = exprData_undefined;
8014 ret->exitCode = XK_NEVERESCAPE;
8015 ret->mustBreak = FALSE;
8016 ret->kind = XPR_INIT;
8020 exprNode exprNode_makeEmptyInitialization (/*@only@*/ idDecl t)
8022 exprNode ret = exprNode_makeInitializationAux (t);
8023 llassert (ret->edata == exprData_undefined);
8024 ret->edata = exprData_makeInit (t, exprNode_undefined);
8028 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
8029 /*@only@*/ exprNode e)
8031 uentry ue = usymtab_lookup (idDecl_observeId (t));
8032 exprNode ret = exprNode_makeInitializationAux (t);
8033 fileloc loc = exprNode_loc (e);
8035 if (exprNode_isError (e))
8037 e = exprNode_createUnknown ();
8040 /* error: assume initializer is defined */
8041 sRef_setDefined (ret->sref, g_currentloc);
8045 ctype ct = ctype_realishType (ret->typ);
8050 ** was addSafeUse --- what's the problem?
8052 ** int x = 3, y = x ?
8055 exprData_free (ret->edata, ret->kind);
8056 ret->edata = exprData_makeInit (t, e);
8058 exprNode_checkUse (ret, e->sref, e->loc);
8060 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
8062 exprNode lhs = exprNode_createId (ue);
8065 ** static storage should be undefined before initializing
8068 if (uentry_isStatic (ue))
8070 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
8073 (void) exprNode_checkOneInit (lhs, e);
8075 if (uentry_isStatic (ue))
8077 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
8080 exprNode_free (lhs);
8084 if (!exprNode_matchType (ct, e))
8086 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
8093 (exprNode_getType (e), e, exprNode_getType (ret), ret,
8095 ("Variable %q initialized to type %t, expects %t: %s",
8096 uentry_getName (ue), exprNode_getType (e),
8097 exprNode_getType (ret),
8098 exprNode_unparse (e)),
8104 if (uentry_isStatic (ue))
8106 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
8109 doAssign (ret, e, TRUE);
8111 if (uentry_isStatic (ue))
8113 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
8117 if (context_inIterDef ())
8119 /* should check if it is yield */
8120 uentry_setUsed (ue, loc);
8127 exprNode_mergeUSs (ret, e);
8131 exprNode exprNode_iter (/*@observer@*/ uentry name,
8132 /*@only@*/ exprNodeList alist,
8133 /*@only@*/ exprNode body,
8134 /*@observer@*/ uentry end)
8139 llassert (uentry_isValid (name));
8141 uentry_setUsed (name, exprNode_loc (body));
8143 ret = exprNode_createPartialCopy (body);
8144 iname = uentry_getName (name);
8146 if (uentry_isInvalid (end))
8149 message ("Iter %s not balanced with end_%s", iname, iname));
8153 cstring ename = uentry_getName (end);
8155 if (!cstring_equalPrefix (ename, "end_"))
8157 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
8158 iname, iname, ename));
8162 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
8165 message ("Iter %s not balanced with end_%s: %s",
8166 iname, iname, ename));
8170 cstring_free (ename);
8173 context_exitIterClause (body);
8175 ret->kind = XPR_ITER;
8176 ret->edata = exprData_makeIter (name, alist, body, end);
8178 if (uentry_isIter (name))
8180 (void) checkArgsReal (name, body,
8181 uentry_getParams (name), alist, TRUE, ret);
8184 cstring_free (iname);
8190 exprNode_iterNewId (/*@only@*/ cstring s)
8192 exprNode e = exprNode_new ();
8193 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
8195 llassert (processingIterVars ());
8197 e->loc = context_getSaveLocation ();
8199 if (fileloc_isUndefined (e->loc))
8201 fileloc_free (e->loc);
8202 e->loc = fileloc_copy (g_currentloc);
8205 e->uses = sRefSet_new ();
8206 e->sets = sRefSet_new ();
8207 e->msets = sRefSet_new ();
8209 e->val = multiVal_unknown ();
8210 e->guards = guardSet_new ();
8212 e->isJumpPoint = FALSE;
8213 e->exitCode = XK_NEVERESCAPE;
8215 /*> missing fields, detected by lclint <*/
8216 e->canBreak = FALSE;
8217 e->mustBreak = FALSE;
8218 e->etext = cstring_undefined;
8220 if (uentry_isYield (ue))
8222 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
8223 fileloc_copy (e->loc),
8227 uue = usymtab_supEntrySrefReturn (uue);
8229 sr = uentry_getSref (uue);
8230 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
8231 sr = uentry_getSref (uue);
8232 sRef_setDefined (sr, e->loc);
8234 e->typ = uentry_getType (uue);
8236 e->edata = exprData_makeId (uue);
8237 uentry_setUsed (uue, g_currentloc);
8243 sRef_setGlobalScope ();
8244 uue = uentry_makeVariableLoc (s, ctype_unknown);
8246 e->typ = ctype_unknown;
8247 e->edata = exprData_makeId (uue);
8249 uentry_setUsed (uue, e->loc);
8250 uentry_setHasNameError (uue);
8252 if (context_getFlag (FLG_REPEATUNRECOG))
8254 uentry_markOwned (uue);
8258 usymtab_supGlobalEntry (uue);
8261 sRef_clearGlobalScope ();
8263 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
8270 exprNode_defineConstraints(e);
8275 exprNode_iterExpr (/*@returned@*/ exprNode e)
8277 if (!processingIterVars ())
8279 llcontbuglit ("checkIterParam: not in iter");
8283 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
8286 if (exprNode_isDefined (e))
8288 if (fileloc_isDefined (e->loc))
8292 message ("Yield parameter is not simple identifier: %s",
8293 exprNode_unparse (e)),
8300 message ("Yield parameter is not simple identifier: %s",
8301 exprNode_unparse (e)),
8311 exprNode_iterId (/*@observer@*/ uentry c)
8315 llassert (processingIterVars ());
8317 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
8320 if (uentry_isYield (ue))
8322 ctype ct = uentry_getType (ue);
8323 exprNode e = exprNode_createPlain (ct);
8324 cstring name = uentry_getName (c);
8325 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
8327 uentry_setUsed (ue, g_currentloc);
8328 uentry_setHasNameError (ue);
8330 cstring_free (name);
8333 e->edata = exprData_makeId (le);
8334 e->loc = context_getSaveLocation ();
8335 e->sref = uentry_getSref (le);
8337 usymtab_supEntrySref (le);
8339 if (!context_inHeader ())
8343 message ("Yield parameter shadows local declaration: %q",
8344 uentry_getName (c)),
8345 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
8347 uentry_showWhereDeclared (c);
8354 return (exprNode_fromIdentifierAux (c));
8357 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
8359 exprNode ret = exprNode_create (ctype_unknown);
8361 ret->kind = XPR_ITERCALL;
8362 ret->edata = exprData_makeIterCall (name, alist);
8364 if (uentry_isIter (name))
8366 uentryList params = uentry_getParams (name);
8368 if (context_inIterDef ()
8369 && uentryList_size (params) == exprNodeList_size (alist))
8373 exprNodeList_elements (alist, arg)
8375 uentry parg = uentryList_getN (params, i);
8377 if (uentry_isYield (parg))
8379 uentry ue = exprNode_getUentry (arg);
8381 if (uentry_isValid (ue))
8388 } end_exprNodeList_elements;
8391 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
8392 checkUnspecCall (ret, params, alist);
8398 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
8400 if (exprNode_isDefined (e))
8403 if (e->sref == defref) /*@noaccess sRef@*/
8406 e->sref = sRef_makeUnknown ();
8407 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
8418 return sRef_undefined;
8422 /*@observer@*/ cstring
8423 exprNode_unparseFirst (exprNode e)
8425 if (exprNode_isDefined (e))
8429 if (e->kind == XPR_STMTLIST
8430 || e->kind == XPR_COMMA || e->kind == XPR_COND)
8432 exprNode first = exprData_getPairA (e->edata);
8434 if (exprNode_isDefined (first))
8436 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
8440 return (cstring_makeLiteralTemp ("..."));
8444 ret = cstring_elide (exprNode_unparse (e), 20);
8445 cstring_markOwned (ret);
8451 return cstring_makeLiteralTemp ("<error>");
8455 /*@observer@*/ cstring
8456 exprNode_unparse (/*@temp@*/ exprNode e)
8458 if (exprNode_isError (e))
8460 return cstring_makeLiteralTemp ("<error>");
8463 if (cstring_isDefined (e->etext))
8469 cstring ret = exprNode_doUnparse (e);
8471 /*@-modifies@*/ /* benevolent */
8478 /*@observer@*/ fileloc
8479 exprNode_loc (exprNode e)
8481 if (exprNode_isError (e))
8483 return (g_currentloc);
8492 ** executes exprNode e
8493 ** recursively rexecutes as though in original parse using
8494 ** information in e->edata
8497 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
8499 exprNodeList ret = exprNodeList_new ();
8501 exprNodeList_elements (e, current)
8503 exprNodeList_addh (ret, exprNode_effect (current));
8504 } end_exprNodeList_elements;
8509 static /*@only@*/ exprNode exprNode_effect (exprNode e)
8510 /*@globals internalState@*/
8512 bool innerEffect = inEffect;
8518 context_clearJustPopped ();
8520 if (exprNode_isError (e))
8522 ret = exprNode_undefined;
8527 ** Turn off expose and dependent transfer checking.
8528 ** Need to pass exposed internal nodes,
8529 ** [ copying would be a waste! ]
8530 ** [ Actually, I think I wasted a lot more time than its worth ]
8531 ** [ trying to do this. ]
8535 /*@-observertrans@*/
8536 /*@-dependenttrans@*/
8543 ret = exprNode_addParens (exprData_getUopTok (data),
8544 exprNode_effect (exprData_getUopNode (data)));
8547 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
8548 exprNode_effect (exprData_getOpB (data)),
8549 exprData_getOpTok (data));
8552 ret = exprNode_undefined;
8555 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
8556 exprNodeList_effect (exprData_getArgs (data)));
8569 cstring id = exprData_getId (data);
8570 uentry ue = usymtab_lookupSafe (id);
8572 ret = exprNode_fromIdentifierAux (ue);
8573 ret->loc = fileloc_update (ret->loc, e->loc);
8580 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
8581 exprNode_effect (exprData_getPairB (data)));
8584 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
8585 exprNode_effect (exprData_getOpB (data)),
8586 exprData_getOpTok (data));
8590 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
8591 exprData_getUopTok (data));
8594 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
8595 exprData_getUopTok (data));
8607 ret = exprNode_vaArg (exprData_getCastTok (data),
8608 exprNode_effect (exprData_getCastNode (data)),
8609 exprData_getCastType (data));
8613 ret = exprNode_cast (exprData_getCastTok (data),
8614 exprNode_effect (exprData_getCastNode (data)),
8615 exprData_getCastType (data));
8618 ret = exprNode_iterStart (exprData_getIterCallIter (data),
8620 (exprData_getIterCallArgs (data)));
8624 ret = exprNode_iter (exprData_getIterSname (data),
8625 exprNodeList_effect (exprData_getIterAlist (data)),
8626 exprNode_effect (exprData_getIterBody (data)),
8627 exprData_getIterEname (data));
8631 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
8632 exprNode_effect (exprData_getPairB (data)));
8636 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
8637 exprNode_effect (exprData_getTripleTest (data)),
8638 exprNode_effect (exprData_getTripleInc (data)));
8642 ret = exprNode_createTok (exprData_getTok (data));
8646 ret = exprNode_goto (exprData_getLiteral (data));
8647 ret->loc = fileloc_update (ret->loc, e->loc);
8651 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
8655 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
8659 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
8662 case XPR_NULLRETURN:
8663 ret = exprNode_nullReturn (exprData_getTok (data));
8667 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
8668 exprNode_effect (exprData_getPairB (data)));
8672 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
8673 exprNode_effect (exprData_getTripleTrue (data)),
8674 exprNode_effect (exprData_getTripleFalse (data)));
8677 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
8678 exprNode_effect (exprData_getPairB (data)));
8682 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
8683 exprNode_effect (exprData_getTripleTrue (data)),
8684 exprNode_effect (exprData_getTripleFalse (data)));
8687 ret = exprNode_whilePred (exprData_getSingle (data));
8691 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
8692 exprNode_effect (exprData_getPairB (data)));
8696 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
8697 exprNode_effect (exprData_getPairB (data)));
8701 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
8705 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
8706 exprData_getUopTok (data));
8710 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
8711 exprNode_effect (exprData_getPairB (data)));
8716 ret = exprNode_caseMarker
8717 (exprNode_effect (exprData_getSingle (data)),
8723 ret = exprNode_createTok (exprData_getTok (data));
8727 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
8728 exprNode_effect (exprData_getPairB (data)));
8732 ret = exprNode_makeInitialization
8733 (exprData_getInitId (data),
8734 exprNode_effect (exprData_getInitNode (data)));
8738 ret = exprNode_fieldAccessAux
8739 (exprNode_effect (exprData_getFieldNode (data)),
8740 exprNode_loc (exprData_getFieldNode (data)),
8741 cstring_copy (exprData_getFieldName (data)));
8745 ret = exprNode_arrowAccessAux
8746 (exprNode_effect (exprData_getFieldNode (data)),
8747 exprNode_loc (exprData_getFieldNode (data)),
8748 cstring_copy (exprData_getFieldName (data)));
8751 case XPR_STRINGLITERAL:
8765 /*@=observertrans@*/
8767 /*@=dependenttrans@*/
8778 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8783 if (exprNode_isError (e))
8785 return cstring_undefined;
8793 ret = exprNode_rootVarName (exprData_getUopNode (data));
8796 ret = exprNode_rootVarName (exprData_getOpA (data));
8800 ret = exprData_getId (data);
8803 ret = idDecl_getName (exprData_getInitId (data));
8828 case XPR_NULLRETURN:
8850 case XPR_STRINGLITERAL:
8851 ret = cstring_undefined;
8858 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8863 if (exprNode_isError (e))
8865 static /*@only@*/ cstring error = cstring_undefined;
8867 if (!cstring_isDefined (error))
8869 error = cstring_makeLiteral ("<error>");
8880 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8883 ret = message ("%s %s %s",
8884 exprNode_unparse (exprData_getOpA (data)),
8885 lltok_unparse (exprData_getOpTok (data)),
8886 exprNode_unparse (exprData_getOpB (data)));
8889 ret = message ("%s(%q)",
8890 exprNode_unparse (exprData_getFcn (data)),
8891 exprNodeList_unparse (exprData_getArgs (data)));
8894 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8897 ret = cstring_undefined;
8900 ret = message ("%s:", exprData_getId (data));
8904 ret = cstring_copy (exprData_getId (data));
8907 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8908 exprNode_unparse (exprData_getPairB (data)));
8911 ret = message ("<body>");
8914 ret = message ("%s %s %s",
8915 exprNode_unparse (exprData_getOpA (data)),
8916 lltok_unparse (exprData_getOpTok (data)),
8917 exprNode_unparse (exprData_getOpB (data)));
8921 ret = message ("%s%s",
8922 lltok_unparse (exprData_getUopTok (data)),
8923 exprNode_unparse (exprData_getUopNode (data)));
8927 ret = message ("%s%s",
8928 exprNode_unparse (exprData_getUopNode (data)),
8929 lltok_unparse (exprData_getUopTok (data)));
8933 ret = message ("offsetof(%s,%q)",
8934 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8935 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8939 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8943 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8947 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8951 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8955 ret = message ("va_arg(%s, %q)",
8956 exprNode_unparse (exprData_getCastNode (data)),
8957 qtype_unparse (exprData_getCastType (data)));
8961 ret = message ("%q(%q)",
8962 uentry_getName (exprData_getIterCallIter (data)),
8963 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8966 ret = message ("%q(%q) %s %q",
8967 uentry_getName (exprData_getIterSname (data)),
8968 exprNodeList_unparse (exprData_getIterAlist (data)),
8969 exprNode_unparse (exprData_getIterBody (data)),
8970 uentry_getName (exprData_getIterEname (data)));
8973 ret = message ("(%q)%s",
8974 qtype_unparse (exprData_getCastType (data)),
8975 exprNode_unparse (exprData_getCastNode (data)));
8979 ret = message ("%s %s",
8980 exprNode_unparse (exprData_getPairA (data)),
8981 exprNode_unparse (exprData_getPairB (data)));
8985 ret = message ("for (%s; %s; %s)",
8986 exprNode_unparse (exprData_getTripleInit (data)),
8987 exprNode_unparse (exprData_getTripleTest (data)),
8988 exprNode_unparse (exprData_getTripleInc (data)));
8992 ret = message ("goto %s", exprData_getLiteral (data));
8996 ret = cstring_makeLiteral ("continue");
9000 ret = cstring_makeLiteral ("break");
9004 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
9007 case XPR_NULLRETURN:
9008 ret = cstring_makeLiteral ("return");
9012 ret = message ("%s, %s",
9013 exprNode_unparse (exprData_getPairA (data)),
9014 exprNode_unparse (exprData_getPairB (data)));
9018 ret = message ("%s ? %s : %s",
9019 exprNode_unparse (exprData_getTriplePred (data)),
9020 exprNode_unparse (exprData_getTripleTrue (data)),
9021 exprNode_unparse (exprData_getTripleFalse (data)));
9024 ret = message ("if (%s) %s",
9025 exprNode_unparse (exprData_getPairA (data)),
9026 exprNode_unparse (exprData_getPairB (data)));
9030 ret = message ("if (%s) %s else %s",
9031 exprNode_unparse (exprData_getTriplePred (data)),
9032 exprNode_unparse (exprData_getTripleTrue (data)),
9033 exprNode_unparse (exprData_getTripleFalse (data)));
9036 ret = message ("while (%s) %s",
9037 exprNode_unparse (exprData_getPairA (data)),
9038 exprNode_unparse (exprData_getPairB (data)));
9042 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
9046 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
9050 ret = message ("do { %s } while (%s)",
9051 exprNode_unparse (exprData_getPairB (data)),
9052 exprNode_unparse (exprData_getPairA (data)));
9056 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
9060 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
9064 ret = message ("%s; %s",
9065 exprNode_unparse (exprData_getPairA (data)),
9066 exprNode_unparse (exprData_getPairB (data)));
9071 ret = cstring_makeLiteral ("default:");
9075 ret = message ("switch (%s) %s",
9076 exprNode_unparse (exprData_getPairA (data)),
9077 exprNode_unparse (exprData_getPairB (data)));
9082 ret = message ("case %s:",
9083 exprNode_unparse (exprData_getSingle (data)));
9087 if (exprNode_isError (exprData_getInitNode (data)))
9089 ret = message ("%q", idDecl_unparseC (exprData_getInitId (data)));
9093 ret = message ("%q = %s",
9094 idDecl_unparseC (exprData_getInitId (data)),
9095 exprNode_unparse (exprData_getInitNode (data)));
9100 ret = message ("%s.%s",
9101 exprNode_unparse (exprData_getFieldNode (data)),
9102 exprData_getFieldName (data));
9106 ret = message ("%s->%s",
9107 exprNode_unparse (exprData_getFieldNode (data)),
9108 exprData_getFieldName (data));
9111 case XPR_STRINGLITERAL:
9112 ret = message ("\"%s\"", exprData_getLiteral (data));
9116 ret = cstring_copy (exprData_getLiteral (data));
9120 ret = cstring_makeLiteral ("<node>");
9128 exprNode_isInitializer (exprNode e)
9130 return (exprNode_isDefined (e)
9131 && e->kind == XPR_INIT);
9135 exprNode_isCharLit (exprNode e)
9137 if (exprNode_isDefined (e))
9139 return (multiVal_isChar (exprNode_getValue (e)));
9148 exprNode_isNumLit (exprNode e)
9150 if (exprNode_isDefined (e))
9152 return (multiVal_isInt (exprNode_getValue (e)));
9161 exprNode_isFalseConstant (exprNode e)
9163 if (exprNode_isDefined (e))
9165 cstring s = exprNode_rootVarName (e);
9167 if (cstring_equal (s, context_getFalseName ()))
9177 exprNode_matchLiteral (ctype expected, exprNode e)
9179 if (exprNode_isDefined (e))
9181 multiVal m = exprNode_getValue (e);
9183 if (multiVal_isDefined (m))
9185 if (multiVal_isInt (m))
9187 long int val = multiVal_forceInt (m);
9189 if (ctype_isDirectBool (ctype_realishType (expected)))
9193 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
9201 if (ctype_isRealInt (expected))
9204 ** unsigned <- [ constant >= 0 is okay ]
9207 if (ctype_isUnsigned (expected))
9216 ** No checks on sizes of integers...maybe add
9220 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
9221 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
9222 bool_unparse (ctype_isInt (exprNode_getType (e)))));
9224 if (context_getFlag (FLG_NUMLITERAL)
9225 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
9231 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
9235 else if (ctype_isChar (expected))
9239 else if (ctype_isArrayPtr (expected))
9243 else if (ctype_isAnyFloat (expected))
9245 return (context_getFlag (FLG_NUMLITERAL));
9252 else if (multiVal_isDouble (m))
9254 if (ctype_isAnyFloat (expected))
9259 else if (multiVal_isChar (m))
9261 char val = multiVal_forceChar (m);
9263 if (ctype_isChar (expected))
9265 if (ctype_isUnsigned (expected) && ((int)val) < 0)
9286 exprNode_matchType (ctype expected, exprNode e)
9290 if (!exprNode_isDefined (e)) return TRUE;
9292 actual = ctype_realishType (exprNode_getType (e));
9294 if (ctype_match (ctype_realishType (expected), actual))
9299 llassert (!exprNode_isError (e));
9300 return (exprNode_matchLiteral (expected, e));
9304 exprNode_matchTypes (exprNode e1, exprNode e2)
9309 if (!exprNode_isDefined (e1)) return TRUE;
9310 if (!exprNode_isDefined (e2)) return TRUE;
9313 ** realish type --- keep bools, bools
9316 t1 = ctype_realishType (exprNode_getType (e1));
9317 t2 = ctype_realishType (exprNode_getType (e2));
9319 if (ctype_match (t1, t2))
9324 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
9332 exprNode_matchArgType (ctype ct, exprNode e)
9336 if (!exprNode_isDefined (e))
9341 et = ctype_realType (exprNode_getType (e));
9343 if (ctype_matchArg (ct, et)) return TRUE;
9345 llassert (!exprNode_isError (e));
9346 return (exprNode_matchLiteral (ct, e));
9349 static /*@only@*/ exprNodeSList
9350 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
9352 if (exprNode_isDefined (e))
9354 if (e->kind == XPR_STMTLIST)
9356 return (exprNodeSList_append
9357 (exprNode_flatten (exprData_getPairA (e->edata)),
9358 exprNode_flatten (exprData_getPairB (e->edata))));
9360 else if (e->kind == XPR_BLOCK)
9362 return (exprNode_flatten (exprData_getSingle (e->edata)));
9366 return (exprNodeSList_singleton (e));
9370 return exprNodeSList_new ();
9373 static /*@exposed@*/ exprNode
9374 exprNode_lastStatement (/*@returned@*/ exprNode e)
9376 if (exprNode_isDefined (e))
9378 if (e->kind == XPR_STMTLIST)
9380 exprNode b = exprData_getPairB (e->edata);
9382 if (exprNode_isDefined (b))
9384 return exprNode_lastStatement (b);
9388 return exprNode_lastStatement (exprData_getPairA (e->edata));
9391 else if (e->kind == XPR_BLOCK)
9393 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
9401 return exprNode_undefined;
9404 static /*@exposed@*/ exprNode
9405 exprNode_firstStatement (/*@returned@*/ exprNode e)
9407 if (exprNode_isDefined (e))
9409 if (e->kind == XPR_STMTLIST)
9411 exprNode b = exprData_getPairA (e->edata);
9413 if (exprNode_isDefined (b))
9415 return exprNode_firstStatement (b);
9419 return exprNode_firstStatement (exprData_getPairB (e->edata));
9422 else if (e->kind == XPR_BLOCK)
9424 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
9432 return exprNode_undefined;
9436 exprNode_mergeUSs (exprNode res, exprNode other)
9438 if (exprNode_isDefined (res) && exprNode_isDefined (other))
9440 res->msets = sRefSet_union (res->msets, other->msets);
9441 res->sets = sRefSet_union (res->sets, other->sets);
9442 res->uses = sRefSet_union (res->uses, other->uses);
9447 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
9449 if (exprNode_isDefined (res))
9451 if (exprNode_isDefined (other1))
9453 res->sets = sRefSet_union (res->sets, other1->sets);
9454 res->msets = sRefSet_union (res->msets, other1->msets);
9455 res->uses = sRefSet_union (res->uses, other1->uses);
9457 if (exprNode_isDefined (other2))
9459 res->sets = sRefSet_union (res->sets, other2->sets);
9460 res->msets = sRefSet_union (res->msets, other2->msets);
9461 res->uses = sRefSet_union (res->uses, other2->uses);
9469 ** Reports errors is s is not defined.
9473 exprNode_addUse (exprNode e, /*@exposed@*/ sRef s)
9475 if (exprNode_isDefined (e))
9477 e->uses = sRefSet_insert (e->uses, s);
9482 exprNode_checkUse (exprNode e, /*@exposed@*/ sRef s, fileloc loc)
9484 if (sRef_isKnown (s) && !sRef_isConst (s))
9487 ** need to check all outer types are useable
9490 DPRINTF (("Check use: %s / %s",
9491 exprNode_unparse (e), sRef_unparse (s)));
9493 exprNode_addUse (e, s);
9495 if (!context_inProtectVars ())
9498 ** only report the deepest error
9501 sRef errorRef = sRef_undefined;
9502 sRef lastRef = sRef_undefined;
9503 bool deadRef = FALSE;
9504 bool unuseable = FALSE;
9505 bool errorMaybe = FALSE;
9507 while (sRef_isValid (s) && sRef_isKnown (s))
9509 ynm readable = sRef_isReadable (s);
9511 DPRINTF (("Readable: %s / %s",
9512 sRef_unparseFull (s), ynm_unparse (readable)));
9514 if (!(ynm_toBoolStrict (readable)))
9516 if (ynm_isMaybe (readable))
9520 DPRINTF (("Setting ERROR: %s", sRef_unparseFull (s)));
9521 deadRef = sRef_isPossiblyDead (errorRef);
9522 unuseable = sRef_isUnuseable (errorRef);
9529 deadRef = sRef_isDead (errorRef);
9530 unuseable = sRef_isUnuseable (errorRef);
9534 if (!sRef_isPartial (s))
9536 DPRINTF (("Defining! %s", sRef_unparseFull (s)));
9537 sRef_setDefined (s, fileloc_undefined);
9541 s = sRef_getBaseSafe (s);
9544 if (sRef_isValid (errorRef))
9546 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
9547 && sRef_isPointer (errorRef))
9554 if (sRef_isThroughArrayFetch (errorRef))
9557 (FLG_STRICTUSERELEASED,
9558 message ("%q %q may be used after being released",
9559 sRef_unparseKindNamePlain (errorRef),
9560 sRef_unparse (errorRef)),
9563 sRef_showRefKilled (errorRef);
9565 if (sRef_isKept (errorRef))
9567 sRef_clearAliasState (errorRef, loc);
9573 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
9577 message ("%q %q %qused after being released",
9578 sRef_unparseKindNamePlain (errorRef),
9579 sRef_unparse (errorRef),
9580 cstring_makeLiteral (errorMaybe
9584 sRef_showRefKilled (errorRef);
9586 if (sRef_isKept (errorRef))
9588 sRef_clearAliasState (errorRef, loc);
9597 message ("%q %q%qused in inconsistent state",
9598 sRef_unparseKindName (errorRef),
9599 sRef_unparseOpt (errorRef),
9600 cstring_makeLiteral (errorMaybe ? "may be " : "")),
9603 sRef_showStateInconsistent (errorRef);
9608 DPRINTF (("HERE: %s", sRef_unparseFull (errorRef)));
9612 message ("%q %q%qused before definition",
9613 sRef_unparseKindName (errorRef),
9614 sRef_unparseOpt (errorRef),
9615 cstring_makeLiteral (errorMaybe ? "may be " : "")),
9618 DPRINTF (("Error: %s", sRef_unparseFull (errorRef)));
9621 sRef_setDefined (errorRef, loc);
9623 if (sRef_isAddress (errorRef))
9625 sRef_setDefined (sRef_getRootBase (errorRef), loc);
9627 } /* end is error */
9635 checkSafeUse (exprNode e, /*@exposed@*/ sRef s)
9637 if (exprNode_isDefined (e) && sRef_isKnown (s))
9639 e->uses = sRefSet_insert (e->uses, s);
9644 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
9646 if (exprNode_isDefined (e))
9648 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
9653 exprNode_checkSet (exprNode e, /*@exposed@*/ sRef s)
9655 sRef defines = sRef_undefined;
9657 if (sRef_isValid (s) && !sRef_isNothing (s))
9659 uentry ue = sRef_getBaseUentry (s);
9661 if (uentry_isValid (ue))
9663 uentry_setLset (ue);
9666 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9668 voptgenerror (FLG_USEDEF,
9669 message ("Attempt to set unuseable storage: %q",
9674 if (sRef_isMeaningful (s))
9676 if (sRef_isDead (s))
9678 sRef base = sRef_getBaseSafe (s);
9680 if (sRef_isValid (base)
9681 && sRef_isDead (base))
9683 sRef_setPartial (s, exprNode_loc (e));
9686 defines = s; /* okay - modifies for only param */
9688 else if (sRef_isPartial (s))
9690 sRef eref = exprNode_getSref (e);
9692 if (!sRef_isPartial (eref))
9695 ** should do something different here???
9698 sRef_setDefinedComplete (eref, exprNode_loc (e));
9702 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
9705 if (sRef_isMeaningful (eref))
9714 else if (sRef_isAllocated (s))
9716 sRef eref = exprNode_getSref (e);
9719 if (!sRef_isAllocated (eref))
9721 sRef_setDefinedComplete (eref, exprNode_loc (e));
9725 sRef base = sRef_getBaseSafe (eref);
9727 if (sRef_isValid (base))
9729 sRef_setPdefined (base, exprNode_loc (e));
9737 sRef_setDefinedNCComplete (s, exprNode_loc (e));
9742 else /* not meaningful...but still need to insert it */
9748 if (exprNode_isDefined (e) && sRef_isValid (defines))
9750 e->sets = sRefSet_insert (e->sets, defines);
9755 exprNode_checkMSet (exprNode e, /*@exposed@*/ sRef s)
9757 if (sRef_isValid (s) && !sRef_isNothing (s))
9759 uentry ue = sRef_getBaseUentry (s);
9761 if (uentry_isValid (ue))
9763 uentry_setLset (ue);
9766 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9768 voptgenerror (FLG_USEDEF,
9769 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9773 if (sRef_isMeaningful (s))
9775 sRef_setDefinedComplete (s, exprNode_loc (e));
9778 if (exprNode_isDefined (e))
9780 e->msets = sRefSet_insert (e->msets, s);
9786 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9788 checkAnyCall (fcn, cstring_undefined, params, args,
9789 FALSE, sRefSet_undefined, FALSE, 0);
9793 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9794 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9798 if (uentry_isYield (ucurrent))
9800 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9801 exprNode_checkSet (current, current->sref);
9805 if (uentry_isSefParam (ucurrent))
9807 sRefSet sets = current->sets;
9808 sRef ref = exprNode_getSref (current);
9810 if (sRef_isMacroParamRef (ref))
9812 uentry ue = sRef_getUentry (ref);
9814 if (!uentry_isSefParam (ue))
9819 ("Parameter %d to %s is declared sef, but "
9820 "the argument is a macro parameter declared "
9822 argno, exprNode_unparse (fcn),
9823 exprNode_unparse (current)),
9824 exprNode_loc (current));
9828 if (!sRefSet_isEmpty (sets))
9830 sRefSet reported = sRefSet_undefined;
9832 sRefSet_realElements (current->sets, el)
9834 if (sRefSet_isSameNameMember (reported, el))
9836 ; /* don't report again */
9840 if (sRef_isUnconstrained (el))
9845 ("Parameter %d to %s is declared sef, but "
9846 "the argument calls unconstrained function %s "
9847 "(no guarantee it will not modify something): %s",
9848 argno, exprNode_unparse (fcn),
9849 sRef_unconstrainedName (el),
9850 exprNode_unparse (current)),
9851 exprNode_loc (current));
9858 ("Parameter %d to %s is declared sef, but "
9859 "the argument may modify %q: %s",
9860 argno, exprNode_unparse (fcn),
9862 exprNode_unparse (current)),
9863 exprNode_loc (current));
9866 } end_sRefSet_realElements;
9870 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9871 exprNode_mergeUSs (fcn, current);
9876 checkAnyCall (/*@dependent@*/ exprNode fcn,
9877 /*@dependent@*/ cstring fname,
9880 bool hasMods, sRefSet mods,
9885 int nargs = exprNodeList_size (args);
9890 ** concat all args ud's to f, add each arg sref as a use unless
9891 ** it was specified as "out", in which case it is a def.
9894 uentryList_reset (pn);
9899 ** if paramn is only or unique, no other arg may alias argn
9902 exprNodeList_elements (args, current)
9906 if (exprNode_isDefined (current))
9908 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9910 uentry ucurrent = uentryList_current (pn);
9912 if (specialArgs == 0
9913 || (paramno < specialArgs))
9915 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9917 if (context_maybeSet (FLG_ALIASUNIQUE))
9919 if (uentry_isOnly (ucurrent)
9920 || uentry_isUnique (ucurrent))
9922 checkUniqueParams (fcn, current, args,
9928 else /* uentry is undefined */
9930 if (specialArgs == 0)
9932 exprNode_checkUseParam (current);
9935 exprNode_mergeUSs (fcn, current);
9938 uentryList_advanceSafe (pn);
9939 } end_exprNodeList_elements;
9945 sRefSet_allElements (mods, s)
9948 sRef rb = sRef_getRootBase (s);
9950 if (sRef_isFileOrGlobalScope (rb))
9952 context_usedGlobal (rb);
9955 fb = sRef_fixBaseParam (s, args);
9957 if (!sRef_isMacroParamRef (fb))
9959 if (sRef_isNothing (fb))
9965 if (sRef_isValid (fb))
9967 uentry ue = sRef_getBaseUentry (s);
9969 if (uentry_isValid (ue))
9971 uentry_setLset (ue);
9975 fcn->sets = sRefSet_insert (fcn->sets, fb);
9978 sRef_clearDerivedComplete (s);
9979 } end_sRefSet_allElements;
9985 if (context_hasMods ())
9987 if (context_maybeSet (FLG_MODUNCON))
9991 message ("Undetected modification possible "
9992 "from call to unconstrained function %s: %s",
9994 exprNode_unparse (fcn)),
9995 exprNode_loc (fcn));
10000 if (context_maybeSet (FLG_MODUNCONNOMODS)
10001 && !(context_inIterDef () || context_inIterEnd ()))
10004 (FLG_MODUNCONNOMODS,
10005 message ("Undetected modification possible "
10006 "from call to unconstrained function %s: %s",
10008 exprNode_unparse (fcn)),
10009 exprNode_loc (fcn));
10013 exprNode_checkSetAny (fcn, fname);
10017 void exprNode_checkUseParam (exprNode current)
10019 if (exprNode_isDefined (current))
10021 exprNode_checkUse (current, current->sref, current->loc);
10026 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
10027 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10032 if (!ctype_match (tr1, tr2))
10034 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
10035 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
10041 (void) gentypeerror
10043 message ("Incompatible types for %s (%s, %s): %s %s %s",
10044 lltok_unparse (op),
10045 ctype_unparse (te1),
10046 ctype_unparse (te2),
10047 exprNode_unparse (e1), lltok_unparse (op),
10048 exprNode_unparse (e2)),
10051 ret = ctype_unknown;
10055 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
10057 ret = ctype_resolveNumerics (tr1, tr2);
10059 else if (!context_msgStrictOps ())
10061 if (ctype_isPointer (tr1))
10063 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
10067 else if (ctype_isInt (tr2))
10073 ret = ctype_unknown;
10076 else if (ctype_isPointer (tr2))
10078 if (ctype_isPointer (tr1))
10082 else if (ctype_isInt (tr1))
10088 ret = ctype_unknown;
10093 ret = ctype_resolveNumerics (tr1, tr2);
10098 int opid = lltok_getTok (op);
10099 bool comparop = (opid == EQ_OP || opid == NE_OP
10100 || opid == TLT || opid == TGT
10101 || opid == LE_OP || opid == GE_OP);
10103 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
10106 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
10107 || (ctype_isBool (tr1) && ctype_isBool (tr2))
10108 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
10114 if (ctype_sameName (te1, te2))
10118 message ("Operands of %s are non-numeric (%t): %s %s %s",
10119 lltok_unparse (op), te1,
10120 exprNode_unparse (e1), lltok_unparse (op),
10121 exprNode_unparse (e2)),
10128 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
10129 lltok_unparse (op), te1, te2,
10130 exprNode_unparse (e1), lltok_unparse (op),
10131 exprNode_unparse (e2)),
10136 else if (!ctype_isNumeric (tr1))
10140 message ("Right operand of %s is non-numeric (%t): %s %s %s",
10141 lltok_unparse (op), te1,
10142 exprNode_unparse (e1), lltok_unparse (op),
10143 exprNode_unparse (e2)),
10148 if (!ctype_isNumeric (tr2))
10152 message ("Left operand of %s is non-numeric (%t): %s %s %s",
10153 lltok_unparse (op), te2,
10154 exprNode_unparse (e1), lltok_unparse (op),
10155 exprNode_unparse (e2)),
10160 ret = ctype_unknown;
10168 abstractOpError (ctype tr1, ctype tr2, lltok op,
10169 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
10170 fileloc loc1, fileloc loc2)
10172 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
10174 if (ctype_match (tr1, tr2))
10178 message ("Operands of %s are abstract type (%t): %s %s %s",
10179 lltok_unparse (op), tr1,
10180 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10187 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
10188 lltok_unparse (op), tr1, tr2,
10189 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10193 else if (ctype_isRealAbstract (tr1))
10197 message ("Left operand of %s is abstract type (%t): %s %s %s",
10198 lltok_unparse (op), tr1,
10199 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10204 if (ctype_isRealAbstract (tr2))
10208 message ("Right operand of %s is abstract type (%t): %s %s %s",
10209 lltok_unparse (op), tr2,
10210 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
10219 ** requies e1 and e2 and not error exprNode's.
10223 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
10224 ** the rep of the abstract type is exposed.
10226 ** The order is very important:
10228 ** check rep expose (move into check transfer)
10234 ** This isn't really a sensible procedure, but the indententation
10235 ** was getting too deep.
10239 checkOneRepExpose (sRef ysr, sRef base,
10240 /*@notnull@*/ exprNode e1,
10241 /*@notnull@*/ exprNode e2, ctype ct,
10244 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
10245 || sRef_isOwned (ysr)
10246 || sRef_isExposed (ysr)))
10248 if (sRef_isAnyParam (base) && !sRef_isExposed (base)
10249 && !sRef_isObserver (base)) /* evans 2001-07-11: added isObserver */
10252 if (sRef_isIReference (ysr))
10254 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10259 ("Assignment of mutable component of parameter %q "
10260 "to component of abstract "
10261 "type %s exposes rep: %s = %s",
10262 sRef_unparse (base),
10263 ctype_unparse (ct),
10264 exprNode_unparse (e1), exprNode_unparse (e2)),
10272 ("Assignment of mutable component of parameter %q "
10273 "(through alias %q) to component of abstract "
10274 "type %s exposes rep: %s = %s",
10275 sRef_unparse (base),
10276 sRef_unparse (e2->sref),
10277 ctype_unparse (ct),
10278 exprNode_unparse (e1), exprNode_unparse (e2)),
10284 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10288 message ("Assignment of mutable parameter %q "
10289 "to component of abstract type %s "
10290 "exposes rep: %s = %s",
10291 sRef_unparse (base),
10292 ctype_unparse (ct),
10293 exprNode_unparse (e1),
10294 exprNode_unparse (e2)),
10301 message ("Assignment of mutable parameter %q "
10302 "(through alias %q) to "
10303 "component of abstract type %s exposes "
10305 sRef_unparse (base),
10306 sRef_unparse (e2->sref),
10307 ctype_unparse (ct),
10308 exprNode_unparse (e1),
10309 exprNode_unparse (e2)),
10315 if (sRef_isFileOrGlobalScope (s2b))
10317 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
10321 message ("Assignment of global %q "
10323 "abstract type %s exposes rep: %s = %s",
10324 sRef_unparse (base),
10325 ctype_unparse (ct),
10326 exprNode_unparse (e1), exprNode_unparse (e2)),
10333 message ("Assignment of global %q (through alias %q) "
10335 "abstract type %s exposes rep: %s = %s",
10336 sRef_unparse (base),
10337 sRef_unparse (e2->sref),
10338 ctype_unparse (ct),
10339 exprNode_unparse (e1), exprNode_unparse (e2)),
10347 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
10349 if (ctype_isRealFunction (exprNode_getType (e1))
10350 && !ctype_isRealPointer (exprNode_getType (e1)))
10354 message ("Invalid left-hand side of assignment (function type %s): %s",
10355 ctype_unparse (exprNode_getType (e1)),
10356 exprNode_unparse (e1)),
10360 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
10362 ctype t2 = exprNode_getType (e2);
10363 sRef sr = sRef_getRootBase (e1->sref);
10364 ctype ct = sRef_getType (sr);
10366 if (ctype_isAbstract (t2)
10367 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
10369 /* it is immutable, okay to reference */
10370 goto donerepexpose;
10373 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
10375 sRef s2b = sRef_getRootBase (e2->sref);
10376 sRef s1 = e1->sref;
10377 sRef s1b = sRef_getRootBase (s1);
10380 aliases = usymtab_canAlias (e2->sref);
10382 if (!sRef_similar (s2b, s1b)
10383 && !sRef_isExposed (s1)
10384 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
10386 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
10387 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
10388 && !sRef_isExposed (s2b))
10390 if (sRef_isIReference (e2->sref))
10395 ("Assignment of mutable component of parameter %q "
10396 "to component of abstract type %s exposes rep: %s = %s",
10397 sRef_unparse (s2b),
10398 ctype_unparse (ct),
10399 exprNode_unparse (e1), exprNode_unparse (e2)),
10406 message ("Assignment of mutable parameter %q to "
10407 "component of abstract type %s exposes rep: %s = %s",
10408 sRef_unparse (s2b),
10409 ctype_unparse (ct),
10410 exprNode_unparse (e1), exprNode_unparse (e2)),
10415 if (sRef_isFileOrGlobalScope (s2b))
10419 message ("Assignment of global %q to component of "
10420 "abstract type %s exposes rep: %s = %s",
10421 sRef_unparse (s2b),
10422 ctype_unparse (ct),
10423 exprNode_unparse (e1), exprNode_unparse (e2)),
10427 sRefSet_realElements (aliases, ysr)
10429 sRef base = sRef_getRootBase (ysr);
10431 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
10432 || sRef_sameName (base, s1b))
10434 ; /* error already reported or same sref */
10438 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
10440 } end_sRefSet_realElements;
10442 sRefSet_free (aliases);
10449 ** function variables don't really work...
10452 if (!ctype_isFunction (ctype_realType (e2->typ)))
10456 DPRINTF (("Check init: %s / %s",
10457 exprNode_unparse (e1), exprNode_unparse (e2)));
10458 checkInitTransfer (e1, e2);
10462 checkAssignTransfer (e1, e2);
10467 sRef fref = e2->sref;
10469 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
10470 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
10472 /* Need to typecheck the annotation on the parameters */
10474 if (ctype_isRealFunction (e1->typ)) {
10475 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
10476 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
10478 if (!uentryList_isMissingParams (e1p)
10479 && !uentryList_isMissingParams (e2p)
10480 && uentryList_size (e1p) > 0) {
10481 if (uentryList_size (e1p) == uentryList_size (e2p)) {
10484 uentryList_elements (e1p, el1) {
10487 el2 = uentryList_getN (e2p, n);
10489 uentry_checkMatchParam (el1, el2, n, e2);
10490 } end_uentryList_elements;
10496 if (isInit && sRef_isFileOrGlobalScope (e1->sref))
10502 DPRINTF (("Update aliases: %s / %s", exprNode_unparse (e1), exprNode_unparse (e2)));
10503 updateAliases (e1, e2);
10508 checkMacroParen (exprNode e)
10510 if (exprNode_isError (e) || e->kind == XPR_CAST)
10516 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
10520 message ("Macro parameter used without parentheses: %s",
10521 exprNode_unparse (e)),
10528 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
10532 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
10536 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
10543 ** if e2 is a parameter or global derived location which
10544 ** can be modified (that is, e2 is a mutable abstract type,
10545 ** or a derived pointer), then e1 can alias e2.
10547 ** e1 can alias everything which e2 can alias.
10549 ** Also, if e1 is guarded, remove from guard sets!
10552 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
10554 if (!context_inProtectVars ())
10557 ** depends on types of e1 and e2
10560 sRef s1 = e1->sref;
10561 sRef s2 = e2->sref;
10562 ctype t1 = exprNode_getType (e1);
10564 /* handle pointer sRefs, record fields, arrays, etc... */
10566 if (!ctype_isRealSU (t1))
10568 DPRINTF (("Copying real! %s", ctype_unparse (t1)));
10569 sRef_copyRealDerivedComplete (s1, s2);
10574 ** Fields should alias
10577 DPRINTF (("Not COPYING!: %s", ctype_unparse (t1)));
10580 if (ctype_isMutable (t1) && sRef_isKnown (s1))
10582 usymtab_clearAlias (s1);
10583 usymtab_addMustAlias (s1, s2);
10584 DPRINTF (("Add must alias: %s / %s", sRef_unparse (s1), sRef_unparse (s2)));
10588 DPRINTF (("Not mutable: %s", ctype_unparse (t1)));
10591 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
10593 usymtab_unguard (s1);
10598 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
10600 if (exprNode_isDefined (e))
10602 e->loc = fileloc_update (e->loc, loc);
10606 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
10612 static void checkUniqueParams (exprNode fcn,
10613 /*@notnull@*/ exprNode current,
10615 int paramno, uentry ucurrent)
10618 sRef thisref = exprNode_getSref (current);
10621 ** Check if any argument could match this argument.
10624 exprNodeList_elements (args, icurrent)
10628 if (iparamno != paramno)
10630 sRef sr = exprNode_getSref (icurrent);
10632 if (sRef_similarRelaxed (thisref, sr))
10634 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
10639 ("Parameter %d (%s) to function %s is declared %s but "
10640 "is aliased by parameter %d (%s)",
10642 exprNode_unparse (current),
10643 exprNode_unparse (fcn),
10644 alkind_unparse (uentry_getAliasKind (ucurrent)),
10645 iparamno, exprNode_unparse (icurrent)),
10651 sRefSet aliases = usymtab_canAlias (sr);
10653 sRefSet_allElements (aliases, asr)
10655 if (ctype_isUnknown (sRef_getType (thisref)))
10657 sRef_setType (thisref, uentry_getType (ucurrent));
10660 if (sRef_similarRelaxed (thisref, asr))
10662 if (sRef_isExternal (asr))
10664 if (sRef_isLocalState (thisref))
10670 sRef base = sRef_getRootBase (asr);
10672 if (!sRef_similar (sRef_getBase (asr), thisref))
10674 if (sRef_isUnique (base) || sRef_isOnly (base)
10675 || sRef_isKept (base)
10676 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
10677 || (sRef_isAddress (thisref)
10678 && sRef_isLocalVar (sRef_getRootBase (thisref))))
10680 ; /* okay, no error */
10685 (FLG_MAYALIASUNIQUE,
10687 ("Parameter %d (%s) to function %s is declared %s but "
10688 "may be aliased externally by parameter %d (%s)",
10690 exprNode_unparse (current),
10691 exprNode_unparse (fcn),
10692 alkind_unparse (uentry_getAliasKind (ucurrent)),
10693 iparamno, exprNode_unparse (icurrent)),
10704 ("Parameter %d (%s) to function %s is declared %s but "
10705 "is aliased externally by parameter %d (%s) through "
10708 exprNode_unparse (current),
10709 exprNode_unparse (fcn),
10710 alkind_unparse (uentry_getAliasKind (ucurrent)),
10711 iparamno, exprNode_unparse (icurrent),
10712 sRef_unparse (asr)),
10716 } end_sRefSet_allElements;
10717 sRefSet_free (aliases);
10720 } end_exprNodeList_elements;
10723 long exprNode_getLongValue (exprNode e) {
10726 if (exprNode_hasValue (e)
10727 && multiVal_isInt (exprNode_getValue (e)))
10729 value = multiVal_forceInt (exprNode_getValue (e));
10739 /*@observer@*/ fileloc exprNode_getfileloc (exprNode p_e)
10741 if (exprNode_isDefined (p_e) )
10742 return ( p_e->loc );
10744 return fileloc_undefined;
10747 /*@only@*/ fileloc exprNode_getNextSequencePoint (exprNode e)
10750 ** Returns the location of the sequence point following e.
10752 ** Only works for statements (for now).
10755 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
10756 lltok t = exprData_getUopTok (e->edata);
10757 return fileloc_copy(lltok_getLoc (t));
10759 /* drl possible problem : warning fix
10760 llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
10762 return fileloc_undefined;
10766 exprNode exprNode_createNew(ctype c)
10770 ret = exprNode_createPlain (c);
10775 bool exprNode_isInitBlock (exprNode e)
10777 return (exprNode_isDefined(e) && e->kind == XPR_INITBLOCK);