2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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 "aliasChecks.h"
36 # include "exprNodeSList.h"
37 # include "exprData.i"
39 static bool exprNode_isEmptyStatement (exprNode p_e);
40 static /*@exposed@*/ exprNode exprNode_firstStatement (/*@returned@*/ exprNode p_e);
41 static bool exprNode_isFalseConstant (exprNode p_e) /*@*/ ;
42 static bool exprNode_isBlock (exprNode p_e);
43 static void checkGlobUse (uentry p_glob, bool p_isCall, /*@notnull@*/ exprNode p_e);
44 static void exprNode_addUse (exprNode p_e, sRef p_s);
45 static bool exprNode_matchArgType (ctype p_ct, exprNode p_e);
46 exprNode exprNode_fakeCopy (exprNode p_e) /*@*/ ;
47 static exprNode exprNode_statementError (/*@only@*/ exprNode p_e, /*@only@*/ lltok p_t);
48 static bool exprNode_matchTypes (exprNode p_e1, exprNode p_e2);
49 static void checkUniqueParams (exprNode p_fcn,
50 /*@notnull@*/ exprNode p_current, exprNodeList p_args,
51 int p_paramno, uentry p_ucurrent);
52 static void updateAliases (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2);
53 static void abstractOpError (ctype p_tr1, ctype p_tr2, lltok p_op,
54 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2,
55 fileloc p_loc1, fileloc p_loc2);
56 static ctype checkNumerics (ctype p_tr1, ctype p_tr2, ctype p_te1, ctype p_te2,
57 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, lltok p_op);
58 static void doAssign (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, bool p_isInit);
59 static void checkSafeUse (exprNode p_e, sRef p_s);
60 static void reflectNullTest (/*@notnull@*/ exprNode p_e, bool p_isnull);
61 static void checkMacroParen (exprNode p_e);
62 static exprNodeSList exprNode_flatten (/*@dependent@*/ exprNode p_e);
63 static void exprNode_checkSetAny (exprNode p_e, /*@dependent@*/ cstring p_name);
64 static void exprNode_checkUse (exprNode p_e, sRef p_s, fileloc p_loc);
65 static void exprNode_mergeUSs (exprNode p_res, exprNode p_other);
66 static void exprNode_mergeCondUSs (exprNode p_res, exprNode p_other1, exprNode p_other2);
67 static /*@only@*/ /*@notnull@*/ exprNode exprNode_fromIdentifierAux (/*@observer@*/ uentry p_c);
68 static void checkAnyCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn,
69 /*@dependent@*/ cstring p_fname,
70 uentryList p_pn, exprNodeList p_args,
71 bool p_hasMods, sRefSet p_mods, bool p_isSpec,
73 static void checkOneArg (uentry p_ucurrent, /*@notnull@*/ exprNode p_current,
74 /*@dependent@*/ exprNode p_fcn, bool p_isSpec, int p_argno, int p_totargs);
76 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn, uentryList p_params, exprNodeList p_args);
78 static /*@only@*/ exprNode exprNode_effect (exprNode p_e)
79 /*@globals internalState@*/ ;
80 static /*@only@*/ cstring exprNode_doUnparse (exprNode p_e);
81 static /*@observer@*/ cstring exprNode_rootVarName (exprNode p_e);
82 static /*@exposed@*/ exprNode
83 exprNode_lastStatement (/*@returned@*/ exprNode p_e);
85 static /*@null@*/ sRef defref = sRef_undefined;
86 static /*@only@*/ exprNode mustExitNode = exprNode_undefined;
88 static int checkArgsReal (uentry p_fcn, /*@dependent@*/ exprNode p_f,
90 exprNodeList p_args, bool p_isIter, exprNode p_ret);
92 static bool inEffect = FALSE;
93 static int nowalloc = 0;
94 static int totalloc = 0;
95 static int maxalloc = 0;
97 static /*@only@*/ uentry regArg;
98 static /*@only@*/ uentry outArg;
99 static /*@only@*/ uentry outStringArg;
100 static /*@exposed@*/ sRef stdinRef;
101 static /*@exposed@*/ sRef stdoutRef;
102 static /*@only@*/ uentry csArg;
103 static /*@only@*/ uentry csOnlyArg;
104 static ctype cstringType;
105 static ctype ctypeType;
106 static ctype filelocType;
107 static bool initMod = FALSE;
110 ** must occur after library has been read
113 void exprNode_initMod (void)
114 /*@globals undef regArg, undef outArg, undef outStringArg,
115 undef csOnlyArg, undef csArg;
122 cstringType = ctype_unknown;
123 ctypeType = ctype_unknown;
124 filelocType = ctype_unknown;
126 defref = sRef_undefined;
128 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
130 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
133 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
135 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
138 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
140 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
143 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdin")))
145 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdin"));
147 else /* define stdin */
149 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdin"),
151 fileloc_getBuiltin (),
153 uentry_setHasNameError (ue);
154 ue = usymtab_supGlobalEntryReturn (ue);
157 stdinRef = sRef_makePointer (uentry_getSref (ue));
159 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdout")))
161 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdout"));
165 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdout"),
167 fileloc_getBuiltin (),
169 uentry_setHasNameError (ue);
170 ue = usymtab_supGlobalEntryReturn (ue);
173 stdoutRef = sRef_makePointer (uentry_getSref (ue));
175 tmp = idDecl_create (cstring_undefined, qtype_create (ctype_unknown));
177 regArg = uentry_makeParam (tmp, PARAMUNKNOWN);
180 qtype_addQual (qtype_create (ctype_makePointer (ctype_unknown)),
183 outArg = uentry_makeParam (tmp, PARAMUNKNOWN);
185 idDecl_setTyp (tmp, qtype_addQual (qtype_create (ctype_string),
188 outStringArg = uentry_makeParam (tmp, PARAMUNKNOWN);
190 idDecl_setTyp (tmp, qtype_addQual (qtype_addQual (qtype_create (cstringType),
192 qual_createNull ()));
194 csOnlyArg = uentry_makeParam (tmp, PARAMUNKNOWN);
196 idDecl_setTyp (tmp, qtype_addQual (qtype_create (cstringType), qual_createNull ()));
197 csArg = uentry_makeParam (tmp, PARAMUNKNOWN);
203 exprNode_destroyMod (void)
204 /*@globals killed regArg, killed outArg, killed outStringArg,
205 killed mustExitNode, initMod @*/
209 uentry_free (regArg);
210 uentry_free (outArg);
211 uentry_free (outStringArg);
213 exprNode_free (mustExitNode);
220 static void exprNode_resetSref (/*@notnull@*/ exprNode e)
225 exprNode exprNode_fakeCopy (exprNode e)
227 /*@-temptrans@*/ /*@-retalias@*/
229 /*@=temptrans@*/ /*@=retalias@*/
232 static bool isFlagKey (char key)
234 return (key == '-' || key == '+' || key == ' ' || key == '#');
237 static void exprNode_combineControl (/*@notnull@*/ exprNode ret,
238 /*@notnull@*/ exprNode ifclause,
239 /*@notnull@*/ exprNode elseclause)
241 ret->canBreak = ifclause->canBreak || elseclause->canBreak;
244 (ifclause->mustBreak || exprNode_mustEscape (ifclause))
245 && (elseclause->mustBreak || exprNode_mustEscape (elseclause));
247 ret->exitCode = exitkind_combine (ifclause->exitCode,
248 elseclause->exitCode);
253 ** For exprNode's returned by exprNode_effect.
256 static bool shallowKind (exprKind kind)
258 return (kind == XPR_STRINGLITERAL
259 || kind == XPR_NUMLIT
262 || kind == XPR_NODE);
266 exprNode_freeIniter (/*@only@*/ exprNode e)
268 if (!exprNode_isError (e))
273 sfree (e->edata->field);
277 exprNode_free (e->edata->op->b);
278 /*@-compdestroy@*/ sfree (e->edata->op); /*@=compdestroy@*/
282 llbug (message ("other: %s", exprNode_unparse (e)));
285 multiVal_free (e->val);
286 cstring_free (e->etext);
287 fileloc_free (e->loc);
288 sRefSet_free (e->uses);
289 sRefSet_free (e->sets);
290 sRefSet_free (e->msets);
291 guardSet_free (e->guards);
297 exprNode_freeShallow (/*@only@*/ exprNode e)
299 if (!exprNode_isError (e))
301 if (shallowKind (e->kind))
308 if (e->kind == XPR_EMPTY
309 || e->kind == XPR_BODY
310 || e->kind == XPR_STRINGLITERAL
311 || e->kind == XPR_NUMLIT
312 || e->kind == XPR_NODE
313 || e->kind == XPR_OFFSETOF
314 || e->kind == XPR_ALIGNOFT
315 || e->kind == XPR_ALIGNOF
316 || e->kind == XPR_SIZEOFT
317 || e->kind == XPR_SIZEOF)
319 /* don't free anything */
323 /* multiVal_free (e->val); */
324 cstring_free (e->etext);
325 fileloc_free (e->loc);
326 sRefSet_free (e->uses);
327 sRefSet_free (e->sets);
328 sRefSet_free (e->msets);
329 guardSet_free (e->guards);
330 exprData_freeShallow (e->edata, e->kind);
332 /*@-compdestroy@*/ sfree (e); /*@=compdestroy@*/
341 exprNode_free (exprNode e)
343 if (!exprNode_isError (e))
347 multiVal_free (e->val);
348 cstring_free (e->etext);
349 fileloc_free (e->loc);
350 sRefSet_free (e->uses);
351 sRefSet_free (e->sets);
352 sRefSet_free (e->msets);
353 guardSet_free (e->guards);
354 exprData_free (e->edata, e->kind);
364 exprNode_makeError ()
366 return exprNode_undefined;
369 static /*@out@*/ /*@only@*/ /*@notnull@*/ exprNode
372 exprNode ret = (exprNode) dmalloc (sizeof (*ret));
373 /* static int lastexpnodes = 0; */
378 if (nowalloc > maxalloc)
386 static /*@notnull@*/ /*@special@*/ exprNode
387 exprNode_createPlain (ctype c)
389 /*@post:isnull result->edata, result->loc, result->val, result->guards,
390 result->uses, result->sets, result->msets, result->etext @*/
393 exprNode e = exprNode_new ();
397 e->val = multiVal_undefined;
399 e->etext = cstring_undefined;
400 e->loc = fileloc_undefined;
401 e->guards = guardSet_undefined;
402 e->uses = sRefSet_undefined;
403 e->sets = sRefSet_undefined;
404 e->msets = sRefSet_undefined;
405 e->edata = exprData_undefined;
406 e->exitCode = XK_NEVERESCAPE;
408 e->mustBreak = FALSE;
409 e->isJumpPoint = FALSE;
410 e->environment = environmentTable_undefined;
411 e->constraints = constraintList_undefined;
415 /*@observer@*/ exprNode exprNode_makeMustExit (void)
417 if (exprNode_isUndefined (mustExitNode))
419 mustExitNode = exprNode_createPlain (ctype_unknown);
420 mustExitNode->exitCode = XK_MUSTEXIT;
427 static /*@notnull@*/ /*@special@*/ exprNode exprNode_create (ctype c)
429 /*@post:isnull result->edata, result->guards, result->val,
430 result->uses, result->sets, result->msets@*/
433 exprNode e = exprNode_createPlain (c);
434 e->loc = fileloc_copy (g_currentloc);
438 static /*@notnull@*/ /*@special@*/ exprNode exprNode_createUnknown (void)
440 /*@post:isnull result->edata, result->guards,
441 result->uses, result->sets, result->msets@*/
444 return (exprNode_create (ctype_unknown));
447 static /*@notnull@*/ /*@special@*/ exprNode
448 exprNode_createLoc (ctype c, /*@keep@*/ fileloc loc)
450 /*@post:isnull result->edata, result->guards, result->val,
451 result->uses, result->sets, result->msets@*/
454 exprNode e = exprNode_createPlain (c);
460 exprNode_copySets (/*@special@*/ /*@notnull@*/ exprNode ret, exprNode e)
461 /*@defines ret->guards, ret->uses, ret->sets, ret->msets@*/
463 if (exprNode_isDefined (e))
465 ret->guards = guardSet_copy (e->guards);
466 ret->uses = sRefSet_newCopy (e->uses);
467 ret->sets = sRefSet_newCopy (e->sets);
468 ret->msets = sRefSet_newCopy (e->msets);
472 ret->guards = guardSet_undefined;
473 ret->uses = sRefSet_undefined;
474 ret->sets = sRefSet_undefined;
475 ret->msets = sRefSet_undefined;
479 static /*@notnull@*/ /*@special@*/ exprNode
480 exprNode_createPartialLocCopy (exprNode e, /*@only@*/ fileloc loc)
482 /*@post:isnull result->edata, result->etext@*/
485 exprNode ret = exprNode_new ();
487 if (exprNode_isError (e))
489 ret->typ = ctype_unknown;
490 ret->val = multiVal_undefined;
492 ret->guards = guardSet_undefined;
493 ret->uses = sRefSet_undefined;
494 ret->sets = sRefSet_undefined;
495 ret->msets = sRefSet_undefined;
500 ret->val = multiVal_copy (e->val);
502 ret->guards = guardSet_copy (e->guards);
503 ret->uses = sRefSet_newCopy (e->uses);
504 ret->sets = sRefSet_newCopy (e->sets);
505 ret->msets = sRefSet_newCopy (e->msets);
508 ret->kind = XPR_EMPTY;
510 ret->etext = cstring_undefined;
511 ret->exitCode = XK_NEVERESCAPE;
512 ret->canBreak = FALSE;
513 ret->mustBreak = FALSE;
514 ret->isJumpPoint = FALSE;
515 ret->edata = exprData_undefined;
521 static /*@notnull@*/ /*@special@*/ exprNode
522 exprNode_createPartialCopy (exprNode e)
524 /*@post:isnull result->edata, result->etext@*/
527 return (exprNode_createPartialLocCopy (e, fileloc_copy (exprNode_loc (e))));
530 static /*@notnull@*/ /*@special@*/ exprNode
531 exprNode_createPartialNVCopy (exprNode e)
533 /*@post:isnull result->edata, result->etext, result->val @*/
536 exprNode ret = exprNode_new ();
538 if (exprNode_isError (e))
540 ret->typ = ctype_unknown;
541 ret->loc = fileloc_undefined;
542 ret->guards = guardSet_undefined;
543 ret->uses = sRefSet_undefined;
544 ret->sets = sRefSet_undefined;
545 ret->msets = sRefSet_undefined;
550 ret->loc = fileloc_copy (e->loc);
551 ret->guards = guardSet_copy (e->guards);
552 ret->uses = sRefSet_newCopy (e->uses);
553 ret->sets = sRefSet_newCopy (e->sets);
554 ret->msets = sRefSet_newCopy (e->msets);
557 ret->val = multiVal_undefined;
558 ret->kind = XPR_EMPTY;
560 ret->etext = cstring_undefined;
561 ret->exitCode = XK_NEVERESCAPE;
562 ret->canBreak = FALSE;
563 ret->mustBreak = FALSE;
564 ret->isJumpPoint = FALSE;
565 ret->edata = exprData_undefined;
570 static /*@notnull@*/ /*@special@*/ exprNode
571 exprNode_createSemiCopy (exprNode e)
573 /*@post:isnull result->edata, result->etext, result->sets,
574 result->msets, result->uses, result->guards@*/
577 if (exprNode_isError (e))
579 return exprNode_createPlain (ctype_unknown);
583 exprNode ret = exprNode_new ();
586 ret->val = multiVal_copy (e->val);
587 ret->loc = fileloc_copy (e->loc);
588 ret->guards = guardSet_undefined;
589 ret->uses = sRefSet_undefined;
590 ret->sets = sRefSet_undefined;
591 ret->msets = sRefSet_undefined;
593 ret->kind = XPR_EMPTY;
595 ret->etext = cstring_undefined;
596 ret->exitCode = XK_NEVERESCAPE;
597 ret->canBreak = FALSE;
598 ret->mustBreak = FALSE;
599 ret->isJumpPoint = FALSE;
600 ret->edata = exprData_undefined;
607 exprNode_isNullValue (exprNode e)
609 if (exprNode_isDefined (e))
611 multiVal m = exprNode_getValue (e);
613 if (multiVal_isInt (m))
615 return (multiVal_forceInt (m) == 0);
623 exprNode_isUnknownConstant (/*@notnull@*/ exprNode e)
625 while (e->kind == XPR_PARENS)
627 e = exprData_getUopNode (e->edata);
628 llassert (exprNode_isDefined (e));
631 if (e->kind == XPR_CONST)
633 multiVal m = exprNode_getValue (e);
635 if (multiVal_isUnknown (m))
645 exprNode_numLiteral (ctype c, /*@temp@*/ cstring t,
646 /*@only@*/ fileloc loc, long val)
648 exprNode e = exprNode_createLoc (c, loc);
650 e->kind = XPR_NUMLIT;
652 llassert (multiVal_isUndefined (e->val));
653 e->val = multiVal_makeInt (val);
654 e->edata = exprData_makeLiteral (cstring_copy (t));
658 e->sref = sRef_makeUnknown ();
659 sRef_setDefNull (e->sref, e->loc);
662 DPRINTF (("Num lit: %s / %s", exprNode_unparse (e), ctype_unparse (exprNode_getType (e))));
667 exprNode_charLiteral (char c, cstring text, /*@only@*/ fileloc loc)
669 exprNode e = exprNode_createLoc (ctype_char, loc);
671 if (context_getFlag (FLG_CHARINTLITERAL))
673 e->typ = ctype_makeConj (ctype_char, ctype_int);
676 e->kind = XPR_NUMLIT;
677 e->val = multiVal_makeChar (c);
679 e->edata = exprData_makeLiteral (cstring_copy (text));
684 exprNode_floatLiteral (double d, ctype ct, cstring text, /*@only@*/ fileloc loc)
686 exprNode e = exprNode_createLoc (ct, loc);
688 e->kind = XPR_NUMLIT;
689 e->val = multiVal_makeDouble (d);
690 e->edata = exprData_makeLiteral (cstring_copy (text));
694 multiVal exprNode_getValue (exprNode e)
696 while (exprNode_isInParens (e)) {
697 if (e->edata != NULL) {
698 e = exprData_getUopNode (e->edata);
704 if (exprNode_isDefined (e)) {
707 return multiVal_undefined;
712 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
714 exprNode e = exprNode_createLoc (ctype_string, loc);
715 int len = cstring_length (t) - 2;
716 char *ts = cstring_toCharsSafe (t);
717 char *s = cstring_toCharsSafe (cstring_create (len + 1));
719 if (context_getFlag (FLG_STRINGLITERALLEN))
721 if (len > context_getValue (FLG_STRINGLITERALLEN))
723 voptgenerror (FLG_STRINGLITERALLEN,
725 ("String literal length (%d) exceeds maximum "
728 context_getValue (FLG_STRINGLITERALLEN),
734 strncpy (s, ts+1, size_fromInt (len));
738 e->kind = XPR_STRINGLITERAL;
739 e->val = multiVal_makeString (cstring_fromCharsO (s));
740 e->edata = exprData_makeLiteral (t);
741 e->sref = sRef_makeType (ctype_string);
742 /* Start modifications */
743 /* This expr is null terminated, so we set the len and size */
744 sRef_setNullTerminatedState(e->sref);
746 TPRINTF("Len is set to : %d\n\n", strlen((char *)multiVal_forceString(e->val)));
747 TPRINTF("Size is set to : %d\n\n", strlen((char *)multiVal_forceString(e->val)));
748 TPRINTF("State is set to: %d\n\n", e->sref->bufinfo.bufstate);
750 sRef_setLen(e->sref, strlen((char *)multiVal_forceString(e->val)));
751 sRef_setSize(e->sref, strlen((char *)multiVal_forceString(e->val)));
753 if (context_getFlag (FLG_READONLYSTRINGS))
755 sRef_setAliasKind (e->sref, AK_STATIC, fileloc_undefined);
756 sRef_setExKind (e->sref, XO_OBSERVER, loc);
760 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
763 return (e); /* s released */
766 exprNode exprNode_fromUIO (cstring c)
768 fileloc loc = context_getSaveLocation ();
769 exprNode e = exprNode_createPlain (ctype_unknown);
773 if (fileloc_isUndefined (loc))
775 loc = fileloc_copy (g_currentloc);
778 e->loc = loc; /* save loc was mangled */
781 if (usymtab_exists (c))
783 uentry ue = usymtab_lookupEither (c);
785 if (uentry_isDatatype (ue)
786 && uentry_isSpecified (ue))
789 (message ("%q: Specified datatype %s used in code, but not defined. "
790 "(Cannot continue reasonably from this error.)",
791 fileloc_unparse (e->loc), c));
799 llassertprint (!usymtab_exists (c), ("Entry exists: %s", c));
802 ** was supercedeGlobalEntry...is this better?
805 if (!context_inIterEnd ())
807 if (context_inMacro ())
809 if (context_getFlag (FLG_UNRECOG))
813 message ("Unrecognized identifier in macro definition: %s", c), e->loc);
817 flagcode_recordSuppressed (FLG_UNRECOG);
823 (FLG_UNRECOG, message ("Unrecognized identifier: %s", c),
828 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
830 /* No alias errors for unrecognized identifiers */
831 sRef_setAliasKind (e->sref, AK_ERROR, loc);
836 exprNode exprNode_createId (/*@observer@*/ uentry c)
838 if (uentry_isValid (c))
840 exprNode e = exprNode_new ();
842 e->typ = uentry_getType (c);
844 if (uentry_isFunction (c)
845 && !sRef_isLocalVar (uentry_getSref (c)))
847 e->sref = sRef_undefined;
851 e->sref = uentry_getSref (c);
854 if (sRef_isStateUnknown (e->sref) && uentry_isNonLocal (c))
856 sRef_setDefined (e->sref, fileloc_undefined);
860 ** yoikes! leaving this out was a heinous bug...that would have been
861 ** caught if i had lclint working first. gag!
864 e->etext = cstring_undefined;
866 if (uentry_isEitherConstant (c))
869 e->val = multiVal_copy (uentry_getConstantValue (c));
874 e->val = multiVal_unknown ();
877 e->edata = exprData_makeId (c);
878 e->loc = context_getSaveLocation ();
880 if (fileloc_isUndefined (e->loc))
882 fileloc_free (e->loc);
883 e->loc = fileloc_copy (g_currentloc);
886 e->guards = guardSet_new ();
887 e->sets = sRefSet_new ();
888 e->msets = sRefSet_new ();
889 e->uses = sRefSet_new ();
891 /*> missing fields, detected by lclint <*/
892 e->exitCode = XK_NEVERESCAPE;
893 e->isJumpPoint = FALSE;
895 e->mustBreak = FALSE;
901 return exprNode_createUnknown ();
905 /*@notnull@*/ exprNode
906 exprNode_fromIdentifier (/*@observer@*/ uentry c)
910 if (context_justPopped ()) /* watch out! c could be dead */
912 uentry ce = usymtab_lookupSafe (LastIdentifier ());
914 if (uentry_isValid (ce))
920 llbuglit ("Looks like Aunt Millie forgot to walk to dog again.");
924 ret = exprNode_fromIdentifierAux (c);
930 static /*@only@*/ /*@notnull@*/ exprNode
931 exprNode_fromIdentifierAux (/*@observer@*/ uentry c)
933 exprNode e = exprNode_createId (c);
936 uentry_setUsed (c, e->loc);
938 if (uentry_isVar (c) && sRef_isGlobal (sr))
940 checkGlobUse (c, FALSE, e);
947 exprNode_isZero (exprNode e)
949 if (exprNode_isDefined (e))
951 multiVal m = exprNode_getValue (e);
953 if (multiVal_isInt (m))
955 return (multiVal_forceInt (m) == 0);
963 exprNode_isNonNegative (exprNode e)
965 if (exprNode_isDefined (e))
967 multiVal m = exprNode_getValue (e);
969 if (multiVal_isInt (m))
971 return (multiVal_forceInt (m) >= 0);
979 ** a[x] - uses a but NOT a[]
980 ** result sref = a[] (set/use in assignment)
982 ** The syntax x[a] is also legal in C, and has the same
983 ** semantics. If ind is an array, and arr is an int, flip
988 exprNode_arrayFetch (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
991 ** error in arr, error propagates (no new messages)
992 ** error in ind, assume valid and continue
995 if (exprNode_isError (e1))
998 return (exprNode_makeError ());
1004 ctype carr = exprNode_getType (e1);
1005 ctype crarr = ctype_realType (carr);
1008 ** this sets up funny aliasing, that leads to spurious
1009 ** lclint errors. Hence, the i2 comments.
1012 if (!ctype_isRealArray (crarr)
1013 && ctype_isRealNumeric (crarr)
1014 && !exprNode_isError (e2)
1015 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1020 carr = exprNode_getType (arr);
1021 crarr = ctype_realType (carr);
1029 if (sRef_possiblyNull (arr->sref))
1031 if (!usymtab_isGuarded (arr->sref))
1033 if (optgenerror (FLG_NULLDEREF,
1034 message ("Index of %s pointer %q: %s",
1035 sRef_nullMessage (arr->sref),
1036 sRef_unparse (arr->sref),
1037 exprNode_unparse (arr)),
1040 sRef_showNullInfo (arr->sref);
1042 /* suppress future messages */
1043 sRef_setNullError (arr->sref);
1048 if (exprNode_isError (ind))
1050 if ((ctype_isArrayPtr (crarr)
1051 && !ctype_isFunction (crarr))
1052 || ctype_isUnknown (carr))
1054 exprNode ret = exprNode_createPartialCopy (arr);
1056 if (ctype_isKnown (carr))
1058 ret->typ = ctype_baseArrayPtr (crarr);
1062 ret->typ = ctype_unknown;
1065 ret->sref = sRef_makeArrayFetch (arr->sref);
1067 ret->kind = XPR_FETCH;
1070 ** Because of funny aliasing (when arr and ind are
1071 ** flipped) spurious errors would be reported here.
1074 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1075 checkSafeUse (ret, arr->sref);
1080 voptgenerror (FLG_TYPE,
1081 message ("Array fetch from non-array (%t): %s[%s]", carr,
1082 exprNode_unparse (e1), exprNode_unparse (e2)),
1084 exprNode_free (arr);
1085 return (exprNode_makeError ());
1090 if (!ctype_isForceRealInt (&(ind->typ)))
1092 ctype rt = ctype_realType (ind->typ);
1094 if (ctype_isChar (rt))
1098 message ("Array fetch using non-integer, %t: %s[%s]",
1100 exprNode_unparse (e1), exprNode_unparse (e2)),
1103 else if (ctype_isEnum (rt))
1107 message ("Array fetch using non-integer, %t: %s[%s]",
1109 exprNode_unparse (e1), exprNode_unparse (e2)),
1116 message ("Array fetch using non-integer, %t: %s[%s]",
1118 exprNode_unparse (e1), exprNode_unparse (e2)),
1122 multiVal_free (ind->val);
1123 ind->val = multiVal_unknown ();
1126 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1128 exprNode ret = exprNode_createSemiCopy (arr);
1129 multiVal m = exprNode_getValue (ind);
1131 ret->typ = ctype_baseArrayPtr (crarr);
1132 ret->kind = XPR_FETCH;
1134 if (multiVal_isInt (m))
1136 int i = (int) multiVal_forceInt (m);
1138 if (sRef_isValid (arr->sref)) {
1139 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1141 ret->sref = sRef_undefined;
1146 ret->sref = sRef_makeArrayFetch (arr->sref);
1149 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1150 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1151 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1153 /* (see comment on spurious errors above) */
1154 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1156 exprNode_checkUse (ret, ind->sref, ind->loc);
1157 exprNode_checkUse (ret, arr->sref, arr->loc);
1163 if (ctype_isUnknown (carr))
1165 exprNode ret = exprNode_createPartialCopy (arr);
1167 ret->kind = XPR_FETCH;
1168 ret->typ = ctype_unknown;
1169 ret->sets = sRefSet_union (ret->sets, ind->sets);
1170 ret->msets = sRefSet_union (ret->msets, ind->msets);
1171 ret->uses = sRefSet_union (ret->uses, ind->uses);
1173 /* (see comment on spurious errors above) */
1174 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1176 exprNode_checkUse (ret, ind->sref, ind->loc);
1177 exprNode_checkUse (ret, arr->sref, arr->loc);
1184 message ("Array fetch from non-array (%t): %s[%s]", carr,
1185 exprNode_unparse (e1), exprNode_unparse (e2)),
1188 exprNode_free (arr);
1189 exprNode_free (ind);
1191 return (exprNode_makeError ());
1201 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1202 exprNodeList args, exprNode ret)
1204 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1208 ** checkPrintfArgs --- checks arguments for printf-like functions
1209 ** Arguments before ... have already been checked.
1210 ** The argument before the ... is a char *.
1211 ** argno is the format string argument.
1215 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1216 exprNodeList args, exprNode ret, int argno)
1219 ** the last argument before the elips is the format string
1224 int nargs = exprNodeList_size (args);
1225 uentryList params = uentry_getParams (fcn);
1229 ** These should be ensured by checkSpecialFunction
1232 llassert (uentryList_size (params) == argno + 1);
1233 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1235 a = exprNodeList_getN (args, argno - 1);
1236 formatloc = fileloc_copy (exprNode_loc (a));
1238 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1239 && exprNode_knownStringValue (a))
1241 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1242 char *code = format;
1245 nargs = exprNodeList_size (args);
1247 while ((code = strchr (code, '%')) != NULL)
1249 char *origcode = code;
1250 char key = *(++code);
1251 ctype modtype = ctype_int;
1252 bool modified = FALSE;
1254 fileloc_addColumn (formatloc, code - ocode);
1257 while (isFlagKey (key))
1260 fileloc_incColumn (formatloc);
1263 if (key == 'm') /* skipped in syslog */
1268 /* ignore field width */
1269 while (isdigit ((int) key) != 0)
1272 fileloc_incColumn (formatloc);
1275 /* ignore precision */
1279 fileloc_incColumn (formatloc);
1282 ** In printf, '*' means: read the next arg as an int for the
1283 ** field width. This seems to be missing from my copy of the
1284 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1285 ** later) but never does.
1290 ; /* don't do anything --- handle later */
1294 while (isdigit ((int) key) != 0)
1297 fileloc_incColumn (formatloc);
1304 modtype = ctype_sint; /* short */
1306 fileloc_incColumn (formatloc);
1308 else if (key == 'l' || key == 'L')
1310 modtype = ctype_lint; /* long */
1312 fileloc_incColumn (formatloc);
1314 if (key == 'l' || key == 'L') {
1315 modtype = ctype_llint; /* long long */
1317 fileloc_incColumn (formatloc);
1325 /* now, key = type of conversion to apply */
1327 fileloc_incColumn (formatloc);
1335 message ("No argument corresponding to %q format "
1336 "code %d (%%%h): \"%s\"",
1337 uentry_getName (fcn),
1339 cstring_fromChars (format)),
1342 if (fileloc_isDefined (formatloc)
1343 && context_getFlag (FLG_SHOWCOL))
1345 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1353 a = exprNodeList_getN (args, i);
1356 if (!exprNode_isError (a))
1362 case '*': /* int argument for fieldwidth */
1363 expecttype = ctype_int;
1364 *(--code) = '%'; /* convert it for next code */
1365 fileloc_subColumn (formatloc, 1);
1366 /*@switchbreak@*/ break;
1369 expecttype = ctype_combine (ctype_uint, modtype);
1370 /*@switchbreak@*/ break;
1372 case 'i': /* int argument */
1374 expecttype = ctype_combine (ctype_int, modtype);
1375 /*@switchbreak@*/ break;
1377 case 'x': /* unsigned int */
1379 expecttype = ctype_combine (ctype_uint, modtype);
1380 /*@switchbreak@*/ break;
1386 case 'f': /* double */
1387 expecttype = ctype_combine (ctype_double, modtype);
1388 /*@switchbreak@*/ break;
1390 case 'c': /* int converted to char (check its a char?) */
1391 expecttype = ctype_makeConj (ctype_char, ctype_uchar);
1392 /*@switchbreak@*/ break;
1394 case 's': /* string */
1395 expecttype = ctype_string;
1396 /*@switchbreak@*/ break;
1399 while (((key = *(++code)) != ']')
1402 fileloc_incColumn (formatloc);
1408 (message ("Bad character set format: %s",
1409 cstring_fromChars (origcode)));
1412 expecttype = ctype_string;
1413 /*@switchbreak@*/ break;
1415 case 'p': /* pointer */
1416 expecttype = ctype_makePointer (ctype_void);
1418 /*@switchbreak@*/ break;
1420 case 'n': /* pointer to int, modified by call! */
1421 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1423 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1424 /*@switchbreak@*/ break;
1426 case 'm': /* in a syslog, it doesn't consume an argument */
1427 /* should check we're really doing syslog */
1429 /*@switchbreak@*/ break;
1433 expecttype = ctype_unknown;
1437 message ("Unrecognized format code: %s",
1438 cstring_fromChars (origcode)),
1439 fileloc_isDefined (formatloc)
1440 ? formatloc : g_currentloc);
1442 /*@switchbreak@*/ break;
1445 if (!(exprNode_matchArgType (expecttype, a)))
1447 if (ctype_isVoidPointer (expecttype)
1448 && ctype_isRealAbstract (a->typ)
1449 && (context_getFlag (FLG_ABSTVOIDP)))
1455 if (llgenformattypeerror
1456 (expecttype, exprNode_undefined,
1458 message ("Format argument %d to %q (%%%h) expects "
1461 uentry_getName (fcn),
1463 a->typ, exprNode_unparse (a)),
1466 if (fileloc_isDefined (formatloc)
1467 && context_getFlag (FLG_SHOWCOL))
1470 (cstring_makeLiteral
1471 ("Corresponding format code"),
1478 uentry_setType (regArg, expecttype);
1479 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1481 if (ctype_equal (expecttype, ctype_string))
1483 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1486 uentry_setType (regArg, ctype_unknown);
1487 uentry_fixupSref (regArg);
1491 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1505 voptgenerror (FLG_TYPE,
1506 message ("Format string for %q has %d arg%p, given %d",
1507 uentry_getName (fcn), i - argno, nargs - argno),
1513 /* no checking possible for compile-time unknown format strings */
1516 fileloc_free (formatloc);
1520 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1521 exprNodeList args, exprNode ret, int argno)
1525 int nargs = exprNodeList_size (args);
1526 uentryList params = uentry_getParams (fcn);
1530 ** These should be ensured by checkSpecialFunction
1533 llassert (uentryList_size (params) == argno + 1);
1534 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1536 a = exprNodeList_getN (args, argno - 1);
1537 formatloc = fileloc_copy (exprNode_loc (a));
1539 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1540 && exprNode_knownStringValue (a))
1542 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1543 char *code = format;
1546 nargs = exprNodeList_size (args);
1548 while ((code = strchr (code, '%')) != NULL)
1550 char *origcode = code;
1551 char key = *(++code);
1552 ctype modtype = ctype_int;
1553 char modifier = '\0';
1554 bool modified = TRUE;
1555 bool ignore = FALSE;
1557 fileloc_addColumn (formatloc, code - ocode);
1560 ** this is based on ANSI standard library description of fscanf
1561 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1564 /* '*' suppresses assignment (does not need match argument) */
1571 fileloc_incColumn (formatloc);
1574 /* ignore field width */
1575 while (isdigit ((int) key) != 0)
1578 fileloc_incColumn (formatloc);
1583 modtype = ctype_sint; /* short */
1585 fileloc_incColumn (formatloc);
1587 else if (key == 'l' || key == 'L')
1589 modtype = ctype_lint; /* long */
1593 fileloc_incColumn (formatloc);
1595 if (key == 'l' || key == 'L') {
1596 modtype = ctype_llint; /* long long */
1598 fileloc_incColumn (formatloc);
1606 /* now, key = type of conversion to apply */
1608 fileloc_incColumn (formatloc);
1622 message ("No argument corresponding to %q format "
1623 "code %d (%%%h): \"%s\"",
1624 uentry_getName (fcn),
1626 cstring_fromChars (format)),
1629 if (fileloc_isDefined (formatloc)
1630 && context_getFlag (FLG_SHOWCOL))
1633 (cstring_makeLiteral ("Corresponding format code"),
1641 a = exprNodeList_getN (args, i);
1644 if (!exprNode_isError (a))
1650 case '*': /* int argument for fieldwidth */
1651 expecttype = ctype_makePointer (ctype_int);
1652 *(--code) = '%'; /* convert it for next code */
1653 fileloc_subColumn (formatloc, 1);
1654 /*@switchbreak@*/ break;
1657 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1658 /*@switchbreak@*/ break;
1663 case 'X': /* unsigned int */
1664 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1665 /*@switchbreak@*/ break;
1672 /* printf is double, scanf is float! */
1674 if (modifier == 'l')
1676 expecttype = ctype_makePointer (ctype_double);
1678 else if (modifier == 'L')
1680 expecttype = ctype_makePointer (ctype_ldouble);
1684 llassert (modifier == '\0');
1685 expecttype = ctype_makePointer (ctype_float);
1687 /*@switchbreak@*/ break;
1689 case 'c': /* int converted to char (check its a char?) */
1690 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1691 /*@switchbreak@*/ break;
1693 case 's': /* string */
1694 expecttype = ctype_string;
1695 /*@switchbreak@*/ break;
1699 while (((key = *(++code)) != ']')
1702 fileloc_incColumn (formatloc);
1708 (message ("Bad character set format: %s",
1709 cstring_fromChars (origcode)));
1712 expecttype = ctype_string;
1713 /*@switchbreak@*/ break;
1715 case 'p': /* pointer */
1716 expecttype = ctype_unknown;
1718 /*@switchbreak@*/ break;
1720 case 'n': /* pointer to int, modified by call! */
1721 expecttype = ctype_makePointer (ctype_int);
1722 /*@switchbreak@*/ break;
1725 expecttype = ctype_unknown;
1729 message ("Unrecognized format code: %s",
1730 cstring_fromChars (origcode)),
1731 fileloc_isDefined (formatloc)
1732 ? formatloc : g_currentloc);
1734 /*@switchbreak@*/ break;
1737 if (!(exprNode_matchArgType (expecttype, a)))
1739 if (ctype_isVoidPointer (expecttype)
1740 && ctype_isRealAbstract (a->typ)
1741 && (context_getFlag (FLG_ABSTVOIDP)))
1747 if (modifier != '\0')
1749 if (llgenformattypeerror
1750 (expecttype, exprNode_undefined,
1752 message ("Format argument %d to %q (%%%h%h) expects "
1755 uentry_getName (fcn),
1758 a->typ, exprNode_unparse (a)),
1761 if (fileloc_isDefined (formatloc)
1762 && context_getFlag (FLG_SHOWCOL))
1765 (cstring_makeLiteral
1766 ("Corresponding format code"),
1774 if (llgenformattypeerror
1775 (expecttype, exprNode_undefined,
1777 message ("Format argument %d to %q (%%%h) expects "
1780 uentry_getName (fcn),
1782 a->typ, exprNode_unparse (a)),
1785 if (fileloc_isDefined (formatloc)
1786 && context_getFlag (FLG_SHOWCOL))
1789 (cstring_makeLiteral
1790 ("Corresponding format code"),
1798 uentry_setType (outArg, expecttype);
1799 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
1800 uentry_setType (outArg, ctype_unknown);
1801 uentry_fixupSref (outArg);
1805 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1810 /* a->sref = defref; */
1820 voptgenerror (FLG_TYPE,
1821 message ("Format string for %q has %d arg%p, given %d",
1822 uentry_getName (fcn), i - argno, nargs - argno),
1828 /* no checking possible for compile-time unknown format strings */
1831 fileloc_free (formatloc);
1835 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
1838 /*@unused@*/ int argno)
1841 ** the last argument before the elips is the format string
1844 int nargs = exprNodeList_size (args);
1849 a = exprNodeList_getN (args, argno - 1);
1850 formatloc = fileloc_copy (exprNode_loc (a));
1852 if (ctype_isUnknown (cstringType)) {
1853 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
1855 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
1859 if (ctype_isUnknown (ctypeType)) {
1860 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
1862 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
1866 if (ctype_isUnknown (filelocType)) {
1867 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
1869 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
1873 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1874 && exprNode_knownStringValue (a))
1876 cstring format = multiVal_forceString (exprNode_getValue (a));
1877 char *code = cstring_toCharsSafe (format);
1880 nargs = exprNodeList_size (args);
1882 while ((code = strchr (code, '%')) != NULL)
1884 char *origcode = code;
1885 char key = *(++code);
1886 bool isOnly = FALSE;
1888 fileloc_addColumn (formatloc, code - ocode);
1890 while (key >= '0' && key <= '9')
1893 fileloc_incColumn (formatloc);
1897 fileloc_incColumn (formatloc);
1910 message ("Message missing format arg %d (%%%h): \"%s\"",
1911 i + 1, key, format),
1917 a = exprNodeList_getN (args, i);
1921 if (!exprNode_isError (a))
1925 /*@-loopswitchbreak@*/
1931 expecttype = ctype_char; break;
1933 expecttype = cstringType; break;
1935 expecttype = cstringType; isOnly = TRUE; break;
1937 expecttype = cstringType; isOnly = TRUE; break;
1938 case 'd': expecttype = ctype_int; break;
1939 case 'u': expecttype = ctype_uint; break;
1940 case 'w': expecttype = ctype_ulint; break;
1941 case 'f': expecttype = ctype_float; break;
1942 case 'b': expecttype = ctype_bool; break;
1943 case 't': expecttype = ctypeType; break;
1944 case 'l': expecttype = filelocType; break;
1945 case 'p': /* a wee bit of a hack methinks */
1946 expecttype = ctype_int;
1948 case 'r': expecttype = ctype_bool; break;
1950 expecttype = ctype_unknown;
1953 message ("Unrecognized format code: %s",
1954 cstring_fromChars (origcode)),
1955 fileloc_isDefined (formatloc)
1956 ? formatloc : g_currentloc);
1959 /*@=loopswitchbreak@*/
1961 if (!(exprNode_matchArgType (expecttype, a)))
1963 if (ctype_isVoidPointer (expecttype)
1964 && ctype_isRealAbstract (a->typ)
1965 && (context_getFlag (FLG_ABSTVOIDP)))
1971 if (llgenformattypeerror
1972 (expecttype, exprNode_undefined,
1974 message ("Format argument %d to %q (%%%h) expects "
1977 uentry_getName (fcn),
1979 a->typ, exprNode_unparse (a)),
1982 if (fileloc_isDefined (formatloc)
1983 && context_getFlag (FLG_SHOWCOL))
1986 (cstring_makeLiteral
1987 ("Corresponding format code"),
1994 if (ctype_equal (expecttype, cstringType))
1998 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
1999 uentry_fixupSref (csOnlyArg);
2003 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2004 uentry_fixupSref (csArg);
2009 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2010 uentry_fixupSref (regArg);
2019 voptgenerror (FLG_TYPE,
2020 message ("Format string for %q has %d arg%p, given %d",
2021 uentry_getName (fcn), i - argno, nargs -argno),
2027 /* no checking possible for compile-time unknown format strings */
2030 fileloc_free (formatloc);
2034 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2035 /*@notnull@*/ exprNode e2,
2041 bool hadUncon = FALSE;
2043 if (sRef_isGlobal (sRef_getRootBase (e1->sref)) &&
2044 sRefSet_hasUnconstrained (sets2))
2047 (FLG_EVALORDERUNCON,
2049 ("Expression may have undefined behavior (%q used in right operand "
2050 "may set global variable %q used in left operand): %s %s %s",
2051 sRefSet_unparseUnconstrained (sets2),
2052 sRef_unparse (sRef_getRootBase (e1->sref)),
2053 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2057 if (sRef_isGlobal (sRef_getRootBase (e2->sref)) &&
2058 sRefSet_hasUnconstrained (sets1))
2061 (FLG_EVALORDERUNCON,
2063 ("Expression has undefined behavior (%q used in left operand "
2064 "may set global variable %q used in right operand): %s %s %s",
2065 sRefSet_unparseUnconstrained (sets1),
2066 sRef_unparse (e2->sref),
2067 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2071 sRefSet_realElements (e1->uses, sr)
2073 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2078 ("Expression has undefined behavior (left operand uses %q, "
2079 "modified by right operand): %s %s %s",
2081 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2084 } end_sRefSet_realElements;
2086 sRefSet_realElements (sets1, sr)
2088 if (sRef_isMeaningful (sr))
2090 if (sRef_same (sr, e2->sref))
2095 ("Expression has undefined behavior (value of right operand "
2096 "modified by left operand): %s %s %s",
2097 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2100 else if (sRefSet_member (e2->uses, sr))
2105 ("Expression has undefined behavior (left operand modifies %q, "
2106 "used by right operand): %s %s %s",
2108 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2113 if (sRefSet_member (sets2, sr))
2115 if (sRef_isUnconstrained (sr))
2123 hadUncon = optgenerror
2124 (FLG_EVALORDERUNCON,
2126 ("Expression may have undefined behavior. Left operand "
2127 "calls %q; right operand calls %q. The unconstrained "
2128 "functions may modify global state used by "
2129 "the other operand): %s %s %s",
2130 sRefSet_unparseUnconstrained (sets1),
2131 sRefSet_unparseUnconstrained (sets2),
2132 exprNode_unparse (e1), lltok_unparse (op),
2133 exprNode_unparse (e2)),
2142 ("Expression has undefined behavior (both "
2143 "operands modify %q): %s %s %s",
2145 exprNode_unparse (e1),
2146 lltok_unparse (op), exprNode_unparse (e2)),
2152 } end_sRefSet_realElements;
2155 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2157 bool hasError = FALSE;
2159 if (exprNode_isError (e1) || exprNode_isError (e2))
2164 if (sRefSet_member (e2->sets, e1->sref))
2166 if (e2->kind == XPR_CALL)
2172 hasError = optgenerror
2174 message ("Expression has undefined behavior "
2175 "(value of left operand is modified "
2176 "by right operand): %s %s %s",
2177 exprNode_unparse (e1), lltok_unparse (op),
2178 exprNode_unparse (e2)),
2183 if (context_getFlag (FLG_EVALORDERUNCON))
2185 if (sRefSet_member (e2->msets, e1->sref))
2187 if (e2->kind == XPR_CALL)
2193 hasError = optgenerror
2196 ("Expression has undefined behavior (value of left "
2197 "operand may be modified by right operand): %s %s %s",
2198 exprNode_unparse (e1), lltok_unparse (op),
2199 exprNode_unparse (e2)),
2207 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2209 if (context_maybeSet (FLG_EVALORDERUNCON))
2211 checkExpressionDefinedAux (e1, e2, e1->msets,
2212 e2->msets, op, FLG_EVALORDERUNCON);
2217 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2220 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2221 exprNodeList args, bool isIter, exprNode ret)
2225 if (!exprNode_isError (f))
2227 if (!uentryList_isMissingParams (cl))
2229 int nargs = exprNodeList_size (args);
2230 int expectargs = uentryList_size (cl);
2234 if (expectargs == 0)
2242 message ("Iter %q invoked with %d args, "
2244 uentry_getName (fcn),
2252 message ("Function %s called with %d args, "
2254 exprNode_unparse (f), nargs),
2261 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2263 exprNodeList_reset (args);
2265 uentryList_elements (cl, current)
2267 ctype ct = uentry_getType (current);
2270 if (ctype_isElips (ct))
2273 ** do special checking for printf/scanf library functions
2275 ** this is kludgey code, just for handling the special case
2279 if (uentry_isPrintfLike (fcn))
2281 checkPrintfArgs (f, fcn, args, ret, i);
2284 else if (uentry_isScanfLike (fcn))
2286 checkScanfArgs (f, fcn, args, ret, i);
2289 else if (uentry_isMessageLike (fcn))
2291 checkMessageArgs (f, fcn, args, i);
2296 llassert (!uentry_isSpecialFunction (fcn));
2299 nargs = expectargs; /* avoid errors */
2304 if (i >= nargs) break;
2306 a = exprNodeList_current (args);
2307 exprNodeList_advance (args);
2311 if (exprNode_isError (a))
2318 probably necessary? I'm not sure about this one
2319 checkMacroParen (a);
2322 f->guards = guardSet_union (f->guards, a->guards);
2324 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2326 if (!(exprNode_matchArgType (ct, a)))
2328 DPRINTF (("Args mismatch!"));
2330 if (ctype_isVoidPointer (ct)
2331 && (ctype_isPointer (a->typ)
2332 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2337 ("Pointer to abstract type (%t) used "
2339 "(arg %d to %q): %s",
2341 uentry_getName (fcn),
2342 exprNode_unparse (a)),
2350 (ct, exprNode_undefined,
2353 ("Iter %q expects arg %d to "
2354 "be %t gets %t: %s",
2355 uentry_getName (fcn),
2356 i, ct, a->typ, exprNode_unparse (a)),
2367 ("Function %q expects arg %d to be %t gets %t: %s",
2368 uentry_getName (fcn),
2369 i, ct, a->typ, exprNode_unparse (a)),
2372 DPRINTF (("Types: %s / %s",
2374 ctype_unparse (a->typ)));
2378 ** Clear null marker for abstract types.
2379 ** (It is not revealed, so suppress future messages.)
2382 if (ctype_isAbstract (a->typ))
2384 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2391 } end_uentryList_elements ;
2394 if (expectargs != nargs) /* note: not != since we may have ... */
2396 if (ctype_isElips (last))
2400 message ("Function %s called with %d args, expects at least %d",
2401 exprNode_unparse (f),
2402 nargs, expectargs - 1),
2411 message ("Iter %q invoked with %d args, expects %d",
2412 uentry_getName (fcn), nargs, expectargs),
2419 message ("Function %s called with %d args, expects %d",
2420 exprNode_unparse (f),
2433 ** Check for undefined code sequences in function arguments:
2435 ** one parameter sets something used by another parameter
2436 ** one parameter sets something set by another parameter
2440 checkSequencingOne (exprNode f, exprNodeList args,
2441 /*@notnull@*/ exprNode el, int argno)
2444 ** Do second loop, iff +undefunspec
2448 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2450 for (checkloop = 0; checkloop < numloops; checkloop++)
2456 thissets = el->sets;
2460 llassert (checkloop == 1);
2461 thissets = el->msets;
2464 sRefSet_realElements (thissets, thisset)
2468 /*@access exprNodeList@*/
2469 for (j = 0; j < args->nelements; j++)
2471 exprNode jl = args->elements[j];
2472 int thisargno = j + 1;
2474 if (thisargno != argno && exprNode_isDefined (jl))
2476 sRefSet otheruses = jl->uses;
2478 if (sRef_isGlobal (sRef_getRootBase (jl->sref)) &&
2479 sRefSet_hasUnconstrained (thissets))
2482 (FLG_EVALORDERUNCON,
2485 ("%q used in argument %d may set "
2486 "global variable %q used by argument %d: %s(%q)",
2487 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2490 sRef_unparse (sRef_getRootBase (jl->sref)),
2492 exprNode_unparse (f), exprNodeList_unparse (args)),
2496 if (sRefSet_member (otheruses, thisset))
2498 if (sRef_isUnconstrained (thisset))
2501 (FLG_EVALORDERUNCON,
2503 ("Unconstrained functions used in arguments %d (%q) "
2504 "and %d (%s) may modify "
2505 "or use global state in undefined way: %s(%q)",
2507 sRefSet_unparseUnconstrainedPlain (otheruses),
2509 sRef_unconstrainedName (thisset),
2510 exprNode_unparse (f),
2511 exprNodeList_unparse (args)),
2519 ("Argument %d modifies %q, used by argument %d "
2520 "(order of evaluation of actual parameters is "
2521 "undefined): %s(%q)",
2522 argno, sRef_unparse (thisset), thisargno,
2523 exprNode_unparse (f), exprNodeList_unparse (args)),
2529 sRefSet othersets = jl->sets;
2531 if (sRefSet_member (othersets, thisset))
2533 if (sRef_isUnconstrained (thisset))
2536 (FLG_EVALORDERUNCON,
2538 ("Unconstrained functions used in "
2539 "arguments %d (%q) and %d (%s) may modify "
2540 "or use global state in undefined way: %s(%q)",
2542 sRefSet_unparseUnconstrainedPlain (othersets),
2544 sRef_unconstrainedName (thisset),
2545 exprNode_unparse (f), exprNodeList_unparse (args)),
2553 ("Argument %d modifies %q, set by argument %d (order of"
2554 " evaluation of actual parameters is undefined): %s(%q)",
2555 argno, sRef_unparse (thisset), thisargno,
2556 exprNode_unparse (f), exprNodeList_unparse (args)),
2563 /*@noaccess exprNodeList@*/
2564 } end_sRefSet_realElements;
2569 checkSequencing (exprNode f, exprNodeList args)
2571 if (exprNodeList_size (args) > 1)
2576 /*@access exprNodeList*/
2578 for (i = 0; i < args->nelements; i++)
2580 el = args->elements[i];
2582 if (!exprNode_isError (el))
2584 checkSequencingOne (f, args, el, i + 1);
2587 /*@noaccess exprNodeList*/
2592 ** requires le = exprNode_getUentry (f)
2596 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2597 uentry le, exprNodeList args,
2598 /*@notnull@*/ exprNode ret, int specialArgs)
2600 bool isSpec = FALSE;
2601 bool hasMods = FALSE;
2603 globSet usesGlobs = globSet_undefined;
2604 sRefSet mods = sRefSet_undefined;
2605 bool freshMods = FALSE;
2606 uentryList params = uentryList_undefined;
2609 ** check globals and modifies
2614 if (!uentry_isValid (le))
2616 ctype fr = ctype_realType (f->typ);
2618 if (ctype_isFunction (fr))
2620 params = ctype_argsFunction (fr);
2624 params = uentryList_missingParams;
2627 if (!context_getFlag (FLG_MODNOMODS)
2628 && !context_getFlag (FLG_GLOBUNSPEC))
2630 checkUnspecCall (f, params, args);
2636 fname = uentry_rawName (le);
2640 if (uentry_isFunction (le))
2642 params = uentry_getParams (le);
2643 mods = uentry_getMods (le);
2644 hasMods = uentry_hasMods (le);
2645 usesGlobs = uentry_getGlobs (le);
2646 isSpec = uentry_isSpecified (le);
2648 else /* not a function */
2650 ctype ct = ctype_realType (uentry_getType (le));
2652 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2653 ("checkModGlobs: uentry not a function: %s",
2654 uentry_unparse (le)));
2656 params = ctype_argsFunction (ct);
2666 globSet_allElements (usesGlobs, el)
2668 if (sRef_isValid (el))
2670 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2672 context_usedGlobal (el);
2673 exprNode_checkUse (f, el, f->loc);
2675 if (context_checkInternalUse ())
2677 if (!context_globAccess (el))
2679 if (sRef_isSystemState (el)
2680 && !context_getFlag (FLG_MODFILESYSTEM))
2689 ("Called procedure %s may access %q, but "
2690 "globals list does not include globals %s",
2691 exprNode_unparse (f),
2693 cstring_makeLiteralTemp (sRef_isInternalState (el)
2701 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2707 uentry gle = sRef_getUentry (el);
2708 sRef sr = sRef_updateSref (el);
2710 if (sRef_isUndefGlob (el))
2712 sRef_setDefined (sr, f->loc);
2713 exprNode_checkSet (f, sr);
2721 if (sRef_isAllocated (el))
2723 exprNode_checkSet (f, sr);
2727 if (sRef_isStateUndefined (sr))
2732 ("%s %q used by function undefined before call: %s",
2733 sRef_getScopeName (sr),
2735 exprNode_unparse (f)),
2737 sRef_setDefined (sr, f->loc);
2739 exprNode_checkUse (f, sr, f->loc);
2742 checkGlobUse (gle, TRUE, f);
2745 if (sRef_isKilledGlob (el))
2747 sRef_kill (sr, f->loc);
2748 context_usedGlobal (sr);
2752 } end_globSet_allElements;
2758 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
2760 sRefSet smods = sRefSet_undefined;
2763 ** NEED to check for modifies anything
2767 ** check each sRef that called function modifies (ml), is
2773 sRefSet_allElements (mods, s) /* s is something which may be modified */
2775 if (sRef_isKindSpecial (s))
2777 if (sRef_isSpecInternalState (s))
2779 if (context_getFlag (FLG_MODINTERNALSTRICT))
2781 exprNode_checkCallModifyVal (s, args, f, ret);
2785 sRefSet mmods = context_modList ();
2787 sRefSet_allElements (mmods, el)
2789 if (sRef_isInternalState (el))
2791 sRef_setModified (el);
2793 } end_sRefSet_allElements ;
2798 exprNode_checkCallModifyVal (s, args, f, ret);
2803 sRef rb = sRef_getRootBase (s);
2805 if (sRef_isGlobal (rb))
2807 context_usedGlobal (rb);
2810 if (sRef_isFileStatic (s)
2811 && !fileId_equal (fileloc_fileId (f->loc),
2812 fileloc_fileId (uentry_whereDefined (le))))
2814 smods = sRefSet_insert (smods, s);
2818 exprNode_checkCallModifyVal (s, args, f, ret);
2821 } end_sRefSet_allElements;
2826 ** Static elements in modifies set can have nasty consequences.
2827 ** (I think...have not been able to reproduce a possible bug.)
2830 if (!sRefSet_isDefined (smods))
2832 mods = sRefSet_newCopy (mods);
2835 sRefSet_allElements (smods, el)
2837 bool res = sRefSet_delete (mods, el);
2840 } end_sRefSet_allElements;
2842 sRefSet_free (smods);
2847 else if (sRefSet_isDefined (mods))
2848 { /* just check observers */
2851 sRefSet_allElements (mods, s) /* s is something which may be modified */
2853 sRef rb = sRef_getRootBase (s);
2857 if (sRef_isParam (rb))
2859 sRef b = sRef_fixBaseParam (s, args);
2861 if (sRef_isObserver (b))
2863 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
2867 message ("Function call may modify observer%q: %s",
2868 sRef_unparsePreOpt (b), exprNode_unparse (e)),
2871 sRef_showExpInfo (b);
2875 } end_sRefSet_allElements;
2879 if (!hasMods) /* no specified modifications */
2881 if (context_getFlag (FLG_MODOBSERVERUNCON))
2883 exprNodeList_elements (args, e)
2885 if (exprNode_isDefined (e))
2887 sRef s = exprNode_getSref (e);
2889 if (sRef_isObserver (s)
2890 && ctype_isMutable (sRef_getType (s)))
2893 (FLG_MODOBSERVERUNCON,
2895 ("Call to unconstrained function %s may modify observer%q: %s",
2896 exprNode_unparse (f),
2897 sRef_unparsePreOpt (s), exprNode_unparse (e)),
2900 sRef_showExpInfo (s);
2904 } end_exprNodeList_elements;
2909 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
2911 ret->uses = sRefSet_union (ret->uses, f->uses);
2912 ret->sets = sRefSet_union (ret->sets, f->sets);
2913 ret->msets = sRefSet_union (ret->msets, f->msets);
2918 ** Spurious errors reported, because lclint can't tell
2919 ** mods must be fresh if freshMods is true.
2922 /*@i@*/ sRefSet_free (mods);
2928 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
2930 if (uentry_isVar (glob))
2932 if (context_inFunctionLike ())
2934 sRef sr = uentry_getSref (glob);
2936 context_usedGlobal (sr);
2938 if (context_checkGlobUse (glob))
2940 if (!context_globAccess (sr))
2946 message ("Called procedure %s may access %s %q",
2947 exprNode_unparse (e),
2948 sRef_unparseScope (sr),
2949 uentry_getName (glob)),
2956 message ("Undocumented use of %s %s",
2957 sRef_unparseScope (sr),
2958 exprNode_unparse (e)),
2967 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
2971 static /*@only@*/ exprNode
2972 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
2973 ctype t, /*@keep@*/ exprNodeList args)
2975 /* requires f is a non-error exprNode, with type function */
2976 cstring fname = exprNode_unparse (f);
2977 uentry le = exprNode_getUentry (f);
2978 exprNode ret = exprNode_createPartialCopy (f);
2983 ret->typ = ctype_returnValue (t);
2984 ret->kind = XPR_CALL;
2986 ret->edata = exprData_makeCall (f, args);
2989 ** Order of these steps is very important!
2991 ** Must check for argument dependencies before messing up uses and sets.
2994 if (context_getFlag (FLG_EVALORDER))
2996 exprNodeList_elements (args, current)
2998 if (exprNode_isDefined (current))
3000 exprNode_addUse (current, current->sref);
3002 } end_exprNodeList_elements;
3004 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3006 checkSequencing (f, args);
3009 exprNodeList_elements (args, current)
3011 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3013 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3015 } end_exprNodeList_elements ;
3018 special = checkArgs (le, f, t, args, ret);
3019 checkGlobMods (f, le, args, ret, special);
3023 if (uentry_isValid (le)
3024 && (uentry_isFunction (le)
3025 || (uentry_isVariable (le)
3026 && ctype_isFunction (uentry_getType (le)))))
3028 exitkind exk = uentry_getExitCode (le);
3030 /* f->typ is already set to the return type */
3032 ret->sref = uentry_returnedRef (le, args);
3034 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3036 qual nullPred = uentry_nullPred (le);
3038 if (qual_isTrueNull (nullPred))
3040 exprNode arg = exprNodeList_head (args);
3042 if (exprNode_isDefined (arg))
3044 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3047 else if (qual_isFalseNull (nullPred))
3049 exprNode arg = exprNodeList_head (args);
3051 if (exprNode_isDefined (arg))
3053 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3058 llassert (qual_isUnknown (nullPred));
3062 if (exitkind_isConditionalExit (exk))
3066 ** if (arg0) then { exit! } else { ; }
3068 ** if (arg0) then { ; } else { exit! }
3073 llassert (!exprNodeList_isEmpty (args));
3074 firstArg = exprNodeList_head (args);
3076 if (exprNode_isDefined (firstArg)
3077 && !guardSet_isEmpty (firstArg->guards))
3079 usymtab_trueBranch (guardSet_undefined);
3080 usymtab_altBranch (guardSet_undefined);
3082 if (exitkind_isTrueExit (exk))
3084 usymtab_popBranches (firstArg,
3085 exprNode_makeMustExit (),
3087 TRUE, TRUEEXITCLAUSE);
3091 usymtab_popBranches (firstArg,
3093 exprNode_makeMustExit (),
3094 TRUE, FALSEEXITCLAUSE);
3098 ret->exitCode = XK_MAYEXIT;
3100 else if (exitkind_mustExit (exk))
3102 ret->exitCode = XK_MUSTEXIT;
3104 else if (exitkind_couldExit (exk))
3106 ret->exitCode = XK_MAYEXIT;
3113 if (cstring_equalLit (fname, "exit"))
3115 if (exprNodeList_size (args) == 1)
3117 exprNode arg = exprNodeList_head (args);
3119 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3121 long int val = multiVal_forceInt (exprNode_getValue (arg));
3128 ("Argument to exit has implementation defined behavior: %s",
3129 exprNode_unparse (arg)),
3130 exprNode_loc (arg));
3139 exprNode_checkSetAny (ret, uentry_rawName (le));
3146 ** this is yucky! should keep the uentry as part of exprNode!
3149 /*@observer@*/ uentry
3150 exprNode_getUentry (exprNode e)
3152 if (exprNode_isError (e))
3154 return uentry_undefined;
3158 cstring s = exprNode_rootVarName (e);
3159 uentry ue = usymtab_lookupSafe (s);
3166 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3168 exprNode ret = exprNode_createPlain (ctype_unknown);
3170 ret->kind = XPR_INITBLOCK;
3171 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3172 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3178 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3184 if (exprNode_isUndefined (f))
3187 exprNodeList_free (args);
3188 return exprNode_undefined;
3191 t = exprNode_getType (f);
3193 if (sRef_isLocalVar (f->sref))
3195 exprNode_checkUse (f, f->sref, f->loc);
3197 if (sRef_possiblyNull (f->sref))
3199 if (!usymtab_isGuarded (f->sref))
3201 if (optgenerror (FLG_NULLDEREF,
3202 message ("Function call using %s pointer %q",
3203 sRef_nullMessage (f->sref),
3204 sRef_unparse (f->sref)),
3207 sRef_showNullInfo (f->sref);
3208 sRef_setNullError (f->sref);
3216 if (ctype_isRealFunction (t))
3218 exprNode ret = functionCallSafe (f, t, args);
3222 else if (ctype_isUnknown (t))
3224 exprNode ret = exprNode_createPartialCopy (f);
3230 exprNodeList_elements (args, current)
3232 if (exprNode_isDefined (current))
3234 exprNode_checkUse (ret, current->sref, ret->loc);
3237 ** also, anything derivable from current->sref may be used
3240 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3241 exprNode_mergeUSs (ret, current);
3243 } end_exprNodeList_elements;
3245 ret->edata = exprData_makeCall (f, args);
3246 ret->kind = XPR_CALL;
3248 tstring = cstring_copy (exprNode_unparse (f));
3250 cstring_markOwned (tstring);
3251 exprNode_checkSetAny (ret, tstring);
3257 voptgenerror (FLG_TYPE,
3258 message ("Call to non-function (type %t): %s", t,
3259 exprNode_unparse (f)),
3262 exprNodeList_free (args);
3264 return (exprNode_makeError ());
3269 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ cstring f)
3271 exprNode ret = exprNode_createPartialCopy (s);
3273 ret->kind = XPR_FACCESS;
3275 if (exprNode_isError (s))
3277 ret->edata = exprData_makeField (s, f);
3282 ctype t = exprNode_getType (s);
3283 ctype tr = ctype_realType (t);
3285 checkMacroParen (s);
3287 ret->edata = exprData_makeField (s, f);
3289 if (ctype_isStructorUnion (tr))
3291 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
3293 if (uentry_isUndefined (tf))
3295 voptgenerror (FLG_TYPE,
3296 message ("Access non-existent field %s of %t: %s", f, t,
3297 exprNode_unparse (ret)),
3304 uentry_setUsed (tf, exprNode_loc (ret));
3306 ret->typ = uentry_getType (tf);
3307 checkSafeUse (ret, s->sref);
3309 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
3313 else /* isStructorUnion */
3315 if (ctype_isRealAbstract (tr))
3319 message ("Access field of abstract type (%t): %s.%s",
3320 t, exprNode_unparse (s), f),
3322 ret->typ = ctype_unknown;
3326 if (ctype_isKnown (tr))
3331 ("Access field of non-struct or union (%t): %s.%s",
3332 t, exprNode_unparse (s), f),
3335 ret->typ = ctype_unknown;
3339 cstring sn = cstring_copy (f);
3341 checkSafeUse (ret, s->sref);
3342 cstring_markOwned (sn);
3343 ret->sref = sRef_makeField (s->sref, sn);
3355 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
3357 exprNode ret = exprNode_createPartialCopy (e);
3359 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
3360 ret->kind = XPR_PARENS;
3361 ret->edata = exprData_makeUop (e, lpar);
3363 if (!exprNode_isError (e))
3365 ret->exitCode = e->exitCode;
3366 ret->canBreak = e->canBreak;
3367 ret->mustBreak = e->mustBreak;
3368 ret->isJumpPoint = e->isJumpPoint;
3369 ret->sref = e->sref;
3376 exprNode_arrowAccess (/*@only@*/ exprNode s, /*@only@*/ cstring f)
3378 exprNode ret = exprNode_createPartialCopy (s);
3380 ret->edata = exprData_makeField (s, f);
3381 ret->kind = XPR_ARROW;
3383 if (exprNode_isError (s))
3389 ctype t = exprNode_getType (s);
3390 ctype tr = ctype_realType (t);
3392 checkMacroParen (s);
3394 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
3396 if (ctype_isRealPointer (tr))
3398 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
3400 if (ctype_isStructorUnion (b))
3402 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
3404 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
3406 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
3410 message ("Arrow access from %s pointer%q: %s",
3411 sRef_nullMessage (s->sref),
3412 sRef_unparsePreOpt (s->sref),
3413 exprNode_unparse (ret)),
3416 sRef_showNullInfo (s->sref);
3417 sRef_setNullError (s->sref);
3422 if (uentry_isUndefined (fentry))
3426 message ("Access non-existent field %s of %t: %s",
3427 f, t, exprNode_unparse (ret)),
3429 ret->typ = ctype_unknown;
3436 ** was safeUse: shouldn't be safe!
3439 ** rec must be defined,
3440 ** *rec must be allocated
3441 ** rec->field need only be defined it if is an rvalue
3444 uentry_setUsed (fentry, exprNode_loc (ret));
3445 ret->typ = uentry_getType (fentry);
3447 exprNode_checkUse (ret, s->sref, s->loc);
3449 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
3450 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
3454 else /* Pointer to something that is not a struct or union*/
3456 if (ctype_isRealAbstract (tr))
3458 ctype xrt = ctype_forceRealType (tr);
3462 message ("Arrow access field of abstract type (%t): %s->%s",
3463 t, exprNode_unparse (s), f),
3467 ** Set the state correctly, as if the abstraction is broken.
3470 if (ctype_isRealPointer (xrt) &&
3471 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
3472 ctype_isStructorUnion (b)))
3474 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
3475 ret->typ = uentry_getType (fentry);
3476 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
3480 ret->typ = ctype_unknown;
3481 ret->sref = sRef_undefined;
3484 else /* not a struct, union or abstract */
3486 if (ctype_isUnknown (tr)) {
3487 cstring sn = cstring_copy (f);
3489 DPRINTF (("Here: %s", exprNode_unparse (s)));
3491 exprNode_checkUse (ret, s->sref, s->loc);
3492 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
3494 cstring_markOwned (sn);
3495 ret->sref = sRef_makeArrow (s->sref, sn);
3497 ret->kind = XPR_ARROW;
3502 message ("Arrow access field of non-struct or union "
3503 "pointer (%t): %s->%s",
3504 t, exprNode_unparse (s), f),
3507 ret->typ = ctype_unknown;
3508 ret->sref = sRef_undefined;
3513 else /* its not a pointer */
3515 if (!ctype_isUnknown (tr))
3519 message ("Arrow access of non-pointer (%t): %s->%s",
3520 t, exprNode_unparse (s), f),
3523 ret->typ = ctype_unknown;
3524 ret->sref = sRef_undefined;
3528 cstring sn = cstring_copy (f);
3530 DPRINTF (("Here: %s", exprNode_unparse (s)));
3532 exprNode_checkUse (ret, s->sref, s->loc);
3533 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
3535 cstring_markOwned (sn);
3536 ret->sref = sRef_makeArrow (s->sref, sn);
3538 ret->kind = XPR_ARROW;
3549 ** only postOp's in C: i++ and i--
3553 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
3555 /* check modification also */
3556 /* cstring opname = lltok_unparse (op);*/
3558 exprNode ret = exprNode_createPartialCopy (e);
3560 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
3561 ret->kind = XPR_POSTOP;
3562 ret->edata = exprData_makeUop (e, op);
3564 if (!exprNode_isDefined (e))
3569 checkMacroParen (e);
3571 exprNode_checkUse (ret, e->sref, e->loc);
3572 exprNode_checkSet (ret, e->sref);
3574 t = exprNode_getType (e);
3576 if (sRef_isUnsafe (e->sref))
3578 voptgenerror (FLG_MACROPARAMS,
3579 message ("Operand of %s is macro parameter (non-functional): %s%s",
3580 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
3582 sRef_makeSafe (e->sref);
3583 sRef_makeSafe (ret->sref);
3586 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
3592 if (ctype_isRealAbstract (t))
3596 message ("Operand of %s is abstract type (%t): %s",
3597 lltok_unparse (op), t, exprNode_unparse (e)),
3604 message ("Operand of %s is non-numeric (%t): %s",
3605 lltok_unparse (op), t, exprNode_unparse (e)),
3608 ret->typ = ctype_unknown;
3611 /* if (ctype_isZero (t)) e->typ = ctype_int; */
3613 exprNode_checkModify (e, ret);
3615 /* added 7/11/2000 D.L */
3617 updateEnvironmentForPostOp (e);
3619 /* start modifications */
3620 /* added by Seejo on 4/16/2000 */
3622 /* Arithmetic operations on pointers wil modify the size/len/null terminated
3624 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
3626 ret->sref = sRef_copy (e->sref);
3629 if (lltok_getTok (op) == INC_OP) {
3630 if (sRef_getSize(e->sref) > 0) {
3632 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
3634 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
3635 /* Assumption: there is only 1 \0 in the buffer */
3636 /* This will not be correct if there are 2 \0's in the buffer */
3637 sRef_setNotNullTerminatedState(ret->sref);
3638 sRef_resetLen(ret->sref);
3640 sRef_setNullTerminatedState(ret->sref);
3641 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
3643 if (sRef_isNullTerminated (ret->sref))
3644 printf ("ret->sref is Null Terminated\n");
3645 else if (sRef_isPossiblyNullTerminated (ret->sref))
3646 printf ("ret->sref is Possibly Null Terminated\n");
3647 else if (sRef_isNotNullTerminated (ret->sref))
3648 printf ("ret->sref is Not Null Terminated\n");
3653 if (lltok_getTok (op) == DEC_OP) {
3654 if (sRef_getSize(e->sref) >= 0) {
3655 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
3656 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
3661 /* end modifications */
3667 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
3669 bool checkMod = FALSE;
3671 int opid = lltok_getTok (op);
3672 exprNode ret = exprNode_createSemiCopy (e);
3674 exprNode_copySets (ret, e);
3676 multiVal_free (ret->val);
3677 ret->val = multiVal_undefined;
3678 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
3679 ret->kind = XPR_PREOP;
3680 ret->edata = exprData_makeUop (e, op);
3682 if (exprNode_isError (e))
3687 checkMacroParen (e);
3689 te = exprNode_getType (e);
3690 tr = ctype_realType (te);
3692 if (opid != TAMPERSAND)
3694 exprNode_checkUse (ret, e->sref, e->loc);
3696 if (ctype_isRealAbstract (tr)
3697 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
3699 if (optgenerror (FLG_ABSTRACT,
3700 message ("Operand of %s is abstract type (%t): %s",
3701 lltok_unparse (op), tr,
3702 exprNode_unparse (ret)),
3705 tr = te = ctype_unknown;
3706 ret->typ = ctype_unknown;
3707 sRef_setNullError (e->sref);
3715 case DEC_OP: /* should also check modification! */
3717 if (sRef_isMacroParamRef (e->sref))
3721 message ("Operand of %s is macro parameter (non-functional): %s",
3722 lltok_unparse (op), exprNode_unparse (ret)),
3727 exprNode_checkSet (ret, e->sref);
3730 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
3735 if (context_msgStrictOps ())
3739 message ("Operand of %s is non-numeric (%t): %s",
3740 lltok_unparse (op), te, exprNode_unparse (ret)),
3743 ret->typ = ctype_int;
3746 /* start modifications */
3747 /* added by Seejo on 4/16/2000 */
3749 /* Arithmetic operations on pointers wil modify the size/len/null terminated
3751 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
3753 ret->sref = sRef_copy (e->sref);
3756 if (lltok_getTok (op) == INC_OP) {
3757 if (sRef_getSize(e->sref) > 0) {
3759 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
3761 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
3762 /* Assumption: there is only 1 \0 in the buffer */
3763 /* This will not be correct if there are 2 \0's in the buffer */
3764 sRef_setNotNullTerminatedState(ret->sref);
3765 sRef_resetLen (ret->sref);
3767 sRef_setNullTerminatedState(ret->sref);
3768 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
3774 if (lltok_getTok (op) == DEC_OP) {
3775 if (sRef_getSize(e->sref) >= 0) {
3776 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
3777 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
3782 /* end modifications */
3789 if (ctype_isForceRealNumeric (&tr))
3793 ret->val = multiVal_invert (exprNode_getValue (e));
3797 ret->val = multiVal_copy (exprNode_getValue (e));
3802 if (context_msgStrictOps ())
3806 message ("Operand of %s is non-numeric (%t): %s",
3807 lltok_unparse (op), te, exprNode_unparse (ret)),
3811 ret->typ = ctype_int;
3815 case TEXCL: /* maybe this should be restricted */
3816 guardSet_flip (ret->guards);
3818 if (ctype_isRealBool (te))
3824 if (ctype_isRealPointer (tr))
3826 if (sRef_isKnown (e->sref))
3828 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
3832 (FLG_BOOLOPS, FLG_PTRNEGATE,
3833 message ("Operand of %s is non-boolean (%t): %s",
3834 lltok_unparse (op), te, exprNode_unparse (ret)),
3841 message ("Operand of %s is non-boolean (%t): %s",
3842 lltok_unparse (op), te, exprNode_unparse (ret)),
3846 ret->typ = ctype_bool;
3851 if (ctype_isForceRealInt (&tr))
3856 if (context_msgStrictOps ())
3860 message ("Operand of %s is non-integer (%t): %s",
3861 lltok_unparse (op), te, exprNode_unparse (ret)),
3865 if (ctype_isInt (e->typ))
3871 ret->typ = ctype_int;
3877 ret->typ = ctype_makePointer (e->typ);
3879 if (sRef_isKnown (e->sref))
3881 ret->sref = sRef_makeAddress (e->sref);
3888 if (ctype_isAP (tr))
3890 ret->typ = ctype_baseArrayPtr (e->typ);
3894 if (ctype_isKnown (te))
3896 if (ctype_isFunction (te))
3902 message ("Dereference of function type (%t): %s",
3903 te, exprNode_unparse (ret)),
3908 voptgenerror (FLG_TYPE,
3909 message ("Dereference of non-pointer (%t): %s",
3910 te, exprNode_unparse (ret)),
3912 ret->typ = ctype_unknown;
3917 ret->typ = ctype_unknown;
3922 if (sRef_isKnown (e->sref))
3924 if (sRef_possiblyNull (e->sref))
3926 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
3930 message ("Dereference of %s pointer %q: %s",
3931 sRef_nullMessage (e->sref),
3932 sRef_unparse (e->sref),
3933 exprNode_unparse (ret)),
3936 sRef_showNullInfo (e->sref);
3937 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
3942 ret->sref = sRef_makePointer (e->sref);
3947 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
3952 exprNode_checkModify (e, ret);
3959 ** any reason to disallow sizeof (abstract type) ?
3963 ** used by both sizeof
3967 ctype sizeof_resultType (void)
3969 static ctype sizet = ctype_unknown;
3971 if (ctype_isUnknown (sizet))
3973 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
3975 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
3979 sizet = ctype_ulint;
3986 exprNode_sizeofType (/*@only@*/ qtype qt)
3988 exprNode ret = exprNode_create (sizeof_resultType ());
3989 ctype ct = qtype_getType (qt);
3991 ret->kind = XPR_SIZEOFT;
3992 ret->edata = exprData_makeSizeofType (qt);
3994 voptgenerror (FLG_SIZEOFTYPE,
3995 message ("Parameter to sizeof is type %s: %s",
3997 exprNode_unparse (ret)),
4004 exprNode_alignofType (/*@only@*/ qtype qt)
4006 exprNode ret = exprNode_create (sizeof_resultType ());
4007 ctype ct = qtype_getType (qt);
4009 ret->kind = XPR_ALIGNOFT;
4010 ret->edata = exprData_makeSizeofType (qt);
4012 voptgenerror (FLG_SIZEOFTYPE,
4013 message ("Parameter to alignof is type %s: %s",
4015 exprNode_unparse (ret)),
4021 exprNode exprNode_offsetof (qtype qt, cstringList s)
4023 exprNode ret = exprNode_create (sizeof_resultType ());
4024 ctype ct = qtype_getType (qt);
4026 ret->kind = XPR_OFFSETOF;
4027 ret->edata = exprData_makeOffsetof (qt, s);
4029 if (!ctype_isRealSU (ct))
4031 voptgenerror (FLG_TYPE,
4032 message ("First parameter to offsetof is not a "
4033 "struct or union type (type %s): %s",
4035 exprNode_unparse (ret)),
4042 cstringList_elements (s, el) {
4046 if (ctype_isUndefined (lt))
4050 else if (!ctype_isRealSU (lt))
4052 voptgenerror (FLG_TYPE,
4053 message ("Inner offsetof type is not a "
4054 "struct or union type (type %s before field %s): %s",
4055 ctype_unparse (lt), el,
4056 exprNode_unparse (ret)),
4062 fields = ctype_getFields (ctype_realType (lt));
4063 fld = uentryList_lookupField (fields, el);
4064 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4066 if (uentry_isUndefined (fld))
4068 if (ctype_equal (lt, ct)) {
4069 voptgenerror (FLG_TYPE,
4070 message ("Field %s in offsetof is not the "
4071 "name of a field of %s: %s",
4074 exprNode_unparse (ret)),
4077 voptgenerror (FLG_TYPE,
4078 message ("Deep field %s in offsetof is not the "
4079 "name of a field of %s: %s",
4082 exprNode_unparse (ret)),
4088 lt = uentry_getType (fld);
4091 } end_cstringList_elements;
4093 /* Should report error if its a bit field - behavior is undefined! */
4100 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4104 if (exprNode_isUndefined (e))
4106 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4107 ret->edata = exprData_makeSingle (e);
4108 ret->typ = sizeof_resultType ();
4109 ret->kind = XPR_SIZEOF;
4113 uentry u = exprNode_getUentry (e);
4115 ret = exprNode_createPartialCopy (e);
4116 ret->edata = exprData_makeSingle (e);
4118 ret->typ = sizeof_resultType ();
4119 ret->kind = XPR_SIZEOF;
4121 if (uentry_isValid (u)
4122 && uentry_isRefParam (u)
4123 && ctype_isRealArray (uentry_getType (u)))
4126 (FLG_SIZEOFFORMALARRAY,
4127 message ("Parameter to sizeof is an array-type function parameter: %s",
4128 exprNode_unparse (ret)),
4134 ** sizeof (x) doesn't "really" use x
4141 exprNode_alignofExpr (/*@only@*/ exprNode e)
4145 if (exprNode_isUndefined (e))
4147 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4151 ret = exprNode_createPartialCopy (e);
4154 ret->edata = exprData_makeSingle (e);
4155 ret->typ = sizeof_resultType ();
4156 ret->kind = XPR_ALIGNOF;
4159 ** sizeof (x) doesn't "really" use x
4166 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4172 if (exprNode_isError (e))
4175 lltok_release (tok);
4176 return exprNode_undefined;
4179 checkMacroParen (e);
4181 c = qtype_getType (q);
4182 t = exprNode_getType (e);
4184 ret = exprNode_createPartialCopy (e);
4186 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
4188 ret->kind = XPR_CAST;
4189 ret->edata = exprData_makeCast (tok, e, q);
4191 if (ctype_isRealSU (ctype_getBaseType (sRef_getType (e->sref))))
4194 ** This is a bit of a hack to avoid a problem
4195 ** when the code does,
4196 ** (some other struct) x
4201 ret->sref = sRef_copy (e->sref);
4202 usymtab_addForceMustAlias (ret->sref, e->sref);
4203 sRef_setTypeFull (ret->sref, c);
4204 DPRINTF (("Cast: %s -> %s", sRef_unparseFull (e->sref),
4205 sRef_unparseFull (ret->sref)));
4209 ret->sref = e->sref;
4210 sRef_setTypeFull (ret->sref, c);
4211 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
4218 ** void * <-> abstract * (if FLG_ABSTVOIDP)
4219 ** abstract * <-> void * (if FLG_ABSTVOIDP)
4222 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
4226 else if (ctype_isRealAP (c)) /* casting to array or pointer */
4228 ctype bc = ctype_getBaseType (c);
4229 ctype bt = ctype_getBaseType (t);
4230 ctype rt = ctype_realType (t);
4232 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
4233 && (ctype_isArrayPtr (rt)
4234 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4238 message ("Cast from function pointer type (%t) to "
4239 "non-function pointer (%t): %s",
4240 c, t, exprNode_unparse (ret)),
4244 if (!ctype_isFunction (ctype_baseArrayPtr (c))
4245 && (ctype_isArrayPtr (rt)
4246 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4250 message ("Cast from non-function pointer type (%t) to "
4251 "function pointer (%t): %s",
4252 c, t, exprNode_unparse (ret)),
4256 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
4257 !(ctype_isRealAbstract (bc)
4258 && context_hasAccess (ctype_typeId (bc))))
4260 ; /* okay to cast zero */
4264 if (ctype_isRealAbstract (bc)
4265 && !context_hasAccess (ctype_typeId (bc)))
4267 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
4271 message ("Cast to underlying abstract type %t: %s",
4272 c, exprNode_unparse (ret)),
4279 message ("Cast to underlying abstract type %t: %s",
4280 c, exprNode_unparse (ret)),
4285 if (ctype_isRealAbstract (bt)
4286 && !context_hasAccess (ctype_typeId (bt)))
4288 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
4292 message ("Cast from underlying abstract type %t: %s",
4293 t, exprNode_unparse (ret)),
4300 message ("Cast from underlying abstract type %t: %s",
4301 t, exprNode_unparse (ret)),
4309 ctype bt = ctype_realType (ctype_getBaseType (t));
4310 ctype bc = ctype_realType (ctype_getBaseType (c));
4312 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
4314 if (ctype_match (c, t))
4316 if (ctype_equal (c, t))
4320 message ("Redundant cast involving abstract type %t: %s",
4321 bt, exprNode_unparse (ret)),
4329 message ("Cast from abstract type %t: %s",
4330 bt, exprNode_unparse (ret)),
4335 if (ctype_isAbstract (bc)
4336 && !context_hasAccess (ctype_typeId (bc)))
4338 if (ctype_match (c, t))
4346 message ("Cast to abstract type %t: %s", bc,
4347 exprNode_unparse (ret)),
4353 if (ctype_isAbstract (c))
4355 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
4357 /* okay, cast exposed to abstract */
4358 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
4362 if (ctype_isVisiblySharable (t)
4363 && sRef_isExternallyVisible (e->sref)
4364 && !(ctype_isAbstract (t)
4365 && context_hasAccess (ctype_typeId (t))))
4369 message ("Cast to abstract type from externally visible "
4370 "mutable storage exposes rep of %s: %s",
4372 exprNode_unparse (e)),
4382 evaluationOrderUndefined (lltok op)
4384 int opid = lltok_getTok (op);
4386 return (opid != AND_OP && opid != OR_OP);
4389 static bool checkIntegral (/*@notnull@*/ exprNode e1,
4390 /*@notnull@*/ exprNode e2,
4391 /*@notnull@*/ exprNode ret,
4396 ctype te1 = exprNode_getType (e1);
4397 ctype te2 = exprNode_getType (e2);
4399 ctype tr1 = ctype_realishType (te1);
4400 ctype tr2 = ctype_realishType (te2);
4402 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
4408 if (context_msgStrictOps ())
4410 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
4412 if (ctype_sameName (te1, te2))
4416 message ("Operands of %s are non-integer (%t): %s",
4417 lltok_unparse (op), te1,
4418 exprNode_unparse (ret)),
4425 message ("Operands of %s are non-integers (%t, %t): %s",
4426 lltok_unparse (op), te1, te2,
4427 exprNode_unparse (ret)),
4431 else if (!ctype_isInt (tr1))
4435 message ("Left operand of %s is non-integer (%t): %s",
4436 lltok_unparse (op), te1, exprNode_unparse (ret)),
4440 /* !ctype_isInt (te2) */
4444 message ("Right operand of %s is non-integer (%t): %s",
4445 lltok_unparse (op), te2, exprNode_unparse (ret)),
4455 ** returns exprNode representing e1 op e2
4457 ** uses msg if there are errors
4458 ** can be used for both assignment ops and regular ops
4463 static /*@only@*/ /*@notnull@*/ exprNode
4464 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
4465 /*@keep@*/ lltok op)
4467 ctype te1, te2, tr1, tr2, tret;
4468 int opid = lltok_getTok (op);
4469 bool hasError = FALSE;
4472 if (exprNode_isError (e1))
4474 ret = exprNode_createPartialNVCopy (e2);
4478 ret = exprNode_createPartialNVCopy (e1);
4481 ret->val = multiVal_undefined;
4483 ret->edata = exprData_makeOp (e1, e2, op);
4485 if (exprNode_isError (e1) || exprNode_isError (e2))
4487 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
4488 || opid == EQ_OP || opid == NE_OP
4489 || opid == AND_OP || opid == OR_OP)
4491 ret->typ = ctype_bool;
4494 if (exprNode_isDefined (e1))
4496 exprNode_checkUse (ret, e1->sref, e1->loc);
4499 if (exprNode_isDefined (e2))
4501 exprNode_mergeUSs (ret, e2);
4502 exprNode_checkUse (ret, e2->sref, e2->loc);
4508 tret = ctype_unknown;
4509 te1 = exprNode_getType (e1);
4510 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
4512 te2 = exprNode_getType (e2);
4514 tr1 = ctype_realishType (te1);
4515 tr2 = ctype_realishType (te2);
4519 ret->guards = guardSet_or (ret->guards, e2->guards);
4521 else if (opid == AND_OP)
4523 ret->guards = guardSet_and (ret->guards, e2->guards);
4530 if (opid == EQ_OP || opid == NE_OP)
4532 exprNode temp1 = e1, temp2 = e2;
4534 /* could do NULL == x */
4536 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
4538 temp1 = e2; temp2 = e1;
4541 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
4543 reflectNullTest (temp1, (opid == NE_OP));
4544 guardSet_free (ret->guards);
4545 ret->guards = guardSet_copy (temp1->guards);
4549 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
4550 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
4555 if (anyAbstract (tr1, tr2) &&
4556 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
4557 (opid == AND_OP || opid == OR_OP
4558 || opid == EQ_OP || opid == NE_OP))))
4560 abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc);
4562 else if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
4564 /* unknown types, no comparisons possible */
4570 case TMULT: /* multiplication and division: */
4572 case MUL_ASSIGN: /* numeric, numeric -> numeric */
4573 case DIV_ASSIGN: /* */
4575 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4578 case TPLUS: /* addition and subtraction: */
4579 case TMINUS: /* pointer, int -> pointer */
4580 case SUB_ASSIGN: /* int, pointer -> pointer */
4581 case ADD_ASSIGN: /* numeric, numeric -> numeric */
4583 tr1 = ctype_fixArrayPtr (tr1);
4585 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
4586 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
4590 if (context_msgPointerArith ())
4594 message ("Pointer arithmetic (%t, %t): %s",
4595 te1, te2, exprNode_unparse (ret)),
4599 if (sRef_possiblyNull (e1->sref)
4600 && !usymtab_isGuarded (e1->sref))
4603 (FLG_NULLPOINTERARITH,
4604 message ("Pointer arithmetic involving possibly "
4605 "null pointer %s: %s",
4606 exprNode_unparse (e1),
4607 exprNode_unparse (ret)),
4611 ret->sref = sRef_copy (e1->sref);
4613 /* start modifications */
4614 /* added by Seejo on 4/16/2000 */
4616 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4618 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
4619 //if (sRef_isKnown (e->sref)) {
4620 //ret->sref = sRef_makeAddress (e->sref);
4623 int val = (int) multiVal_forceInt (e2->val);
4625 /* Operator : + or += */
4626 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4627 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
4628 val should not result in a
4629 size < 0 (size = 0 is ok !) */
4631 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
4633 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
4634 sRef_setNotNullTerminatedState(ret->sref);
4635 sRef_resetLen (ret->sref);
4637 sRef_setNullTerminatedState(ret->sref);
4638 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
4643 /* Operator : - or -= */
4644 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4645 if (sRef_getSize(e1->sref) >= 0) {
4646 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
4647 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
4652 /* end modifications */
4654 sRef_setNullError (ret->sref);
4657 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4658 ** since is points to storage that should not be deallocated
4659 ** through this pointer.
4662 if (sRef_isOnly (ret->sref)
4663 || sRef_isFresh (ret->sref))
4665 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4670 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
4671 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
4673 if (context_msgPointerArith ())
4677 message ("Pointer arithmetic (%t, %t): %s",
4678 te1, te2, exprNode_unparse (ret)),
4682 if (sRef_possiblyNull (e1->sref)
4683 && !usymtab_isGuarded (e1->sref))
4686 (FLG_NULLPOINTERARITH,
4687 message ("Pointer arithmetic involving possibly "
4688 "null pointer %s: %s",
4689 exprNode_unparse (e2),
4690 exprNode_unparse (ret)),
4694 ret->sref = sRef_copy (e2->sref);
4696 /* start modifications */
4697 /* added by Seejo on 4/16/2000 */
4699 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4702 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
4703 //if (sRef_isKnown (e->sref)) {
4704 //ret->sref = sRef_makeAddress (e->sref);
4707 int val = (int) multiVal_forceInt (e1->val);
4709 /* Operator : + or += */
4710 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4711 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
4712 val should not result in a
4713 size < 0 (size = 0 is ok !) */
4715 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
4717 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
4718 sRef_setNotNullTerminatedState(ret->sref);
4719 sRef_resetLen (ret->sref);
4721 sRef_setNullTerminatedState(ret->sref);
4722 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
4727 /* Operator : - or -= */
4728 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4729 if (sRef_getSize(e2->sref) >= 0) {
4730 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
4731 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
4736 /* end modifications */
4738 sRef_setNullError (ret->sref);
4741 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4742 ** since is points to storage that should not be deallocated
4743 ** through this pointer.
4746 if (sRef_isOnly (ret->sref)
4747 || sRef_isFresh (ret->sref)) {
4748 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4752 ret->sref = e2->sref;
4756 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4761 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
4765 case TAMPERSAND: /* bitwise & */
4767 case TCIRC: /* ^ (XOR) */
4772 bool reported = FALSE;
4773 flagcode code = FLG_BITWISEOPS;
4775 if (opid == LEFT_OP || opid == LEFT_ASSIGN
4776 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
4777 code = FLG_SHIFTSIGNED;
4780 if (!ctype_isUnsigned (tr1))
4782 if (exprNode_isNonNegative (e1)) {
4785 reported = optgenerror
4787 message ("Left operand of %s is not unsigned value (%t): %s",
4788 lltok_unparse (op), te1,
4789 exprNode_unparse (ret)),
4799 /* right need not be signed for shifts */
4800 if (code != FLG_SHIFTSIGNED
4801 && !ctype_isUnsigned (tr2))
4803 if (!exprNode_isNonNegative (e2)) {
4804 reported = optgenerror
4806 message ("Right operand of %s is not unsigned value (%t): %s",
4807 lltok_unparse (op), te2,
4808 exprNode_unparse (ret)),
4816 if (!checkIntegral (e1, e2, ret, op)) {
4817 te1 = ctype_unknown;
4821 DPRINTF (("Set: %s", ctype_unparse (te1)));
4824 ** tret is the widest type of te1 and te2
4827 tret = ctype_widest (te1, te2);
4832 if (checkIntegral (e1, e2, ret, op)) {
4835 tret = ctype_unknown;
4840 case TLT: /* comparisons */
4841 case TGT: /* numeric, numeric -> bool */
4842 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
4843 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
4846 bool fepsilon = FALSE;
4848 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
4853 if (opid == TLT || opid == TGT)
4855 uentry ue1 = exprNode_getUentry (e1);
4856 uentry ue2 = exprNode_getUentry (e2);
4859 ** FLT_EPSILON, etc. really is a variable, not
4863 if (uentry_isVariable (ue1))
4865 cstring uname = uentry_rawName (ue1);
4867 if (cstring_equalLit (uname, "FLT_EPSILON")
4868 || cstring_equalLit (uname, "DBL_EPSILON")
4869 || cstring_equalLit (uname, "LDBL_EPSILON"))
4875 if (uentry_isVariable (ue2))
4877 cstring uname = uentry_rawName (ue2);
4879 if (cstring_equalLit (uname, "FLT_EPSILON")
4880 || cstring_equalLit (uname, "DBL_EPSILON")
4881 || cstring_equalLit (uname, "LDBL_EPSILON"))
4890 ; /* Don't complain. */
4896 message ("Dangerous comparison involving %s types: %s",
4897 ctype_unparse (rtype),
4898 exprNode_unparse (ret)),
4907 ** Types should match.
4910 if (!exprNode_matchTypes (e1, e2))
4912 hasError = gentypeerror
4914 message ("Operands of %s have incompatible types (%t, %t): %s",
4915 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
4921 || (ctype_isForceRealNumeric (&tr1)
4922 && ctype_isForceRealNumeric (&tr2)) ||
4923 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
4929 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
4930 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
4934 message ("Comparison of pointer and numeric (%t, %t): %s",
4935 te1, te2, exprNode_unparse (ret)),
4940 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4945 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
4947 if ((opid == EQ_OP || opid == NE_OP) &&
4948 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
4951 ** is one a variable?
4954 if (uentry_isVariable (exprNode_getUentry (e1))
4955 || uentry_isVariable (exprNode_getUentry (e2)))
4958 ** comparisons with FALSE are okay
4961 if (exprNode_isFalseConstant (e1)
4962 || exprNode_isFalseConstant (e2))
4971 ("Use of %q with %s variables (risks inconsistency because "
4972 "of multiple true values): %s",
4973 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
4974 context_printBoolName (), exprNode_unparse (ret)),
4981 case AND_OP: /* bool, bool -> bool */
4984 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
4990 if (context_maybeSet (FLG_BOOLOPS))
4992 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
4994 if (ctype_sameName (te1, te2))
4998 message ("Operands of %s are non-boolean (%t): %s",
4999 lltok_unparse (op), te1,
5000 exprNode_unparse (ret)),
5008 ("Operands of %s are non-booleans (%t, %t): %s",
5009 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5013 else if (!ctype_isRealBool (te1))
5017 message ("Left operand of %s is non-boolean (%t): %s",
5018 lltok_unparse (op), te1, exprNode_unparse (ret)),
5021 else if (!ctype_isRealBool (te2))
5025 message ("Right operand of %s is non-boolean (%t): %s",
5026 lltok_unparse (op), te2, exprNode_unparse (ret)),
5039 (cstring_makeLiteral
5040 ("There has been a problem in the parser. This is due to a bug "
5041 "in either lclint, bison or gcc version 2.95 optimizations, "
5042 "but it has not been confirmed. Please try rebuidling LCLint "
5043 "without the -O<n> option."));
5048 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5051 exprNode_checkUse (ret, e1->sref, e1->loc);
5052 exprNode_mergeUSs (ret, e2);
5053 exprNode_checkUse (ret, e2->sref, e2->loc);
5059 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5060 /*@only@*/ lltok op)
5064 checkMacroParen (e1);
5065 checkMacroParen (e2);
5067 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5069 checkExpressionDefined (e1, e2, op);
5072 ret = exprNode_makeOp (e1, e2, op);
5077 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5080 ** This is somewhat bogus!
5082 ** Assigning to a nested observer in a non-observer datatype
5083 ** should not produce an error.
5086 sRef ref = exprNode_getSref (e1);
5088 DPRINTF (("Check assign mod: %s",
5089 sRef_unparseFull (ref)));
5091 if (sRef_isObserver (ref)
5092 || ((sRef_isFileStatic (ref) || sRef_isGlobal (ref))
5093 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5095 sRef base = sRef_getBase (ref);
5097 if (sRef_isValid (base) && sRef_isObserver (base))
5099 exprNode_checkModify (e1, ret);
5103 exprNode_checkModifyVal (e1, ret);
5108 exprNode_checkModify (e1, ret);
5113 exprNode_assign (/*@only@*/ exprNode e1,
5114 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5116 bool isalloc = FALSE;
5117 bool isjustalloc = FALSE;
5120 DPRINTF (("%s [%s] <- %s [%s]",
5121 exprNode_unparse (e1),
5122 ctype_unparse (e1->typ),
5123 exprNode_unparse (e2),
5124 ctype_unparse (e2->typ)));
5126 if (lltok_getTok (op) != TASSIGN)
5128 ret = exprNode_makeOp (e1, e2, op);
5132 ret = exprNode_createPartialCopy (e1);
5133 ret->kind = XPR_ASSIGN;
5134 ret->edata = exprData_makeOp (e1, e2, op);
5136 if (!exprNode_isError (e2))
5138 ret->sets = sRefSet_union (ret->sets, e2->sets);
5139 ret->msets = sRefSet_union (ret->msets, e2->msets);
5140 ret->uses = sRefSet_union (ret->uses, e2->uses);
5144 checkExpressionDefined (e1, e2, op);
5146 if (exprNode_isError (e1))
5148 if (!exprNode_isError (e2))
5150 ret->loc = fileloc_update (ret->loc, e2->loc);
5154 ret->loc = fileloc_update (ret->loc, g_currentloc);
5158 if (!exprNode_isError (e2))
5160 checkMacroParen (e2);
5163 if (exprNode_isDefined (e1))
5165 if (sRef_isMacroParamRef (e1->sref))
5167 if (context_inIterDef ())
5169 uentry ue = sRef_getUentry (e1->sref);
5171 if (uentry_isYield (ue))
5177 if (fileloc_isDefined (e1->loc))
5181 message ("Assignment to non-yield iter parameter: %q",
5182 sRef_unparse (e1->sref)),
5189 message ("Assignment to non-yield iter parameter: %q",
5190 sRef_unparse (e1->sref)),
5197 if (fileloc_isDefined (e1->loc))
5201 message ("Assignment to macro parameter: %q",
5202 sRef_unparse (e1->sref)),
5209 message ("Assignment to macro parameter: %q",
5210 sRef_unparse (e1->sref)),
5217 exprNode_checkAssignMod (e1, ret);
5220 if (exprNode_isDefined (e2))
5222 if (lltok_getTok (op) == TASSIGN)
5224 ctype te1 = exprNode_getType (e1);
5225 ctype te2 = exprNode_getType (e2);
5227 if (!ctype_forceMatch (te1, te2))
5229 if (exprNode_matchLiteral (te1, e2))
5237 message ("Assignment of %t to %t: %s %s %s",
5238 te2, te1, exprNode_unparse (e1),
5240 exprNode_unparse (e2)),
5246 exprNode_mergeUSs (ret, e2);
5247 exprNode_checkUse (ret, e2->sref, e2->loc);
5249 doAssign (e1, e2, FALSE);
5250 ret->sref = e1->sref;
5254 if (exprNode_isDefined (e2))
5256 exprNode_mergeUSs (ret, e2);
5257 exprNode_checkUse (ret, e2->sref, e2->loc);
5261 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5263 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5266 isjustalloc = sRef_isJustAllocated (e1->sref);
5267 isalloc = sRef_isAllocated (e1->sref);
5269 if (sRef_isField (e1->sref))
5271 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5273 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5275 exprNode_checkUse (ret, root, e1->loc);
5281 ** be careful! this defines e1->sref.
5284 if (!sRef_isMacroParamRef (e1->sref))
5286 exprNode_checkSet (ret, e1->sref);
5291 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5292 ? e2->loc : e1->loc);
5298 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5307 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5308 /*@keep@*/ exprNode elseclause)
5312 if (!exprNode_isError (pred))
5314 ret = exprNode_createPartialCopy (pred);
5315 checkMacroParen (pred);
5316 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
5318 if (!exprNode_isError (ifclause))
5320 checkMacroParen (ifclause); /* update macro counts! */
5322 if (!exprNode_isError (elseclause))
5324 checkMacroParen (elseclause);
5326 if (!exprNode_matchTypes (ifclause, elseclause))
5329 (exprNode_getType (ifclause),
5331 exprNode_getType (elseclause),
5333 message ("Conditional clauses are not of same type: "
5335 exprNode_unparse (ifclause),
5336 exprNode_getType (ifclause),
5337 exprNode_unparse (elseclause),
5338 exprNode_getType (elseclause)),
5341 ret->sref = sRef_undefined;
5342 ret->typ = ctype_unknown;
5347 /* for now...should merge the states */
5348 ret->sref = ifclause->sref;
5349 ret->typ = ifclause->typ;
5351 if (exprNode_isNullValue (ifclause))
5353 ret->typ = elseclause->typ;
5357 exprNode_checkUse (ret, pred->sref, pred->loc);
5358 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5359 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5361 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5366 ret->typ = ifclause->typ;
5368 exprNode_checkUse (pred, pred->sref, pred->loc);
5369 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5371 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
5376 if (!exprNode_isError (elseclause))
5378 ret->typ = elseclause->typ;
5380 exprNode_checkUse (pred, pred->sref, pred->loc);
5381 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5383 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5387 else /* pred is error */
5389 if (!exprNode_isError (ifclause))
5391 ret = exprNode_createSemiCopy (ifclause);
5393 checkMacroParen (ifclause); /* update macro counts! */
5395 if (!exprNode_isError (elseclause))
5397 checkMacroParen (elseclause);
5399 ret->typ = ifclause->typ;
5401 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
5404 (exprNode_getType (ifclause),
5406 exprNode_getType (elseclause),
5408 message ("Conditional clauses are not of same type: "
5410 exprNode_unparse (ifclause),
5411 exprNode_getType (ifclause),
5412 exprNode_unparse (elseclause),
5413 exprNode_getType (elseclause)),
5416 ret->typ = ctype_unknown;
5420 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5421 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5423 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5426 else if (!exprNode_isError (elseclause)) /* pred, if errors */
5428 ret = exprNode_createSemiCopy (ifclause);
5430 ret->typ = elseclause->typ;
5431 checkMacroParen (elseclause);
5433 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5434 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5436 else /* all errors! */
5438 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5442 ret->kind = XPR_COND;
5443 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
5445 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
5447 exprNode_combineControl (ret, ifclause, elseclause);
5454 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
5456 ctype totype = qtype_getType (qt);
5458 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
5462 ** check use of va_arg : <valist>, type -> type
5465 if (exprNode_isError (arg))
5470 targ = exprNode_getType (arg);
5473 ** arg should have be a pointer
5476 if (!ctype_isUA (targ) ||
5477 (!usymId_equal (ctype_typeId (targ),
5478 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
5482 message ("First argument to va_arg is not a va_list (type %t): %s",
5483 targ, exprNode_unparse (arg)),
5487 exprNode_checkSet (ret, arg->sref);
5491 ** return type is totype
5495 ret->kind = XPR_VAARG;
5496 ret->edata = exprData_makeCast (tok, arg, qt);
5501 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
5503 exprNode ret = exprNode_createPlain (ctype_undefined);
5504 ret->kind = XPR_LABEL;
5505 ret->edata = exprData_makeLiteral (label);
5506 ret->isJumpPoint = TRUE;
5508 return (ret); /* for now, ignore label */
5511 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
5513 if (exprNode_isDefined (stmt))
5515 stmt->isJumpPoint = TRUE;
5517 /* This prevent stray no return path errors, etc. */
5518 stmt->exitCode = XK_MUSTEXIT;
5524 bool exprNode_isDefaultMarker (exprNode e)
5526 if (exprNode_isDefined (e))
5528 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
5534 bool exprNode_isCaseMarker (exprNode e)
5536 if (exprNode_isDefined (e))
5538 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
5544 bool exprNode_isLabelMarker (exprNode e)
5546 if (exprNode_isDefined (e))
5548 return (e->kind == XPR_LABEL);
5554 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
5556 exprNode ret = exprNode_createPartialCopy (test);
5558 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5560 if (exprNode_isError (test)) {
5564 exprNode_checkUse (ret, test->sref, test->loc);
5566 usymtab_setExitCode (ret->exitCode);
5570 usymtab_setMustBreak ();
5573 ret->edata = exprData_makeSingle (test);
5574 ret->isJumpPoint = TRUE;
5580 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
5582 exprNode ret = exprNode_createPartialCopy (test);
5584 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5585 ret->edata = exprData_makePair (test, stmt);
5586 ret->isJumpPoint = TRUE;
5588 if (exprNode_isError (test))
5593 exprNode_checkUse (ret, test->sref, test->loc);
5595 if (exprNode_isError (stmt))
5600 exprNode_mergeUSs (ret, stmt);
5602 ret->exitCode = stmt->exitCode;
5603 ret->mustBreak = stmt->mustBreak;
5604 ret->canBreak = stmt->canBreak;
5606 usymtab_setExitCode (ret->exitCode);
5610 usymtab_setMustBreak ();
5617 /*@notnull@*/ /*@only@*/ exprNode
5618 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
5620 exprNode ret = exprNode_createTok (def);
5622 ret->isJumpPoint = TRUE;
5623 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
5628 exprNode_mayEscape (exprNode e)
5630 if (exprNode_isDefined (e))
5632 return exitkind_couldEscape (e->exitCode);
5638 exprNode_mustBreak (exprNode e)
5640 if (exprNode_isDefined (e))
5642 return e->mustBreak;
5648 exprNode_mustEscape (exprNode e)
5650 if (exprNode_isDefined (e))
5652 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
5659 exprNode_errorEscape (exprNode e)
5661 if (exprNode_isDefined (e))
5663 return exitkind_isError (e->exitCode);
5669 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
5671 exprNode ret = exprNode_createPartialCopy (e1);
5673 ret->edata = exprData_makePair (e1, e2);
5674 ret->kind = XPR_STMTLIST;
5676 if (exprNode_isDefined (e1))
5678 ret->isJumpPoint = e1->isJumpPoint;
5679 ret->canBreak = e1->canBreak;
5683 if (exprNode_isDefined (e2))
5685 ret->loc = fileloc_update (ret->loc, e2->loc);
5689 if (exprNode_isDefined (e2))
5691 ret->exitCode = e2->exitCode;
5692 ret->mustBreak = e2->mustBreak;
5693 if (e2->canBreak) ret->canBreak = TRUE;
5697 ** if e1 must return, then e2 is unreachable!
5700 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
5702 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
5703 && !(e2->isJumpPoint))
5705 if (context_getFlag (FLG_UNREACHABLE))
5709 if (e2->kind == XPR_STMT)
5711 nr = exprData_getUopNode (e2->edata);
5714 if ((nr->kind == XPR_TOK
5715 && lltok_isSemi (exprData_getTok (nr->edata))))
5717 /* okay to have unreachable ";" */
5718 ret->exitCode = XK_MUSTEXIT;
5719 ret->canBreak = TRUE;
5723 if (optgenerror (FLG_UNREACHABLE,
5724 message ("Unreachable code: %s",
5725 exprNode_unparseFirst (nr)),
5728 ret->isJumpPoint = TRUE;
5729 ret->mustBreak = FALSE;
5730 ret->exitCode = XK_ERROR;
5731 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
5735 ret->exitCode = XK_MUSTEXIT;
5736 ret->canBreak = TRUE;
5744 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
5747 ** We want a warning anytime we have:
5749 ** yyy; <<<- no break or return
5753 exprNode lastStmt = exprNode_lastStatement (e1);
5755 if (exprNode_isDefined (lastStmt)
5756 && !exprNode_mustEscape (lastStmt)
5757 && !exprNode_mustBreak (lastStmt)
5758 && !exprNode_isCaseMarker (lastStmt)
5759 && !exprNode_isDefaultMarker (lastStmt)
5760 && !exprNode_isLabelMarker (lastStmt))
5762 voptgenerror (FLG_CASEBREAK,
5764 ("Fall through case (no preceeding break)"),
5771 exprNode_mergeUSs (ret, e2);
5772 ret = exprNode_mergeEnvironments (ret, e1, e2);
5773 usymtab_setExitCode (ret->exitCode);
5777 usymtab_setMustBreak ();
5783 exprNode exprNode_createTok (/*@only@*/ lltok t)
5785 exprNode ret = exprNode_create (ctype_unknown);
5786 ret->kind = XPR_TOK;
5787 ret->edata = exprData_makeTok (t);
5791 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5793 if (!exprNode_isError (e))
5795 exprNode_checkStatement(e);
5798 return (exprNode_statementError (e, t));
5801 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5803 exprNode ret = exprNode_createPartialCopy (e);
5805 if (!exprNode_isError (e))
5807 if (e->kind != XPR_ASSIGN)
5809 exprNode_checkUse (ret, e->sref, e->loc);
5812 ret->exitCode = e->exitCode;
5813 ret->canBreak = e->canBreak;
5814 ret->mustBreak = e->mustBreak;
5817 ret->edata = exprData_makeUop (e, t);
5818 ret->kind = XPR_STMT;
5823 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
5825 if (!exprNode_isError (e))
5827 if (e->kind != XPR_ASSIGN)
5829 exprNode_checkUse (e, e->sref, e->loc);
5836 void exprNode_produceGuards (exprNode pred)
5838 if (!exprNode_isError (pred))
5840 if (ctype_isRealPointer (pred->typ))
5842 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
5845 exprNode_checkUse (pred, pred->sref, pred->loc);
5846 exprNode_resetSref (pred);
5850 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
5852 exprNode ret = exprNode_createPartialCopy (e);
5854 if (!exprNode_isError (e))
5856 ret->exitCode = e->exitCode;
5857 ret->canBreak = e->canBreak;
5858 ret->mustBreak = e->mustBreak;
5861 ret->edata = exprData_makeSingle (e);
5862 ret->kind = XPR_BLOCK;
5866 bool exprNode_isBlock (exprNode e)
5868 return (exprNode_isDefined (e)
5869 && ((e)->kind == XPR_BLOCK));
5872 bool exprNode_isAssign (exprNode e)
5874 if (exprNode_isDefined (e))
5876 return (e->kind == XPR_ASSIGN);
5882 bool exprNode_isEmptyStatement (exprNode e)
5884 return (exprNode_isDefined (e)
5885 && (e->kind == XPR_TOK)
5886 && (lltok_isSemi (exprData_getTok (e->edata))));
5889 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
5892 bool emptyErr = FALSE;
5894 if (context_maybeSet (FLG_IFEMPTY))
5896 if (exprNode_isEmptyStatement (tclause))
5898 emptyErr = optgenerror (FLG_IFEMPTY,
5900 ("Body of if statement is empty"),
5901 exprNode_loc (tclause));
5905 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
5907 if (exprNode_isDefined (tclause)
5908 && !exprNode_isBlock (tclause))
5910 voptgenerror (FLG_IFBLOCK,
5912 ("Body of if statement is not a block: %s",
5913 exprNode_unparse (tclause)),
5914 exprNode_loc (tclause));
5918 if (exprNode_isError (pred))
5920 if (exprNode_isError (tclause))
5922 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5926 ret = exprNode_createPartialCopy (tclause);
5931 if (exprNode_mustEscape (pred))
5935 message ("Predicate always exits: %s", exprNode_unparse (pred)),
5936 exprNode_loc (pred));
5939 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
5940 exprNode_checkUse (pred, pred->sref, pred->loc);
5942 if (!exprNode_isError (tclause))
5944 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
5947 ret = exprNode_createPartialCopy (pred);
5951 ret->edata = exprData_makePair (pred, tclause);
5953 ret->exitCode = XK_UNKNOWN;
5955 if (exprNode_isDefined (tclause))
5957 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
5958 ret->canBreak = tclause->canBreak;
5959 ret->sets = sRefSet_union (ret->sets, tclause->sets);
5960 ret->msets = sRefSet_union (ret->msets, tclause->msets);
5961 ret->uses = sRefSet_union (ret->uses, tclause->uses);
5964 ret->mustBreak = FALSE;
5969 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
5970 /*@only@*/ exprNode tclause,
5971 /*@only@*/ exprNode eclause)
5974 bool tEmptyErr = FALSE;
5975 bool eEmptyErr = FALSE;
5977 if (context_maybeSet (FLG_IFEMPTY))
5979 if (exprNode_isEmptyStatement (tclause))
5981 tEmptyErr = optgenerror
5984 ("Body of if clause of if statement is empty"),
5985 exprNode_loc (tclause));
5988 if (exprNode_isEmptyStatement (eclause))
5990 eEmptyErr = optgenerror
5993 ("Body of else clause of if statement is empty"),
5994 exprNode_loc (eclause));
5998 if (context_maybeSet (FLG_IFBLOCK))
6001 && exprNode_isDefined (tclause)
6002 && !exprNode_isBlock (tclause))
6004 voptgenerror (FLG_IFBLOCK,
6006 ("Body of if clause of if statement is not a block: %s",
6007 exprNode_unparse (tclause)),
6008 exprNode_loc (tclause));
6012 && exprNode_isDefined (eclause)
6013 && !exprNode_isBlock (eclause)
6014 && !(eclause->kind == XPR_IF)
6015 && !(eclause->kind == XPR_IFELSE))
6020 ("Body of else clause of if statement is not a block: %s",
6021 exprNode_unparse (eclause)),
6022 exprNode_loc (eclause));
6026 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6028 if (exprNode_isDefined (eclause)
6029 && (eclause->kind == XPR_IF))
6031 voptgenerror (FLG_ELSEIFCOMPLETE,
6032 message ("Incomplete else if logic (no final else): %s",
6033 exprNode_unparse (eclause)),
6034 exprNode_loc (eclause));
6038 if (exprNode_isError (pred))
6040 if (exprNode_isError (tclause))
6042 if (exprNode_isError (eclause))
6044 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6048 ret = exprNode_createPartialCopy (eclause);
6053 ret = exprNode_createPartialCopy (tclause);
6056 else /* pred is okay */
6058 ret = exprNode_createPartialCopy (pred);
6060 if (exprNode_mustEscape (pred))
6064 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6065 exprNode_loc (pred));
6068 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6069 exprNode_checkUse (ret, pred->sref, pred->loc);
6071 exprNode_mergeCondUSs (ret, tclause, eclause);
6074 ret->kind = XPR_IFELSE;
6075 ret->edata = exprData_makeCond (pred, tclause, eclause);
6077 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6079 exprNode_combineControl (ret, tclause, eclause);
6080 ret->loc = fileloc_update (ret->loc, eclause->loc);
6087 ** *allpaths <- TRUE iff all executions paths must go through the switch
6091 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6093 exprNodeSList el = exprNode_flatten (e);
6094 bool mustReturn = TRUE; /* find a branch that doesn't */
6095 bool thisReturn = FALSE;
6096 bool hasDefault = FALSE;
6097 bool hasAllMembers = FALSE;
6098 bool inSwitch = FALSE;
6099 bool isEnumSwitch = FALSE;
6100 bool canBreak = FALSE;
6101 bool fallThrough = FALSE;
6102 ctype ct = ctype_unknown;
6103 enumNameSList usedEnums;
6106 if (exprNode_isDefined (test))
6111 ttype = ctype_realType (ct);
6113 if (ctype_isEnum (ttype))
6115 isEnumSwitch = TRUE;
6116 enums = ctype_elist (ttype);
6117 usedEnums = enumNameSList_new ();
6121 exprNodeSList_elements (el, current)
6123 if (exprNode_isDefined (current))
6125 switch (current->kind)
6133 message ("Duplicate default cases in switch"),
6134 exprNode_loc (current));
6139 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6147 exprNode st = exprData_getSingle (current->edata);
6148 uentry ue = exprNode_getUentry (st);
6150 if (uentry_isValid (ue))
6152 cstring cname = uentry_rawName (ue);
6154 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6156 if (enumNameSList_member
6157 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6161 message ("Duplicate case in switch: %s",
6167 enumNameSList_addh (usedEnums, cname);
6174 message ("Case in switch not %s member: %s",
6175 ctype_unparse (ct), cname),
6182 if (inSwitch && !fallThrough)
6184 if (!thisReturn || canBreak)
6194 /*@switchbreak@*/ break;
6196 thisReturn = thisReturn || exprNode_mustEscape (current);
6197 canBreak = canBreak || current->canBreak;
6198 if (canBreak) fallThrough = FALSE;
6201 } end_exprNodeSList_elements;
6203 if (inSwitch) /* check the last one! */
6205 if (!thisReturn || canBreak)
6214 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6215 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6217 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6219 voptgenerror (FLG_MISSCASE,
6220 message ("Missing case%s in switch: %q",
6221 cstring_makeLiteralTemp
6222 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6223 enumNameSList_unparse (unused)),
6226 enumNameSList_free (unused);
6230 hasAllMembers = TRUE;
6234 enumNameSList_free (usedEnums);
6238 *allpaths = hasDefault;
6241 exprNodeSList_free (el);
6242 return ((hasDefault || hasAllMembers) && mustReturn);
6245 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6247 exprNode ret = exprNode_createPartialCopy (e);
6250 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6252 ret->kind = XPR_SWITCH;
6253 ret->edata = exprData_makePair (e, s);
6255 if (!exprNode_isError (s))
6257 exprNode fs = exprNode_firstStatement (s);
6258 ret->loc = fileloc_update (ret->loc, s->loc);
6260 if (exprNode_isUndefined (fs)
6261 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6262 || exprNode_isDefaultMarker (fs)) {
6265 voptgenerror (FLG_FIRSTCASE,
6267 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6272 if (!exprNode_isError (e))
6274 if (checkSwitchExpr (e, s, &allpaths))
6276 ret->exitCode = XK_MUSTRETURN;
6280 ret->exitCode = e->exitCode;
6283 ret->canBreak = e->canBreak;
6284 ret->mustBreak = e->mustBreak;
6288 ** exprNode.c:3883,32: Variable allpaths used before definition
6295 DPRINTF (("Context exit switch!"));
6296 context_exitSwitch (ret, allpaths);
6297 DPRINTF (("Context exit switch done!"));
6302 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6303 /*@notnull@*/ exprNode body)
6305 sRefSet tuses = test->uses;
6307 if (!sRefSet_isEmpty (test->uses))
6309 sRefSet sets = sRefSet_newCopy (body->sets);
6310 bool hasError = TRUE;
6311 bool innerState = FALSE;
6312 sRefSet tuncon = sRefSet_undefined;
6314 sets = sRefSet_union (sets, test->sets);
6315 sets = sRefSet_union (sets, body->msets);
6316 sets = sRefSet_union (sets, test->msets);
6318 sRefSet_allElements (tuses, el)
6320 if (sRef_isUnconstrained (el))
6322 tuncon = sRefSet_insert (tuncon, el);
6326 if (sRefSet_member (sets, el))
6333 if (sRef_isInternalState (el)
6334 || sRef_isFileStatic (sRef_getRootBase (el)))
6338 } end_sRefSet_allElements ;
6342 sRefSet suncon = sRefSet_undefined;
6343 bool sinner = FALSE;
6345 sRefSet_allElements (sets, el)
6347 if (sRef_isUnconstrained (el))
6349 suncon = sRefSet_insert (suncon, el);
6351 else if (sRef_isInternalState (el))
6359 } end_sRefSet_allElements ;
6361 if (sinner && innerState)
6365 else if (sRefSet_isEmpty (tuncon)
6366 && sRefSet_isEmpty (suncon))
6371 ("Suspected infinite loop. No value used in loop test (%q) "
6372 "is modified by test or loop body.",
6373 sRefSet_unparsePlain (tuses)),
6378 if (sRefSet_isEmpty (tuncon))
6382 message ("Suspected infinite loop. No condition values "
6383 "modified. Modification possible through "
6384 "unconstrained calls: %q",
6385 sRefSet_unparsePlain (suncon)),
6392 message ("Suspected infinite loop. No condition values "
6393 "modified. Possible undetected dependency through "
6394 "unconstrained calls in loop test: %q",
6395 sRefSet_unparsePlain (tuncon)),
6401 sRefSet_free (sets);
6405 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
6408 bool emptyErr = FALSE;
6410 s = exprNode_generateConstraints (t);
6411 // printf("pred: %s\n", s);
6412 s = exprNode_generateConstraints (b);
6413 //printf ("body: %s\n", s);
6414 //constraintList_print(b->constraints);
6416 if (context_maybeSet (FLG_WHILEEMPTY))
6418 if (exprNode_isEmptyStatement (b))
6420 emptyErr = optgenerror
6423 ("Body of while statement is empty"),
6428 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
6430 if (exprNode_isDefined (b)
6431 && !exprNode_isBlock (b))
6433 if (context_inIterDef ()
6434 && (b->kind == XPR_STMTLIST
6435 || b->kind == XPR_TOK))
6441 voptgenerror (FLG_WHILEBLOCK,
6443 ("Body of while statement is not a block: %s",
6444 exprNode_unparse (b)),
6450 if (exprNode_isError (t))
6452 if (exprNode_isError (b))
6454 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6458 ret = exprNode_createPartialCopy (b);
6465 ret = exprNode_createPartialCopy (t);
6467 llassert (t->kind == XPR_WHILEPRED);
6469 test = exprData_getSingle (t->edata);
6471 if (!exprNode_isError (b) && exprNode_isDefined (test))
6473 if (context_maybeSet (FLG_INFLOOPS)
6474 || context_maybeSet (FLG_INFLOOPSUNCON))
6477 ** check that some variable in the predicate is set by the body
6478 ** if the predicate uses any variables
6481 checkInfiniteLoop (test, b);
6484 exprNode_mergeUSs (ret, b);
6486 if (exprNode_isDefined (b))
6488 ret->exitCode = exitkind_makeConditional (b->exitCode);
6493 ret->edata = exprData_makePair (t, b);
6494 ret->kind = XPR_WHILE;
6496 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
6500 message ("Predicate always exits: %s", exprNode_unparse (t)),
6504 ret->exitCode = XK_NEVERESCAPE;
6507 ** If loop is infinite, and there is no break inside,
6508 ** exit code is never reach.
6511 if (exprNode_knownIntValue (t))
6513 if (!exprNode_isZero (t))
6515 if (exprNode_isDefined (b))
6519 /* Really, it means never reached. */
6520 ret->exitCode = XK_MUSTEXIT;
6530 ret->canBreak = FALSE;
6531 ret->mustBreak = FALSE;
6537 ** do { b } while (t);
6539 ** note: body passed as first argument
6542 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
6546 if (exprNode_isError (t))
6548 if (exprNode_isError (b))
6550 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6554 ret = exprNode_createPartialCopy (b);
6556 ret->exitCode = exitkind_makeConditional (b->exitCode);
6557 exprNode_checkUse (ret, b->sref, b->loc);
6558 ret->exitCode = b->exitCode;
6559 ret->canBreak = b->canBreak;
6560 ret->mustBreak = b->mustBreak;
6565 ret = exprNode_createPartialCopy (t);
6566 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
6568 if (!exprNode_isError (b))
6571 ** forgot the copy's --- why wasn't this detected??
6574 ret->sets = sRefSet_copy (ret->sets, b->sets);
6575 ret->msets = sRefSet_copy (ret->msets, b->msets);
6576 ret->uses = sRefSet_copy (ret->uses, b->uses);
6578 /* left this out --- causes and aliasing bug (infinite loop)
6579 should be detected?? */
6581 exprNode_checkUse (ret, b->sref, b->loc);
6582 exprNode_mergeUSs (ret, t);
6583 exprNode_checkUse (ret, t->sref, t->loc);
6585 ret->exitCode = b->exitCode;
6586 ret->canBreak = b->canBreak;
6587 ret->mustBreak = b->mustBreak;
6591 context_exitDoWhileClause (t);
6593 ret->kind = XPR_DOWHILE;
6594 ret->edata = exprData_makePair (t, b);
6598 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
6601 bool emptyErr = FALSE;
6603 if (context_maybeSet (FLG_FOREMPTY))
6605 if (exprNode_isEmptyStatement (body))
6607 emptyErr = optgenerror
6610 ("Body of for statement is empty"),
6611 exprNode_loc (body));
6615 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
6617 if (exprNode_isDefined (body)
6618 && !exprNode_isBlock (body))
6620 if (context_inIterDef ()
6621 && (body->kind == XPR_STMTLIST
6622 || body->kind == XPR_TOK))
6628 voptgenerror (FLG_FORBLOCK,
6630 ("Body of for statement is not a block: %s",
6631 exprNode_unparse (body)),
6632 exprNode_loc (body));
6638 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
6641 if (exprNode_isError (body))
6643 ret = exprNode_createPartialCopy (inc);
6647 ret = exprNode_createPartialCopy (body);
6649 ret->exitCode = exitkind_makeConditional (body->exitCode);
6651 exprNode_mergeUSs (inc, body);
6653 if (exprNode_isDefined (inc))
6657 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
6660 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
6661 exprNode_freeShallow (tmp);
6663 context_clearMessageAnnote ();
6664 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
6666 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
6667 exprNode_freeShallow (tmp);
6669 context_clearMessageAnnote ();
6671 ret->uses = sRefSet_copy (ret->uses, inc->uses);
6672 ret->sets = sRefSet_copy (ret->sets, inc->sets);
6673 ret->msets = sRefSet_copy (ret->msets, inc->msets);
6677 ret->kind = XPR_FOR;
6678 ret->edata = exprData_makePair (inc, body);
6680 if (exprNode_isDefined (inc)) {
6681 exprNode test = exprData_getTripleTest (inc->edata);
6683 if (exprNode_isUndefined (test)) {
6684 if (exprNode_isDefined (body)) {
6685 if (!body->canBreak) {
6686 /* Really, it means never reached. */
6687 ret->exitCode = XK_MUSTEXIT;
6697 ** for (init; test; inc)
6700 ** while (test) { body; inc; }
6702 ** Now: check use of init (may set vars for test)
6703 ** check use of test
6707 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
6711 if (exprNode_isError (pred)) return guardSet_undefined;
6713 llassert (pred->kind == XPR_FORPRED);
6715 test = exprData_getTripleTest (pred->edata);
6717 if (!exprNode_isError (test))
6719 return (test->guards);
6722 return guardSet_undefined;
6725 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
6727 exprNode ret = exprNode_createSemiCopy (test);
6729 if (exprNode_isDefined (test))
6731 exprNode_copySets (ret, test);
6732 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
6733 exprNode_checkUse (ret, test->sref, test->loc);
6735 exprNode_produceGuards (test);
6737 ret->guards = guardSet_copy (test->guards);
6740 ret->edata = exprData_makeSingle (test);
6741 ret->kind = XPR_WHILEPRED;
6745 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
6746 /*@only@*/ exprNode inc)
6751 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
6754 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
6756 if (!exprNode_isError (inc))
6758 ret = exprNode_createPartialCopy (inc);
6762 if (!exprNode_isError (init))
6764 ret = exprNode_createPartialCopy (init);
6766 else if (!exprNode_isError (test))
6768 ret = exprNode_createPartialCopy (test);
6772 ret = exprNode_createUnknown ();
6776 exprNode_mergeUSs (ret, init);
6778 if (exprNode_isDefined (init))
6780 exprNode_checkUse (ret, init->sref, init->loc);
6783 exprNode_mergeUSs (ret, test);
6785 if (exprNode_isDefined (test))
6787 exprNode_checkUse (ret, test->sref, test->loc);
6790 ret->kind = XPR_FORPRED;
6791 ret->edata = exprData_makeFor (init, test, inc);
6795 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
6797 exprNode ret = exprNode_createUnknown ();
6799 if (context_inMacro ())
6801 voptgenerror (FLG_MACROSTMT,
6802 message ("Macro %s uses goto (not functional)",
6803 context_inFunctionName ()),
6807 ret->kind = XPR_GOTO;
6808 ret->edata = exprData_makeLiteral (label);
6809 ret->mustBreak = TRUE;
6810 ret->exitCode = XK_GOTO;
6811 ret->canBreak = TRUE;
6815 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
6817 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6819 ret->kind = XPR_CONTINUE;
6820 ret->edata = exprData_makeTok (l);
6821 ret->canBreak = TRUE;
6822 ret->mustBreak = TRUE;
6824 if (qcontinue == QSAFEBREAK)
6828 else if (qcontinue == QINNERCONTINUE)
6830 if (!context_inDeepLoop ())
6833 (FLG_LOOPLOOPCONTINUE,
6834 cstring_makeLiteral ("Continue statement marked with innercontinue "
6835 "is not inside a nested loop"),
6836 exprNode_loc (ret));
6839 else if (qcontinue == BADTOK)
6841 if (context_inDeepLoop ())
6844 (FLG_LOOPLOOPCONTINUE,
6845 cstring_makeLiteral ("Continue statement in nested loop"),
6846 exprNode_loc (ret));
6851 llbuglit ("exprNode_continue: bad qcontinue");
6857 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
6859 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6860 clause breakClause = context_breakClause ();
6862 ret->kind = XPR_BREAK;
6863 ret->edata = exprData_makeTok (l);
6864 ret->canBreak = TRUE;
6865 ret->mustBreak = TRUE;
6867 if (breakClause == NOCLAUSE)
6871 cstring_makeLiteral ("Break not inside while, for or switch statement"),
6872 exprNode_loc (ret));
6876 if (bqual != BADTOK)
6883 if (breakClause == SWITCHCLAUSE)
6885 if (!context_inDeepSwitch ())
6887 voptgenerror (FLG_SYNTAX,
6889 ("Break preceded by innerbreak is not in a deep switch"),
6890 exprNode_loc (ret));
6895 if (!context_inDeepLoop ())
6897 voptgenerror (FLG_SYNTAX,
6899 ("Break preceded by innerbreak is not in a deep loop"),
6900 exprNode_loc (ret));
6905 if (breakClause == SWITCHCLAUSE)
6907 voptgenerror (FLG_SYNTAX,
6909 ("Break preceded by loopbreak is breaking a switch"),
6910 exprNode_loc (ret));
6914 if (breakClause != SWITCHCLAUSE)
6918 message ("Break preceded by switchbreak is breaking %s",
6919 cstring_makeLiteralTemp
6920 ((breakClause == WHILECLAUSE
6921 || breakClause == DOWHILECLAUSE) ? "a while loop"
6922 : (breakClause == FORCLAUSE) ? "a for loop"
6923 : (breakClause == ITERCLAUSE) ? "an iterator"
6925 exprNode_loc (ret));
6933 if (breakClause == SWITCHCLAUSE)
6935 clause nextBreakClause = context_nextBreakClause ();
6937 switch (nextBreakClause)
6939 case NOCLAUSE: break;
6945 (FLG_LOOPSWITCHBREAK,
6946 cstring_makeLiteral ("Break statement in switch inside loop"),
6947 exprNode_loc (ret));
6951 (FLG_SWITCHSWITCHBREAK,
6952 cstring_makeLiteral ("Break statement in switch inside switch"),
6953 exprNode_loc (ret));
6960 if (context_inDeepLoop ())
6964 cstring_makeLiteral ("Break statement in nested loop"),
6965 exprNode_loc (ret));
6969 if (context_inDeepLoopSwitch ())
6972 (FLG_SWITCHLOOPBREAK,
6973 cstring_makeLiteral ("Break statement in loop inside switch"),
6974 exprNode_loc (ret));
6984 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
6986 fileloc loc = lltok_getLoc (t);
6987 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
6989 context_returnFunction ();
6990 exprChecks_checkNullReturn (loc);
6992 ret->kind = XPR_NULLRETURN;
6993 ret->edata = exprData_makeTok (t);
6994 ret->exitCode = XK_MUSTRETURN;
6998 exprNode exprNode_return (/*@only@*/ exprNode e)
7002 if (exprNode_isError (e))
7004 ret = exprNode_createUnknown ();
7008 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7010 exprNode_checkUse (ret, e->sref, e->loc);
7011 exprNode_checkReturn (e);
7014 context_returnFunction ();
7015 ret->kind = XPR_RETURN;
7016 ret->edata = exprData_makeSingle (e);
7017 ret->exitCode = XK_MUSTRETURN;
7022 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7026 if (exprNode_isError (e1))
7028 if (exprNode_isError (e2))
7030 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
7034 ret = exprNode_createPartialCopy (e2);
7035 exprNode_checkUse (ret, e2->sref, e2->loc);
7036 ret->sref = e2->sref;
7041 ret = exprNode_createPartialCopy (e1);
7043 exprNode_checkUse (ret, e1->sref, e1->loc);
7045 if (!exprNode_isError (e2))
7047 exprNode_mergeUSs (ret, e2);
7048 exprNode_checkUse (ret, e2->sref, e2->loc);
7049 ret->sref = e2->sref;
7053 ret->kind = XPR_COMMA;
7054 ret->edata = exprData_makePair (e1, e2);
7056 if (exprNode_isDefined (e1))
7058 if (exprNode_isDefined (e2))
7062 if (exprNode_mustEscape (e1) || e1->mustBreak)
7066 message ("Second clause of comma expression is unreachable: %s",
7067 exprNode_unparse (e2)),
7071 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7072 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7073 ret->canBreak = e1->canBreak || e2->canBreak;
7077 if (exprNode_mustEscape (e1) || e1->mustBreak)
7081 message ("Second clause of comma expression is unreachable: %s",
7082 exprNode_unparse (e2)),
7086 ret->exitCode = e1->exitCode;
7087 ret->canBreak = e1->canBreak;
7092 if (exprNode_isDefined (e2))
7094 ret->exitCode = e2->exitCode;
7095 ret->mustBreak = e2->mustBreak;
7096 ret->canBreak = e2->canBreak;
7103 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7105 ctype t1 = exprNode_getType (el);
7106 ctype t2 = exprNode_getType (val);
7107 bool hasError = FALSE;
7109 if (ctype_isUnknown (t1))
7111 voptgenerror (FLG_IMPTYPE,
7112 message ("Variable has unknown (implicitly int) type: %s",
7113 exprNode_unparse (el)),
7117 el->typ = ctype_int;
7120 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7122 exprNodeList vals = exprData_getArgs (val->edata);
7124 if (ctype_isRealAP (t1))
7129 exprNodeList_elements (vals, oneval)
7131 cstring istring = message ("%d", i);
7134 (exprNode_fakeCopy (el),
7135 exprNode_numLiteral (ctype_int, istring,
7136 fileloc_copy (el->loc), i));
7138 if (exprNode_isDefined (newel))
7140 if (exprNodeList_size (vals) == 1
7141 && ctype_isString (exprNode_getType (oneval))
7142 && ctype_isChar (exprNode_getType (newel)))
7144 exprNode_freeIniter (newel);
7148 if (exprNode_checkOneInit (newel, oneval))
7153 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7156 (message ("Additional initialization errors "
7157 "for %s not reported",
7158 exprNode_unparse (el)),
7160 exprNode_freeIniter (newel);
7165 exprNode_freeIniter (newel);
7170 exprNode_freeIniter (newel);
7175 cstring_free (istring);
7178 } end_exprNodeList_elements;
7181 else if (ctype_isStruct (ctype_realType (t1)))
7183 uentryList fields = ctype_getFields (t1);
7186 if (uentryList_size (fields) != exprNodeList_size (vals))
7188 if (uentryList_size (fields) > exprNodeList_size (vals))
7190 hasError = optgenerror
7192 message ("Initializer block for "
7193 "%s has %d field%p, but %s has %d field%p: %q",
7194 exprNode_unparse (el),
7195 exprNodeList_size (vals),
7197 uentryList_size (fields),
7198 exprNodeList_unparse (vals)),
7203 hasError = optgenerror
7205 message ("Initializer block for "
7206 "%s has %d field%p, but %s has %d field%p: %q",
7207 exprNode_unparse (el),
7208 exprNodeList_size (vals),
7210 uentryList_size (fields),
7211 exprNodeList_unparse (vals)),
7217 exprNodeList_elements (vals, oneval)
7219 uentry thisfield = uentryList_getN (fields, i);
7221 exprNode_fieldAccess (exprNode_fakeCopy (el),
7222 uentry_getName (thisfield));
7224 if (exprNode_isDefined (newel))
7226 if (exprNode_checkOneInit (newel, oneval))
7231 exprNode_freeIniter (newel);
7235 } end_exprNodeList_elements;
7240 hasError = optgenerror
7242 message ("Initializer block used for "
7243 "%s where %t is expected: %s",
7244 exprNode_unparse (el), t1, exprNode_unparse (val)),
7250 if (exprNode_isDefined (val))
7252 doAssign (el, val, TRUE);
7254 if (!exprNode_matchType (t1, val))
7256 hasError = gentypeerror
7258 message ("Initial value of %s is type %t, "
7260 exprNode_unparse (el),
7261 t2, t1, exprNode_unparse (val)),
7270 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
7271 /*@only@*/ exprNode e)
7273 uentry ue = usymtab_lookup (idDecl_observeId (t));
7274 bool isUsed = uentry_isUsed (ue);
7275 exprNode ret = exprNode_fromIdentifierAux (ue);
7276 ctype ct = ctype_realishType (ret->typ);
7279 if (ctype_isUnknown (ct))
7281 voptgenerror (FLG_IMPTYPE,
7282 message ("Variable has unknown (implicitly int) type: %s",
7283 idDecl_getName (t)),
7284 exprNode_isDefined (e) ? exprNode_loc (e) : g_currentloc);
7289 if (exprNode_isError (e))
7291 e = exprNode_createUnknown ();
7294 /* error: assume initializer is defined */
7295 sRef_setDefined (ret->sref, loc);
7299 loc = exprNode_loc (e);
7304 ** was addSafeUse --- what's the problem?
7306 ** int x = 3, y = x ?
7309 exprNode_checkUse (ret, e->sref, e->loc);
7311 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
7313 exprNode lhs = exprNode_createId (ue);
7316 ** static storage should be undefined before initializing
7319 if (uentry_isStatic (ue))
7321 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
7324 (void) exprNode_checkOneInit (lhs, e);
7326 if (uentry_isStatic (ue))
7328 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
7331 exprNode_free (lhs);
7335 if (!exprNode_matchType (ct, e))
7337 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
7344 (exprNode_getType (e), e, exprNode_getType (ret), ret,
7346 ("Variable %s initialized to type %t, expects %t: %s",
7347 exprNode_unparse (ret), exprNode_getType (e),
7348 exprNode_getType (ret),
7349 exprNode_unparse (e)),
7355 if (uentry_isStatic (ue))
7357 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
7360 doAssign (ret, e, TRUE);
7362 if (uentry_isStatic (ue))
7364 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
7368 if (context_inIterDef ())
7370 /* should check if it is yield */
7371 uentry_setUsed (ue, loc);
7375 if (!isUsed) /* could be @unused@-qualified variable */
7377 uentry_setNotUsed (ue);
7381 ret->exitCode = XK_NEVERESCAPE;
7382 ret->mustBreak = FALSE;
7385 ** Must be before new kind is assigned!
7388 exprData_free (ret->edata, ret->kind);
7390 ret->kind = XPR_INIT;
7391 ret->edata = exprData_makeInit (t, e);
7392 exprNode_mergeUSs (ret, e);
7396 exprNode exprNode_iter (/*@observer@*/ uentry name,
7397 /*@only@*/ exprNodeList alist,
7398 /*@only@*/ exprNode body,
7399 /*@observer@*/ uentry end)
7404 llassert (uentry_isValid (name));
7406 uentry_setUsed (name, exprNode_loc (body));
7408 ret = exprNode_createPartialCopy (body);
7409 iname = uentry_getName (name);
7411 if (uentry_isInvalid (end))
7414 message ("Iter %s not balanced with end_%s", iname, iname));
7418 cstring ename = uentry_getName (end);
7420 if (!cstring_equalPrefix (ename, "end_"))
7422 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
7423 iname, iname, ename));
7427 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
7430 message ("Iter %s not balanced with end_%s: %s",
7431 iname, iname, ename));
7435 cstring_free (ename);
7438 context_exitIterClause (body);
7440 ret->kind = XPR_ITER;
7441 ret->edata = exprData_makeIter (name, alist, body, end);
7443 if (uentry_isIter (name))
7445 (void) checkArgsReal (name, body,
7446 uentry_getParams (name), alist, TRUE, ret);
7449 cstring_free (iname);
7455 exprNode_iterNewId (/*@only@*/ cstring s)
7457 exprNode e = exprNode_new ();
7458 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
7460 llassert (processingIterVars ());
7462 e->loc = context_getSaveLocation ();
7464 if (fileloc_isUndefined (e->loc))
7466 fileloc_free (e->loc);
7467 e->loc = fileloc_copy (g_currentloc);
7470 e->uses = sRefSet_new ();
7471 e->sets = sRefSet_new ();
7472 e->msets = sRefSet_new ();
7474 e->val = multiVal_unknown ();
7475 e->guards = guardSet_new ();
7477 e->isJumpPoint = FALSE;
7478 e->exitCode = XK_NEVERESCAPE;
7480 /*> missing fields, detected by lclint <*/
7481 e->canBreak = FALSE;
7482 e->mustBreak = FALSE;
7483 e->etext = cstring_undefined;
7485 if (uentry_isYield (ue))
7487 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
7488 fileloc_copy (e->loc),
7492 uue = usymtab_supEntrySrefReturn (uue);
7494 sr = uentry_getSref (uue);
7495 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
7496 sr = uentry_getSref (uue);
7497 sRef_setDefined (sr, e->loc);
7499 e->typ = uentry_getType (uue);
7501 e->edata = exprData_makeId (uue);
7502 uentry_setUsed (uue, g_currentloc);
7508 sRef_setGlobalScope ();
7509 uue = uentry_makeVariableLoc (s, ctype_unknown);
7511 e->typ = ctype_unknown;
7512 e->edata = exprData_makeId (uue);
7514 uentry_setUsed (uue, e->loc);
7515 uentry_setHasNameError (uue);
7517 if (context_getFlag (FLG_REPEATUNRECOG))
7519 uentry_markOwned (uue);
7523 usymtab_supGlobalEntry (uue);
7526 sRef_clearGlobalScope ();
7528 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
7538 exprNode_iterExpr (/*@returned@*/ exprNode e)
7540 if (!processingIterVars ())
7542 llcontbuglit ("checkIterParam: not in iter");
7546 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
7549 if (exprNode_isDefined (e))
7551 if (fileloc_isDefined (e->loc))
7555 message ("Yield parameter is not simple identifier: %s",
7556 exprNode_unparse (e)),
7563 message ("Yield parameter is not simple identifier: %s",
7564 exprNode_unparse (e)),
7574 exprNode_iterId (/*@observer@*/ uentry c)
7578 llassert (processingIterVars ());
7580 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
7583 if (uentry_isYield (ue))
7585 ctype ct = uentry_getType (ue);
7586 exprNode e = exprNode_createPlain (ct);
7587 cstring name = uentry_getName (c);
7588 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
7590 uentry_setUsed (ue, g_currentloc);
7591 uentry_setHasNameError (ue);
7593 cstring_free (name);
7596 e->edata = exprData_makeId (le);
7597 e->loc = context_getSaveLocation ();
7598 e->sref = uentry_getSref (le);
7600 usymtab_supEntrySref (le);
7602 if (!context_inHeader ())
7606 message ("Yield parameter shadows local declaration: %q",
7607 uentry_getName (c)),
7608 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
7610 uentry_showWhereDeclared (c);
7617 return (exprNode_fromIdentifierAux (c));
7620 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
7622 exprNode ret = exprNode_create (ctype_unknown);
7624 ret->kind = XPR_ITERCALL;
7625 ret->edata = exprData_makeIterCall (name, alist);
7627 if (uentry_isIter (name))
7629 uentryList params = uentry_getParams (name);
7631 if (context_inIterDef ()
7632 && uentryList_size (params) == exprNodeList_size (alist))
7636 exprNodeList_elements (alist, arg)
7638 uentry parg = uentryList_getN (params, i);
7640 if (uentry_isYield (parg))
7642 uentry ue = exprNode_getUentry (arg);
7644 if (uentry_isValid (ue))
7651 } end_exprNodeList_elements;
7654 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
7655 checkUnspecCall (ret, params, alist);
7661 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
7663 if (exprNode_isDefined (e))
7666 if (e->sref == defref) /*@noaccess sRef@*/
7669 e->sref = sRef_makeUnknown ();
7670 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
7681 return sRef_undefined;
7685 /*@observer@*/ cstring
7686 exprNode_unparseFirst (exprNode e)
7688 if (exprNode_isDefined (e))
7692 if (e->kind == XPR_STMTLIST
7693 || e->kind == XPR_COMMA || e->kind == XPR_COND)
7695 exprNode first = exprData_getPairA (e->edata);
7697 if (exprNode_isDefined (first))
7699 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
7703 return (cstring_makeLiteralTemp ("..."));
7707 ret = cstring_elide (exprNode_unparse (e), 20);
7708 cstring_markOwned (ret);
7714 return cstring_makeLiteralTemp ("<error>");
7718 /*@observer@*/ cstring
7719 exprNode_unparse (exprNode e)
7721 if (exprNode_isError (e))
7723 return cstring_makeLiteralTemp ("<error>");
7726 if (cstring_isDefined (e->etext))
7732 cstring ret = exprNode_doUnparse (e);
7734 /*@-modifies@*/ /* benevolent */
7741 /*@observer@*/ fileloc
7742 exprNode_loc (exprNode e)
7744 if (exprNode_isError (e))
7746 return (g_currentloc);
7755 ** executes exprNode e
7756 ** recursively rexecutes as though in original parse using
7757 ** information in e->edata
7760 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
7762 exprNodeList ret = exprNodeList_new ();
7764 exprNodeList_elements (e, current)
7766 exprNodeList_addh (ret, exprNode_effect (current));
7767 } end_exprNodeList_elements;
7772 static /*@only@*/ exprNode exprNode_effect (exprNode e)
7773 /*@globals internalState@*/
7775 bool innerEffect = inEffect;
7781 context_clearJustPopped ();
7783 if (exprNode_isError (e))
7785 ret = exprNode_undefined;
7790 ** Turn off expose and dependent transfer checking.
7791 ** Need to pass exposed internal nodes,
7792 ** [ copying would be a waste! ]
7793 ** [ Actually, I think I wasted a lot more time than its worth ]
7794 ** [ trying to do this. ]
7798 /*@-observertrans@*/
7799 /*@-dependenttrans@*/
7806 ret = exprNode_addParens (exprData_getUopTok (data),
7807 exprNode_effect (exprData_getUopNode (data)));
7810 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
7811 exprNode_effect (exprData_getOpB (data)),
7812 exprData_getOpTok (data));
7815 ret = exprNode_undefined;
7818 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
7819 exprNodeList_effect (exprData_getArgs (data)));
7832 cstring id = exprData_getId (data);
7833 uentry ue = usymtab_lookupSafe (id);
7835 ret = exprNode_fromIdentifierAux (ue);
7836 ret->loc = fileloc_update (ret->loc, e->loc);
7843 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
7844 exprNode_effect (exprData_getPairB (data)));
7847 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
7848 exprNode_effect (exprData_getOpB (data)),
7849 exprData_getOpTok (data));
7853 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
7854 exprData_getUopTok (data));
7857 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
7858 exprData_getUopTok (data));
7870 ret = exprNode_vaArg (exprData_getCastTok (data),
7871 exprNode_effect (exprData_getCastNode (data)),
7872 exprData_getCastType (data));
7876 ret = exprNode_cast (exprData_getCastTok (data),
7877 exprNode_effect (exprData_getCastNode (data)),
7878 exprData_getCastType (data));
7881 ret = exprNode_iterStart (exprData_getIterCallIter (data),
7883 (exprData_getIterCallArgs (data)));
7887 ret = exprNode_iter (exprData_getIterSname (data),
7888 exprNodeList_effect (exprData_getIterAlist (data)),
7889 exprNode_effect (exprData_getIterBody (data)),
7890 exprData_getIterEname (data));
7894 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
7895 exprNode_effect (exprData_getPairB (data)));
7899 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
7900 exprNode_effect (exprData_getTripleTest (data)),
7901 exprNode_effect (exprData_getTripleInc (data)));
7905 ret = exprNode_createTok (exprData_getTok (data));
7909 ret = exprNode_goto (exprData_getLiteral (data));
7910 ret->loc = fileloc_update (ret->loc, e->loc);
7914 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
7918 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
7922 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
7925 case XPR_NULLRETURN:
7926 ret = exprNode_nullReturn (exprData_getTok (data));
7930 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
7931 exprNode_effect (exprData_getPairB (data)));
7935 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
7936 exprNode_effect (exprData_getTripleTrue (data)),
7937 exprNode_effect (exprData_getTripleFalse (data)));
7940 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
7941 exprNode_effect (exprData_getPairB (data)));
7945 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
7946 exprNode_effect (exprData_getTripleTrue (data)),
7947 exprNode_effect (exprData_getTripleFalse (data)));
7950 ret = exprNode_whilePred (exprData_getSingle (data));
7954 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
7955 exprNode_effect (exprData_getPairB (data)));
7959 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
7960 exprNode_effect (exprData_getPairB (data)));
7964 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
7968 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
7969 exprData_getUopTok (data));
7973 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
7974 exprNode_effect (exprData_getPairB (data)));
7979 ret = exprNode_caseMarker
7980 (exprNode_effect (exprData_getSingle (data)),
7986 ret = exprNode_createTok (exprData_getTok (data));
7990 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
7991 exprNode_effect (exprData_getPairB (data)));
7995 ret = exprNode_makeInitialization
7996 (exprData_getInitId (data),
7997 exprNode_effect (exprData_getInitNode (data)));
8001 ret = exprNode_fieldAccess (exprNode_effect (exprData_getFieldNode (data)),
8002 cstring_copy (exprData_getFieldName (data)));
8006 ret = exprNode_arrowAccess (exprNode_effect (exprData_getFieldNode (data)),
8007 cstring_copy (exprData_getFieldName (data)));
8010 case XPR_STRINGLITERAL:
8024 /*@=observertrans@*/
8026 /*@=dependenttrans@*/
8037 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8042 if (exprNode_isError (e))
8044 return cstring_undefined;
8052 ret = exprNode_rootVarName (exprData_getUopNode (data));
8055 ret = exprNode_rootVarName (exprData_getOpA (data));
8059 ret = exprData_getId (data);
8084 case XPR_NULLRETURN:
8107 case XPR_STRINGLITERAL:
8108 ret = cstring_undefined;
8116 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8121 if (exprNode_isError (e))
8123 static /*@only@*/ cstring error = cstring_undefined;
8125 if (!cstring_isDefined (error))
8127 error = cstring_makeLiteral ("<error>");
8138 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8141 ret = message ("%s %s %s",
8142 exprNode_unparse (exprData_getOpA (data)),
8143 lltok_unparse (exprData_getOpTok (data)),
8144 exprNode_unparse (exprData_getOpB (data)));
8147 ret = message ("%s(%q)",
8148 exprNode_unparse (exprData_getFcn (data)),
8149 exprNodeList_unparse (exprData_getArgs (data)));
8152 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8155 ret = cstring_undefined;
8158 ret = message ("%s:", exprData_getId (data));
8162 ret = cstring_copy (exprData_getId (data));
8165 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8166 exprNode_unparse (exprData_getPairB (data)));
8169 ret = message ("<body>");
8172 ret = message ("%s %s %s",
8173 exprNode_unparse (exprData_getOpA (data)),
8174 lltok_unparse (exprData_getOpTok (data)),
8175 exprNode_unparse (exprData_getOpB (data)));
8179 ret = message ("%s%s",
8180 lltok_unparse (exprData_getUopTok (data)),
8181 exprNode_unparse (exprData_getUopNode (data)));
8185 ret = message ("%s%s",
8186 exprNode_unparse (exprData_getUopNode (data)),
8187 lltok_unparse (exprData_getUopTok (data)));
8191 ret = message ("offsetof(%s,%q)",
8192 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8193 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8197 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8201 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8205 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8209 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8213 ret = message ("va_arg(%s, %q)",
8214 exprNode_unparse (exprData_getCastNode (data)),
8215 qtype_unparse (exprData_getCastType (data)));
8219 ret = message ("%q(%q)",
8220 uentry_getName (exprData_getIterCallIter (data)),
8221 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8224 ret = message ("%q(%q) %s %q",
8225 uentry_getName (exprData_getIterSname (data)),
8226 exprNodeList_unparse (exprData_getIterAlist (data)),
8227 exprNode_unparse (exprData_getIterBody (data)),
8228 uentry_getName (exprData_getIterEname (data)));
8231 ret = message ("(%q)%s",
8232 qtype_unparse (exprData_getCastType (data)),
8233 exprNode_unparse (exprData_getCastNode (data)));
8237 ret = message ("%s %s",
8238 exprNode_unparse (exprData_getPairA (data)),
8239 exprNode_unparse (exprData_getPairB (data)));
8243 ret = message ("for (%s; %s; %s)",
8244 exprNode_unparse (exprData_getTripleInit (data)),
8245 exprNode_unparse (exprData_getTripleTest (data)),
8246 exprNode_unparse (exprData_getTripleInc (data)));
8250 ret = message ("goto %s", exprData_getLiteral (data));
8254 ret = cstring_makeLiteral ("continue");
8258 ret = cstring_makeLiteral ("break");
8262 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
8265 case XPR_NULLRETURN:
8266 ret = cstring_makeLiteral ("return");
8270 ret = message ("%s, %s",
8271 exprNode_unparse (exprData_getPairA (data)),
8272 exprNode_unparse (exprData_getPairB (data)));
8276 ret = message ("%s ? %s : %s",
8277 exprNode_unparse (exprData_getTriplePred (data)),
8278 exprNode_unparse (exprData_getTripleTrue (data)),
8279 exprNode_unparse (exprData_getTripleFalse (data)));
8282 ret = message ("if (%s) %s",
8283 exprNode_unparse (exprData_getPairA (data)),
8284 exprNode_unparse (exprData_getPairB (data)));
8288 ret = message ("if (%s) %s else %s",
8289 exprNode_unparse (exprData_getTriplePred (data)),
8290 exprNode_unparse (exprData_getTripleTrue (data)),
8291 exprNode_unparse (exprData_getTripleFalse (data)));
8294 ret = message ("while (%s) %s",
8295 exprNode_unparse (exprData_getPairA (data)),
8296 exprNode_unparse (exprData_getPairB (data)));
8300 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
8304 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
8308 ret = message ("do { %s } while (%s)",
8309 exprNode_unparse (exprData_getPairB (data)),
8310 exprNode_unparse (exprData_getPairA (data)));
8314 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
8318 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
8322 ret = message ("%s; %s",
8323 exprNode_unparse (exprData_getPairA (data)),
8324 exprNode_unparse (exprData_getPairB (data)));
8329 ret = cstring_makeLiteral ("default:");
8333 ret = message ("switch (%s) %s",
8334 exprNode_unparse (exprData_getPairA (data)),
8335 exprNode_unparse (exprData_getPairB (data)));
8340 ret = message ("case %s:",
8341 exprNode_unparse (exprData_getSingle (data)));
8345 ret = message ("%s = %s",
8346 idDecl_getName (exprData_getInitId (data)),
8347 exprNode_unparse (exprData_getInitNode (data)));
8351 ret = message ("%s.%s",
8352 exprNode_unparse (exprData_getFieldNode (data)),
8353 exprData_getFieldName (data));
8357 ret = message ("%s->%s",
8358 exprNode_unparse (exprData_getFieldNode (data)),
8359 exprData_getFieldName (data));
8362 case XPR_STRINGLITERAL:
8363 ret = cstring_copy (exprData_getLiteral (data));
8367 ret = cstring_copy (exprData_getLiteral (data));
8371 ret = cstring_makeLiteral ("<node>");
8379 exprNode_isCharLit (exprNode e)
8381 if (exprNode_isDefined (e))
8383 return (multiVal_isChar (exprNode_getValue (e)));
8392 exprNode_isNumLit (exprNode e)
8394 if (exprNode_isDefined (e))
8396 return (multiVal_isInt (exprNode_getValue (e)));
8405 exprNode_isFalseConstant (exprNode e)
8407 if (exprNode_isDefined (e))
8409 cstring s = exprNode_rootVarName (e);
8411 if (cstring_equal (s, context_getFalseName ()))
8421 exprNode_matchLiteral (ctype expected, exprNode e)
8423 if (exprNode_isDefined (e))
8425 multiVal m = exprNode_getValue (e);
8427 if (multiVal_isDefined (m))
8429 if (multiVal_isInt (m))
8431 long int val = multiVal_forceInt (m);
8433 if (ctype_isDirectBool (ctype_realishType (expected)))
8437 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
8445 if (ctype_isRealInt (expected))
8448 ** unsigned <- [ constant >= 0 is okay ]
8451 if (ctype_isUnsigned (expected))
8460 ** No checks on sizes of integers...maybe add
8464 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
8465 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
8466 bool_unparse (ctype_isInt (exprNode_getType (e)))));
8468 if (context_getFlag (FLG_NUMLITERAL)
8469 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
8475 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
8479 else if (ctype_isChar (expected))
8483 else if (ctype_isArrayPtr (expected))
8487 else if (ctype_isAnyFloat (expected))
8489 return (context_getFlag (FLG_NUMLITERAL));
8496 else if (multiVal_isDouble (m))
8498 if (ctype_isAnyFloat (expected))
8503 else if (multiVal_isChar (m))
8505 char val = multiVal_forceChar (m);
8507 if (ctype_isChar (expected))
8509 if (ctype_isUnsigned (expected) && ((int)val) < 0)
8530 exprNode_matchType (ctype expected, exprNode e)
8534 if (!exprNode_isDefined (e)) return TRUE;
8536 actual = ctype_realishType (exprNode_getType (e));
8538 if (ctype_match (ctype_realishType (expected), actual))
8543 llassert (!exprNode_isError (e));
8544 return (exprNode_matchLiteral (expected, e));
8548 exprNode_matchTypes (exprNode e1, exprNode e2)
8553 if (!exprNode_isDefined (e1)) return TRUE;
8554 if (!exprNode_isDefined (e2)) return TRUE;
8557 ** realish type --- keep bools, bools
8560 t1 = ctype_realishType (exprNode_getType (e1));
8561 t2 = ctype_realishType (exprNode_getType (e2));
8563 if (ctype_match (t1, t2))
8568 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
8576 exprNode_matchArgType (ctype ct, exprNode e)
8580 if (!exprNode_isDefined (e))
8585 et = ctype_realType (exprNode_getType (e));
8587 if (ctype_matchArg (ct, et)) return TRUE;
8589 llassert (!exprNode_isError (e));
8590 return (exprNode_matchLiteral (ct, e));
8593 static /*@only@*/ exprNodeSList
8594 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
8596 if (exprNode_isDefined (e))
8598 if (e->kind == XPR_STMTLIST)
8600 return (exprNodeSList_append
8601 (exprNode_flatten (exprData_getPairA (e->edata)),
8602 exprNode_flatten (exprData_getPairB (e->edata))));
8604 else if (e->kind == XPR_BLOCK)
8606 return (exprNode_flatten (exprData_getSingle (e->edata)));
8610 return (exprNodeSList_singleton (e));
8614 return exprNodeSList_new ();
8617 static /*@exposed@*/ exprNode
8618 exprNode_lastStatement (/*@returned@*/ exprNode e)
8620 if (exprNode_isDefined (e))
8622 if (e->kind == XPR_STMTLIST)
8624 exprNode b = exprData_getPairB (e->edata);
8626 if (exprNode_isDefined (b))
8628 return exprNode_lastStatement (b);
8632 return exprNode_lastStatement (exprData_getPairA (e->edata));
8635 else if (e->kind == XPR_BLOCK)
8637 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
8645 return exprNode_undefined;
8648 static /*@exposed@*/ exprNode
8649 exprNode_firstStatement (/*@returned@*/ exprNode e)
8651 if (exprNode_isDefined (e))
8653 if (e->kind == XPR_STMTLIST)
8655 exprNode b = exprData_getPairA (e->edata);
8657 if (exprNode_isDefined (b))
8659 return exprNode_firstStatement (b);
8663 return exprNode_firstStatement (exprData_getPairB (e->edata));
8666 else if (e->kind == XPR_BLOCK)
8668 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
8676 return exprNode_undefined;
8680 exprNode_mergeUSs (exprNode res, exprNode other)
8682 if (exprNode_isDefined (res) && exprNode_isDefined (other))
8684 res->msets = sRefSet_union (res->msets, other->msets);
8685 res->sets = sRefSet_union (res->sets, other->sets);
8686 res->uses = sRefSet_union (res->uses, other->uses);
8691 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
8693 if (exprNode_isDefined (res))
8695 if (exprNode_isDefined (other1))
8697 res->sets = sRefSet_union (res->sets, other1->sets);
8698 res->msets = sRefSet_union (res->msets, other1->msets);
8699 res->uses = sRefSet_union (res->uses, other1->uses);
8701 if (exprNode_isDefined (other2))
8703 res->sets = sRefSet_union (res->sets, other2->sets);
8704 res->msets = sRefSet_union (res->msets, other2->msets);
8705 res->uses = sRefSet_union (res->uses, other2->uses);
8713 ** Reports errors is s is not defined.
8717 exprNode_addUse (exprNode e, sRef s)
8719 if (exprNode_isDefined (e))
8721 e->uses = sRefSet_insert (e->uses, s);
8726 exprNode_checkUse (exprNode e, sRef s, fileloc loc)
8728 if (sRef_isKnown (s) && !sRef_isConst (s))
8731 ** need to check all outer types are useable
8734 DPRINTF (("Check use: %s / %s",
8735 exprNode_unparse (e), sRef_unparse (s)));
8737 exprNode_addUse (e, s);
8739 if (!context_inProtectVars ())
8742 ** only report the deepest error
8745 sRef errorRef = sRef_undefined;
8746 sRef lastRef = sRef_undefined;
8747 bool deadRef = FALSE;
8748 bool unuseable = FALSE;
8749 bool errorMaybe = FALSE;
8751 while (sRef_isValid (s) && sRef_isKnown (s))
8753 ynm readable = sRef_isReadable (s);
8755 if (!(ynm_toBoolStrict (readable)))
8757 if (ynm_isMaybe (readable))
8761 deadRef = sRef_isPossiblyDead (errorRef);
8762 unuseable = sRef_isUnuseable (errorRef);
8769 deadRef = sRef_isDead (errorRef);
8770 unuseable = sRef_isUnuseable (errorRef);
8774 if (!sRef_isPartial (s))
8776 sRef_setDefined (s, fileloc_undefined);
8780 s = sRef_getBaseSafe (s);
8783 if (sRef_isValid (errorRef))
8785 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
8786 && sRef_isPointer (errorRef))
8793 if (sRef_isThroughArrayFetch (errorRef))
8796 (FLG_STRICTUSERELEASED,
8797 message ("%q %q may be used after being released",
8798 sRef_unparseKindNamePlain (errorRef),
8799 sRef_unparse (errorRef)),
8802 sRef_showRefKilled (errorRef);
8804 if (sRef_isKept (errorRef))
8806 sRef_clearAliasState (errorRef, loc);
8812 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8816 message ("%q %q %qused after being released",
8817 sRef_unparseKindNamePlain (errorRef),
8818 sRef_unparse (errorRef),
8819 cstring_makeLiteral (errorMaybe
8823 sRef_showRefKilled (errorRef);
8825 if (sRef_isKept (errorRef))
8827 sRef_clearAliasState (errorRef, loc);
8836 message ("%q %q%qused in inconsistent state",
8837 sRef_unparseKindName (errorRef),
8838 sRef_unparseOpt (errorRef),
8839 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8842 sRef_showStateInconsistent (errorRef);
8847 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8851 message ("%q %q%qused before definition",
8852 sRef_unparseKindName (errorRef),
8853 sRef_unparseOpt (errorRef),
8854 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8858 sRef_setDefined (errorRef, loc);
8860 if (sRef_isAddress (errorRef))
8862 sRef_setDefined (sRef_getRootBase (errorRef), loc);
8864 } /* end is error */
8872 checkSafeUse (exprNode e, sRef s)
8874 if (exprNode_isDefined (e) && sRef_isKnown (s))
8876 e->uses = sRefSet_insert (e->uses, s);
8881 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
8883 if (exprNode_isDefined (e))
8885 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
8890 exprNode_checkSet (exprNode e, sRef s)
8892 sRef defines = sRef_undefined;
8894 if (sRef_isValid (s) && !sRef_isNothing (s))
8896 uentry ue = sRef_getBaseUentry (s);
8898 if (uentry_isValid (ue))
8900 uentry_setLset (ue);
8903 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
8905 voptgenerror (FLG_USEDEF,
8906 message ("Attempt to set unuseable storage: %q",
8911 if (sRef_isMeaningful (s))
8914 if (sRef_isDead (s))
8916 sRef base = sRef_getBaseSafe (s);
8918 if (sRef_isValid (base)
8919 && sRef_isDead (base))
8921 sRef_setPartial (s, exprNode_loc (e));
8924 defines = s; /* okay - modifies for only param */
8926 else if (sRef_isPartial (s))
8928 sRef eref = exprNode_getSref (e);
8930 if (!sRef_isPartial (eref))
8933 ** should do something different here???
8936 sRef_setDefinedComplete (eref, exprNode_loc (e));
8940 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
8943 if (sRef_isMeaningful (eref))
8952 else if (sRef_isAllocated (s))
8954 sRef eref = exprNode_getSref (e);
8957 if (!sRef_isAllocated (eref))
8959 sRef_setDefinedComplete (eref, exprNode_loc (e));
8963 sRef base = sRef_getBaseSafe (eref);
8965 if (sRef_isValid (base))
8967 sRef_setPdefined (base, exprNode_loc (e));
8975 sRef_setDefinedNCComplete (s, exprNode_loc (e));
8980 else /* not meaningful...but still need to insert it */
8986 if (exprNode_isDefined (e) && sRef_isValid (defines))
8988 e->sets = sRefSet_insert (e->sets, defines);
8993 exprNode_checkMSet (exprNode e, sRef s)
8995 if (sRef_isValid (s) && !sRef_isNothing (s))
8997 uentry ue = sRef_getBaseUentry (s);
8999 if (uentry_isValid (ue))
9001 uentry_setLset (ue);
9004 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9006 voptgenerror (FLG_USEDEF,
9007 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9011 if (sRef_isMeaningful (s))
9013 sRef_setDefinedComplete (s, exprNode_loc (e));
9016 if (exprNode_isDefined (e))
9018 e->msets = sRefSet_insert (e->msets, s);
9024 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9026 checkAnyCall (fcn, cstring_undefined, params, args,
9027 FALSE, sRefSet_undefined, FALSE, 0);
9031 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9032 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9036 if (uentry_isYield (ucurrent))
9038 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9039 exprNode_checkSet (current, current->sref);
9043 if (uentry_isSefParam (ucurrent))
9045 sRefSet sets = current->sets;
9046 sRef ref = exprNode_getSref (current);
9048 if (sRef_isMacroParamRef (ref))
9050 uentry ue = sRef_getUentry (ref);
9052 if (!uentry_isSefParam (ue))
9057 ("Parameter %d to %s is declared sef, but "
9058 "the argument is a macro parameter declared "
9060 argno, exprNode_unparse (fcn),
9061 exprNode_unparse (current)),
9062 exprNode_loc (current));
9066 if (!sRefSet_isEmpty (sets))
9068 sRefSet reported = sRefSet_undefined;
9070 sRefSet_realElements (current->sets, el)
9072 if (sRefSet_isSameNameMember (reported, el))
9074 ; /* don't report again */
9078 if (sRef_isUnconstrained (el))
9083 ("Parameter %d to %s is declared sef, but "
9084 "the argument calls unconstrained function %s "
9085 "(no guarantee it will not modify something): %s",
9086 argno, exprNode_unparse (fcn),
9087 sRef_unconstrainedName (el),
9088 exprNode_unparse (current)),
9089 exprNode_loc (current));
9096 ("Parameter %d to %s is declared sef, but "
9097 "the argument may modify %q: %s",
9098 argno, exprNode_unparse (fcn),
9100 exprNode_unparse (current)),
9101 exprNode_loc (current));
9104 } end_sRefSet_realElements;
9108 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9109 exprNode_mergeUSs (fcn, current);
9114 checkAnyCall (/*@dependent@*/ exprNode fcn,
9115 /*@dependent@*/ cstring fname,
9118 bool hasMods, sRefSet mods,
9123 int nargs = exprNodeList_size (args);
9128 ** concat all args ud's to f, add each arg sref as a use unless
9129 ** it was specified as "out", in which case it is a def.
9132 uentryList_reset (pn);
9137 ** if paramn is only or unique, no other arg may alias argn
9140 exprNodeList_elements (args, current)
9144 if (exprNode_isDefined (current))
9146 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9148 uentry ucurrent = uentryList_current (pn);
9150 if (specialArgs == 0
9151 || (paramno < specialArgs))
9153 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9155 if (context_maybeSet (FLG_ALIASUNIQUE))
9157 if (uentry_isOnly (ucurrent)
9158 || uentry_isUnique (ucurrent))
9160 checkUniqueParams (fcn, current, args,
9166 else /* uentry is undefined */
9168 if (specialArgs == 0)
9170 exprNode_checkUseParam (current);
9173 exprNode_mergeUSs (fcn, current);
9176 uentryList_advanceSafe (pn);
9177 } end_exprNodeList_elements;
9183 sRefSet_allElements (mods, s)
9186 sRef rb = sRef_getRootBase (s);
9188 if (sRef_isGlobal (rb))
9190 context_usedGlobal (rb);
9193 fb = sRef_fixBaseParam (s, args);
9195 if (!sRef_isMacroParamRef (fb))
9197 if (sRef_isNothing (fb))
9203 if (sRef_isValid (fb))
9205 uentry ue = sRef_getBaseUentry (s);
9207 if (uentry_isValid (ue))
9209 uentry_setLset (ue);
9213 fcn->sets = sRefSet_insert (fcn->sets, fb);
9216 sRef_clearDerivedComplete (s);
9217 } end_sRefSet_allElements;
9223 if (context_hasMods ())
9225 if (context_maybeSet (FLG_MODUNCON))
9229 message ("Undetected modification possible "
9230 "from call to unconstrained function %s: %s",
9232 exprNode_unparse (fcn)),
9233 exprNode_loc (fcn));
9238 if (context_maybeSet (FLG_MODUNCONNOMODS)
9239 && !(context_inIterDef () || context_inIterEnd ()))
9242 (FLG_MODUNCONNOMODS,
9243 message ("Undetected modification possible "
9244 "from call to unconstrained function %s: %s",
9246 exprNode_unparse (fcn)),
9247 exprNode_loc (fcn));
9251 exprNode_checkSetAny (fcn, fname);
9255 void exprNode_checkUseParam (exprNode current)
9257 if (exprNode_isDefined (current))
9259 exprNode_checkUse (current, current->sref, current->loc);
9264 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
9265 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9270 if (!ctype_match (tr1, tr2))
9272 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
9273 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
9281 message ("Incompatible types for %s (%s, %s): %s %s %s",
9283 ctype_unparse (te1),
9284 ctype_unparse (te2),
9285 exprNode_unparse (e1), lltok_unparse (op),
9286 exprNode_unparse (e2)),
9289 ret = ctype_unknown;
9293 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
9295 ret = ctype_resolveNumerics (tr1, tr2);
9297 else if (!context_msgStrictOps ())
9299 if (ctype_isPointer (tr1))
9301 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
9305 else if (ctype_isInt (tr2))
9311 ret = ctype_unknown;
9314 else if (ctype_isPointer (tr2))
9316 if (ctype_isPointer (tr1))
9320 else if (ctype_isInt (tr1))
9326 ret = ctype_unknown;
9331 ret = ctype_resolveNumerics (tr1, tr2);
9336 int opid = lltok_getTok (op);
9337 bool comparop = (opid == EQ_OP || opid == NE_OP
9338 || opid == TLT || opid == TGT
9339 || opid == LE_OP || opid == GE_OP);
9341 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
9344 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
9345 || (ctype_isBool (tr1) && ctype_isBool (tr2))
9346 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
9352 if (ctype_sameName (te1, te2))
9356 message ("Operands of %s are non-numeric (%t): %s %s %s",
9357 lltok_unparse (op), te1,
9358 exprNode_unparse (e1), lltok_unparse (op),
9359 exprNode_unparse (e2)),
9366 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
9367 lltok_unparse (op), te1, te2,
9368 exprNode_unparse (e1), lltok_unparse (op),
9369 exprNode_unparse (e2)),
9374 else if (!ctype_isNumeric (tr1))
9378 message ("Right operand of %s is non-numeric (%t): %s %s %s",
9379 lltok_unparse (op), te1,
9380 exprNode_unparse (e1), lltok_unparse (op),
9381 exprNode_unparse (e2)),
9386 if (!ctype_isNumeric (tr2))
9390 message ("Left operand of %s is non-numeric (%t): %s %s %s",
9391 lltok_unparse (op), te2,
9392 exprNode_unparse (e1), lltok_unparse (op),
9393 exprNode_unparse (e2)),
9398 ret = ctype_unknown;
9406 abstractOpError (ctype tr1, ctype tr2, lltok op,
9407 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9408 fileloc loc1, fileloc loc2)
9410 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
9412 if (ctype_match (tr1, tr2))
9416 message ("Operands of %s are abstract type (%t): %s %s %s",
9417 lltok_unparse (op), tr1,
9418 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9425 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
9426 lltok_unparse (op), tr1, tr2,
9427 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9431 else if (ctype_isRealAbstract (tr1))
9435 message ("Left operand of %s is abstract type (%t): %s %s %s",
9436 lltok_unparse (op), tr1,
9437 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9442 if (ctype_isRealAbstract (tr2))
9446 message ("Right operand of %s is abstract type (%t): %s %s %s",
9447 lltok_unparse (op), tr2,
9448 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9457 ** requies e1 and e2 and not error exprNode's.
9461 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
9462 ** the rep of the abstract type is exposed.
9464 ** The order is very important:
9466 ** check rep expose (move into check transfer)
9472 ** This isn't really a sensible procedure, but the indententation
9473 ** was getting too deep.
9477 checkOneRepExpose (sRef ysr, sRef base,
9478 /*@notnull@*/ exprNode e1,
9479 /*@notnull@*/ exprNode e2, ctype ct,
9482 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
9483 || sRef_isOwned (ysr) || sRef_isExposed (ysr)))
9485 if (sRef_isAnyParam (base) && !sRef_isExposed (base))
9487 if (sRef_isIReference (ysr))
9489 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9494 ("Assignment of mutable component of parameter %q "
9495 "to component of abstract "
9496 "type %s exposes rep: %s = %s",
9497 sRef_unparse (base),
9499 exprNode_unparse (e1), exprNode_unparse (e2)),
9507 ("Assignment of mutable component of parameter %q "
9508 "(through alias %q) to component of abstract "
9509 "type %s exposes rep: %s = %s",
9510 sRef_unparse (base),
9511 sRef_unparse (e2->sref),
9513 exprNode_unparse (e1), exprNode_unparse (e2)),
9519 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9523 message ("Assignment of mutable parameter %q "
9524 "to component of abstract type %s "
9525 "exposes rep: %s = %s",
9526 sRef_unparse (base),
9528 exprNode_unparse (e1),
9529 exprNode_unparse (e2)),
9536 message ("Assignment of mutable parameter %q "
9537 "(through alias %q) to "
9538 "component of abstract type %s exposes "
9540 sRef_unparse (base),
9541 sRef_unparse (e2->sref),
9543 exprNode_unparse (e1),
9544 exprNode_unparse (e2)),
9550 if (sRef_isGlobal (s2b))
9552 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9556 message ("Assignment of global %q "
9558 "abstract type %s exposes rep: %s = %s",
9559 sRef_unparse (base),
9561 exprNode_unparse (e1), exprNode_unparse (e2)),
9568 message ("Assignment of global %q (through alias %q) "
9570 "abstract type %s exposes rep: %s = %s",
9571 sRef_unparse (base),
9572 sRef_unparse (e2->sref),
9574 exprNode_unparse (e1), exprNode_unparse (e2)),
9582 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
9584 if (ctype_isRealFunction (exprNode_getType (e1))
9585 && !ctype_isRealPointer (exprNode_getType (e1)))
9589 message ("Invalid left-hand side of assignment (function type %s): %s",
9590 ctype_unparse (exprNode_getType (e1)),
9591 exprNode_unparse (e1)),
9595 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
9597 ctype t2 = exprNode_getType (e2);
9598 sRef sr = sRef_getRootBase (e1->sref);
9599 ctype ct = sRef_getType (sr);
9601 if (ctype_isAbstract (t2)
9602 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
9604 /* it is immutable, okay to reference */
9608 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
9610 sRef s2b = sRef_getRootBase (e2->sref);
9612 sRef s1b = sRef_getRootBase (s1);
9615 aliases = usymtab_canAlias (e2->sref);
9617 if (!sRef_similar (s2b, s1b)
9618 && !sRef_isExposed (s1)
9619 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
9621 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
9622 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
9623 && !sRef_isExposed (s2b))
9625 if (sRef_isIReference (e2->sref))
9630 ("Assignment of mutable component of parameter %q "
9631 "to component of abstract type %s exposes rep: %s = %s",
9634 exprNode_unparse (e1), exprNode_unparse (e2)),
9641 message ("Assignment of mutable parameter %q to "
9642 "component of abstract type %s exposes rep: %s = %s",
9645 exprNode_unparse (e1), exprNode_unparse (e2)),
9650 if (sRef_isGlobal (s2b))
9654 message ("Assignment of global %q to component of "
9655 "abstract type %s exposes rep: %s = %s",
9658 exprNode_unparse (e1), exprNode_unparse (e2)),
9662 sRefSet_realElements (aliases, ysr)
9664 sRef base = sRef_getRootBase (ysr);
9666 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
9667 || sRef_sameName (base, s1b))
9669 ; /* error already reported or same sref */
9673 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
9675 } end_sRefSet_realElements;
9677 sRefSet_free (aliases);
9684 ** function variables don't really work...
9687 if (!ctype_isFunction (ctype_realType (e2->typ)))
9691 checkInitTransfer (e1, e2);
9695 checkAssignTransfer (e1, e2);
9700 sRef fref = e2->sref;
9702 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
9703 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
9705 /* Need to typecheck the annotation on the parameters */
9707 if (ctype_isRealFunction (e1->typ)) {
9708 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
9709 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
9711 if (!uentryList_isMissingParams (e1p)
9712 && !uentryList_isMissingParams (e2p)
9713 && uentryList_size (e1p) > 0) {
9714 if (uentryList_size (e1p) == uentryList_size (e2p)) {
9717 uentryList_elements (e1p, el1) {
9720 el2 = uentryList_getN (e2p, n);
9722 uentry_checkMatchParam (el1, el2, n, e2);
9723 } end_uentryList_elements;
9729 if (isInit && sRef_isGlobal (e1->sref))
9735 updateAliases (e1, e2);
9737 updateEnvironment (e1, e2);
9741 checkMacroParen (exprNode e)
9743 if (exprNode_isError (e) || e->kind == XPR_CAST)
9749 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
9753 message ("Macro parameter used without parentheses: %s",
9754 exprNode_unparse (e)),
9761 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
9765 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
9769 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
9776 ** if e2 is a parameter or global derived location which
9777 ** can be modified (that is, e2 is a mutable abstract type,
9778 ** or a derived pointer), then e1 can alias e2.
9780 ** e1 can alias everything which e2 can alias.
9782 ** Also, if e1 is guarded, remove from guard sets!
9785 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
9787 if (!context_inProtectVars ())
9790 ** depends on types of e1 and e2
9795 ctype t1 = exprNode_getType (e1);
9797 /* handle pointer sRefs, record fields, arrays, etc... */
9799 if (!ctype_isRealSU (t1))
9801 sRef_copyRealDerivedComplete (s1, s2);
9804 if (ctype_isMutable (t1) && sRef_isKnown (s1))
9806 usymtab_clearAlias (s1);
9807 usymtab_addMustAlias (s1, s2);
9810 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
9812 usymtab_unguard (s1);
9817 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
9819 if (exprNode_isDefined (e))
9821 e->loc = fileloc_update (e->loc, loc);
9825 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
9831 static void checkUniqueParams (exprNode fcn,
9832 /*@notnull@*/ exprNode current,
9834 int paramno, uentry ucurrent)
9837 sRef thisref = exprNode_getSref (current);
9840 ** Check if any argument could match this argument.
9843 exprNodeList_elements (args, icurrent)
9847 if (iparamno != paramno)
9849 sRef sr = exprNode_getSref (icurrent);
9851 if (sRef_similarRelaxed (thisref, sr))
9853 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
9858 ("Parameter %d (%s) to function %s is declared %s but "
9859 "is aliased by parameter %d (%s)",
9861 exprNode_unparse (current),
9862 exprNode_unparse (fcn),
9863 alkind_unparse (uentry_getAliasKind (ucurrent)),
9864 iparamno, exprNode_unparse (icurrent)),
9870 sRefSet aliases = usymtab_canAlias (sr);
9872 sRefSet_allElements (aliases, asr)
9874 if (ctype_isUnknown (sRef_getType (thisref)))
9876 sRef_setType (thisref, uentry_getType (ucurrent));
9879 if (sRef_similarRelaxed (thisref, asr))
9881 if (sRef_isExternal (asr))
9883 if (sRef_isLocalState (thisref))
9889 sRef base = sRef_getRootBase (asr);
9891 if (!sRef_similar (sRef_getBase (asr), thisref))
9893 if (sRef_isUnique (base) || sRef_isOnly (base)
9894 || sRef_isKept (base)
9895 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
9896 || (sRef_isAddress (thisref)
9897 && sRef_isLocalVar (sRef_getRootBase (thisref))))
9899 ; /* okay, no error */
9904 (FLG_MAYALIASUNIQUE,
9906 ("Parameter %d (%s) to function %s is declared %s but "
9907 "may be aliased externally by parameter %d (%s)",
9909 exprNode_unparse (current),
9910 exprNode_unparse (fcn),
9911 alkind_unparse (uentry_getAliasKind (ucurrent)),
9912 iparamno, exprNode_unparse (icurrent)),
9923 ("Parameter %d (%s) to function %s is declared %s but "
9924 "is aliased externally by parameter %d (%s) through "
9927 exprNode_unparse (current),
9928 exprNode_unparse (fcn),
9929 alkind_unparse (uentry_getAliasKind (ucurrent)),
9930 iparamno, exprNode_unparse (icurrent),
9931 sRef_unparse (asr)),
9935 } end_sRefSet_allElements;
9936 sRefSet_free (aliases);
9939 } end_exprNodeList_elements;
9942 long exprNode_getLongValue (exprNode e) {
9945 if (exprNode_hasValue (e)
9946 && multiVal_isInt (exprNode_getValue (e)))
9948 value = multiVal_forceInt (exprNode_getValue (e));
9958 fileloc exprNode_getfileloc (exprNode p_e)
9960 return fileloc_copy ( p_e->loc );
9963 fileloc exprNode_getNextSequencePoint (exprNode e)
9966 ** Returns the location of the sequence point following e.
9968 ** Only works for statements (for now).
9971 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
9972 lltok t = exprData_getUopTok (e->edata);
9973 printf ("!!!!!!!!!!!!!!!!!!Tok is \n\n%s\n", lltok_unparse(t) );
9974 return lltok_getLoc (t);
9976 llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
9977 return fileloc_undefined;