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 static bool isFlagKey (char key)
227 return (key == '-' || key == '+' || key == ' ' || key == '#');
230 static void exprNode_combineControl (/*@notnull@*/ exprNode ret,
231 /*@notnull@*/ exprNode ifclause,
232 /*@notnull@*/ exprNode elseclause)
234 ret->canBreak = ifclause->canBreak || elseclause->canBreak;
237 (ifclause->mustBreak || exprNode_mustEscape (ifclause))
238 && (elseclause->mustBreak || exprNode_mustEscape (elseclause));
240 ret->exitCode = exitkind_combine (ifclause->exitCode,
241 elseclause->exitCode);
246 ** For exprNode's returned by exprNode_effect.
249 static bool shallowKind (exprKind kind)
251 return (kind == XPR_STRINGLITERAL
252 || kind == XPR_NUMLIT
255 || kind == XPR_NODE);
259 exprNode_freeIniter (/*@only@*/ exprNode e)
261 if (!exprNode_isError (e))
266 sfree (e->edata->field);
270 exprNode_free (e->edata->op->b);
271 /*@-compdestroy@*/ sfree (e->edata->op); /*@=compdestroy@*/
275 llbug (message ("other: %s", exprNode_unparse (e)));
278 multiVal_free (e->val);
279 cstring_free (e->etext);
280 fileloc_free (e->loc);
281 sRefSet_free (e->uses);
282 sRefSet_free (e->sets);
283 sRefSet_free (e->msets);
284 guardSet_free (e->guards);
290 exprNode_freeShallow (/*@only@*/ exprNode e)
292 if (!exprNode_isError (e))
294 if (shallowKind (e->kind))
301 if (e->kind == XPR_EMPTY
302 || e->kind == XPR_BODY
303 || e->kind == XPR_STRINGLITERAL
304 || e->kind == XPR_NUMLIT
305 || e->kind == XPR_NODE
306 || e->kind == XPR_OFFSETOF
307 || e->kind == XPR_ALIGNOFT
308 || e->kind == XPR_ALIGNOF
309 || e->kind == XPR_SIZEOFT
310 || e->kind == XPR_SIZEOF)
312 /* don't free anything */
316 /* multiVal_free (e->val); */
317 cstring_free (e->etext);
318 fileloc_free (e->loc);
319 sRefSet_free (e->uses);
320 sRefSet_free (e->sets);
321 sRefSet_free (e->msets);
322 guardSet_free (e->guards);
323 exprData_freeShallow (e->edata, e->kind);
325 /*@-compdestroy@*/ sfree (e); /*@=compdestroy@*/
334 exprNode_free (exprNode e)
336 if (!exprNode_isError (e))
340 multiVal_free (e->val);
341 cstring_free (e->etext);
342 fileloc_free (e->loc);
343 sRefSet_free (e->uses);
344 sRefSet_free (e->sets);
345 sRefSet_free (e->msets);
346 guardSet_free (e->guards);
347 exprData_free (e->edata, e->kind);
357 exprNode_makeError ()
359 return exprNode_undefined;
362 static /*@out@*/ /*@only@*/ /*@notnull@*/ exprNode
365 exprNode ret = (exprNode) dmalloc (sizeof (*ret));
366 /* static int lastexpnodes = 0; */
371 if (nowalloc > maxalloc)
379 static /*@notnull@*/ /*@special@*/ exprNode
380 exprNode_createPlain (ctype c)
382 /*@post:isnull result->edata, result->loc, result->val, result->guards,
383 result->uses, result->sets, result->msets, result->etext @*/
386 exprNode e = exprNode_new ();
390 e->val = multiVal_undefined;
392 e->etext = cstring_undefined;
393 e->loc = fileloc_undefined;
394 e->guards = guardSet_undefined;
395 e->uses = sRefSet_undefined;
396 e->sets = sRefSet_undefined;
397 e->msets = sRefSet_undefined;
398 e->edata = exprData_undefined;
399 e->exitCode = XK_NEVERESCAPE;
401 e->mustBreak = FALSE;
402 e->isJumpPoint = FALSE;
403 e->environment = environmentTable_undefined;
404 e->requiresConstraints = constraintList_makeNew();
405 e->ensuresConstraints = constraintList_makeNew();
410 /*@observer@*/ exprNode exprNode_makeMustExit (void)
412 if (exprNode_isUndefined (mustExitNode))
414 mustExitNode = exprNode_createPlain (ctype_unknown);
415 mustExitNode->exitCode = XK_MUSTEXIT;
422 static /*@notnull@*/ /*@special@*/ exprNode exprNode_create (ctype c)
424 /*@post:isnull result->edata, result->guards, result->val,
425 result->uses, result->sets, result->msets@*/
428 exprNode e = exprNode_createPlain (c);
429 e->loc = fileloc_copy (g_currentloc);
433 static /*@notnull@*/ /*@special@*/ exprNode exprNode_createUnknown (void)
435 /*@post:isnull result->edata, result->guards,
436 result->uses, result->sets, result->msets@*/
439 return (exprNode_create (ctype_unknown));
442 static /*@notnull@*/ /*@special@*/ exprNode
443 exprNode_createLoc (ctype c, /*@keep@*/ fileloc loc)
445 /*@post:isnull result->edata, result->guards, result->val,
446 result->uses, result->sets, result->msets@*/
449 exprNode e = exprNode_createPlain (c);
455 exprNode_copySets (/*@special@*/ /*@notnull@*/ exprNode ret, exprNode e)
456 /*@defines ret->guards, ret->uses, ret->sets, ret->msets@*/
458 if (exprNode_isDefined (e))
460 ret->guards = guardSet_copy (e->guards);
461 ret->uses = sRefSet_newCopy (e->uses);
462 ret->sets = sRefSet_newCopy (e->sets);
463 ret->msets = sRefSet_newCopy (e->msets);
467 ret->guards = guardSet_undefined;
468 ret->uses = sRefSet_undefined;
469 ret->sets = sRefSet_undefined;
470 ret->msets = sRefSet_undefined;
474 static /*@notnull@*/ /*@special@*/ exprNode
475 exprNode_createPartialLocCopy (exprNode e, /*@only@*/ fileloc loc)
477 /*@post:isnull result->edata, result->etext@*/
480 exprNode ret = exprNode_new ();
482 if (exprNode_isError (e))
484 ret->typ = ctype_unknown;
485 ret->val = multiVal_undefined;
487 ret->guards = guardSet_undefined;
488 ret->uses = sRefSet_undefined;
489 ret->sets = sRefSet_undefined;
490 ret->msets = sRefSet_undefined;
495 ret->val = multiVal_copy (e->val);
497 ret->guards = guardSet_copy (e->guards);
498 ret->uses = sRefSet_newCopy (e->uses);
499 ret->sets = sRefSet_newCopy (e->sets);
500 ret->msets = sRefSet_newCopy (e->msets);
503 ret->kind = XPR_EMPTY;
505 ret->etext = cstring_undefined;
506 ret->exitCode = XK_NEVERESCAPE;
507 ret->canBreak = FALSE;
508 ret->mustBreak = FALSE;
509 ret->isJumpPoint = FALSE;
510 ret->edata = exprData_undefined;
516 static /*@notnull@*/ /*@special@*/ exprNode
517 exprNode_createPartialCopy (exprNode e)
519 /*@post:isnull result->edata, result->etext@*/
522 return (exprNode_createPartialLocCopy (e, fileloc_copy (exprNode_loc (e))));
525 static /*@notnull@*/ /*@special@*/ exprNode
526 exprNode_createPartialNVCopy (exprNode e)
528 /*@post:isnull result->edata, result->etext, result->val @*/
531 exprNode ret = exprNode_new ();
533 if (exprNode_isError (e))
535 ret->typ = ctype_unknown;
536 ret->loc = fileloc_undefined;
537 ret->guards = guardSet_undefined;
538 ret->uses = sRefSet_undefined;
539 ret->sets = sRefSet_undefined;
540 ret->msets = sRefSet_undefined;
545 ret->loc = fileloc_copy (e->loc);
546 ret->guards = guardSet_copy (e->guards);
547 ret->uses = sRefSet_newCopy (e->uses);
548 ret->sets = sRefSet_newCopy (e->sets);
549 ret->msets = sRefSet_newCopy (e->msets);
552 ret->val = multiVal_undefined;
553 ret->kind = XPR_EMPTY;
555 ret->etext = cstring_undefined;
556 ret->exitCode = XK_NEVERESCAPE;
557 ret->canBreak = FALSE;
558 ret->mustBreak = FALSE;
559 ret->isJumpPoint = FALSE;
560 ret->edata = exprData_undefined;
565 static /*@notnull@*/ /*@special@*/ exprNode
566 exprNode_createSemiCopy (exprNode e)
568 /*@post:isnull result->edata, result->etext, result->sets,
569 result->msets, result->uses, result->guards@*/
572 if (exprNode_isError (e))
574 return exprNode_createPlain (ctype_unknown);
578 exprNode ret = exprNode_new ();
581 ret->val = multiVal_copy (e->val);
582 ret->loc = fileloc_copy (e->loc);
583 ret->guards = guardSet_undefined;
584 ret->uses = sRefSet_undefined;
585 ret->sets = sRefSet_undefined;
586 ret->msets = sRefSet_undefined;
588 ret->kind = XPR_EMPTY;
590 ret->etext = cstring_undefined;
591 ret->exitCode = XK_NEVERESCAPE;
592 ret->canBreak = FALSE;
593 ret->mustBreak = FALSE;
594 ret->isJumpPoint = FALSE;
595 ret->edata = exprData_undefined;
602 exprNode_isNullValue (exprNode e)
604 if (exprNode_isDefined (e))
606 multiVal m = exprNode_getValue (e);
608 if (multiVal_isInt (m))
610 return (multiVal_forceInt (m) == 0);
618 exprNode_isUnknownConstant (/*@notnull@*/ exprNode e)
620 while (e->kind == XPR_PARENS)
622 e = exprData_getUopNode (e->edata);
623 llassert (exprNode_isDefined (e));
626 if (e->kind == XPR_CONST)
628 multiVal m = exprNode_getValue (e);
630 if (multiVal_isUnknown (m))
640 exprNode_numLiteral (ctype c, /*@temp@*/ cstring t,
641 /*@only@*/ fileloc loc, long val)
643 exprNode e = exprNode_createLoc (c, loc);
645 e->kind = XPR_NUMLIT;
647 llassert (multiVal_isUndefined (e->val));
648 e->val = multiVal_makeInt (val);
649 e->edata = exprData_makeLiteral (cstring_copy (t));
653 e->sref = sRef_makeUnknown ();
654 sRef_setDefNull (e->sref, e->loc);
657 DPRINTF (("Num lit: %s / %s", exprNode_unparse (e), ctype_unparse (exprNode_getType (e))));
662 exprNode_charLiteral (char c, cstring text, /*@only@*/ fileloc loc)
664 exprNode e = exprNode_createLoc (ctype_char, loc);
666 if (context_getFlag (FLG_CHARINTLITERAL))
668 e->typ = ctype_makeConj (ctype_char, ctype_int);
671 e->kind = XPR_NUMLIT;
672 e->val = multiVal_makeChar (c);
674 e->edata = exprData_makeLiteral (cstring_copy (text));
679 exprNode_floatLiteral (double d, ctype ct, cstring text, /*@only@*/ fileloc loc)
681 exprNode e = exprNode_createLoc (ct, loc);
683 e->kind = XPR_NUMLIT;
684 e->val = multiVal_makeDouble (d);
685 e->edata = exprData_makeLiteral (cstring_copy (text));
689 multiVal exprNode_getValue (exprNode e)
691 while (exprNode_isInParens (e)) {
692 if (e->edata != NULL) {
693 e = exprData_getUopNode (e->edata);
699 if (exprNode_isDefined (e)) {
702 return multiVal_undefined;
707 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
709 exprNode e = exprNode_createLoc (ctype_string, loc);
710 int len = cstring_length (t) - 2;
711 char *ts = cstring_toCharsSafe (t);
712 char *s = cstring_toCharsSafe (cstring_create (len + 1));
714 if (context_getFlag (FLG_STRINGLITERALLEN))
716 if (len > context_getValue (FLG_STRINGLITERALLEN))
718 voptgenerror (FLG_STRINGLITERALLEN,
720 ("String literal length (%d) exceeds maximum "
723 context_getValue (FLG_STRINGLITERALLEN),
729 strncpy (s, ts+1, size_fromInt (len));
733 e->kind = XPR_STRINGLITERAL;
734 e->val = multiVal_makeString (cstring_fromCharsO (s));
735 e->edata = exprData_makeLiteral (t);
736 e->sref = sRef_makeType (ctype_string);
737 /* Start modifications */
738 /* This expr is null terminated, so we set the len and size */
739 sRef_setNullTerminatedState(e->sref);
741 DPRINTF("Len is set to : %d\n\n", strlen((char *)multiVal_forceString(e->val)));
742 DPRINTF("Size is set to : %d\n\n", strlen((char *)multiVal_forceString(e->val)));
743 DPRINTF("State is set to: %d\n\n", e->sref->bufinfo.bufstate);
745 sRef_setLen(e->sref, strlen((char *)multiVal_forceString(e->val)));
746 sRef_setSize(e->sref, strlen((char *)multiVal_forceString(e->val)));
748 if (context_getFlag (FLG_READONLYSTRINGS))
750 sRef_setAliasKind (e->sref, AK_STATIC, fileloc_undefined);
751 sRef_setExKind (e->sref, XO_OBSERVER, loc);
755 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
758 return (e); /* s released */
761 exprNode exprNode_fromUIO (cstring c)
763 fileloc loc = context_getSaveLocation ();
764 exprNode e = exprNode_createPlain (ctype_unknown);
768 if (fileloc_isUndefined (loc))
770 loc = fileloc_copy (g_currentloc);
773 e->loc = loc; /* save loc was mangled */
776 if (usymtab_exists (c))
778 uentry ue = usymtab_lookupEither (c);
780 if (uentry_isDatatype (ue)
781 && uentry_isSpecified (ue))
784 (message ("%q: Specified datatype %s used in code, but not defined. "
785 "(Cannot continue reasonably from this error.)",
786 fileloc_unparse (e->loc), c));
794 llassertprint (!usymtab_exists (c), ("Entry exists: %s", c));
797 ** was supercedeGlobalEntry...is this better?
800 if (!context_inIterEnd ())
802 if (context_inMacro ())
804 if (context_getFlag (FLG_UNRECOG))
808 message ("Unrecognized identifier in macro definition: %s", c), e->loc);
812 flagcode_recordSuppressed (FLG_UNRECOG);
818 (FLG_UNRECOG, message ("Unrecognized identifier: %s", c),
823 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
825 /* No alias errors for unrecognized identifiers */
826 sRef_setAliasKind (e->sref, AK_ERROR, loc);
831 exprNode exprNode_createId (/*@observer@*/ uentry c)
833 if (uentry_isValid (c))
835 exprNode e = exprNode_new ();
837 e->typ = uentry_getType (c);
839 if (uentry_isFunction (c)
840 && !sRef_isLocalVar (uentry_getSref (c)))
842 e->sref = sRef_undefined;
846 e->sref = uentry_getSref (c);
849 if (sRef_isStateUnknown (e->sref) && uentry_isNonLocal (c))
851 sRef_setDefined (e->sref, fileloc_undefined);
855 ** yoikes! leaving this out was a heinous bug...that would have been
856 ** caught if i had lclint working first. gag!
859 e->etext = cstring_undefined;
861 if (uentry_isEitherConstant (c))
864 e->val = multiVal_copy (uentry_getConstantValue (c));
869 e->val = multiVal_unknown ();
872 e->edata = exprData_makeId (c);
873 e->loc = context_getSaveLocation ();
875 if (fileloc_isUndefined (e->loc))
877 fileloc_free (e->loc);
878 e->loc = fileloc_copy (g_currentloc);
881 e->guards = guardSet_new ();
882 e->sets = sRefSet_new ();
883 e->msets = sRefSet_new ();
884 e->uses = sRefSet_new ();
886 /*> missing fields, detected by lclint <*/
887 e->exitCode = XK_NEVERESCAPE;
888 e->isJumpPoint = FALSE;
890 e->mustBreak = FALSE;
896 return exprNode_createUnknown ();
900 /*@notnull@*/ exprNode
901 exprNode_fromIdentifier (/*@observer@*/ uentry c)
905 if (context_justPopped ()) /* watch out! c could be dead */
907 uentry ce = usymtab_lookupSafe (LastIdentifier ());
909 if (uentry_isValid (ce))
915 llbuglit ("Looks like Aunt Millie forgot to walk to dog again.");
919 ret = exprNode_fromIdentifierAux (c);
925 static /*@only@*/ /*@notnull@*/ exprNode
926 exprNode_fromIdentifierAux (/*@observer@*/ uentry c)
928 exprNode e = exprNode_createId (c);
931 uentry_setUsed (c, e->loc);
933 if (uentry_isVar (c) && sRef_isGlobal (sr))
935 checkGlobUse (c, FALSE, e);
942 exprNode_isZero (exprNode e)
944 if (exprNode_isDefined (e))
946 multiVal m = exprNode_getValue (e);
948 if (multiVal_isInt (m))
950 return (multiVal_forceInt (m) == 0);
958 exprNode_isNonNegative (exprNode e)
960 if (exprNode_isDefined (e))
962 multiVal m = exprNode_getValue (e);
964 if (multiVal_isInt (m))
966 return (multiVal_forceInt (m) >= 0);
974 ** a[x] - uses a but NOT a[]
975 ** result sref = a[] (set/use in assignment)
977 ** The syntax x[a] is also legal in C, and has the same
978 ** semantics. If ind is an array, and arr is an int, flip
983 exprNode_arrayFetch (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
986 ** error in arr, error propagates (no new messages)
987 ** error in ind, assume valid and continue
990 if (exprNode_isError (e1))
993 return (exprNode_makeError ());
999 ctype carr = exprNode_getType (e1);
1000 ctype crarr = ctype_realType (carr);
1003 ** this sets up funny aliasing, that leads to spurious
1004 ** lclint errors. Hence, the i2 comments.
1007 if (!ctype_isRealArray (crarr)
1008 && ctype_isRealNumeric (crarr)
1009 && !exprNode_isError (e2)
1010 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1015 carr = exprNode_getType (arr);
1016 crarr = ctype_realType (carr);
1024 if (sRef_possiblyNull (arr->sref))
1026 if (!usymtab_isGuarded (arr->sref))
1028 if (optgenerror (FLG_NULLDEREF,
1029 message ("Index of %s pointer %q: %s",
1030 sRef_nullMessage (arr->sref),
1031 sRef_unparse (arr->sref),
1032 exprNode_unparse (arr)),
1035 sRef_showNullInfo (arr->sref);
1037 /* suppress future messages */
1038 sRef_setNullError (arr->sref);
1043 if (exprNode_isError (ind))
1045 if ((ctype_isArrayPtr (crarr)
1046 && !ctype_isFunction (crarr))
1047 || ctype_isUnknown (carr))
1049 exprNode ret = exprNode_createPartialCopy (arr);
1051 if (ctype_isKnown (carr))
1053 ret->typ = ctype_baseArrayPtr (crarr);
1057 ret->typ = ctype_unknown;
1060 ret->sref = sRef_makeArrayFetch (arr->sref);
1062 ret->kind = XPR_FETCH;
1065 ** Because of funny aliasing (when arr and ind are
1066 ** flipped) spurious errors would be reported here.
1069 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1070 checkSafeUse (ret, arr->sref);
1075 voptgenerror (FLG_TYPE,
1076 message ("Array fetch from non-array (%t): %s[%s]", carr,
1077 exprNode_unparse (e1), exprNode_unparse (e2)),
1079 exprNode_free (arr);
1080 return (exprNode_makeError ());
1085 if (!ctype_isForceRealInt (&(ind->typ)))
1087 ctype rt = ctype_realType (ind->typ);
1089 if (ctype_isChar (rt))
1093 message ("Array fetch using non-integer, %t: %s[%s]",
1095 exprNode_unparse (e1), exprNode_unparse (e2)),
1098 else if (ctype_isEnum (rt))
1102 message ("Array fetch using non-integer, %t: %s[%s]",
1104 exprNode_unparse (e1), exprNode_unparse (e2)),
1111 message ("Array fetch using non-integer, %t: %s[%s]",
1113 exprNode_unparse (e1), exprNode_unparse (e2)),
1117 multiVal_free (ind->val);
1118 ind->val = multiVal_unknown ();
1121 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1123 exprNode ret = exprNode_createSemiCopy (arr);
1124 multiVal m = exprNode_getValue (ind);
1126 ret->typ = ctype_baseArrayPtr (crarr);
1127 ret->kind = XPR_FETCH;
1129 if (multiVal_isInt (m))
1131 int i = (int) multiVal_forceInt (m);
1133 if (sRef_isValid (arr->sref)) {
1134 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1136 ret->sref = sRef_undefined;
1141 ret->sref = sRef_makeArrayFetch (arr->sref);
1144 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1145 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1146 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1148 /* (see comment on spurious errors above) */
1149 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1151 exprNode_checkUse (ret, ind->sref, ind->loc);
1152 exprNode_checkUse (ret, arr->sref, arr->loc);
1158 if (ctype_isUnknown (carr))
1160 exprNode ret = exprNode_createPartialCopy (arr);
1162 ret->kind = XPR_FETCH;
1163 ret->typ = ctype_unknown;
1164 ret->sets = sRefSet_union (ret->sets, ind->sets);
1165 ret->msets = sRefSet_union (ret->msets, ind->msets);
1166 ret->uses = sRefSet_union (ret->uses, ind->uses);
1168 /* (see comment on spurious errors above) */
1169 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1171 exprNode_checkUse (ret, ind->sref, ind->loc);
1172 exprNode_checkUse (ret, arr->sref, arr->loc);
1179 message ("Array fetch from non-array (%t): %s[%s]", carr,
1180 exprNode_unparse (e1), exprNode_unparse (e2)),
1183 exprNode_free (arr);
1184 exprNode_free (ind);
1186 return (exprNode_makeError ());
1196 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1197 exprNodeList args, exprNode ret)
1199 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1203 ** checkPrintfArgs --- checks arguments for printf-like functions
1204 ** Arguments before ... have already been checked.
1205 ** The argument before the ... is a char *.
1206 ** argno is the format string argument.
1210 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1211 exprNodeList args, exprNode ret, int argno)
1214 ** the last argument before the elips is the format string
1219 int nargs = exprNodeList_size (args);
1220 uentryList params = uentry_getParams (fcn);
1224 ** These should be ensured by checkSpecialFunction
1227 llassert (uentryList_size (params) == argno + 1);
1228 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1230 a = exprNodeList_getN (args, argno - 1);
1231 formatloc = fileloc_copy (exprNode_loc (a));
1233 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1234 && exprNode_knownStringValue (a))
1236 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1237 char *code = format;
1240 nargs = exprNodeList_size (args);
1242 while ((code = strchr (code, '%')) != NULL)
1244 char *origcode = code;
1245 char key = *(++code);
1246 ctype modtype = ctype_int;
1247 bool modified = FALSE;
1249 fileloc_addColumn (formatloc, code - ocode);
1252 while (isFlagKey (key))
1255 fileloc_incColumn (formatloc);
1258 if (key == 'm') /* skipped in syslog */
1263 /* ignore field width */
1264 while (isdigit ((int) key) != 0)
1267 fileloc_incColumn (formatloc);
1270 /* ignore precision */
1274 fileloc_incColumn (formatloc);
1277 ** In printf, '*' means: read the next arg as an int for the
1278 ** field width. This seems to be missing from my copy of the
1279 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1280 ** later) but never does.
1285 ; /* don't do anything --- handle later */
1289 while (isdigit ((int) key) != 0)
1292 fileloc_incColumn (formatloc);
1299 modtype = ctype_sint; /* short */
1301 fileloc_incColumn (formatloc);
1303 else if (key == 'l' || key == 'L')
1305 modtype = ctype_lint; /* long */
1307 fileloc_incColumn (formatloc);
1309 if (key == 'l' || key == 'L') {
1310 modtype = ctype_llint; /* long long */
1312 fileloc_incColumn (formatloc);
1320 /* now, key = type of conversion to apply */
1322 fileloc_incColumn (formatloc);
1330 message ("No argument corresponding to %q format "
1331 "code %d (%%%h): \"%s\"",
1332 uentry_getName (fcn),
1334 cstring_fromChars (format)),
1337 if (fileloc_isDefined (formatloc)
1338 && context_getFlag (FLG_SHOWCOL))
1340 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1348 a = exprNodeList_getN (args, i);
1351 if (!exprNode_isError (a))
1357 case '*': /* int argument for fieldwidth */
1358 expecttype = ctype_int;
1359 *(--code) = '%'; /* convert it for next code */
1360 fileloc_subColumn (formatloc, 1);
1361 /*@switchbreak@*/ break;
1364 expecttype = ctype_combine (ctype_uint, modtype);
1365 /*@switchbreak@*/ break;
1367 case 'i': /* int argument */
1369 expecttype = ctype_combine (ctype_int, modtype);
1370 /*@switchbreak@*/ break;
1372 case 'x': /* unsigned int */
1374 expecttype = ctype_combine (ctype_uint, modtype);
1375 /*@switchbreak@*/ break;
1381 case 'f': /* double */
1382 expecttype = ctype_combine (ctype_double, modtype);
1383 /*@switchbreak@*/ break;
1385 case 'c': /* int converted to char (check its a char?) */
1386 expecttype = ctype_makeConj (ctype_char, ctype_uchar);
1387 /*@switchbreak@*/ break;
1389 case 's': /* string */
1390 expecttype = ctype_string;
1391 /*@switchbreak@*/ break;
1394 while (((key = *(++code)) != ']')
1397 fileloc_incColumn (formatloc);
1403 (message ("Bad character set format: %s",
1404 cstring_fromChars (origcode)));
1407 expecttype = ctype_string;
1408 /*@switchbreak@*/ break;
1410 case 'p': /* pointer */
1411 expecttype = ctype_makePointer (ctype_void);
1413 /*@switchbreak@*/ break;
1415 case 'n': /* pointer to int, modified by call! */
1416 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1418 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1419 /*@switchbreak@*/ break;
1421 case 'm': /* in a syslog, it doesn't consume an argument */
1422 /* should check we're really doing syslog */
1424 /*@switchbreak@*/ break;
1428 expecttype = ctype_unknown;
1432 message ("Unrecognized format code: %s",
1433 cstring_fromChars (origcode)),
1434 fileloc_isDefined (formatloc)
1435 ? formatloc : g_currentloc);
1437 /*@switchbreak@*/ break;
1440 if (!(exprNode_matchArgType (expecttype, a)))
1442 if (ctype_isVoidPointer (expecttype)
1443 && ctype_isRealAbstract (a->typ)
1444 && (context_getFlag (FLG_ABSTVOIDP)))
1450 if (llgenformattypeerror
1451 (expecttype, exprNode_undefined,
1453 message ("Format argument %d to %q (%%%h) expects "
1456 uentry_getName (fcn),
1458 a->typ, exprNode_unparse (a)),
1461 if (fileloc_isDefined (formatloc)
1462 && context_getFlag (FLG_SHOWCOL))
1465 (cstring_makeLiteral
1466 ("Corresponding format code"),
1473 uentry_setType (regArg, expecttype);
1474 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1476 if (ctype_equal (expecttype, ctype_string))
1478 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1481 uentry_setType (regArg, ctype_unknown);
1482 uentry_fixupSref (regArg);
1486 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1500 voptgenerror (FLG_TYPE,
1501 message ("Format string for %q has %d arg%p, given %d",
1502 uentry_getName (fcn), i - argno, nargs - argno),
1508 /* no checking possible for compile-time unknown format strings */
1511 fileloc_free (formatloc);
1515 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1516 exprNodeList args, exprNode ret, int argno)
1520 int nargs = exprNodeList_size (args);
1521 uentryList params = uentry_getParams (fcn);
1525 ** These should be ensured by checkSpecialFunction
1528 llassert (uentryList_size (params) == argno + 1);
1529 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1531 a = exprNodeList_getN (args, argno - 1);
1532 formatloc = fileloc_copy (exprNode_loc (a));
1534 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1535 && exprNode_knownStringValue (a))
1537 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1538 char *code = format;
1541 nargs = exprNodeList_size (args);
1543 while ((code = strchr (code, '%')) != NULL)
1545 char *origcode = code;
1546 char key = *(++code);
1547 ctype modtype = ctype_int;
1548 char modifier = '\0';
1549 bool modified = TRUE;
1550 bool ignore = FALSE;
1552 fileloc_addColumn (formatloc, code - ocode);
1555 ** this is based on ANSI standard library description of fscanf
1556 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1559 /* '*' suppresses assignment (does not need match argument) */
1566 fileloc_incColumn (formatloc);
1569 /* ignore field width */
1570 while (isdigit ((int) key) != 0)
1573 fileloc_incColumn (formatloc);
1578 modtype = ctype_sint; /* short */
1580 fileloc_incColumn (formatloc);
1582 else if (key == 'l' || key == 'L')
1584 modtype = ctype_lint; /* long */
1588 fileloc_incColumn (formatloc);
1590 if (key == 'l' || key == 'L') {
1591 modtype = ctype_llint; /* long long */
1593 fileloc_incColumn (formatloc);
1601 /* now, key = type of conversion to apply */
1603 fileloc_incColumn (formatloc);
1617 message ("No argument corresponding to %q format "
1618 "code %d (%%%h): \"%s\"",
1619 uentry_getName (fcn),
1621 cstring_fromChars (format)),
1624 if (fileloc_isDefined (formatloc)
1625 && context_getFlag (FLG_SHOWCOL))
1628 (cstring_makeLiteral ("Corresponding format code"),
1636 a = exprNodeList_getN (args, i);
1639 if (!exprNode_isError (a))
1645 case '*': /* int argument for fieldwidth */
1646 expecttype = ctype_makePointer (ctype_int);
1647 *(--code) = '%'; /* convert it for next code */
1648 fileloc_subColumn (formatloc, 1);
1649 /*@switchbreak@*/ break;
1652 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1653 /*@switchbreak@*/ break;
1658 case 'X': /* unsigned int */
1659 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1660 /*@switchbreak@*/ break;
1667 /* printf is double, scanf is float! */
1669 if (modifier == 'l')
1671 expecttype = ctype_makePointer (ctype_double);
1673 else if (modifier == 'L')
1675 expecttype = ctype_makePointer (ctype_ldouble);
1679 llassert (modifier == '\0');
1680 expecttype = ctype_makePointer (ctype_float);
1682 /*@switchbreak@*/ break;
1684 case 'c': /* int converted to char (check its a char?) */
1685 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1686 /*@switchbreak@*/ break;
1688 case 's': /* string */
1689 expecttype = ctype_string;
1690 /*@switchbreak@*/ break;
1694 while (((key = *(++code)) != ']')
1697 fileloc_incColumn (formatloc);
1703 (message ("Bad character set format: %s",
1704 cstring_fromChars (origcode)));
1707 expecttype = ctype_string;
1708 /*@switchbreak@*/ break;
1710 case 'p': /* pointer */
1711 expecttype = ctype_unknown;
1713 /*@switchbreak@*/ break;
1715 case 'n': /* pointer to int, modified by call! */
1716 expecttype = ctype_makePointer (ctype_int);
1717 /*@switchbreak@*/ break;
1720 expecttype = ctype_unknown;
1724 message ("Unrecognized format code: %s",
1725 cstring_fromChars (origcode)),
1726 fileloc_isDefined (formatloc)
1727 ? formatloc : g_currentloc);
1729 /*@switchbreak@*/ break;
1732 if (!(exprNode_matchArgType (expecttype, a)))
1734 if (ctype_isVoidPointer (expecttype)
1735 && ctype_isRealAbstract (a->typ)
1736 && (context_getFlag (FLG_ABSTVOIDP)))
1742 if (modifier != '\0')
1744 if (llgenformattypeerror
1745 (expecttype, exprNode_undefined,
1747 message ("Format argument %d to %q (%%%h%h) expects "
1750 uentry_getName (fcn),
1753 a->typ, exprNode_unparse (a)),
1756 if (fileloc_isDefined (formatloc)
1757 && context_getFlag (FLG_SHOWCOL))
1760 (cstring_makeLiteral
1761 ("Corresponding format code"),
1769 if (llgenformattypeerror
1770 (expecttype, exprNode_undefined,
1772 message ("Format argument %d to %q (%%%h) expects "
1775 uentry_getName (fcn),
1777 a->typ, exprNode_unparse (a)),
1780 if (fileloc_isDefined (formatloc)
1781 && context_getFlag (FLG_SHOWCOL))
1784 (cstring_makeLiteral
1785 ("Corresponding format code"),
1793 uentry_setType (outArg, expecttype);
1794 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
1795 uentry_setType (outArg, ctype_unknown);
1796 uentry_fixupSref (outArg);
1800 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1805 /* a->sref = defref; */
1815 voptgenerror (FLG_TYPE,
1816 message ("Format string for %q has %d arg%p, given %d",
1817 uentry_getName (fcn), i - argno, nargs - argno),
1823 /* no checking possible for compile-time unknown format strings */
1826 fileloc_free (formatloc);
1830 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
1833 /*@unused@*/ int argno)
1836 ** the last argument before the elips is the format string
1839 int nargs = exprNodeList_size (args);
1844 a = exprNodeList_getN (args, argno - 1);
1845 formatloc = fileloc_copy (exprNode_loc (a));
1847 if (ctype_isUnknown (cstringType)) {
1848 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
1850 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
1854 if (ctype_isUnknown (ctypeType)) {
1855 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
1857 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
1861 if (ctype_isUnknown (filelocType)) {
1862 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
1864 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
1868 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1869 && exprNode_knownStringValue (a))
1871 cstring format = multiVal_forceString (exprNode_getValue (a));
1872 char *code = cstring_toCharsSafe (format);
1875 nargs = exprNodeList_size (args);
1877 while ((code = strchr (code, '%')) != NULL)
1879 char *origcode = code;
1880 char key = *(++code);
1881 bool isOnly = FALSE;
1883 fileloc_addColumn (formatloc, code - ocode);
1885 while (key >= '0' && key <= '9')
1888 fileloc_incColumn (formatloc);
1892 fileloc_incColumn (formatloc);
1905 message ("Message missing format arg %d (%%%h): \"%s\"",
1906 i + 1, key, format),
1912 a = exprNodeList_getN (args, i);
1916 if (!exprNode_isError (a))
1920 /*@-loopswitchbreak@*/
1926 expecttype = ctype_char; break;
1928 expecttype = cstringType; break;
1930 expecttype = cstringType; isOnly = TRUE; break;
1932 expecttype = cstringType; isOnly = TRUE; break;
1933 case 'd': expecttype = ctype_int; break;
1934 case 'u': expecttype = ctype_uint; break;
1935 case 'w': expecttype = ctype_ulint; break;
1936 case 'f': expecttype = ctype_float; break;
1937 case 'b': expecttype = ctype_bool; break;
1938 case 't': expecttype = ctypeType; break;
1939 case 'l': expecttype = filelocType; break;
1940 case 'p': /* a wee bit of a hack methinks */
1941 expecttype = ctype_int;
1943 case 'r': expecttype = ctype_bool; break;
1945 expecttype = ctype_unknown;
1948 message ("Unrecognized format code: %s",
1949 cstring_fromChars (origcode)),
1950 fileloc_isDefined (formatloc)
1951 ? formatloc : g_currentloc);
1954 /*@=loopswitchbreak@*/
1956 if (!(exprNode_matchArgType (expecttype, a)))
1958 if (ctype_isVoidPointer (expecttype)
1959 && ctype_isRealAbstract (a->typ)
1960 && (context_getFlag (FLG_ABSTVOIDP)))
1966 if (llgenformattypeerror
1967 (expecttype, exprNode_undefined,
1969 message ("Format argument %d to %q (%%%h) expects "
1972 uentry_getName (fcn),
1974 a->typ, exprNode_unparse (a)),
1977 if (fileloc_isDefined (formatloc)
1978 && context_getFlag (FLG_SHOWCOL))
1981 (cstring_makeLiteral
1982 ("Corresponding format code"),
1989 if (ctype_equal (expecttype, cstringType))
1993 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
1994 uentry_fixupSref (csOnlyArg);
1998 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
1999 uentry_fixupSref (csArg);
2004 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2005 uentry_fixupSref (regArg);
2014 voptgenerror (FLG_TYPE,
2015 message ("Format string for %q has %d arg%p, given %d",
2016 uentry_getName (fcn), i - argno, nargs -argno),
2022 /* no checking possible for compile-time unknown format strings */
2025 fileloc_free (formatloc);
2029 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2030 /*@notnull@*/ exprNode e2,
2036 bool hadUncon = FALSE;
2038 if (sRef_isGlobal (sRef_getRootBase (e1->sref)) &&
2039 sRefSet_hasUnconstrained (sets2))
2042 (FLG_EVALORDERUNCON,
2044 ("Expression may have undefined behavior (%q used in right operand "
2045 "may set global variable %q used in left operand): %s %s %s",
2046 sRefSet_unparseUnconstrained (sets2),
2047 sRef_unparse (sRef_getRootBase (e1->sref)),
2048 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2052 if (sRef_isGlobal (sRef_getRootBase (e2->sref)) &&
2053 sRefSet_hasUnconstrained (sets1))
2056 (FLG_EVALORDERUNCON,
2058 ("Expression has undefined behavior (%q used in left operand "
2059 "may set global variable %q used in right operand): %s %s %s",
2060 sRefSet_unparseUnconstrained (sets1),
2061 sRef_unparse (e2->sref),
2062 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2066 sRefSet_realElements (e1->uses, sr)
2068 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2073 ("Expression has undefined behavior (left operand uses %q, "
2074 "modified by right operand): %s %s %s",
2076 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2079 } end_sRefSet_realElements;
2081 sRefSet_realElements (sets1, sr)
2083 if (sRef_isMeaningful (sr))
2085 if (sRef_same (sr, e2->sref))
2090 ("Expression has undefined behavior (value of right operand "
2091 "modified by left operand): %s %s %s",
2092 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2095 else if (sRefSet_member (e2->uses, sr))
2100 ("Expression has undefined behavior (left operand modifies %q, "
2101 "used by right operand): %s %s %s",
2103 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2108 if (sRefSet_member (sets2, sr))
2110 if (sRef_isUnconstrained (sr))
2118 hadUncon = optgenerror
2119 (FLG_EVALORDERUNCON,
2121 ("Expression may have undefined behavior. Left operand "
2122 "calls %q; right operand calls %q. The unconstrained "
2123 "functions may modify global state used by "
2124 "the other operand): %s %s %s",
2125 sRefSet_unparseUnconstrained (sets1),
2126 sRefSet_unparseUnconstrained (sets2),
2127 exprNode_unparse (e1), lltok_unparse (op),
2128 exprNode_unparse (e2)),
2137 ("Expression has undefined behavior (both "
2138 "operands modify %q): %s %s %s",
2140 exprNode_unparse (e1),
2141 lltok_unparse (op), exprNode_unparse (e2)),
2147 } end_sRefSet_realElements;
2150 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2152 bool hasError = FALSE;
2154 if (exprNode_isError (e1) || exprNode_isError (e2))
2159 if (sRefSet_member (e2->sets, e1->sref))
2161 if (e2->kind == XPR_CALL)
2167 hasError = optgenerror
2169 message ("Expression has undefined behavior "
2170 "(value of left operand is modified "
2171 "by right operand): %s %s %s",
2172 exprNode_unparse (e1), lltok_unparse (op),
2173 exprNode_unparse (e2)),
2178 if (context_getFlag (FLG_EVALORDERUNCON))
2180 if (sRefSet_member (e2->msets, e1->sref))
2182 if (e2->kind == XPR_CALL)
2188 hasError = optgenerror
2191 ("Expression has undefined behavior (value of left "
2192 "operand may be modified by right operand): %s %s %s",
2193 exprNode_unparse (e1), lltok_unparse (op),
2194 exprNode_unparse (e2)),
2202 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2204 if (context_maybeSet (FLG_EVALORDERUNCON))
2206 checkExpressionDefinedAux (e1, e2, e1->msets,
2207 e2->msets, op, FLG_EVALORDERUNCON);
2212 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2215 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2216 exprNodeList args, bool isIter, exprNode ret)
2220 if (!exprNode_isError (f))
2222 if (!uentryList_isMissingParams (cl))
2224 int nargs = exprNodeList_size (args);
2225 int expectargs = uentryList_size (cl);
2229 if (expectargs == 0)
2237 message ("Iter %q invoked with %d args, "
2239 uentry_getName (fcn),
2247 message ("Function %s called with %d args, "
2249 exprNode_unparse (f), nargs),
2256 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2258 exprNodeList_reset (args);
2260 uentryList_elements (cl, current)
2262 ctype ct = uentry_getType (current);
2265 if (ctype_isElips (ct))
2268 ** do special checking for printf/scanf library functions
2270 ** this is kludgey code, just for handling the special case
2274 if (uentry_isPrintfLike (fcn))
2276 checkPrintfArgs (f, fcn, args, ret, i);
2279 else if (uentry_isScanfLike (fcn))
2281 checkScanfArgs (f, fcn, args, ret, i);
2284 else if (uentry_isMessageLike (fcn))
2286 checkMessageArgs (f, fcn, args, i);
2291 llassert (!uentry_isSpecialFunction (fcn));
2294 nargs = expectargs; /* avoid errors */
2299 if (i >= nargs) break;
2301 a = exprNodeList_current (args);
2302 exprNodeList_advance (args);
2306 if (exprNode_isError (a))
2313 probably necessary? I'm not sure about this one
2314 checkMacroParen (a);
2317 f->guards = guardSet_union (f->guards, a->guards);
2319 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2321 if (!(exprNode_matchArgType (ct, a)))
2323 DPRINTF (("Args mismatch!"));
2325 if (ctype_isVoidPointer (ct)
2326 && (ctype_isPointer (a->typ)
2327 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2332 ("Pointer to abstract type (%t) used "
2334 "(arg %d to %q): %s",
2336 uentry_getName (fcn),
2337 exprNode_unparse (a)),
2345 (ct, exprNode_undefined,
2348 ("Iter %q expects arg %d to "
2349 "be %t gets %t: %s",
2350 uentry_getName (fcn),
2351 i, ct, a->typ, exprNode_unparse (a)),
2362 ("Function %q expects arg %d to be %t gets %t: %s",
2363 uentry_getName (fcn),
2364 i, ct, a->typ, exprNode_unparse (a)),
2367 DPRINTF (("Types: %s / %s",
2369 ctype_unparse (a->typ)));
2373 ** Clear null marker for abstract types.
2374 ** (It is not revealed, so suppress future messages.)
2377 if (ctype_isAbstract (a->typ))
2379 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2386 } end_uentryList_elements ;
2389 if (expectargs != nargs) /* note: not != since we may have ... */
2391 if (ctype_isElips (last))
2395 message ("Function %s called with %d args, expects at least %d",
2396 exprNode_unparse (f),
2397 nargs, expectargs - 1),
2406 message ("Iter %q invoked with %d args, expects %d",
2407 uentry_getName (fcn), nargs, expectargs),
2414 message ("Function %s called with %d args, expects %d",
2415 exprNode_unparse (f),
2428 ** Check for undefined code sequences in function arguments:
2430 ** one parameter sets something used by another parameter
2431 ** one parameter sets something set by another parameter
2435 checkSequencingOne (exprNode f, exprNodeList args,
2436 /*@notnull@*/ exprNode el, int argno)
2439 ** Do second loop, iff +undefunspec
2443 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2445 for (checkloop = 0; checkloop < numloops; checkloop++)
2451 thissets = el->sets;
2455 llassert (checkloop == 1);
2456 thissets = el->msets;
2459 sRefSet_realElements (thissets, thisset)
2463 /*@access exprNodeList@*/
2464 for (j = 0; j < args->nelements; j++)
2466 exprNode jl = args->elements[j];
2467 int thisargno = j + 1;
2469 if (thisargno != argno && exprNode_isDefined (jl))
2471 sRefSet otheruses = jl->uses;
2473 if (sRef_isGlobal (sRef_getRootBase (jl->sref)) &&
2474 sRefSet_hasUnconstrained (thissets))
2477 (FLG_EVALORDERUNCON,
2480 ("%q used in argument %d may set "
2481 "global variable %q used by argument %d: %s(%q)",
2482 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2485 sRef_unparse (sRef_getRootBase (jl->sref)),
2487 exprNode_unparse (f), exprNodeList_unparse (args)),
2491 if (sRefSet_member (otheruses, thisset))
2493 if (sRef_isUnconstrained (thisset))
2496 (FLG_EVALORDERUNCON,
2498 ("Unconstrained functions used in arguments %d (%q) "
2499 "and %d (%s) may modify "
2500 "or use global state in undefined way: %s(%q)",
2502 sRefSet_unparseUnconstrainedPlain (otheruses),
2504 sRef_unconstrainedName (thisset),
2505 exprNode_unparse (f),
2506 exprNodeList_unparse (args)),
2514 ("Argument %d modifies %q, used by argument %d "
2515 "(order of evaluation of actual parameters is "
2516 "undefined): %s(%q)",
2517 argno, sRef_unparse (thisset), thisargno,
2518 exprNode_unparse (f), exprNodeList_unparse (args)),
2524 sRefSet othersets = jl->sets;
2526 if (sRefSet_member (othersets, thisset))
2528 if (sRef_isUnconstrained (thisset))
2531 (FLG_EVALORDERUNCON,
2533 ("Unconstrained functions used in "
2534 "arguments %d (%q) and %d (%s) may modify "
2535 "or use global state in undefined way: %s(%q)",
2537 sRefSet_unparseUnconstrainedPlain (othersets),
2539 sRef_unconstrainedName (thisset),
2540 exprNode_unparse (f), exprNodeList_unparse (args)),
2548 ("Argument %d modifies %q, set by argument %d (order of"
2549 " evaluation of actual parameters is undefined): %s(%q)",
2550 argno, sRef_unparse (thisset), thisargno,
2551 exprNode_unparse (f), exprNodeList_unparse (args)),
2558 /*@noaccess exprNodeList@*/
2559 } end_sRefSet_realElements;
2564 checkSequencing (exprNode f, exprNodeList args)
2566 if (exprNodeList_size (args) > 1)
2571 /*@access exprNodeList*/
2573 for (i = 0; i < args->nelements; i++)
2575 el = args->elements[i];
2577 if (!exprNode_isError (el))
2579 checkSequencingOne (f, args, el, i + 1);
2582 /*@noaccess exprNodeList*/
2587 ** requires le = exprNode_getUentry (f)
2591 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2592 uentry le, exprNodeList args,
2593 /*@notnull@*/ exprNode ret, int specialArgs)
2595 bool isSpec = FALSE;
2596 bool hasMods = FALSE;
2598 globSet usesGlobs = globSet_undefined;
2599 sRefSet mods = sRefSet_undefined;
2600 bool freshMods = FALSE;
2601 uentryList params = uentryList_undefined;
2604 ** check globals and modifies
2609 if (!uentry_isValid (le))
2611 ctype fr = ctype_realType (f->typ);
2613 if (ctype_isFunction (fr))
2615 params = ctype_argsFunction (fr);
2619 params = uentryList_missingParams;
2622 if (!context_getFlag (FLG_MODNOMODS)
2623 && !context_getFlag (FLG_GLOBUNSPEC))
2625 checkUnspecCall (f, params, args);
2631 fname = uentry_rawName (le);
2635 if (uentry_isFunction (le))
2637 params = uentry_getParams (le);
2638 mods = uentry_getMods (le);
2639 hasMods = uentry_hasMods (le);
2640 usesGlobs = uentry_getGlobs (le);
2641 isSpec = uentry_isSpecified (le);
2643 else /* not a function */
2645 ctype ct = ctype_realType (uentry_getType (le));
2647 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2648 ("checkModGlobs: uentry not a function: %s",
2649 uentry_unparse (le)));
2651 params = ctype_argsFunction (ct);
2661 globSet_allElements (usesGlobs, el)
2663 if (sRef_isValid (el))
2665 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2667 context_usedGlobal (el);
2668 exprNode_checkUse (f, el, f->loc);
2670 if (context_checkInternalUse ())
2672 if (!context_globAccess (el))
2674 if (sRef_isSystemState (el)
2675 && !context_getFlag (FLG_MODFILESYSTEM))
2684 ("Called procedure %s may access %q, but "
2685 "globals list does not include globals %s",
2686 exprNode_unparse (f),
2688 cstring_makeLiteralTemp (sRef_isInternalState (el)
2696 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2702 uentry gle = sRef_getUentry (el);
2703 sRef sr = sRef_updateSref (el);
2705 if (sRef_isUndefGlob (el))
2707 sRef_setDefined (sr, f->loc);
2708 exprNode_checkSet (f, sr);
2716 if (sRef_isAllocated (el))
2718 exprNode_checkSet (f, sr);
2722 if (sRef_isStateUndefined (sr))
2727 ("%s %q used by function undefined before call: %s",
2728 sRef_getScopeName (sr),
2730 exprNode_unparse (f)),
2732 sRef_setDefined (sr, f->loc);
2734 exprNode_checkUse (f, sr, f->loc);
2737 checkGlobUse (gle, TRUE, f);
2740 if (sRef_isKilledGlob (el))
2742 sRef_kill (sr, f->loc);
2743 context_usedGlobal (sr);
2747 } end_globSet_allElements;
2753 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
2755 sRefSet smods = sRefSet_undefined;
2758 ** NEED to check for modifies anything
2762 ** check each sRef that called function modifies (ml), is
2768 sRefSet_allElements (mods, s) /* s is something which may be modified */
2770 if (sRef_isKindSpecial (s))
2772 if (sRef_isSpecInternalState (s))
2774 if (context_getFlag (FLG_MODINTERNALSTRICT))
2776 exprNode_checkCallModifyVal (s, args, f, ret);
2780 sRefSet mmods = context_modList ();
2782 sRefSet_allElements (mmods, el)
2784 if (sRef_isInternalState (el))
2786 sRef_setModified (el);
2788 } end_sRefSet_allElements ;
2793 exprNode_checkCallModifyVal (s, args, f, ret);
2798 sRef rb = sRef_getRootBase (s);
2800 if (sRef_isGlobal (rb))
2802 context_usedGlobal (rb);
2805 if (sRef_isFileStatic (s)
2806 && !fileId_equal (fileloc_fileId (f->loc),
2807 fileloc_fileId (uentry_whereDefined (le))))
2809 smods = sRefSet_insert (smods, s);
2813 exprNode_checkCallModifyVal (s, args, f, ret);
2816 } end_sRefSet_allElements;
2821 ** Static elements in modifies set can have nasty consequences.
2822 ** (I think...have not been able to reproduce a possible bug.)
2825 if (!sRefSet_isDefined (smods))
2827 mods = sRefSet_newCopy (mods);
2830 sRefSet_allElements (smods, el)
2832 bool res = sRefSet_delete (mods, el);
2835 } end_sRefSet_allElements;
2837 sRefSet_free (smods);
2842 else if (sRefSet_isDefined (mods))
2843 { /* just check observers */
2846 sRefSet_allElements (mods, s) /* s is something which may be modified */
2848 sRef rb = sRef_getRootBase (s);
2852 if (sRef_isParam (rb))
2854 sRef b = sRef_fixBaseParam (s, args);
2856 if (sRef_isObserver (b))
2858 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
2862 message ("Function call may modify observer%q: %s",
2863 sRef_unparsePreOpt (b), exprNode_unparse (e)),
2866 sRef_showExpInfo (b);
2870 } end_sRefSet_allElements;
2874 if (!hasMods) /* no specified modifications */
2876 if (context_getFlag (FLG_MODOBSERVERUNCON))
2878 exprNodeList_elements (args, e)
2880 if (exprNode_isDefined (e))
2882 sRef s = exprNode_getSref (e);
2884 if (sRef_isObserver (s)
2885 && ctype_isMutable (sRef_getType (s)))
2888 (FLG_MODOBSERVERUNCON,
2890 ("Call to unconstrained function %s may modify observer%q: %s",
2891 exprNode_unparse (f),
2892 sRef_unparsePreOpt (s), exprNode_unparse (e)),
2895 sRef_showExpInfo (s);
2899 } end_exprNodeList_elements;
2904 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
2906 ret->uses = sRefSet_union (ret->uses, f->uses);
2907 ret->sets = sRefSet_union (ret->sets, f->sets);
2908 ret->msets = sRefSet_union (ret->msets, f->msets);
2913 ** Spurious errors reported, because lclint can't tell
2914 ** mods must be fresh if freshMods is true.
2917 /*@i@*/ sRefSet_free (mods);
2923 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
2925 if (uentry_isVar (glob))
2927 if (context_inFunctionLike ())
2929 sRef sr = uentry_getSref (glob);
2931 context_usedGlobal (sr);
2933 if (context_checkGlobUse (glob))
2935 if (!context_globAccess (sr))
2941 message ("Called procedure %s may access %s %q",
2942 exprNode_unparse (e),
2943 sRef_unparseScope (sr),
2944 uentry_getName (glob)),
2951 message ("Undocumented use of %s %s",
2952 sRef_unparseScope (sr),
2953 exprNode_unparse (e)),
2962 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
2966 static /*@only@*/ exprNode
2967 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
2968 ctype t, /*@keep@*/ exprNodeList args)
2970 /* requires f is a non-error exprNode, with type function */
2971 cstring fname = exprNode_unparse (f);
2972 uentry le = exprNode_getUentry (f);
2973 exprNode ret = exprNode_createPartialCopy (f);
2978 ret->typ = ctype_returnValue (t);
2979 ret->kind = XPR_CALL;
2981 ret->edata = exprData_makeCall (f, args);
2984 ** Order of these steps is very important!
2986 ** Must check for argument dependencies before messing up uses and sets.
2989 if (context_getFlag (FLG_EVALORDER))
2991 exprNodeList_elements (args, current)
2993 if (exprNode_isDefined (current))
2995 exprNode_addUse (current, current->sref);
2997 } end_exprNodeList_elements;
2999 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3001 checkSequencing (f, args);
3004 exprNodeList_elements (args, current)
3006 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3008 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3010 } end_exprNodeList_elements ;
3013 special = checkArgs (le, f, t, args, ret);
3014 checkGlobMods (f, le, args, ret, special);
3018 if (uentry_isValid (le)
3019 && (uentry_isFunction (le)
3020 || (uentry_isVariable (le)
3021 && ctype_isFunction (uentry_getType (le)))))
3023 exitkind exk = uentry_getExitCode (le);
3025 /* f->typ is already set to the return type */
3027 ret->sref = uentry_returnedRef (le, args);
3029 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3031 qual nullPred = uentry_nullPred (le);
3033 if (qual_isTrueNull (nullPred))
3035 exprNode arg = exprNodeList_head (args);
3037 if (exprNode_isDefined (arg))
3039 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3042 else if (qual_isFalseNull (nullPred))
3044 exprNode arg = exprNodeList_head (args);
3046 if (exprNode_isDefined (arg))
3048 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3053 llassert (qual_isUnknown (nullPred));
3057 if (exitkind_isConditionalExit (exk))
3061 ** if (arg0) then { exit! } else { ; }
3063 ** if (arg0) then { ; } else { exit! }
3068 llassert (!exprNodeList_isEmpty (args));
3069 firstArg = exprNodeList_head (args);
3071 if (exprNode_isDefined (firstArg)
3072 && !guardSet_isEmpty (firstArg->guards))
3074 usymtab_trueBranch (guardSet_undefined);
3075 usymtab_altBranch (guardSet_undefined);
3077 if (exitkind_isTrueExit (exk))
3079 usymtab_popBranches (firstArg,
3080 exprNode_makeMustExit (),
3082 TRUE, TRUEEXITCLAUSE);
3086 usymtab_popBranches (firstArg,
3088 exprNode_makeMustExit (),
3089 TRUE, FALSEEXITCLAUSE);
3093 ret->exitCode = XK_MAYEXIT;
3095 else if (exitkind_mustExit (exk))
3097 ret->exitCode = XK_MUSTEXIT;
3099 else if (exitkind_couldExit (exk))
3101 ret->exitCode = XK_MAYEXIT;
3108 if (cstring_equalLit (fname, "exit"))
3110 if (exprNodeList_size (args) == 1)
3112 exprNode arg = exprNodeList_head (args);
3114 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3116 long int val = multiVal_forceInt (exprNode_getValue (arg));
3123 ("Argument to exit has implementation defined behavior: %s",
3124 exprNode_unparse (arg)),
3125 exprNode_loc (arg));
3134 exprNode_checkSetAny (ret, uentry_rawName (le));
3141 ** this is yucky! should keep the uentry as part of exprNode!
3144 /*@observer@*/ uentry
3145 exprNode_getUentry (exprNode e)
3147 if (exprNode_isError (e))
3149 return uentry_undefined;
3153 cstring s = exprNode_rootVarName (e);
3154 uentry ue = usymtab_lookupSafe (s);
3161 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3163 exprNode ret = exprNode_createPlain (ctype_unknown);
3165 ret->kind = XPR_INITBLOCK;
3166 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3167 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3173 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3179 if (exprNode_isUndefined (f))
3182 exprNodeList_free (args);
3183 return exprNode_undefined;
3186 t = exprNode_getType (f);
3188 if (sRef_isLocalVar (f->sref))
3190 exprNode_checkUse (f, f->sref, f->loc);
3192 if (sRef_possiblyNull (f->sref))
3194 if (!usymtab_isGuarded (f->sref))
3196 if (optgenerror (FLG_NULLDEREF,
3197 message ("Function call using %s pointer %q",
3198 sRef_nullMessage (f->sref),
3199 sRef_unparse (f->sref)),
3202 sRef_showNullInfo (f->sref);
3203 sRef_setNullError (f->sref);
3211 if (ctype_isRealFunction (t))
3213 exprNode ret = functionCallSafe (f, t, args);
3217 else if (ctype_isUnknown (t))
3219 exprNode ret = exprNode_createPartialCopy (f);
3225 exprNodeList_elements (args, current)
3227 if (exprNode_isDefined (current))
3229 exprNode_checkUse (ret, current->sref, ret->loc);
3232 ** also, anything derivable from current->sref may be used
3235 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3236 exprNode_mergeUSs (ret, current);
3238 } end_exprNodeList_elements;
3240 ret->edata = exprData_makeCall (f, args);
3241 ret->kind = XPR_CALL;
3243 tstring = cstring_copy (exprNode_unparse (f));
3245 cstring_markOwned (tstring);
3246 exprNode_checkSetAny (ret, tstring);
3252 voptgenerror (FLG_TYPE,
3253 message ("Call to non-function (type %t): %s", t,
3254 exprNode_unparse (f)),
3257 exprNodeList_free (args);
3259 return (exprNode_makeError ());
3264 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ cstring f)
3266 exprNode ret = exprNode_createPartialCopy (s);
3268 ret->kind = XPR_FACCESS;
3270 if (exprNode_isError (s))
3272 ret->edata = exprData_makeField (s, f);
3277 ctype t = exprNode_getType (s);
3278 ctype tr = ctype_realType (t);
3280 checkMacroParen (s);
3282 ret->edata = exprData_makeField (s, f);
3284 if (ctype_isStructorUnion (tr))
3286 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
3288 if (uentry_isUndefined (tf))
3290 voptgenerror (FLG_TYPE,
3291 message ("Access non-existent field %s of %t: %s", f, t,
3292 exprNode_unparse (ret)),
3299 uentry_setUsed (tf, exprNode_loc (ret));
3301 ret->typ = uentry_getType (tf);
3302 checkSafeUse (ret, s->sref);
3304 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
3308 else /* isStructorUnion */
3310 if (ctype_isRealAbstract (tr))
3314 message ("Access field of abstract type (%t): %s.%s",
3315 t, exprNode_unparse (s), f),
3317 ret->typ = ctype_unknown;
3321 if (ctype_isKnown (tr))
3326 ("Access field of non-struct or union (%t): %s.%s",
3327 t, exprNode_unparse (s), f),
3330 ret->typ = ctype_unknown;
3334 cstring sn = cstring_copy (f);
3336 checkSafeUse (ret, s->sref);
3337 cstring_markOwned (sn);
3338 ret->sref = sRef_makeField (s->sref, sn);
3350 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
3352 exprNode ret = exprNode_createPartialCopy (e);
3354 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
3355 ret->kind = XPR_PARENS;
3356 ret->edata = exprData_makeUop (e, lpar);
3358 if (!exprNode_isError (e))
3360 ret->exitCode = e->exitCode;
3361 ret->canBreak = e->canBreak;
3362 ret->mustBreak = e->mustBreak;
3363 ret->isJumpPoint = e->isJumpPoint;
3364 ret->sref = e->sref;
3371 exprNode_arrowAccess (/*@only@*/ exprNode s, /*@only@*/ cstring f)
3373 exprNode ret = exprNode_createPartialCopy (s);
3375 ret->edata = exprData_makeField (s, f);
3376 ret->kind = XPR_ARROW;
3378 if (exprNode_isError (s))
3384 ctype t = exprNode_getType (s);
3385 ctype tr = ctype_realType (t);
3387 checkMacroParen (s);
3389 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
3391 if (ctype_isRealPointer (tr))
3393 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
3395 if (ctype_isStructorUnion (b))
3397 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
3399 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
3401 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
3405 message ("Arrow access from %s pointer%q: %s",
3406 sRef_nullMessage (s->sref),
3407 sRef_unparsePreOpt (s->sref),
3408 exprNode_unparse (ret)),
3411 sRef_showNullInfo (s->sref);
3412 sRef_setNullError (s->sref);
3417 if (uentry_isUndefined (fentry))
3421 message ("Access non-existent field %s of %t: %s",
3422 f, t, exprNode_unparse (ret)),
3424 ret->typ = ctype_unknown;
3431 ** was safeUse: shouldn't be safe!
3434 ** rec must be defined,
3435 ** *rec must be allocated
3436 ** rec->field need only be defined it if is an rvalue
3439 uentry_setUsed (fentry, exprNode_loc (ret));
3440 ret->typ = uentry_getType (fentry);
3442 exprNode_checkUse (ret, s->sref, s->loc);
3444 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
3445 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
3449 else /* Pointer to something that is not a struct or union*/
3451 if (ctype_isRealAbstract (tr))
3453 ctype xrt = ctype_forceRealType (tr);
3457 message ("Arrow access field of abstract type (%t): %s->%s",
3458 t, exprNode_unparse (s), f),
3462 ** Set the state correctly, as if the abstraction is broken.
3465 if (ctype_isRealPointer (xrt) &&
3466 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
3467 ctype_isStructorUnion (b)))
3469 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
3470 ret->typ = uentry_getType (fentry);
3471 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
3475 ret->typ = ctype_unknown;
3476 ret->sref = sRef_undefined;
3479 else /* not a struct, union or abstract */
3481 if (ctype_isUnknown (tr)) {
3482 cstring sn = cstring_copy (f);
3484 DPRINTF (("Here: %s", exprNode_unparse (s)));
3486 exprNode_checkUse (ret, s->sref, s->loc);
3487 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
3489 cstring_markOwned (sn);
3490 ret->sref = sRef_makeArrow (s->sref, sn);
3492 ret->kind = XPR_ARROW;
3497 message ("Arrow access field of non-struct or union "
3498 "pointer (%t): %s->%s",
3499 t, exprNode_unparse (s), f),
3502 ret->typ = ctype_unknown;
3503 ret->sref = sRef_undefined;
3508 else /* its not a pointer */
3510 if (!ctype_isUnknown (tr))
3514 message ("Arrow access of non-pointer (%t): %s->%s",
3515 t, exprNode_unparse (s), f),
3518 ret->typ = ctype_unknown;
3519 ret->sref = sRef_undefined;
3523 cstring sn = cstring_copy (f);
3525 DPRINTF (("Here: %s", exprNode_unparse (s)));
3527 exprNode_checkUse (ret, s->sref, s->loc);
3528 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
3530 cstring_markOwned (sn);
3531 ret->sref = sRef_makeArrow (s->sref, sn);
3533 ret->kind = XPR_ARROW;
3544 ** only postOp's in C: i++ and i--
3548 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
3550 /* check modification also */
3551 /* cstring opname = lltok_unparse (op);*/
3553 exprNode ret = exprNode_createPartialCopy (e);
3555 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
3556 ret->kind = XPR_POSTOP;
3557 ret->edata = exprData_makeUop (e, op);
3559 if (!exprNode_isDefined (e))
3564 checkMacroParen (e);
3566 exprNode_checkUse (ret, e->sref, e->loc);
3567 exprNode_checkSet (ret, e->sref);
3569 t = exprNode_getType (e);
3571 if (sRef_isUnsafe (e->sref))
3573 voptgenerror (FLG_MACROPARAMS,
3574 message ("Operand of %s is macro parameter (non-functional): %s%s",
3575 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
3577 sRef_makeSafe (e->sref);
3578 sRef_makeSafe (ret->sref);
3581 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
3587 if (ctype_isRealAbstract (t))
3591 message ("Operand of %s is abstract type (%t): %s",
3592 lltok_unparse (op), t, exprNode_unparse (e)),
3599 message ("Operand of %s is non-numeric (%t): %s",
3600 lltok_unparse (op), t, exprNode_unparse (e)),
3603 ret->typ = ctype_unknown;
3606 /* if (ctype_isZero (t)) e->typ = ctype_int; */
3608 exprNode_checkModify (e, ret);
3610 /* added 7/11/2000 D.L */
3612 // updateEnvironmentForPostOp (e);
3614 /* start modifications */
3615 /* added by Seejo on 4/16/2000 */
3617 /* Arithmetic operations on pointers wil modify the size/len/null terminated
3619 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
3621 ret->sref = sRef_copy (e->sref);
3624 if (lltok_getTok (op) == INC_OP) {
3625 if (sRef_getSize(e->sref) > 0) {
3627 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
3629 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
3630 /* Assumption: there is only 1 \0 in the buffer */
3631 /* This will not be correct if there are 2 \0's in the buffer */
3632 sRef_setNotNullTerminatedState(ret->sref);
3633 sRef_resetLen(ret->sref);
3635 sRef_setNullTerminatedState(ret->sref);
3636 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
3638 if (sRef_isNullTerminated (ret->sref))
3639 printf ("ret->sref is Null Terminated\n");
3640 else if (sRef_isPossiblyNullTerminated (ret->sref))
3641 printf ("ret->sref is Possibly Null Terminated\n");
3642 else if (sRef_isNotNullTerminated (ret->sref))
3643 printf ("ret->sref is Not Null Terminated\n");
3648 if (lltok_getTok (op) == DEC_OP) {
3649 if (sRef_getSize(e->sref) >= 0) {
3650 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
3651 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
3656 /* end modifications */
3662 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
3664 bool checkMod = FALSE;
3666 int opid = lltok_getTok (op);
3667 exprNode ret = exprNode_createSemiCopy (e);
3669 exprNode_copySets (ret, e);
3671 multiVal_free (ret->val);
3672 ret->val = multiVal_undefined;
3673 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
3674 ret->kind = XPR_PREOP;
3675 ret->edata = exprData_makeUop (e, op);
3677 if (exprNode_isError (e))
3682 checkMacroParen (e);
3684 te = exprNode_getType (e);
3685 tr = ctype_realType (te);
3687 if (opid != TAMPERSAND)
3689 exprNode_checkUse (ret, e->sref, e->loc);
3691 if (ctype_isRealAbstract (tr)
3692 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
3694 if (optgenerror (FLG_ABSTRACT,
3695 message ("Operand of %s is abstract type (%t): %s",
3696 lltok_unparse (op), tr,
3697 exprNode_unparse (ret)),
3700 tr = te = ctype_unknown;
3701 ret->typ = ctype_unknown;
3702 sRef_setNullError (e->sref);
3710 case DEC_OP: /* should also check modification! */
3712 if (sRef_isMacroParamRef (e->sref))
3716 message ("Operand of %s is macro parameter (non-functional): %s",
3717 lltok_unparse (op), exprNode_unparse (ret)),
3722 exprNode_checkSet (ret, e->sref);
3725 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
3730 if (context_msgStrictOps ())
3734 message ("Operand of %s is non-numeric (%t): %s",
3735 lltok_unparse (op), te, exprNode_unparse (ret)),
3738 ret->typ = ctype_int;
3741 /* start modifications */
3742 /* added by Seejo on 4/16/2000 */
3744 /* Arithmetic operations on pointers wil modify the size/len/null terminated
3746 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
3748 ret->sref = sRef_copy (e->sref);
3751 if (lltok_getTok (op) == INC_OP) {
3752 if (sRef_getSize(e->sref) > 0) {
3754 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
3756 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
3757 /* Assumption: there is only 1 \0 in the buffer */
3758 /* This will not be correct if there are 2 \0's in the buffer */
3759 sRef_setNotNullTerminatedState(ret->sref);
3760 sRef_resetLen (ret->sref);
3762 sRef_setNullTerminatedState(ret->sref);
3763 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
3769 if (lltok_getTok (op) == DEC_OP) {
3770 if (sRef_getSize(e->sref) >= 0) {
3771 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
3772 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
3777 /* end modifications */
3784 if (ctype_isForceRealNumeric (&tr))
3788 ret->val = multiVal_invert (exprNode_getValue (e));
3792 ret->val = multiVal_copy (exprNode_getValue (e));
3797 if (context_msgStrictOps ())
3801 message ("Operand of %s is non-numeric (%t): %s",
3802 lltok_unparse (op), te, exprNode_unparse (ret)),
3806 ret->typ = ctype_int;
3810 case TEXCL: /* maybe this should be restricted */
3811 guardSet_flip (ret->guards);
3813 if (ctype_isRealBool (te))
3819 if (ctype_isRealPointer (tr))
3821 if (sRef_isKnown (e->sref))
3823 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
3827 (FLG_BOOLOPS, FLG_PTRNEGATE,
3828 message ("Operand of %s is non-boolean (%t): %s",
3829 lltok_unparse (op), te, exprNode_unparse (ret)),
3836 message ("Operand of %s is non-boolean (%t): %s",
3837 lltok_unparse (op), te, exprNode_unparse (ret)),
3841 ret->typ = ctype_bool;
3846 if (ctype_isForceRealInt (&tr))
3851 if (context_msgStrictOps ())
3855 message ("Operand of %s is non-integer (%t): %s",
3856 lltok_unparse (op), te, exprNode_unparse (ret)),
3860 if (ctype_isInt (e->typ))
3866 ret->typ = ctype_int;
3872 ret->typ = ctype_makePointer (e->typ);
3874 if (sRef_isKnown (e->sref))
3876 ret->sref = sRef_makeAddress (e->sref);
3883 if (ctype_isAP (tr))
3885 ret->typ = ctype_baseArrayPtr (e->typ);
3889 if (ctype_isKnown (te))
3891 if (ctype_isFunction (te))
3897 message ("Dereference of function type (%t): %s",
3898 te, exprNode_unparse (ret)),
3903 voptgenerror (FLG_TYPE,
3904 message ("Dereference of non-pointer (%t): %s",
3905 te, exprNode_unparse (ret)),
3907 ret->typ = ctype_unknown;
3912 ret->typ = ctype_unknown;
3917 if (sRef_isKnown (e->sref))
3919 if (sRef_possiblyNull (e->sref))
3921 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
3925 message ("Dereference of %s pointer %q: %s",
3926 sRef_nullMessage (e->sref),
3927 sRef_unparse (e->sref),
3928 exprNode_unparse (ret)),
3931 sRef_showNullInfo (e->sref);
3932 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
3937 ret->sref = sRef_makePointer (e->sref);
3942 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
3947 exprNode_checkModify (e, ret);
3954 ** any reason to disallow sizeof (abstract type) ?
3958 ** used by both sizeof
3962 ctype sizeof_resultType (void)
3964 static ctype sizet = ctype_unknown;
3966 if (ctype_isUnknown (sizet))
3968 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
3970 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
3974 sizet = ctype_ulint;
3981 exprNode_sizeofType (/*@only@*/ qtype qt)
3983 exprNode ret = exprNode_create (sizeof_resultType ());
3984 ctype ct = qtype_getType (qt);
3986 ret->kind = XPR_SIZEOFT;
3987 ret->edata = exprData_makeSizeofType (qt);
3989 voptgenerror (FLG_SIZEOFTYPE,
3990 message ("Parameter to sizeof is type %s: %s",
3992 exprNode_unparse (ret)),
3999 exprNode_alignofType (/*@only@*/ qtype qt)
4001 exprNode ret = exprNode_create (sizeof_resultType ());
4002 ctype ct = qtype_getType (qt);
4004 ret->kind = XPR_ALIGNOFT;
4005 ret->edata = exprData_makeSizeofType (qt);
4007 voptgenerror (FLG_SIZEOFTYPE,
4008 message ("Parameter to alignof is type %s: %s",
4010 exprNode_unparse (ret)),
4016 exprNode exprNode_offsetof (qtype qt, cstringList s)
4018 exprNode ret = exprNode_create (sizeof_resultType ());
4019 ctype ct = qtype_getType (qt);
4021 ret->kind = XPR_OFFSETOF;
4022 ret->edata = exprData_makeOffsetof (qt, s);
4024 if (!ctype_isRealSU (ct))
4026 voptgenerror (FLG_TYPE,
4027 message ("First parameter to offsetof is not a "
4028 "struct or union type (type %s): %s",
4030 exprNode_unparse (ret)),
4037 cstringList_elements (s, el) {
4041 if (ctype_isUndefined (lt))
4045 else if (!ctype_isRealSU (lt))
4047 voptgenerror (FLG_TYPE,
4048 message ("Inner offsetof type is not a "
4049 "struct or union type (type %s before field %s): %s",
4050 ctype_unparse (lt), el,
4051 exprNode_unparse (ret)),
4057 fields = ctype_getFields (ctype_realType (lt));
4058 fld = uentryList_lookupField (fields, el);
4059 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4061 if (uentry_isUndefined (fld))
4063 if (ctype_equal (lt, ct)) {
4064 voptgenerror (FLG_TYPE,
4065 message ("Field %s in offsetof is not the "
4066 "name of a field of %s: %s",
4069 exprNode_unparse (ret)),
4072 voptgenerror (FLG_TYPE,
4073 message ("Deep field %s in offsetof is not the "
4074 "name of a field of %s: %s",
4077 exprNode_unparse (ret)),
4083 lt = uentry_getType (fld);
4086 } end_cstringList_elements;
4088 /* Should report error if its a bit field - behavior is undefined! */
4095 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4099 if (exprNode_isUndefined (e))
4101 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4102 ret->edata = exprData_makeSingle (e);
4103 ret->typ = sizeof_resultType ();
4104 ret->kind = XPR_SIZEOF;
4108 uentry u = exprNode_getUentry (e);
4110 ret = exprNode_createPartialCopy (e);
4111 ret->edata = exprData_makeSingle (e);
4113 ret->typ = sizeof_resultType ();
4114 ret->kind = XPR_SIZEOF;
4116 if (uentry_isValid (u)
4117 && uentry_isRefParam (u)
4118 && ctype_isRealArray (uentry_getType (u)))
4121 (FLG_SIZEOFFORMALARRAY,
4122 message ("Parameter to sizeof is an array-type function parameter: %s",
4123 exprNode_unparse (ret)),
4129 ** sizeof (x) doesn't "really" use x
4136 exprNode_alignofExpr (/*@only@*/ exprNode e)
4140 if (exprNode_isUndefined (e))
4142 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4146 ret = exprNode_createPartialCopy (e);
4149 ret->edata = exprData_makeSingle (e);
4150 ret->typ = sizeof_resultType ();
4151 ret->kind = XPR_ALIGNOF;
4154 ** sizeof (x) doesn't "really" use x
4161 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4167 if (exprNode_isError (e))
4170 lltok_release (tok);
4171 return exprNode_undefined;
4174 checkMacroParen (e);
4176 c = qtype_getType (q);
4177 t = exprNode_getType (e);
4179 ret = exprNode_createPartialCopy (e);
4181 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
4183 ret->kind = XPR_CAST;
4184 ret->edata = exprData_makeCast (tok, e, q);
4186 if (ctype_isRealSU (ctype_getBaseType (sRef_getType (e->sref))))
4189 ** This is a bit of a hack to avoid a problem
4190 ** when the code does,
4191 ** (some other struct) x
4196 ret->sref = sRef_copy (e->sref);
4197 usymtab_addForceMustAlias (ret->sref, e->sref);
4198 sRef_setTypeFull (ret->sref, c);
4199 DPRINTF (("Cast: %s -> %s", sRef_unparseFull (e->sref),
4200 sRef_unparseFull (ret->sref)));
4204 ret->sref = e->sref;
4205 sRef_setTypeFull (ret->sref, c);
4206 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
4213 ** void * <-> abstract * (if FLG_ABSTVOIDP)
4214 ** abstract * <-> void * (if FLG_ABSTVOIDP)
4217 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
4221 else if (ctype_isRealAP (c)) /* casting to array or pointer */
4223 ctype bc = ctype_getBaseType (c);
4224 ctype bt = ctype_getBaseType (t);
4225 ctype rt = ctype_realType (t);
4227 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
4228 && (ctype_isArrayPtr (rt)
4229 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4233 message ("Cast from function pointer type (%t) to "
4234 "non-function pointer (%t): %s",
4235 c, t, exprNode_unparse (ret)),
4239 if (!ctype_isFunction (ctype_baseArrayPtr (c))
4240 && (ctype_isArrayPtr (rt)
4241 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4245 message ("Cast from non-function pointer type (%t) to "
4246 "function pointer (%t): %s",
4247 c, t, exprNode_unparse (ret)),
4251 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
4252 !(ctype_isRealAbstract (bc)
4253 && context_hasAccess (ctype_typeId (bc))))
4255 ; /* okay to cast zero */
4259 if (ctype_isRealAbstract (bc)
4260 && !context_hasAccess (ctype_typeId (bc)))
4262 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
4266 message ("Cast to underlying abstract type %t: %s",
4267 c, exprNode_unparse (ret)),
4274 message ("Cast to underlying abstract type %t: %s",
4275 c, exprNode_unparse (ret)),
4280 if (ctype_isRealAbstract (bt)
4281 && !context_hasAccess (ctype_typeId (bt)))
4283 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
4287 message ("Cast from underlying abstract type %t: %s",
4288 t, exprNode_unparse (ret)),
4295 message ("Cast from underlying abstract type %t: %s",
4296 t, exprNode_unparse (ret)),
4304 ctype bt = ctype_realType (ctype_getBaseType (t));
4305 ctype bc = ctype_realType (ctype_getBaseType (c));
4307 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
4309 if (ctype_match (c, t))
4311 if (ctype_equal (c, t))
4315 message ("Redundant cast involving abstract type %t: %s",
4316 bt, exprNode_unparse (ret)),
4324 message ("Cast from abstract type %t: %s",
4325 bt, exprNode_unparse (ret)),
4330 if (ctype_isAbstract (bc)
4331 && !context_hasAccess (ctype_typeId (bc)))
4333 if (ctype_match (c, t))
4341 message ("Cast to abstract type %t: %s", bc,
4342 exprNode_unparse (ret)),
4348 if (ctype_isAbstract (c))
4350 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
4352 /* okay, cast exposed to abstract */
4353 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
4357 if (ctype_isVisiblySharable (t)
4358 && sRef_isExternallyVisible (e->sref)
4359 && !(ctype_isAbstract (t)
4360 && context_hasAccess (ctype_typeId (t))))
4364 message ("Cast to abstract type from externally visible "
4365 "mutable storage exposes rep of %s: %s",
4367 exprNode_unparse (e)),
4377 evaluationOrderUndefined (lltok op)
4379 int opid = lltok_getTok (op);
4381 return (opid != AND_OP && opid != OR_OP);
4384 static bool checkIntegral (/*@notnull@*/ exprNode e1,
4385 /*@notnull@*/ exprNode e2,
4386 /*@notnull@*/ exprNode ret,
4391 ctype te1 = exprNode_getType (e1);
4392 ctype te2 = exprNode_getType (e2);
4394 ctype tr1 = ctype_realishType (te1);
4395 ctype tr2 = ctype_realishType (te2);
4397 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
4403 if (context_msgStrictOps ())
4405 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
4407 if (ctype_sameName (te1, te2))
4411 message ("Operands of %s are non-integer (%t): %s",
4412 lltok_unparse (op), te1,
4413 exprNode_unparse (ret)),
4420 message ("Operands of %s are non-integers (%t, %t): %s",
4421 lltok_unparse (op), te1, te2,
4422 exprNode_unparse (ret)),
4426 else if (!ctype_isInt (tr1))
4430 message ("Left operand of %s is non-integer (%t): %s",
4431 lltok_unparse (op), te1, exprNode_unparse (ret)),
4435 /* !ctype_isInt (te2) */
4439 message ("Right operand of %s is non-integer (%t): %s",
4440 lltok_unparse (op), te2, exprNode_unparse (ret)),
4450 ** returns exprNode representing e1 op e2
4452 ** uses msg if there are errors
4453 ** can be used for both assignment ops and regular ops
4458 static /*@only@*/ /*@notnull@*/ exprNode
4459 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
4460 /*@keep@*/ lltok op)
4462 ctype te1, te2, tr1, tr2, tret;
4463 int opid = lltok_getTok (op);
4464 bool hasError = FALSE;
4467 if (exprNode_isError (e1))
4469 ret = exprNode_createPartialNVCopy (e2);
4473 ret = exprNode_createPartialNVCopy (e1);
4476 ret->val = multiVal_undefined;
4478 ret->edata = exprData_makeOp (e1, e2, op);
4480 if (exprNode_isError (e1) || exprNode_isError (e2))
4482 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
4483 || opid == EQ_OP || opid == NE_OP
4484 || opid == AND_OP || opid == OR_OP)
4486 ret->typ = ctype_bool;
4489 if (exprNode_isDefined (e1))
4491 exprNode_checkUse (ret, e1->sref, e1->loc);
4494 if (exprNode_isDefined (e2))
4496 exprNode_mergeUSs (ret, e2);
4497 exprNode_checkUse (ret, e2->sref, e2->loc);
4503 tret = ctype_unknown;
4504 te1 = exprNode_getType (e1);
4505 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
4507 te2 = exprNode_getType (e2);
4509 tr1 = ctype_realishType (te1);
4510 tr2 = ctype_realishType (te2);
4514 ret->guards = guardSet_or (ret->guards, e2->guards);
4516 else if (opid == AND_OP)
4518 ret->guards = guardSet_and (ret->guards, e2->guards);
4525 if (opid == EQ_OP || opid == NE_OP)
4527 exprNode temp1 = e1, temp2 = e2;
4529 /* could do NULL == x */
4531 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
4533 temp1 = e2; temp2 = e1;
4536 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
4538 reflectNullTest (temp1, (opid == NE_OP));
4539 guardSet_free (ret->guards);
4540 ret->guards = guardSet_copy (temp1->guards);
4544 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
4545 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
4550 if (anyAbstract (tr1, tr2) &&
4551 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
4552 (opid == AND_OP || opid == OR_OP
4553 || opid == EQ_OP || opid == NE_OP))))
4555 abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc);
4557 else if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
4559 /* unknown types, no comparisons possible */
4565 case TMULT: /* multiplication and division: */
4567 case MUL_ASSIGN: /* numeric, numeric -> numeric */
4568 case DIV_ASSIGN: /* */
4570 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4573 case TPLUS: /* addition and subtraction: */
4574 case TMINUS: /* pointer, int -> pointer */
4575 case SUB_ASSIGN: /* int, pointer -> pointer */
4576 case ADD_ASSIGN: /* numeric, numeric -> numeric */
4578 tr1 = ctype_fixArrayPtr (tr1);
4580 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
4581 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
4585 if (context_msgPointerArith ())
4589 message ("Pointer arithmetic (%t, %t): %s",
4590 te1, te2, exprNode_unparse (ret)),
4594 if (sRef_possiblyNull (e1->sref)
4595 && !usymtab_isGuarded (e1->sref))
4598 (FLG_NULLPOINTERARITH,
4599 message ("Pointer arithmetic involving possibly "
4600 "null pointer %s: %s",
4601 exprNode_unparse (e1),
4602 exprNode_unparse (ret)),
4606 ret->sref = sRef_copy (e1->sref);
4608 /* start modifications */
4609 /* added by Seejo on 4/16/2000 */
4611 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4613 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
4614 //if (sRef_isKnown (e->sref)) {
4615 //ret->sref = sRef_makeAddress (e->sref);
4620 added ugly fixed to stop
4621 program from crashing on point + int +int
4622 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
4624 if (!multiVal_isInt (e2->val) )
4628 val = (int) multiVal_forceInt (e2->val);
4630 /* Operator : + or += */
4631 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4632 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
4633 val should not result in a
4634 size < 0 (size = 0 is ok !) */
4636 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
4638 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
4639 sRef_setNotNullTerminatedState(ret->sref);
4640 sRef_resetLen (ret->sref);
4642 sRef_setNullTerminatedState(ret->sref);
4643 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
4648 /* Operator : - or -= */
4649 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4650 if (sRef_getSize(e1->sref) >= 0) {
4651 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
4652 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
4657 /* end modifications */
4659 sRef_setNullError (ret->sref);
4662 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4663 ** since is points to storage that should not be deallocated
4664 ** through this pointer.
4667 if (sRef_isOnly (ret->sref)
4668 || sRef_isFresh (ret->sref))
4670 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4675 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
4676 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
4678 if (context_msgPointerArith ())
4682 message ("Pointer arithmetic (%t, %t): %s",
4683 te1, te2, exprNode_unparse (ret)),
4687 if (sRef_possiblyNull (e1->sref)
4688 && !usymtab_isGuarded (e1->sref))
4691 (FLG_NULLPOINTERARITH,
4692 message ("Pointer arithmetic involving possibly "
4693 "null pointer %s: %s",
4694 exprNode_unparse (e2),
4695 exprNode_unparse (ret)),
4699 ret->sref = sRef_copy (e2->sref);
4701 /* start modifications */
4702 /* added by Seejo on 4/16/2000 */
4704 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4707 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
4708 //if (sRef_isKnown (e->sref)) {
4709 //ret->sref = sRef_makeAddress (e->sref);
4712 int val = (int) multiVal_forceInt (e1->val);
4714 /* Operator : + or += */
4715 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4716 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
4717 val should not result in a
4718 size < 0 (size = 0 is ok !) */
4720 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
4722 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
4723 sRef_setNotNullTerminatedState(ret->sref);
4724 sRef_resetLen (ret->sref);
4726 sRef_setNullTerminatedState(ret->sref);
4727 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
4732 /* Operator : - or -= */
4733 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4734 if (sRef_getSize(e2->sref) >= 0) {
4735 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
4736 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
4741 /* end modifications */
4743 sRef_setNullError (ret->sref);
4746 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4747 ** since is points to storage that should not be deallocated
4748 ** through this pointer.
4751 if (sRef_isOnly (ret->sref)
4752 || sRef_isFresh (ret->sref)) {
4753 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4757 ret->sref = e2->sref;
4761 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4766 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
4770 case TAMPERSAND: /* bitwise & */
4772 case TCIRC: /* ^ (XOR) */
4777 bool reported = FALSE;
4778 flagcode code = FLG_BITWISEOPS;
4780 if (opid == LEFT_OP || opid == LEFT_ASSIGN
4781 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
4782 code = FLG_SHIFTSIGNED;
4785 if (!ctype_isUnsigned (tr1))
4787 if (exprNode_isNonNegative (e1)) {
4790 reported = optgenerror
4792 message ("Left operand of %s is not unsigned value (%t): %s",
4793 lltok_unparse (op), te1,
4794 exprNode_unparse (ret)),
4804 /* right need not be signed for shifts */
4805 if (code != FLG_SHIFTSIGNED
4806 && !ctype_isUnsigned (tr2))
4808 if (!exprNode_isNonNegative (e2)) {
4809 reported = optgenerror
4811 message ("Right operand of %s is not unsigned value (%t): %s",
4812 lltok_unparse (op), te2,
4813 exprNode_unparse (ret)),
4821 if (!checkIntegral (e1, e2, ret, op)) {
4822 te1 = ctype_unknown;
4826 DPRINTF (("Set: %s", ctype_unparse (te1)));
4829 ** tret is the widest type of te1 and te2
4832 tret = ctype_widest (te1, te2);
4837 if (checkIntegral (e1, e2, ret, op)) {
4840 tret = ctype_unknown;
4845 case TLT: /* comparisons */
4846 case TGT: /* numeric, numeric -> bool */
4847 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
4848 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
4851 bool fepsilon = FALSE;
4853 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
4858 if (opid == TLT || opid == TGT)
4860 uentry ue1 = exprNode_getUentry (e1);
4861 uentry ue2 = exprNode_getUentry (e2);
4864 ** FLT_EPSILON, etc. really is a variable, not
4868 if (uentry_isVariable (ue1))
4870 cstring uname = uentry_rawName (ue1);
4872 if (cstring_equalLit (uname, "FLT_EPSILON")
4873 || cstring_equalLit (uname, "DBL_EPSILON")
4874 || cstring_equalLit (uname, "LDBL_EPSILON"))
4880 if (uentry_isVariable (ue2))
4882 cstring uname = uentry_rawName (ue2);
4884 if (cstring_equalLit (uname, "FLT_EPSILON")
4885 || cstring_equalLit (uname, "DBL_EPSILON")
4886 || cstring_equalLit (uname, "LDBL_EPSILON"))
4895 ; /* Don't complain. */
4901 message ("Dangerous comparison involving %s types: %s",
4902 ctype_unparse (rtype),
4903 exprNode_unparse (ret)),
4912 ** Types should match.
4915 if (!exprNode_matchTypes (e1, e2))
4917 hasError = gentypeerror
4919 message ("Operands of %s have incompatible types (%t, %t): %s",
4920 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
4926 || (ctype_isForceRealNumeric (&tr1)
4927 && ctype_isForceRealNumeric (&tr2)) ||
4928 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
4934 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
4935 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
4939 message ("Comparison of pointer and numeric (%t, %t): %s",
4940 te1, te2, exprNode_unparse (ret)),
4945 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4950 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
4952 if ((opid == EQ_OP || opid == NE_OP) &&
4953 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
4956 ** is one a variable?
4959 if (uentry_isVariable (exprNode_getUentry (e1))
4960 || uentry_isVariable (exprNode_getUentry (e2)))
4963 ** comparisons with FALSE are okay
4966 if (exprNode_isFalseConstant (e1)
4967 || exprNode_isFalseConstant (e2))
4976 ("Use of %q with %s variables (risks inconsistency because "
4977 "of multiple true values): %s",
4978 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
4979 context_printBoolName (), exprNode_unparse (ret)),
4986 case AND_OP: /* bool, bool -> bool */
4989 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
4995 if (context_maybeSet (FLG_BOOLOPS))
4997 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
4999 if (ctype_sameName (te1, te2))
5003 message ("Operands of %s are non-boolean (%t): %s",
5004 lltok_unparse (op), te1,
5005 exprNode_unparse (ret)),
5013 ("Operands of %s are non-booleans (%t, %t): %s",
5014 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5018 else if (!ctype_isRealBool (te1))
5022 message ("Left operand of %s is non-boolean (%t): %s",
5023 lltok_unparse (op), te1, exprNode_unparse (ret)),
5026 else if (!ctype_isRealBool (te2))
5030 message ("Right operand of %s is non-boolean (%t): %s",
5031 lltok_unparse (op), te2, exprNode_unparse (ret)),
5044 (cstring_makeLiteral
5045 ("There has been a problem in the parser. This is due to a bug "
5046 "in either lclint, bison or gcc version 2.95 optimizations, "
5047 "but it has not been confirmed. Please try rebuidling LCLint "
5048 "without the -O<n> option."));
5053 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5056 exprNode_checkUse (ret, e1->sref, e1->loc);
5057 exprNode_mergeUSs (ret, e2);
5058 exprNode_checkUse (ret, e2->sref, e2->loc);
5064 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5065 /*@only@*/ lltok op)
5069 checkMacroParen (e1);
5070 checkMacroParen (e2);
5072 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5074 checkExpressionDefined (e1, e2, op);
5077 ret = exprNode_makeOp (e1, e2, op);
5082 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5085 ** This is somewhat bogus!
5087 ** Assigning to a nested observer in a non-observer datatype
5088 ** should not produce an error.
5091 sRef ref = exprNode_getSref (e1);
5093 DPRINTF (("Check assign mod: %s",
5094 sRef_unparseFull (ref)));
5096 if (sRef_isObserver (ref)
5097 || ((sRef_isFileStatic (ref) || sRef_isGlobal (ref))
5098 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5100 sRef base = sRef_getBase (ref);
5102 if (sRef_isValid (base) && sRef_isObserver (base))
5104 exprNode_checkModify (e1, ret);
5108 exprNode_checkModifyVal (e1, ret);
5113 exprNode_checkModify (e1, ret);
5118 exprNode_assign (/*@only@*/ exprNode e1,
5119 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5121 bool isalloc = FALSE;
5122 bool isjustalloc = FALSE;
5125 DPRINTF (("%s [%s] <- %s [%s]",
5126 exprNode_unparse (e1),
5127 ctype_unparse (e1->typ),
5128 exprNode_unparse (e2),
5129 ctype_unparse (e2->typ)));
5131 if (lltok_getTok (op) != TASSIGN)
5133 ret = exprNode_makeOp (e1, e2, op);
5137 ret = exprNode_createPartialCopy (e1);
5138 ret->kind = XPR_ASSIGN;
5139 ret->edata = exprData_makeOp (e1, e2, op);
5141 if (!exprNode_isError (e2))
5143 ret->sets = sRefSet_union (ret->sets, e2->sets);
5144 ret->msets = sRefSet_union (ret->msets, e2->msets);
5145 ret->uses = sRefSet_union (ret->uses, e2->uses);
5149 checkExpressionDefined (e1, e2, op);
5151 if (exprNode_isError (e1))
5153 if (!exprNode_isError (e2))
5155 ret->loc = fileloc_update (ret->loc, e2->loc);
5159 ret->loc = fileloc_update (ret->loc, g_currentloc);
5163 if (!exprNode_isError (e2))
5165 checkMacroParen (e2);
5168 if (exprNode_isDefined (e1))
5170 if (sRef_isMacroParamRef (e1->sref))
5172 if (context_inIterDef ())
5174 uentry ue = sRef_getUentry (e1->sref);
5176 if (uentry_isYield (ue))
5182 if (fileloc_isDefined (e1->loc))
5186 message ("Assignment to non-yield iter parameter: %q",
5187 sRef_unparse (e1->sref)),
5194 message ("Assignment to non-yield iter parameter: %q",
5195 sRef_unparse (e1->sref)),
5202 if (fileloc_isDefined (e1->loc))
5206 message ("Assignment to macro parameter: %q",
5207 sRef_unparse (e1->sref)),
5214 message ("Assignment to macro parameter: %q",
5215 sRef_unparse (e1->sref)),
5222 exprNode_checkAssignMod (e1, ret);
5225 if (exprNode_isDefined (e2))
5227 if (lltok_getTok (op) == TASSIGN)
5229 ctype te1 = exprNode_getType (e1);
5230 ctype te2 = exprNode_getType (e2);
5232 if (!ctype_forceMatch (te1, te2))
5234 if (exprNode_matchLiteral (te1, e2))
5242 message ("Assignment of %t to %t: %s %s %s",
5243 te2, te1, exprNode_unparse (e1),
5245 exprNode_unparse (e2)),
5251 exprNode_mergeUSs (ret, e2);
5252 exprNode_checkUse (ret, e2->sref, e2->loc);
5254 doAssign (e1, e2, FALSE);
5255 ret->sref = e1->sref;
5259 if (exprNode_isDefined (e2))
5261 exprNode_mergeUSs (ret, e2);
5262 exprNode_checkUse (ret, e2->sref, e2->loc);
5266 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5268 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5271 isjustalloc = sRef_isJustAllocated (e1->sref);
5272 isalloc = sRef_isAllocated (e1->sref);
5274 if (sRef_isField (e1->sref))
5276 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5278 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5280 exprNode_checkUse (ret, root, e1->loc);
5286 ** be careful! this defines e1->sref.
5289 if (!sRef_isMacroParamRef (e1->sref))
5291 exprNode_checkSet (ret, e1->sref);
5296 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5297 ? e2->loc : e1->loc);
5303 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5312 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5313 /*@keep@*/ exprNode elseclause)
5317 if (!exprNode_isError (pred))
5319 ret = exprNode_createPartialCopy (pred);
5320 checkMacroParen (pred);
5321 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
5323 if (!exprNode_isError (ifclause))
5325 checkMacroParen (ifclause); /* update macro counts! */
5327 if (!exprNode_isError (elseclause))
5329 checkMacroParen (elseclause);
5331 if (!exprNode_matchTypes (ifclause, elseclause))
5334 (exprNode_getType (ifclause),
5336 exprNode_getType (elseclause),
5338 message ("Conditional clauses are not of same type: "
5340 exprNode_unparse (ifclause),
5341 exprNode_getType (ifclause),
5342 exprNode_unparse (elseclause),
5343 exprNode_getType (elseclause)),
5346 ret->sref = sRef_undefined;
5347 ret->typ = ctype_unknown;
5352 /* for now...should merge the states */
5353 ret->sref = ifclause->sref;
5354 ret->typ = ifclause->typ;
5356 if (exprNode_isNullValue (ifclause))
5358 ret->typ = elseclause->typ;
5362 exprNode_checkUse (ret, pred->sref, pred->loc);
5363 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5364 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5366 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5371 ret->typ = ifclause->typ;
5373 exprNode_checkUse (pred, pred->sref, pred->loc);
5374 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5376 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
5381 if (!exprNode_isError (elseclause))
5383 ret->typ = elseclause->typ;
5385 exprNode_checkUse (pred, pred->sref, pred->loc);
5386 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5388 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5392 else /* pred is error */
5394 if (!exprNode_isError (ifclause))
5396 ret = exprNode_createSemiCopy (ifclause);
5398 checkMacroParen (ifclause); /* update macro counts! */
5400 if (!exprNode_isError (elseclause))
5402 checkMacroParen (elseclause);
5404 ret->typ = ifclause->typ;
5406 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
5409 (exprNode_getType (ifclause),
5411 exprNode_getType (elseclause),
5413 message ("Conditional clauses are not of same type: "
5415 exprNode_unparse (ifclause),
5416 exprNode_getType (ifclause),
5417 exprNode_unparse (elseclause),
5418 exprNode_getType (elseclause)),
5421 ret->typ = ctype_unknown;
5425 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5426 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5428 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5431 else if (!exprNode_isError (elseclause)) /* pred, if errors */
5433 ret = exprNode_createSemiCopy (ifclause);
5435 ret->typ = elseclause->typ;
5436 checkMacroParen (elseclause);
5438 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5439 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5441 else /* all errors! */
5443 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5447 ret->kind = XPR_COND;
5448 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
5450 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
5452 exprNode_combineControl (ret, ifclause, elseclause);
5459 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
5461 ctype totype = qtype_getType (qt);
5463 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
5467 ** check use of va_arg : <valist>, type -> type
5470 if (exprNode_isError (arg))
5475 targ = exprNode_getType (arg);
5478 ** arg should have be a pointer
5481 if (!ctype_isUA (targ) ||
5482 (!usymId_equal (ctype_typeId (targ),
5483 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
5487 message ("First argument to va_arg is not a va_list (type %t): %s",
5488 targ, exprNode_unparse (arg)),
5492 exprNode_checkSet (ret, arg->sref);
5496 ** return type is totype
5500 ret->kind = XPR_VAARG;
5501 ret->edata = exprData_makeCast (tok, arg, qt);
5506 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
5508 exprNode ret = exprNode_createPlain (ctype_undefined);
5509 ret->kind = XPR_LABEL;
5510 ret->edata = exprData_makeLiteral (label);
5511 ret->isJumpPoint = TRUE;
5513 return (ret); /* for now, ignore label */
5516 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
5518 if (exprNode_isDefined (stmt))
5520 stmt->isJumpPoint = TRUE;
5522 /* This prevent stray no return path errors, etc. */
5523 stmt->exitCode = XK_MUSTEXIT;
5529 bool exprNode_isDefaultMarker (exprNode e)
5531 if (exprNode_isDefined (e))
5533 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
5539 bool exprNode_isCaseMarker (exprNode e)
5541 if (exprNode_isDefined (e))
5543 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
5549 bool exprNode_isLabelMarker (exprNode e)
5551 if (exprNode_isDefined (e))
5553 return (e->kind == XPR_LABEL);
5559 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
5561 exprNode ret = exprNode_createPartialCopy (test);
5563 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5565 if (exprNode_isError (test)) {
5569 exprNode_checkUse (ret, test->sref, test->loc);
5571 usymtab_setExitCode (ret->exitCode);
5575 usymtab_setMustBreak ();
5578 ret->edata = exprData_makeSingle (test);
5579 ret->isJumpPoint = TRUE;
5585 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
5587 exprNode ret = exprNode_createPartialCopy (test);
5589 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5590 ret->edata = exprData_makePair (test, stmt);
5591 ret->isJumpPoint = TRUE;
5593 if (exprNode_isError (test))
5598 exprNode_checkUse (ret, test->sref, test->loc);
5600 if (exprNode_isError (stmt))
5605 exprNode_mergeUSs (ret, stmt);
5607 ret->exitCode = stmt->exitCode;
5608 ret->mustBreak = stmt->mustBreak;
5609 ret->canBreak = stmt->canBreak;
5611 usymtab_setExitCode (ret->exitCode);
5615 usymtab_setMustBreak ();
5622 /*@notnull@*/ /*@only@*/ exprNode
5623 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
5625 exprNode ret = exprNode_createTok (def);
5627 ret->isJumpPoint = TRUE;
5628 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
5633 exprNode_mayEscape (exprNode e)
5635 if (exprNode_isDefined (e))
5637 return exitkind_couldEscape (e->exitCode);
5643 exprNode_mustBreak (exprNode e)
5645 if (exprNode_isDefined (e))
5647 return e->mustBreak;
5653 exprNode_mustEscape (exprNode e)
5655 if (exprNode_isDefined (e))
5657 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
5664 exprNode_errorEscape (exprNode e)
5666 if (exprNode_isDefined (e))
5668 return exitkind_isError (e->exitCode);
5674 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
5676 exprNode ret = exprNode_createPartialCopy (e1);
5678 ret->edata = exprData_makePair (e1, e2);
5679 ret->kind = XPR_STMTLIST;
5681 if (exprNode_isDefined (e1))
5683 ret->isJumpPoint = e1->isJumpPoint;
5684 ret->canBreak = e1->canBreak;
5688 if (exprNode_isDefined (e2))
5690 ret->loc = fileloc_update (ret->loc, e2->loc);
5694 if (exprNode_isDefined (e2))
5696 ret->exitCode = e2->exitCode;
5697 ret->mustBreak = e2->mustBreak;
5698 if (e2->canBreak) ret->canBreak = TRUE;
5702 ** if e1 must return, then e2 is unreachable!
5705 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
5707 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
5708 && !(e2->isJumpPoint))
5710 if (context_getFlag (FLG_UNREACHABLE))
5714 if (e2->kind == XPR_STMT)
5716 nr = exprData_getUopNode (e2->edata);
5719 if ((nr->kind == XPR_TOK
5720 && lltok_isSemi (exprData_getTok (nr->edata))))
5722 /* okay to have unreachable ";" */
5723 ret->exitCode = XK_MUSTEXIT;
5724 ret->canBreak = TRUE;
5728 if (optgenerror (FLG_UNREACHABLE,
5729 message ("Unreachable code: %s",
5730 exprNode_unparseFirst (nr)),
5733 ret->isJumpPoint = TRUE;
5734 ret->mustBreak = FALSE;
5735 ret->exitCode = XK_ERROR;
5736 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
5740 ret->exitCode = XK_MUSTEXIT;
5741 ret->canBreak = TRUE;
5749 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
5752 ** We want a warning anytime we have:
5754 ** yyy; <<<- no break or return
5758 exprNode lastStmt = exprNode_lastStatement (e1);
5760 if (exprNode_isDefined (lastStmt)
5761 && !exprNode_mustEscape (lastStmt)
5762 && !exprNode_mustBreak (lastStmt)
5763 && !exprNode_isCaseMarker (lastStmt)
5764 && !exprNode_isDefaultMarker (lastStmt)
5765 && !exprNode_isLabelMarker (lastStmt))
5767 voptgenerror (FLG_CASEBREAK,
5769 ("Fall through case (no preceeding break)"),
5776 exprNode_mergeUSs (ret, e2);
5777 // ret = exprNode_mergeEnvironments (ret, e1, e2);
5778 usymtab_setExitCode (ret->exitCode);
5782 usymtab_setMustBreak ();
5788 exprNode exprNode_createTok (/*@only@*/ lltok t)
5790 exprNode ret = exprNode_create (ctype_unknown);
5791 ret->kind = XPR_TOK;
5792 ret->edata = exprData_makeTok (t);
5796 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5798 if (!exprNode_isError (e))
5800 exprNode_checkStatement(e);
5803 return (exprNode_statementError (e, t));
5806 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5808 exprNode ret = exprNode_createPartialCopy (e);
5810 if (!exprNode_isError (e))
5812 if (e->kind != XPR_ASSIGN)
5814 exprNode_checkUse (ret, e->sref, e->loc);
5817 ret->exitCode = e->exitCode;
5818 ret->canBreak = e->canBreak;
5819 ret->mustBreak = e->mustBreak;
5822 ret->edata = exprData_makeUop (e, t);
5823 ret->kind = XPR_STMT;
5828 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
5830 if (!exprNode_isError (e))
5832 if (e->kind != XPR_ASSIGN)
5834 exprNode_checkUse (e, e->sref, e->loc);
5841 void exprNode_produceGuards (exprNode pred)
5843 if (!exprNode_isError (pred))
5845 if (ctype_isRealPointer (pred->typ))
5847 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
5850 exprNode_checkUse (pred, pred->sref, pred->loc);
5851 exprNode_resetSref (pred);
5855 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
5857 exprNode ret = exprNode_createPartialCopy (e);
5859 if (!exprNode_isError (e))
5861 ret->exitCode = e->exitCode;
5862 ret->canBreak = e->canBreak;
5863 ret->mustBreak = e->mustBreak;
5866 ret->edata = exprData_makeSingle (e);
5867 ret->kind = XPR_BLOCK;
5871 bool exprNode_isBlock (exprNode e)
5873 return (exprNode_isDefined (e)
5874 && ((e)->kind == XPR_BLOCK));
5877 bool exprNode_isAssign (exprNode e)
5879 if (exprNode_isDefined (e))
5881 return (e->kind == XPR_ASSIGN);
5887 bool exprNode_isEmptyStatement (exprNode e)
5889 return (exprNode_isDefined (e)
5890 && (e->kind == XPR_TOK)
5891 && (lltok_isSemi (exprData_getTok (e->edata))));
5894 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
5897 bool emptyErr = FALSE;
5899 if (context_maybeSet (FLG_IFEMPTY))
5901 if (exprNode_isEmptyStatement (tclause))
5903 emptyErr = optgenerror (FLG_IFEMPTY,
5905 ("Body of if statement is empty"),
5906 exprNode_loc (tclause));
5910 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
5912 if (exprNode_isDefined (tclause)
5913 && !exprNode_isBlock (tclause))
5915 voptgenerror (FLG_IFBLOCK,
5917 ("Body of if statement is not a block: %s",
5918 exprNode_unparse (tclause)),
5919 exprNode_loc (tclause));
5923 if (exprNode_isError (pred))
5925 if (exprNode_isError (tclause))
5927 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5931 ret = exprNode_createPartialCopy (tclause);
5936 if (exprNode_mustEscape (pred))
5940 message ("Predicate always exits: %s", exprNode_unparse (pred)),
5941 exprNode_loc (pred));
5944 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
5945 exprNode_checkUse (pred, pred->sref, pred->loc);
5947 if (!exprNode_isError (tclause))
5949 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
5952 ret = exprNode_createPartialCopy (pred);
5956 ret->edata = exprData_makePair (pred, tclause);
5958 ret->exitCode = XK_UNKNOWN;
5960 if (exprNode_isDefined (tclause))
5962 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
5963 ret->canBreak = tclause->canBreak;
5964 ret->sets = sRefSet_union (ret->sets, tclause->sets);
5965 ret->msets = sRefSet_union (ret->msets, tclause->msets);
5966 ret->uses = sRefSet_union (ret->uses, tclause->uses);
5969 ret->mustBreak = FALSE;
5974 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
5975 /*@only@*/ exprNode tclause,
5976 /*@only@*/ exprNode eclause)
5979 bool tEmptyErr = FALSE;
5980 bool eEmptyErr = FALSE;
5982 if (context_maybeSet (FLG_IFEMPTY))
5984 if (exprNode_isEmptyStatement (tclause))
5986 tEmptyErr = optgenerror
5989 ("Body of if clause of if statement is empty"),
5990 exprNode_loc (tclause));
5993 if (exprNode_isEmptyStatement (eclause))
5995 eEmptyErr = optgenerror
5998 ("Body of else clause of if statement is empty"),
5999 exprNode_loc (eclause));
6003 if (context_maybeSet (FLG_IFBLOCK))
6006 && exprNode_isDefined (tclause)
6007 && !exprNode_isBlock (tclause))
6009 voptgenerror (FLG_IFBLOCK,
6011 ("Body of if clause of if statement is not a block: %s",
6012 exprNode_unparse (tclause)),
6013 exprNode_loc (tclause));
6017 && exprNode_isDefined (eclause)
6018 && !exprNode_isBlock (eclause)
6019 && !(eclause->kind == XPR_IF)
6020 && !(eclause->kind == XPR_IFELSE))
6025 ("Body of else clause of if statement is not a block: %s",
6026 exprNode_unparse (eclause)),
6027 exprNode_loc (eclause));
6031 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6033 if (exprNode_isDefined (eclause)
6034 && (eclause->kind == XPR_IF))
6036 voptgenerror (FLG_ELSEIFCOMPLETE,
6037 message ("Incomplete else if logic (no final else): %s",
6038 exprNode_unparse (eclause)),
6039 exprNode_loc (eclause));
6043 if (exprNode_isError (pred))
6045 if (exprNode_isError (tclause))
6047 if (exprNode_isError (eclause))
6049 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6053 ret = exprNode_createPartialCopy (eclause);
6058 ret = exprNode_createPartialCopy (tclause);
6061 else /* pred is okay */
6063 ret = exprNode_createPartialCopy (pred);
6065 if (exprNode_mustEscape (pred))
6069 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6070 exprNode_loc (pred));
6073 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6074 exprNode_checkUse (ret, pred->sref, pred->loc);
6076 exprNode_mergeCondUSs (ret, tclause, eclause);
6079 ret->kind = XPR_IFELSE;
6080 ret->edata = exprData_makeCond (pred, tclause, eclause);
6082 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6084 exprNode_combineControl (ret, tclause, eclause);
6085 ret->loc = fileloc_update (ret->loc, eclause->loc);
6092 ** *allpaths <- TRUE iff all executions paths must go through the switch
6096 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6098 exprNodeSList el = exprNode_flatten (e);
6099 bool mustReturn = TRUE; /* find a branch that doesn't */
6100 bool thisReturn = FALSE;
6101 bool hasDefault = FALSE;
6102 bool hasAllMembers = FALSE;
6103 bool inSwitch = FALSE;
6104 bool isEnumSwitch = FALSE;
6105 bool canBreak = FALSE;
6106 bool fallThrough = FALSE;
6107 ctype ct = ctype_unknown;
6108 enumNameSList usedEnums;
6111 if (exprNode_isDefined (test))
6116 ttype = ctype_realType (ct);
6118 if (ctype_isEnum (ttype))
6120 isEnumSwitch = TRUE;
6121 enums = ctype_elist (ttype);
6122 usedEnums = enumNameSList_new ();
6126 exprNodeSList_elements (el, current)
6128 if (exprNode_isDefined (current))
6130 switch (current->kind)
6138 message ("Duplicate default cases in switch"),
6139 exprNode_loc (current));
6144 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6152 exprNode st = exprData_getSingle (current->edata);
6153 uentry ue = exprNode_getUentry (st);
6155 if (uentry_isValid (ue))
6157 cstring cname = uentry_rawName (ue);
6159 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6161 if (enumNameSList_member
6162 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6166 message ("Duplicate case in switch: %s",
6172 enumNameSList_addh (usedEnums, cname);
6179 message ("Case in switch not %s member: %s",
6180 ctype_unparse (ct), cname),
6187 if (inSwitch && !fallThrough)
6189 if (!thisReturn || canBreak)
6199 /*@switchbreak@*/ break;
6201 thisReturn = thisReturn || exprNode_mustEscape (current);
6202 canBreak = canBreak || current->canBreak;
6203 if (canBreak) fallThrough = FALSE;
6206 } end_exprNodeSList_elements;
6208 if (inSwitch) /* check the last one! */
6210 if (!thisReturn || canBreak)
6219 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6220 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6222 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6224 voptgenerror (FLG_MISSCASE,
6225 message ("Missing case%s in switch: %q",
6226 cstring_makeLiteralTemp
6227 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6228 enumNameSList_unparse (unused)),
6231 enumNameSList_free (unused);
6235 hasAllMembers = TRUE;
6239 enumNameSList_free (usedEnums);
6243 *allpaths = hasDefault;
6246 exprNodeSList_free (el);
6247 return ((hasDefault || hasAllMembers) && mustReturn);
6250 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6252 exprNode ret = exprNode_createPartialCopy (e);
6255 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6257 ret->kind = XPR_SWITCH;
6258 ret->edata = exprData_makePair (e, s);
6260 if (!exprNode_isError (s))
6262 exprNode fs = exprNode_firstStatement (s);
6263 ret->loc = fileloc_update (ret->loc, s->loc);
6265 if (exprNode_isUndefined (fs)
6266 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6267 || exprNode_isDefaultMarker (fs)) {
6270 voptgenerror (FLG_FIRSTCASE,
6272 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6277 if (!exprNode_isError (e))
6279 if (checkSwitchExpr (e, s, &allpaths))
6281 ret->exitCode = XK_MUSTRETURN;
6285 ret->exitCode = e->exitCode;
6288 ret->canBreak = e->canBreak;
6289 ret->mustBreak = e->mustBreak;
6293 ** exprNode.c:3883,32: Variable allpaths used before definition
6300 DPRINTF (("Context exit switch!"));
6301 context_exitSwitch (ret, allpaths);
6302 DPRINTF (("Context exit switch done!"));
6307 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6308 /*@notnull@*/ exprNode body)
6310 sRefSet tuses = test->uses;
6312 if (!sRefSet_isEmpty (test->uses))
6314 sRefSet sets = sRefSet_newCopy (body->sets);
6315 bool hasError = TRUE;
6316 bool innerState = FALSE;
6317 sRefSet tuncon = sRefSet_undefined;
6319 sets = sRefSet_union (sets, test->sets);
6320 sets = sRefSet_union (sets, body->msets);
6321 sets = sRefSet_union (sets, test->msets);
6323 sRefSet_allElements (tuses, el)
6325 if (sRef_isUnconstrained (el))
6327 tuncon = sRefSet_insert (tuncon, el);
6331 if (sRefSet_member (sets, el))
6338 if (sRef_isInternalState (el)
6339 || sRef_isFileStatic (sRef_getRootBase (el)))
6343 } end_sRefSet_allElements ;
6347 sRefSet suncon = sRefSet_undefined;
6348 bool sinner = FALSE;
6350 sRefSet_allElements (sets, el)
6352 if (sRef_isUnconstrained (el))
6354 suncon = sRefSet_insert (suncon, el);
6356 else if (sRef_isInternalState (el))
6364 } end_sRefSet_allElements ;
6366 if (sinner && innerState)
6370 else if (sRefSet_isEmpty (tuncon)
6371 && sRefSet_isEmpty (suncon))
6376 ("Suspected infinite loop. No value used in loop test (%q) "
6377 "is modified by test or loop body.",
6378 sRefSet_unparsePlain (tuses)),
6383 if (sRefSet_isEmpty (tuncon))
6387 message ("Suspected infinite loop. No condition values "
6388 "modified. Modification possible through "
6389 "unconstrained calls: %q",
6390 sRefSet_unparsePlain (suncon)),
6397 message ("Suspected infinite loop. No condition values "
6398 "modified. Possible undetected dependency through "
6399 "unconstrained calls in loop test: %q",
6400 sRefSet_unparsePlain (tuncon)),
6406 sRefSet_free (sets);
6410 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
6413 bool emptyErr = FALSE;
6415 // s = exprNode_generateConstraints (t);
6416 // printf("pred: %s\n", s);
6417 // s = exprNode_generateConstraints (b);
6418 //printf ("body: %s\n", s);
6419 //constraintList_print(b->constraints);
6421 if (context_maybeSet (FLG_WHILEEMPTY))
6423 if (exprNode_isEmptyStatement (b))
6425 emptyErr = optgenerror
6428 ("Body of while statement is empty"),
6433 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
6435 if (exprNode_isDefined (b)
6436 && !exprNode_isBlock (b))
6438 if (context_inIterDef ()
6439 && (b->kind == XPR_STMTLIST
6440 || b->kind == XPR_TOK))
6446 voptgenerror (FLG_WHILEBLOCK,
6448 ("Body of while statement is not a block: %s",
6449 exprNode_unparse (b)),
6455 if (exprNode_isError (t))
6457 if (exprNode_isError (b))
6459 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6463 ret = exprNode_createPartialCopy (b);
6470 ret = exprNode_createPartialCopy (t);
6472 llassert (t->kind == XPR_WHILEPRED);
6474 test = exprData_getSingle (t->edata);
6476 if (!exprNode_isError (b) && exprNode_isDefined (test))
6478 if (context_maybeSet (FLG_INFLOOPS)
6479 || context_maybeSet (FLG_INFLOOPSUNCON))
6482 ** check that some variable in the predicate is set by the body
6483 ** if the predicate uses any variables
6486 checkInfiniteLoop (test, b);
6489 exprNode_mergeUSs (ret, b);
6491 if (exprNode_isDefined (b))
6493 ret->exitCode = exitkind_makeConditional (b->exitCode);
6498 ret->edata = exprData_makePair (t, b);
6499 ret->kind = XPR_WHILE;
6501 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
6505 message ("Predicate always exits: %s", exprNode_unparse (t)),
6509 ret->exitCode = XK_NEVERESCAPE;
6512 ** If loop is infinite, and there is no break inside,
6513 ** exit code is never reach.
6516 if (exprNode_knownIntValue (t))
6518 if (!exprNode_isZero (t))
6520 if (exprNode_isDefined (b))
6524 /* Really, it means never reached. */
6525 ret->exitCode = XK_MUSTEXIT;
6535 ret->canBreak = FALSE;
6536 ret->mustBreak = FALSE;
6542 ** do { b } while (t);
6544 ** note: body passed as first argument
6547 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
6551 if (exprNode_isError (t))
6553 if (exprNode_isError (b))
6555 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6559 ret = exprNode_createPartialCopy (b);
6561 ret->exitCode = exitkind_makeConditional (b->exitCode);
6562 exprNode_checkUse (ret, b->sref, b->loc);
6563 ret->exitCode = b->exitCode;
6564 ret->canBreak = b->canBreak;
6565 ret->mustBreak = b->mustBreak;
6570 ret = exprNode_createPartialCopy (t);
6571 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
6573 if (!exprNode_isError (b))
6576 ** forgot the copy's --- why wasn't this detected??
6579 ret->sets = sRefSet_copy (ret->sets, b->sets);
6580 ret->msets = sRefSet_copy (ret->msets, b->msets);
6581 ret->uses = sRefSet_copy (ret->uses, b->uses);
6583 /* left this out --- causes and aliasing bug (infinite loop)
6584 should be detected?? */
6586 exprNode_checkUse (ret, b->sref, b->loc);
6587 exprNode_mergeUSs (ret, t);
6588 exprNode_checkUse (ret, t->sref, t->loc);
6590 ret->exitCode = b->exitCode;
6591 ret->canBreak = b->canBreak;
6592 ret->mustBreak = b->mustBreak;
6596 context_exitDoWhileClause (t);
6598 ret->kind = XPR_DOWHILE;
6599 ret->edata = exprData_makePair (t, b);
6603 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
6606 bool emptyErr = FALSE;
6608 if (context_maybeSet (FLG_FOREMPTY))
6610 if (exprNode_isEmptyStatement (body))
6612 emptyErr = optgenerror
6615 ("Body of for statement is empty"),
6616 exprNode_loc (body));
6620 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
6622 if (exprNode_isDefined (body)
6623 && !exprNode_isBlock (body))
6625 if (context_inIterDef ()
6626 && (body->kind == XPR_STMTLIST
6627 || body->kind == XPR_TOK))
6633 voptgenerror (FLG_FORBLOCK,
6635 ("Body of for statement is not a block: %s",
6636 exprNode_unparse (body)),
6637 exprNode_loc (body));
6643 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
6646 if (exprNode_isError (body))
6648 ret = exprNode_createPartialCopy (inc);
6652 ret = exprNode_createPartialCopy (body);
6654 ret->exitCode = exitkind_makeConditional (body->exitCode);
6656 exprNode_mergeUSs (inc, body);
6658 if (exprNode_isDefined (inc))
6662 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
6665 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
6666 exprNode_freeShallow (tmp);
6668 context_clearMessageAnnote ();
6669 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
6671 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
6672 exprNode_freeShallow (tmp);
6674 context_clearMessageAnnote ();
6676 ret->uses = sRefSet_copy (ret->uses, inc->uses);
6677 ret->sets = sRefSet_copy (ret->sets, inc->sets);
6678 ret->msets = sRefSet_copy (ret->msets, inc->msets);
6682 ret->kind = XPR_FOR;
6683 ret->edata = exprData_makePair (inc, body);
6685 if (exprNode_isDefined (inc)) {
6686 exprNode test = exprData_getTripleTest (inc->edata);
6688 if (exprNode_isUndefined (test)) {
6689 if (exprNode_isDefined (body)) {
6690 if (!body->canBreak) {
6691 /* Really, it means never reached. */
6692 ret->exitCode = XK_MUSTEXIT;
6702 ** for (init; test; inc)
6705 ** while (test) { body; inc; }
6707 ** Now: check use of init (may set vars for test)
6708 ** check use of test
6712 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
6716 if (exprNode_isError (pred)) return guardSet_undefined;
6718 llassert (pred->kind == XPR_FORPRED);
6720 test = exprData_getTripleTest (pred->edata);
6722 if (!exprNode_isError (test))
6724 return (test->guards);
6727 return guardSet_undefined;
6730 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
6732 exprNode ret = exprNode_createSemiCopy (test);
6734 if (exprNode_isDefined (test))
6736 exprNode_copySets (ret, test);
6737 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
6738 exprNode_checkUse (ret, test->sref, test->loc);
6740 exprNode_produceGuards (test);
6742 ret->guards = guardSet_copy (test->guards);
6745 ret->edata = exprData_makeSingle (test);
6746 ret->kind = XPR_WHILEPRED;
6750 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
6751 /*@only@*/ exprNode inc)
6756 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
6759 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
6761 if (!exprNode_isError (inc))
6763 ret = exprNode_createPartialCopy (inc);
6767 if (!exprNode_isError (init))
6769 ret = exprNode_createPartialCopy (init);
6771 else if (!exprNode_isError (test))
6773 ret = exprNode_createPartialCopy (test);
6777 ret = exprNode_createUnknown ();
6781 exprNode_mergeUSs (ret, init);
6783 if (exprNode_isDefined (init))
6785 exprNode_checkUse (ret, init->sref, init->loc);
6788 exprNode_mergeUSs (ret, test);
6790 if (exprNode_isDefined (test))
6792 exprNode_checkUse (ret, test->sref, test->loc);
6795 ret->kind = XPR_FORPRED;
6796 ret->edata = exprData_makeFor (init, test, inc);
6800 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
6802 exprNode ret = exprNode_createUnknown ();
6804 if (context_inMacro ())
6806 voptgenerror (FLG_MACROSTMT,
6807 message ("Macro %s uses goto (not functional)",
6808 context_inFunctionName ()),
6812 ret->kind = XPR_GOTO;
6813 ret->edata = exprData_makeLiteral (label);
6814 ret->mustBreak = TRUE;
6815 ret->exitCode = XK_GOTO;
6816 ret->canBreak = TRUE;
6820 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
6822 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6824 ret->kind = XPR_CONTINUE;
6825 ret->edata = exprData_makeTok (l);
6826 ret->canBreak = TRUE;
6827 ret->mustBreak = TRUE;
6829 if (qcontinue == QSAFEBREAK)
6833 else if (qcontinue == QINNERCONTINUE)
6835 if (!context_inDeepLoop ())
6838 (FLG_LOOPLOOPCONTINUE,
6839 cstring_makeLiteral ("Continue statement marked with innercontinue "
6840 "is not inside a nested loop"),
6841 exprNode_loc (ret));
6844 else if (qcontinue == BADTOK)
6846 if (context_inDeepLoop ())
6849 (FLG_LOOPLOOPCONTINUE,
6850 cstring_makeLiteral ("Continue statement in nested loop"),
6851 exprNode_loc (ret));
6856 llbuglit ("exprNode_continue: bad qcontinue");
6862 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
6864 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6865 clause breakClause = context_breakClause ();
6867 ret->kind = XPR_BREAK;
6868 ret->edata = exprData_makeTok (l);
6869 ret->canBreak = TRUE;
6870 ret->mustBreak = TRUE;
6872 if (breakClause == NOCLAUSE)
6876 cstring_makeLiteral ("Break not inside while, for or switch statement"),
6877 exprNode_loc (ret));
6881 if (bqual != BADTOK)
6888 if (breakClause == SWITCHCLAUSE)
6890 if (!context_inDeepSwitch ())
6892 voptgenerror (FLG_SYNTAX,
6894 ("Break preceded by innerbreak is not in a deep switch"),
6895 exprNode_loc (ret));
6900 if (!context_inDeepLoop ())
6902 voptgenerror (FLG_SYNTAX,
6904 ("Break preceded by innerbreak is not in a deep loop"),
6905 exprNode_loc (ret));
6910 if (breakClause == SWITCHCLAUSE)
6912 voptgenerror (FLG_SYNTAX,
6914 ("Break preceded by loopbreak is breaking a switch"),
6915 exprNode_loc (ret));
6919 if (breakClause != SWITCHCLAUSE)
6923 message ("Break preceded by switchbreak is breaking %s",
6924 cstring_makeLiteralTemp
6925 ((breakClause == WHILECLAUSE
6926 || breakClause == DOWHILECLAUSE) ? "a while loop"
6927 : (breakClause == FORCLAUSE) ? "a for loop"
6928 : (breakClause == ITERCLAUSE) ? "an iterator"
6930 exprNode_loc (ret));
6938 if (breakClause == SWITCHCLAUSE)
6940 clause nextBreakClause = context_nextBreakClause ();
6942 switch (nextBreakClause)
6944 case NOCLAUSE: break;
6950 (FLG_LOOPSWITCHBREAK,
6951 cstring_makeLiteral ("Break statement in switch inside loop"),
6952 exprNode_loc (ret));
6956 (FLG_SWITCHSWITCHBREAK,
6957 cstring_makeLiteral ("Break statement in switch inside switch"),
6958 exprNode_loc (ret));
6965 if (context_inDeepLoop ())
6969 cstring_makeLiteral ("Break statement in nested loop"),
6970 exprNode_loc (ret));
6974 if (context_inDeepLoopSwitch ())
6977 (FLG_SWITCHLOOPBREAK,
6978 cstring_makeLiteral ("Break statement in loop inside switch"),
6979 exprNode_loc (ret));
6989 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
6991 fileloc loc = lltok_getLoc (t);
6992 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
6994 context_returnFunction ();
6995 exprChecks_checkNullReturn (loc);
6997 ret->kind = XPR_NULLRETURN;
6998 ret->edata = exprData_makeTok (t);
6999 ret->exitCode = XK_MUSTRETURN;
7003 exprNode exprNode_return (/*@only@*/ exprNode e)
7007 if (exprNode_isError (e))
7009 ret = exprNode_createUnknown ();
7013 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7015 exprNode_checkUse (ret, e->sref, e->loc);
7016 exprNode_checkReturn (e);
7019 context_returnFunction ();
7020 ret->kind = XPR_RETURN;
7021 ret->edata = exprData_makeSingle (e);
7022 ret->exitCode = XK_MUSTRETURN;
7027 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7031 if (exprNode_isError (e1))
7033 if (exprNode_isError (e2))
7035 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
7039 ret = exprNode_createPartialCopy (e2);
7040 exprNode_checkUse (ret, e2->sref, e2->loc);
7041 ret->sref = e2->sref;
7046 ret = exprNode_createPartialCopy (e1);
7048 exprNode_checkUse (ret, e1->sref, e1->loc);
7050 if (!exprNode_isError (e2))
7052 exprNode_mergeUSs (ret, e2);
7053 exprNode_checkUse (ret, e2->sref, e2->loc);
7054 ret->sref = e2->sref;
7058 ret->kind = XPR_COMMA;
7059 ret->edata = exprData_makePair (e1, e2);
7061 if (exprNode_isDefined (e1))
7063 if (exprNode_isDefined (e2))
7067 if (exprNode_mustEscape (e1) || e1->mustBreak)
7071 message ("Second clause of comma expression is unreachable: %s",
7072 exprNode_unparse (e2)),
7076 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7077 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7078 ret->canBreak = e1->canBreak || e2->canBreak;
7082 if (exprNode_mustEscape (e1) || e1->mustBreak)
7086 message ("Second clause of comma expression is unreachable: %s",
7087 exprNode_unparse (e2)),
7091 ret->exitCode = e1->exitCode;
7092 ret->canBreak = e1->canBreak;
7097 if (exprNode_isDefined (e2))
7099 ret->exitCode = e2->exitCode;
7100 ret->mustBreak = e2->mustBreak;
7101 ret->canBreak = e2->canBreak;
7108 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7110 ctype t1 = exprNode_getType (el);
7111 ctype t2 = exprNode_getType (val);
7112 bool hasError = FALSE;
7114 if (ctype_isUnknown (t1))
7116 voptgenerror (FLG_IMPTYPE,
7117 message ("Variable has unknown (implicitly int) type: %s",
7118 exprNode_unparse (el)),
7122 el->typ = ctype_int;
7125 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7127 exprNodeList vals = exprData_getArgs (val->edata);
7129 if (ctype_isRealAP (t1))
7134 exprNodeList_elements (vals, oneval)
7136 cstring istring = message ("%d", i);
7139 (exprNode_fakeCopy (el),
7140 exprNode_numLiteral (ctype_int, istring,
7141 fileloc_copy (el->loc), i));
7143 if (exprNode_isDefined (newel))
7145 if (exprNodeList_size (vals) == 1
7146 && ctype_isString (exprNode_getType (oneval))
7147 && ctype_isChar (exprNode_getType (newel)))
7149 exprNode_freeIniter (newel);
7153 if (exprNode_checkOneInit (newel, oneval))
7158 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7161 (message ("Additional initialization errors "
7162 "for %s not reported",
7163 exprNode_unparse (el)),
7165 exprNode_freeIniter (newel);
7170 exprNode_freeIniter (newel);
7175 exprNode_freeIniter (newel);
7180 cstring_free (istring);
7183 } end_exprNodeList_elements;
7186 else if (ctype_isStruct (ctype_realType (t1)))
7188 uentryList fields = ctype_getFields (t1);
7191 if (uentryList_size (fields) != exprNodeList_size (vals))
7193 if (uentryList_size (fields) > exprNodeList_size (vals))
7195 hasError = optgenerror
7197 message ("Initializer block for "
7198 "%s has %d field%p, but %s has %d field%p: %q",
7199 exprNode_unparse (el),
7200 exprNodeList_size (vals),
7202 uentryList_size (fields),
7203 exprNodeList_unparse (vals)),
7208 hasError = optgenerror
7210 message ("Initializer block for "
7211 "%s has %d field%p, but %s has %d field%p: %q",
7212 exprNode_unparse (el),
7213 exprNodeList_size (vals),
7215 uentryList_size (fields),
7216 exprNodeList_unparse (vals)),
7222 exprNodeList_elements (vals, oneval)
7224 uentry thisfield = uentryList_getN (fields, i);
7226 exprNode_fieldAccess (exprNode_fakeCopy (el),
7227 uentry_getName (thisfield));
7229 if (exprNode_isDefined (newel))
7231 if (exprNode_checkOneInit (newel, oneval))
7236 exprNode_freeIniter (newel);
7240 } end_exprNodeList_elements;
7245 hasError = optgenerror
7247 message ("Initializer block used for "
7248 "%s where %t is expected: %s",
7249 exprNode_unparse (el), t1, exprNode_unparse (val)),
7255 if (exprNode_isDefined (val))
7257 doAssign (el, val, TRUE);
7259 if (!exprNode_matchType (t1, val))
7261 hasError = gentypeerror
7263 message ("Initial value of %s is type %t, "
7265 exprNode_unparse (el),
7266 t2, t1, exprNode_unparse (val)),
7275 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
7276 /*@only@*/ exprNode e)
7278 uentry ue = usymtab_lookup (idDecl_observeId (t));
7279 bool isUsed = uentry_isUsed (ue);
7280 exprNode ret = exprNode_fromIdentifierAux (ue);
7281 ctype ct = ctype_realishType (ret->typ);
7284 if (ctype_isUnknown (ct))
7286 voptgenerror (FLG_IMPTYPE,
7287 message ("Variable has unknown (implicitly int) type: %s",
7288 idDecl_getName (t)),
7289 exprNode_isDefined (e) ? exprNode_loc (e) : g_currentloc);
7294 if (exprNode_isError (e))
7296 e = exprNode_createUnknown ();
7299 /* error: assume initializer is defined */
7300 sRef_setDefined (ret->sref, loc);
7304 loc = exprNode_loc (e);
7309 ** was addSafeUse --- what's the problem?
7311 ** int x = 3, y = x ?
7314 exprNode_checkUse (ret, e->sref, e->loc);
7316 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
7318 exprNode lhs = exprNode_createId (ue);
7321 ** static storage should be undefined before initializing
7324 if (uentry_isStatic (ue))
7326 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
7329 (void) exprNode_checkOneInit (lhs, e);
7331 if (uentry_isStatic (ue))
7333 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
7336 exprNode_free (lhs);
7340 if (!exprNode_matchType (ct, e))
7342 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
7349 (exprNode_getType (e), e, exprNode_getType (ret), ret,
7351 ("Variable %s initialized to type %t, expects %t: %s",
7352 exprNode_unparse (ret), exprNode_getType (e),
7353 exprNode_getType (ret),
7354 exprNode_unparse (e)),
7360 if (uentry_isStatic (ue))
7362 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
7365 doAssign (ret, e, TRUE);
7367 if (uentry_isStatic (ue))
7369 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
7373 if (context_inIterDef ())
7375 /* should check if it is yield */
7376 uentry_setUsed (ue, loc);
7380 if (!isUsed) /* could be @unused@-qualified variable */
7382 uentry_setNotUsed (ue);
7386 ret->exitCode = XK_NEVERESCAPE;
7387 ret->mustBreak = FALSE;
7390 ** Must be before new kind is assigned!
7393 exprData_free (ret->edata, ret->kind);
7395 ret->kind = XPR_INIT;
7396 ret->edata = exprData_makeInit (t, e);
7397 exprNode_mergeUSs (ret, e);
7401 exprNode exprNode_iter (/*@observer@*/ uentry name,
7402 /*@only@*/ exprNodeList alist,
7403 /*@only@*/ exprNode body,
7404 /*@observer@*/ uentry end)
7409 llassert (uentry_isValid (name));
7411 uentry_setUsed (name, exprNode_loc (body));
7413 ret = exprNode_createPartialCopy (body);
7414 iname = uentry_getName (name);
7416 if (uentry_isInvalid (end))
7419 message ("Iter %s not balanced with end_%s", iname, iname));
7423 cstring ename = uentry_getName (end);
7425 if (!cstring_equalPrefix (ename, "end_"))
7427 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
7428 iname, iname, ename));
7432 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
7435 message ("Iter %s not balanced with end_%s: %s",
7436 iname, iname, ename));
7440 cstring_free (ename);
7443 context_exitIterClause (body);
7445 ret->kind = XPR_ITER;
7446 ret->edata = exprData_makeIter (name, alist, body, end);
7448 if (uentry_isIter (name))
7450 (void) checkArgsReal (name, body,
7451 uentry_getParams (name), alist, TRUE, ret);
7454 cstring_free (iname);
7460 exprNode_iterNewId (/*@only@*/ cstring s)
7462 exprNode e = exprNode_new ();
7463 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
7465 llassert (processingIterVars ());
7467 e->loc = context_getSaveLocation ();
7469 if (fileloc_isUndefined (e->loc))
7471 fileloc_free (e->loc);
7472 e->loc = fileloc_copy (g_currentloc);
7475 e->uses = sRefSet_new ();
7476 e->sets = sRefSet_new ();
7477 e->msets = sRefSet_new ();
7479 e->val = multiVal_unknown ();
7480 e->guards = guardSet_new ();
7482 e->isJumpPoint = FALSE;
7483 e->exitCode = XK_NEVERESCAPE;
7485 /*> missing fields, detected by lclint <*/
7486 e->canBreak = FALSE;
7487 e->mustBreak = FALSE;
7488 e->etext = cstring_undefined;
7490 if (uentry_isYield (ue))
7492 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
7493 fileloc_copy (e->loc),
7497 uue = usymtab_supEntrySrefReturn (uue);
7499 sr = uentry_getSref (uue);
7500 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
7501 sr = uentry_getSref (uue);
7502 sRef_setDefined (sr, e->loc);
7504 e->typ = uentry_getType (uue);
7506 e->edata = exprData_makeId (uue);
7507 uentry_setUsed (uue, g_currentloc);
7513 sRef_setGlobalScope ();
7514 uue = uentry_makeVariableLoc (s, ctype_unknown);
7516 e->typ = ctype_unknown;
7517 e->edata = exprData_makeId (uue);
7519 uentry_setUsed (uue, e->loc);
7520 uentry_setHasNameError (uue);
7522 if (context_getFlag (FLG_REPEATUNRECOG))
7524 uentry_markOwned (uue);
7528 usymtab_supGlobalEntry (uue);
7531 sRef_clearGlobalScope ();
7533 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
7543 exprNode_iterExpr (/*@returned@*/ exprNode e)
7545 if (!processingIterVars ())
7547 llcontbuglit ("checkIterParam: not in iter");
7551 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
7554 if (exprNode_isDefined (e))
7556 if (fileloc_isDefined (e->loc))
7560 message ("Yield parameter is not simple identifier: %s",
7561 exprNode_unparse (e)),
7568 message ("Yield parameter is not simple identifier: %s",
7569 exprNode_unparse (e)),
7579 exprNode_iterId (/*@observer@*/ uentry c)
7583 llassert (processingIterVars ());
7585 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
7588 if (uentry_isYield (ue))
7590 ctype ct = uentry_getType (ue);
7591 exprNode e = exprNode_createPlain (ct);
7592 cstring name = uentry_getName (c);
7593 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
7595 uentry_setUsed (ue, g_currentloc);
7596 uentry_setHasNameError (ue);
7598 cstring_free (name);
7601 e->edata = exprData_makeId (le);
7602 e->loc = context_getSaveLocation ();
7603 e->sref = uentry_getSref (le);
7605 usymtab_supEntrySref (le);
7607 if (!context_inHeader ())
7611 message ("Yield parameter shadows local declaration: %q",
7612 uentry_getName (c)),
7613 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
7615 uentry_showWhereDeclared (c);
7622 return (exprNode_fromIdentifierAux (c));
7625 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
7627 exprNode ret = exprNode_create (ctype_unknown);
7629 ret->kind = XPR_ITERCALL;
7630 ret->edata = exprData_makeIterCall (name, alist);
7632 if (uentry_isIter (name))
7634 uentryList params = uentry_getParams (name);
7636 if (context_inIterDef ()
7637 && uentryList_size (params) == exprNodeList_size (alist))
7641 exprNodeList_elements (alist, arg)
7643 uentry parg = uentryList_getN (params, i);
7645 if (uentry_isYield (parg))
7647 uentry ue = exprNode_getUentry (arg);
7649 if (uentry_isValid (ue))
7656 } end_exprNodeList_elements;
7659 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
7660 checkUnspecCall (ret, params, alist);
7666 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
7668 if (exprNode_isDefined (e))
7671 if (e->sref == defref) /*@noaccess sRef@*/
7674 e->sref = sRef_makeUnknown ();
7675 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
7686 return sRef_undefined;
7690 /*@observer@*/ cstring
7691 exprNode_unparseFirst (exprNode e)
7693 if (exprNode_isDefined (e))
7697 if (e->kind == XPR_STMTLIST
7698 || e->kind == XPR_COMMA || e->kind == XPR_COND)
7700 exprNode first = exprData_getPairA (e->edata);
7702 if (exprNode_isDefined (first))
7704 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
7708 return (cstring_makeLiteralTemp ("..."));
7712 ret = cstring_elide (exprNode_unparse (e), 20);
7713 cstring_markOwned (ret);
7719 return cstring_makeLiteralTemp ("<error>");
7723 /*@observer@*/ cstring
7724 exprNode_unparse (exprNode e)
7726 if (exprNode_isError (e))
7728 return cstring_makeLiteralTemp ("<error>");
7731 if (cstring_isDefined (e->etext))
7737 cstring ret = exprNode_doUnparse (e);
7739 /*@-modifies@*/ /* benevolent */
7746 /*@observer@*/ fileloc
7747 exprNode_loc (exprNode e)
7749 if (exprNode_isError (e))
7751 return (g_currentloc);
7760 ** executes exprNode e
7761 ** recursively rexecutes as though in original parse using
7762 ** information in e->edata
7765 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
7767 exprNodeList ret = exprNodeList_new ();
7769 exprNodeList_elements (e, current)
7771 exprNodeList_addh (ret, exprNode_effect (current));
7772 } end_exprNodeList_elements;
7777 static /*@only@*/ exprNode exprNode_effect (exprNode e)
7778 /*@globals internalState@*/
7780 bool innerEffect = inEffect;
7786 context_clearJustPopped ();
7788 if (exprNode_isError (e))
7790 ret = exprNode_undefined;
7795 ** Turn off expose and dependent transfer checking.
7796 ** Need to pass exposed internal nodes,
7797 ** [ copying would be a waste! ]
7798 ** [ Actually, I think I wasted a lot more time than its worth ]
7799 ** [ trying to do this. ]
7803 /*@-observertrans@*/
7804 /*@-dependenttrans@*/
7811 ret = exprNode_addParens (exprData_getUopTok (data),
7812 exprNode_effect (exprData_getUopNode (data)));
7815 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
7816 exprNode_effect (exprData_getOpB (data)),
7817 exprData_getOpTok (data));
7820 ret = exprNode_undefined;
7823 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
7824 exprNodeList_effect (exprData_getArgs (data)));
7837 cstring id = exprData_getId (data);
7838 uentry ue = usymtab_lookupSafe (id);
7840 ret = exprNode_fromIdentifierAux (ue);
7841 ret->loc = fileloc_update (ret->loc, e->loc);
7848 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
7849 exprNode_effect (exprData_getPairB (data)));
7852 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
7853 exprNode_effect (exprData_getOpB (data)),
7854 exprData_getOpTok (data));
7858 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
7859 exprData_getUopTok (data));
7862 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
7863 exprData_getUopTok (data));
7875 ret = exprNode_vaArg (exprData_getCastTok (data),
7876 exprNode_effect (exprData_getCastNode (data)),
7877 exprData_getCastType (data));
7881 ret = exprNode_cast (exprData_getCastTok (data),
7882 exprNode_effect (exprData_getCastNode (data)),
7883 exprData_getCastType (data));
7886 ret = exprNode_iterStart (exprData_getIterCallIter (data),
7888 (exprData_getIterCallArgs (data)));
7892 ret = exprNode_iter (exprData_getIterSname (data),
7893 exprNodeList_effect (exprData_getIterAlist (data)),
7894 exprNode_effect (exprData_getIterBody (data)),
7895 exprData_getIterEname (data));
7899 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
7900 exprNode_effect (exprData_getPairB (data)));
7904 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
7905 exprNode_effect (exprData_getTripleTest (data)),
7906 exprNode_effect (exprData_getTripleInc (data)));
7910 ret = exprNode_createTok (exprData_getTok (data));
7914 ret = exprNode_goto (exprData_getLiteral (data));
7915 ret->loc = fileloc_update (ret->loc, e->loc);
7919 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
7923 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
7927 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
7930 case XPR_NULLRETURN:
7931 ret = exprNode_nullReturn (exprData_getTok (data));
7935 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
7936 exprNode_effect (exprData_getPairB (data)));
7940 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
7941 exprNode_effect (exprData_getTripleTrue (data)),
7942 exprNode_effect (exprData_getTripleFalse (data)));
7945 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
7946 exprNode_effect (exprData_getPairB (data)));
7950 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
7951 exprNode_effect (exprData_getTripleTrue (data)),
7952 exprNode_effect (exprData_getTripleFalse (data)));
7955 ret = exprNode_whilePred (exprData_getSingle (data));
7959 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
7960 exprNode_effect (exprData_getPairB (data)));
7964 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
7965 exprNode_effect (exprData_getPairB (data)));
7969 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
7973 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
7974 exprData_getUopTok (data));
7978 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
7979 exprNode_effect (exprData_getPairB (data)));
7984 ret = exprNode_caseMarker
7985 (exprNode_effect (exprData_getSingle (data)),
7991 ret = exprNode_createTok (exprData_getTok (data));
7995 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
7996 exprNode_effect (exprData_getPairB (data)));
8000 ret = exprNode_makeInitialization
8001 (exprData_getInitId (data),
8002 exprNode_effect (exprData_getInitNode (data)));
8006 ret = exprNode_fieldAccess (exprNode_effect (exprData_getFieldNode (data)),
8007 cstring_copy (exprData_getFieldName (data)));
8011 ret = exprNode_arrowAccess (exprNode_effect (exprData_getFieldNode (data)),
8012 cstring_copy (exprData_getFieldName (data)));
8015 case XPR_STRINGLITERAL:
8029 /*@=observertrans@*/
8031 /*@=dependenttrans@*/
8042 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8047 if (exprNode_isError (e))
8049 return cstring_undefined;
8057 ret = exprNode_rootVarName (exprData_getUopNode (data));
8060 ret = exprNode_rootVarName (exprData_getOpA (data));
8064 ret = exprData_getId (data);
8089 case XPR_NULLRETURN:
8112 case XPR_STRINGLITERAL:
8113 ret = cstring_undefined;
8121 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8126 if (exprNode_isError (e))
8128 static /*@only@*/ cstring error = cstring_undefined;
8130 if (!cstring_isDefined (error))
8132 error = cstring_makeLiteral ("<error>");
8143 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8146 ret = message ("%s %s %s",
8147 exprNode_unparse (exprData_getOpA (data)),
8148 lltok_unparse (exprData_getOpTok (data)),
8149 exprNode_unparse (exprData_getOpB (data)));
8152 ret = message ("%s(%q)",
8153 exprNode_unparse (exprData_getFcn (data)),
8154 exprNodeList_unparse (exprData_getArgs (data)));
8157 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8160 ret = cstring_undefined;
8163 ret = message ("%s:", exprData_getId (data));
8167 ret = cstring_copy (exprData_getId (data));
8170 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8171 exprNode_unparse (exprData_getPairB (data)));
8174 ret = message ("<body>");
8177 ret = message ("%s %s %s",
8178 exprNode_unparse (exprData_getOpA (data)),
8179 lltok_unparse (exprData_getOpTok (data)),
8180 exprNode_unparse (exprData_getOpB (data)));
8184 ret = message ("%s%s",
8185 lltok_unparse (exprData_getUopTok (data)),
8186 exprNode_unparse (exprData_getUopNode (data)));
8190 ret = message ("%s%s",
8191 exprNode_unparse (exprData_getUopNode (data)),
8192 lltok_unparse (exprData_getUopTok (data)));
8196 ret = message ("offsetof(%s,%q)",
8197 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8198 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8202 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8206 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8210 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8214 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8218 ret = message ("va_arg(%s, %q)",
8219 exprNode_unparse (exprData_getCastNode (data)),
8220 qtype_unparse (exprData_getCastType (data)));
8224 ret = message ("%q(%q)",
8225 uentry_getName (exprData_getIterCallIter (data)),
8226 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8229 ret = message ("%q(%q) %s %q",
8230 uentry_getName (exprData_getIterSname (data)),
8231 exprNodeList_unparse (exprData_getIterAlist (data)),
8232 exprNode_unparse (exprData_getIterBody (data)),
8233 uentry_getName (exprData_getIterEname (data)));
8236 ret = message ("(%q)%s",
8237 qtype_unparse (exprData_getCastType (data)),
8238 exprNode_unparse (exprData_getCastNode (data)));
8242 ret = message ("%s %s",
8243 exprNode_unparse (exprData_getPairA (data)),
8244 exprNode_unparse (exprData_getPairB (data)));
8248 ret = message ("for (%s; %s; %s)",
8249 exprNode_unparse (exprData_getTripleInit (data)),
8250 exprNode_unparse (exprData_getTripleTest (data)),
8251 exprNode_unparse (exprData_getTripleInc (data)));
8255 ret = message ("goto %s", exprData_getLiteral (data));
8259 ret = cstring_makeLiteral ("continue");
8263 ret = cstring_makeLiteral ("break");
8267 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
8270 case XPR_NULLRETURN:
8271 ret = cstring_makeLiteral ("return");
8275 ret = message ("%s, %s",
8276 exprNode_unparse (exprData_getPairA (data)),
8277 exprNode_unparse (exprData_getPairB (data)));
8281 ret = message ("%s ? %s : %s",
8282 exprNode_unparse (exprData_getTriplePred (data)),
8283 exprNode_unparse (exprData_getTripleTrue (data)),
8284 exprNode_unparse (exprData_getTripleFalse (data)));
8287 ret = message ("if (%s) %s",
8288 exprNode_unparse (exprData_getPairA (data)),
8289 exprNode_unparse (exprData_getPairB (data)));
8293 ret = message ("if (%s) %s else %s",
8294 exprNode_unparse (exprData_getTriplePred (data)),
8295 exprNode_unparse (exprData_getTripleTrue (data)),
8296 exprNode_unparse (exprData_getTripleFalse (data)));
8299 ret = message ("while (%s) %s",
8300 exprNode_unparse (exprData_getPairA (data)),
8301 exprNode_unparse (exprData_getPairB (data)));
8305 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
8309 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
8313 ret = message ("do { %s } while (%s)",
8314 exprNode_unparse (exprData_getPairB (data)),
8315 exprNode_unparse (exprData_getPairA (data)));
8319 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
8323 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
8327 ret = message ("%s; %s",
8328 exprNode_unparse (exprData_getPairA (data)),
8329 exprNode_unparse (exprData_getPairB (data)));
8334 ret = cstring_makeLiteral ("default:");
8338 ret = message ("switch (%s) %s",
8339 exprNode_unparse (exprData_getPairA (data)),
8340 exprNode_unparse (exprData_getPairB (data)));
8345 ret = message ("case %s:",
8346 exprNode_unparse (exprData_getSingle (data)));
8350 ret = message ("%s = %s",
8351 idDecl_getName (exprData_getInitId (data)),
8352 exprNode_unparse (exprData_getInitNode (data)));
8356 ret = message ("%s.%s",
8357 exprNode_unparse (exprData_getFieldNode (data)),
8358 exprData_getFieldName (data));
8362 ret = message ("%s->%s",
8363 exprNode_unparse (exprData_getFieldNode (data)),
8364 exprData_getFieldName (data));
8367 case XPR_STRINGLITERAL:
8368 ret = cstring_copy (exprData_getLiteral (data));
8372 ret = cstring_copy (exprData_getLiteral (data));
8376 ret = cstring_makeLiteral ("<node>");
8384 exprNode_isCharLit (exprNode e)
8386 if (exprNode_isDefined (e))
8388 return (multiVal_isChar (exprNode_getValue (e)));
8397 exprNode_isNumLit (exprNode e)
8399 if (exprNode_isDefined (e))
8401 return (multiVal_isInt (exprNode_getValue (e)));
8410 exprNode_isFalseConstant (exprNode e)
8412 if (exprNode_isDefined (e))
8414 cstring s = exprNode_rootVarName (e);
8416 if (cstring_equal (s, context_getFalseName ()))
8426 exprNode_matchLiteral (ctype expected, exprNode e)
8428 if (exprNode_isDefined (e))
8430 multiVal m = exprNode_getValue (e);
8432 if (multiVal_isDefined (m))
8434 if (multiVal_isInt (m))
8436 long int val = multiVal_forceInt (m);
8438 if (ctype_isDirectBool (ctype_realishType (expected)))
8442 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
8450 if (ctype_isRealInt (expected))
8453 ** unsigned <- [ constant >= 0 is okay ]
8456 if (ctype_isUnsigned (expected))
8465 ** No checks on sizes of integers...maybe add
8469 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
8470 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
8471 bool_unparse (ctype_isInt (exprNode_getType (e)))));
8473 if (context_getFlag (FLG_NUMLITERAL)
8474 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
8480 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
8484 else if (ctype_isChar (expected))
8488 else if (ctype_isArrayPtr (expected))
8492 else if (ctype_isAnyFloat (expected))
8494 return (context_getFlag (FLG_NUMLITERAL));
8501 else if (multiVal_isDouble (m))
8503 if (ctype_isAnyFloat (expected))
8508 else if (multiVal_isChar (m))
8510 char val = multiVal_forceChar (m);
8512 if (ctype_isChar (expected))
8514 if (ctype_isUnsigned (expected) && ((int)val) < 0)
8535 exprNode_matchType (ctype expected, exprNode e)
8539 if (!exprNode_isDefined (e)) return TRUE;
8541 actual = ctype_realishType (exprNode_getType (e));
8543 if (ctype_match (ctype_realishType (expected), actual))
8548 llassert (!exprNode_isError (e));
8549 return (exprNode_matchLiteral (expected, e));
8553 exprNode_matchTypes (exprNode e1, exprNode e2)
8558 if (!exprNode_isDefined (e1)) return TRUE;
8559 if (!exprNode_isDefined (e2)) return TRUE;
8562 ** realish type --- keep bools, bools
8565 t1 = ctype_realishType (exprNode_getType (e1));
8566 t2 = ctype_realishType (exprNode_getType (e2));
8568 if (ctype_match (t1, t2))
8573 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
8581 exprNode_matchArgType (ctype ct, exprNode e)
8585 if (!exprNode_isDefined (e))
8590 et = ctype_realType (exprNode_getType (e));
8592 if (ctype_matchArg (ct, et)) return TRUE;
8594 llassert (!exprNode_isError (e));
8595 return (exprNode_matchLiteral (ct, e));
8598 static /*@only@*/ exprNodeSList
8599 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
8601 if (exprNode_isDefined (e))
8603 if (e->kind == XPR_STMTLIST)
8605 return (exprNodeSList_append
8606 (exprNode_flatten (exprData_getPairA (e->edata)),
8607 exprNode_flatten (exprData_getPairB (e->edata))));
8609 else if (e->kind == XPR_BLOCK)
8611 return (exprNode_flatten (exprData_getSingle (e->edata)));
8615 return (exprNodeSList_singleton (e));
8619 return exprNodeSList_new ();
8622 static /*@exposed@*/ exprNode
8623 exprNode_lastStatement (/*@returned@*/ exprNode e)
8625 if (exprNode_isDefined (e))
8627 if (e->kind == XPR_STMTLIST)
8629 exprNode b = exprData_getPairB (e->edata);
8631 if (exprNode_isDefined (b))
8633 return exprNode_lastStatement (b);
8637 return exprNode_lastStatement (exprData_getPairA (e->edata));
8640 else if (e->kind == XPR_BLOCK)
8642 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
8650 return exprNode_undefined;
8653 static /*@exposed@*/ exprNode
8654 exprNode_firstStatement (/*@returned@*/ exprNode e)
8656 if (exprNode_isDefined (e))
8658 if (e->kind == XPR_STMTLIST)
8660 exprNode b = exprData_getPairA (e->edata);
8662 if (exprNode_isDefined (b))
8664 return exprNode_firstStatement (b);
8668 return exprNode_firstStatement (exprData_getPairB (e->edata));
8671 else if (e->kind == XPR_BLOCK)
8673 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
8681 return exprNode_undefined;
8685 exprNode_mergeUSs (exprNode res, exprNode other)
8687 if (exprNode_isDefined (res) && exprNode_isDefined (other))
8689 res->msets = sRefSet_union (res->msets, other->msets);
8690 res->sets = sRefSet_union (res->sets, other->sets);
8691 res->uses = sRefSet_union (res->uses, other->uses);
8696 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
8698 if (exprNode_isDefined (res))
8700 if (exprNode_isDefined (other1))
8702 res->sets = sRefSet_union (res->sets, other1->sets);
8703 res->msets = sRefSet_union (res->msets, other1->msets);
8704 res->uses = sRefSet_union (res->uses, other1->uses);
8706 if (exprNode_isDefined (other2))
8708 res->sets = sRefSet_union (res->sets, other2->sets);
8709 res->msets = sRefSet_union (res->msets, other2->msets);
8710 res->uses = sRefSet_union (res->uses, other2->uses);
8718 ** Reports errors is s is not defined.
8722 exprNode_addUse (exprNode e, sRef s)
8724 if (exprNode_isDefined (e))
8726 e->uses = sRefSet_insert (e->uses, s);
8731 exprNode_checkUse (exprNode e, sRef s, fileloc loc)
8733 if (sRef_isKnown (s) && !sRef_isConst (s))
8736 ** need to check all outer types are useable
8739 DPRINTF (("Check use: %s / %s",
8740 exprNode_unparse (e), sRef_unparse (s)));
8742 exprNode_addUse (e, s);
8744 if (!context_inProtectVars ())
8747 ** only report the deepest error
8750 sRef errorRef = sRef_undefined;
8751 sRef lastRef = sRef_undefined;
8752 bool deadRef = FALSE;
8753 bool unuseable = FALSE;
8754 bool errorMaybe = FALSE;
8756 while (sRef_isValid (s) && sRef_isKnown (s))
8758 ynm readable = sRef_isReadable (s);
8760 if (!(ynm_toBoolStrict (readable)))
8762 if (ynm_isMaybe (readable))
8766 deadRef = sRef_isPossiblyDead (errorRef);
8767 unuseable = sRef_isUnuseable (errorRef);
8774 deadRef = sRef_isDead (errorRef);
8775 unuseable = sRef_isUnuseable (errorRef);
8779 if (!sRef_isPartial (s))
8781 sRef_setDefined (s, fileloc_undefined);
8785 s = sRef_getBaseSafe (s);
8788 if (sRef_isValid (errorRef))
8790 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
8791 && sRef_isPointer (errorRef))
8798 if (sRef_isThroughArrayFetch (errorRef))
8801 (FLG_STRICTUSERELEASED,
8802 message ("%q %q may be used after being released",
8803 sRef_unparseKindNamePlain (errorRef),
8804 sRef_unparse (errorRef)),
8807 sRef_showRefKilled (errorRef);
8809 if (sRef_isKept (errorRef))
8811 sRef_clearAliasState (errorRef, loc);
8817 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8821 message ("%q %q %qused after being released",
8822 sRef_unparseKindNamePlain (errorRef),
8823 sRef_unparse (errorRef),
8824 cstring_makeLiteral (errorMaybe
8828 sRef_showRefKilled (errorRef);
8830 if (sRef_isKept (errorRef))
8832 sRef_clearAliasState (errorRef, loc);
8841 message ("%q %q%qused in inconsistent state",
8842 sRef_unparseKindName (errorRef),
8843 sRef_unparseOpt (errorRef),
8844 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8847 sRef_showStateInconsistent (errorRef);
8852 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8856 message ("%q %q%qused before definition",
8857 sRef_unparseKindName (errorRef),
8858 sRef_unparseOpt (errorRef),
8859 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8863 sRef_setDefined (errorRef, loc);
8865 if (sRef_isAddress (errorRef))
8867 sRef_setDefined (sRef_getRootBase (errorRef), loc);
8869 } /* end is error */
8877 checkSafeUse (exprNode e, sRef s)
8879 if (exprNode_isDefined (e) && sRef_isKnown (s))
8881 e->uses = sRefSet_insert (e->uses, s);
8886 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
8888 if (exprNode_isDefined (e))
8890 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
8895 exprNode_checkSet (exprNode e, sRef s)
8897 sRef defines = sRef_undefined;
8899 if (sRef_isValid (s) && !sRef_isNothing (s))
8901 uentry ue = sRef_getBaseUentry (s);
8903 if (uentry_isValid (ue))
8905 uentry_setLset (ue);
8908 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
8910 voptgenerror (FLG_USEDEF,
8911 message ("Attempt to set unuseable storage: %q",
8916 if (sRef_isMeaningful (s))
8919 if (sRef_isDead (s))
8921 sRef base = sRef_getBaseSafe (s);
8923 if (sRef_isValid (base)
8924 && sRef_isDead (base))
8926 sRef_setPartial (s, exprNode_loc (e));
8929 defines = s; /* okay - modifies for only param */
8931 else if (sRef_isPartial (s))
8933 sRef eref = exprNode_getSref (e);
8935 if (!sRef_isPartial (eref))
8938 ** should do something different here???
8941 sRef_setDefinedComplete (eref, exprNode_loc (e));
8945 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
8948 if (sRef_isMeaningful (eref))
8957 else if (sRef_isAllocated (s))
8959 sRef eref = exprNode_getSref (e);
8962 if (!sRef_isAllocated (eref))
8964 sRef_setDefinedComplete (eref, exprNode_loc (e));
8968 sRef base = sRef_getBaseSafe (eref);
8970 if (sRef_isValid (base))
8972 sRef_setPdefined (base, exprNode_loc (e));
8980 sRef_setDefinedNCComplete (s, exprNode_loc (e));
8985 else /* not meaningful...but still need to insert it */
8991 if (exprNode_isDefined (e) && sRef_isValid (defines))
8993 e->sets = sRefSet_insert (e->sets, defines);
8998 exprNode_checkMSet (exprNode e, sRef s)
9000 if (sRef_isValid (s) && !sRef_isNothing (s))
9002 uentry ue = sRef_getBaseUentry (s);
9004 if (uentry_isValid (ue))
9006 uentry_setLset (ue);
9009 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9011 voptgenerror (FLG_USEDEF,
9012 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9016 if (sRef_isMeaningful (s))
9018 sRef_setDefinedComplete (s, exprNode_loc (e));
9021 if (exprNode_isDefined (e))
9023 e->msets = sRefSet_insert (e->msets, s);
9029 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9031 checkAnyCall (fcn, cstring_undefined, params, args,
9032 FALSE, sRefSet_undefined, FALSE, 0);
9036 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9037 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9041 if (uentry_isYield (ucurrent))
9043 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9044 exprNode_checkSet (current, current->sref);
9048 if (uentry_isSefParam (ucurrent))
9050 sRefSet sets = current->sets;
9051 sRef ref = exprNode_getSref (current);
9053 if (sRef_isMacroParamRef (ref))
9055 uentry ue = sRef_getUentry (ref);
9057 if (!uentry_isSefParam (ue))
9062 ("Parameter %d to %s is declared sef, but "
9063 "the argument is a macro parameter declared "
9065 argno, exprNode_unparse (fcn),
9066 exprNode_unparse (current)),
9067 exprNode_loc (current));
9071 if (!sRefSet_isEmpty (sets))
9073 sRefSet reported = sRefSet_undefined;
9075 sRefSet_realElements (current->sets, el)
9077 if (sRefSet_isSameNameMember (reported, el))
9079 ; /* don't report again */
9083 if (sRef_isUnconstrained (el))
9088 ("Parameter %d to %s is declared sef, but "
9089 "the argument calls unconstrained function %s "
9090 "(no guarantee it will not modify something): %s",
9091 argno, exprNode_unparse (fcn),
9092 sRef_unconstrainedName (el),
9093 exprNode_unparse (current)),
9094 exprNode_loc (current));
9101 ("Parameter %d to %s is declared sef, but "
9102 "the argument may modify %q: %s",
9103 argno, exprNode_unparse (fcn),
9105 exprNode_unparse (current)),
9106 exprNode_loc (current));
9109 } end_sRefSet_realElements;
9113 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9114 exprNode_mergeUSs (fcn, current);
9119 checkAnyCall (/*@dependent@*/ exprNode fcn,
9120 /*@dependent@*/ cstring fname,
9123 bool hasMods, sRefSet mods,
9128 int nargs = exprNodeList_size (args);
9133 ** concat all args ud's to f, add each arg sref as a use unless
9134 ** it was specified as "out", in which case it is a def.
9137 uentryList_reset (pn);
9142 ** if paramn is only or unique, no other arg may alias argn
9145 exprNodeList_elements (args, current)
9149 if (exprNode_isDefined (current))
9151 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9153 uentry ucurrent = uentryList_current (pn);
9155 if (specialArgs == 0
9156 || (paramno < specialArgs))
9158 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9160 if (context_maybeSet (FLG_ALIASUNIQUE))
9162 if (uentry_isOnly (ucurrent)
9163 || uentry_isUnique (ucurrent))
9165 checkUniqueParams (fcn, current, args,
9171 else /* uentry is undefined */
9173 if (specialArgs == 0)
9175 exprNode_checkUseParam (current);
9178 exprNode_mergeUSs (fcn, current);
9181 uentryList_advanceSafe (pn);
9182 } end_exprNodeList_elements;
9188 sRefSet_allElements (mods, s)
9191 sRef rb = sRef_getRootBase (s);
9193 if (sRef_isGlobal (rb))
9195 context_usedGlobal (rb);
9198 fb = sRef_fixBaseParam (s, args);
9200 if (!sRef_isMacroParamRef (fb))
9202 if (sRef_isNothing (fb))
9208 if (sRef_isValid (fb))
9210 uentry ue = sRef_getBaseUentry (s);
9212 if (uentry_isValid (ue))
9214 uentry_setLset (ue);
9218 fcn->sets = sRefSet_insert (fcn->sets, fb);
9221 sRef_clearDerivedComplete (s);
9222 } end_sRefSet_allElements;
9228 if (context_hasMods ())
9230 if (context_maybeSet (FLG_MODUNCON))
9234 message ("Undetected modification possible "
9235 "from call to unconstrained function %s: %s",
9237 exprNode_unparse (fcn)),
9238 exprNode_loc (fcn));
9243 if (context_maybeSet (FLG_MODUNCONNOMODS)
9244 && !(context_inIterDef () || context_inIterEnd ()))
9247 (FLG_MODUNCONNOMODS,
9248 message ("Undetected modification possible "
9249 "from call to unconstrained function %s: %s",
9251 exprNode_unparse (fcn)),
9252 exprNode_loc (fcn));
9256 exprNode_checkSetAny (fcn, fname);
9260 void exprNode_checkUseParam (exprNode current)
9262 if (exprNode_isDefined (current))
9264 exprNode_checkUse (current, current->sref, current->loc);
9269 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
9270 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9275 if (!ctype_match (tr1, tr2))
9277 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
9278 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
9286 message ("Incompatible types for %s (%s, %s): %s %s %s",
9288 ctype_unparse (te1),
9289 ctype_unparse (te2),
9290 exprNode_unparse (e1), lltok_unparse (op),
9291 exprNode_unparse (e2)),
9294 ret = ctype_unknown;
9298 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
9300 ret = ctype_resolveNumerics (tr1, tr2);
9302 else if (!context_msgStrictOps ())
9304 if (ctype_isPointer (tr1))
9306 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
9310 else if (ctype_isInt (tr2))
9316 ret = ctype_unknown;
9319 else if (ctype_isPointer (tr2))
9321 if (ctype_isPointer (tr1))
9325 else if (ctype_isInt (tr1))
9331 ret = ctype_unknown;
9336 ret = ctype_resolveNumerics (tr1, tr2);
9341 int opid = lltok_getTok (op);
9342 bool comparop = (opid == EQ_OP || opid == NE_OP
9343 || opid == TLT || opid == TGT
9344 || opid == LE_OP || opid == GE_OP);
9346 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
9349 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
9350 || (ctype_isBool (tr1) && ctype_isBool (tr2))
9351 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
9357 if (ctype_sameName (te1, te2))
9361 message ("Operands of %s are non-numeric (%t): %s %s %s",
9362 lltok_unparse (op), te1,
9363 exprNode_unparse (e1), lltok_unparse (op),
9364 exprNode_unparse (e2)),
9371 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
9372 lltok_unparse (op), te1, te2,
9373 exprNode_unparse (e1), lltok_unparse (op),
9374 exprNode_unparse (e2)),
9379 else if (!ctype_isNumeric (tr1))
9383 message ("Right operand of %s is non-numeric (%t): %s %s %s",
9384 lltok_unparse (op), te1,
9385 exprNode_unparse (e1), lltok_unparse (op),
9386 exprNode_unparse (e2)),
9391 if (!ctype_isNumeric (tr2))
9395 message ("Left operand of %s is non-numeric (%t): %s %s %s",
9396 lltok_unparse (op), te2,
9397 exprNode_unparse (e1), lltok_unparse (op),
9398 exprNode_unparse (e2)),
9403 ret = ctype_unknown;
9411 abstractOpError (ctype tr1, ctype tr2, lltok op,
9412 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9413 fileloc loc1, fileloc loc2)
9415 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
9417 if (ctype_match (tr1, tr2))
9421 message ("Operands of %s are abstract type (%t): %s %s %s",
9422 lltok_unparse (op), tr1,
9423 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9430 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
9431 lltok_unparse (op), tr1, tr2,
9432 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9436 else if (ctype_isRealAbstract (tr1))
9440 message ("Left operand of %s is abstract type (%t): %s %s %s",
9441 lltok_unparse (op), tr1,
9442 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9447 if (ctype_isRealAbstract (tr2))
9451 message ("Right operand of %s is abstract type (%t): %s %s %s",
9452 lltok_unparse (op), tr2,
9453 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9462 ** requies e1 and e2 and not error exprNode's.
9466 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
9467 ** the rep of the abstract type is exposed.
9469 ** The order is very important:
9471 ** check rep expose (move into check transfer)
9477 ** This isn't really a sensible procedure, but the indententation
9478 ** was getting too deep.
9482 checkOneRepExpose (sRef ysr, sRef base,
9483 /*@notnull@*/ exprNode e1,
9484 /*@notnull@*/ exprNode e2, ctype ct,
9487 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
9488 || sRef_isOwned (ysr) || sRef_isExposed (ysr)))
9490 if (sRef_isAnyParam (base) && !sRef_isExposed (base))
9492 if (sRef_isIReference (ysr))
9494 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9499 ("Assignment of mutable component of parameter %q "
9500 "to component of abstract "
9501 "type %s exposes rep: %s = %s",
9502 sRef_unparse (base),
9504 exprNode_unparse (e1), exprNode_unparse (e2)),
9512 ("Assignment of mutable component of parameter %q "
9513 "(through alias %q) to component of abstract "
9514 "type %s exposes rep: %s = %s",
9515 sRef_unparse (base),
9516 sRef_unparse (e2->sref),
9518 exprNode_unparse (e1), exprNode_unparse (e2)),
9524 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9528 message ("Assignment of mutable parameter %q "
9529 "to component of abstract type %s "
9530 "exposes rep: %s = %s",
9531 sRef_unparse (base),
9533 exprNode_unparse (e1),
9534 exprNode_unparse (e2)),
9541 message ("Assignment of mutable parameter %q "
9542 "(through alias %q) to "
9543 "component of abstract type %s exposes "
9545 sRef_unparse (base),
9546 sRef_unparse (e2->sref),
9548 exprNode_unparse (e1),
9549 exprNode_unparse (e2)),
9555 if (sRef_isGlobal (s2b))
9557 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9561 message ("Assignment of global %q "
9563 "abstract type %s exposes rep: %s = %s",
9564 sRef_unparse (base),
9566 exprNode_unparse (e1), exprNode_unparse (e2)),
9573 message ("Assignment of global %q (through alias %q) "
9575 "abstract type %s exposes rep: %s = %s",
9576 sRef_unparse (base),
9577 sRef_unparse (e2->sref),
9579 exprNode_unparse (e1), exprNode_unparse (e2)),
9587 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
9589 if (ctype_isRealFunction (exprNode_getType (e1))
9590 && !ctype_isRealPointer (exprNode_getType (e1)))
9594 message ("Invalid left-hand side of assignment (function type %s): %s",
9595 ctype_unparse (exprNode_getType (e1)),
9596 exprNode_unparse (e1)),
9600 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
9602 ctype t2 = exprNode_getType (e2);
9603 sRef sr = sRef_getRootBase (e1->sref);
9604 ctype ct = sRef_getType (sr);
9606 if (ctype_isAbstract (t2)
9607 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
9609 /* it is immutable, okay to reference */
9613 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
9615 sRef s2b = sRef_getRootBase (e2->sref);
9617 sRef s1b = sRef_getRootBase (s1);
9620 aliases = usymtab_canAlias (e2->sref);
9622 if (!sRef_similar (s2b, s1b)
9623 && !sRef_isExposed (s1)
9624 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
9626 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
9627 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
9628 && !sRef_isExposed (s2b))
9630 if (sRef_isIReference (e2->sref))
9635 ("Assignment of mutable component of parameter %q "
9636 "to component of abstract type %s exposes rep: %s = %s",
9639 exprNode_unparse (e1), exprNode_unparse (e2)),
9646 message ("Assignment of mutable parameter %q to "
9647 "component of abstract type %s exposes rep: %s = %s",
9650 exprNode_unparse (e1), exprNode_unparse (e2)),
9655 if (sRef_isGlobal (s2b))
9659 message ("Assignment of global %q to component of "
9660 "abstract type %s exposes rep: %s = %s",
9663 exprNode_unparse (e1), exprNode_unparse (e2)),
9667 sRefSet_realElements (aliases, ysr)
9669 sRef base = sRef_getRootBase (ysr);
9671 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
9672 || sRef_sameName (base, s1b))
9674 ; /* error already reported or same sref */
9678 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
9680 } end_sRefSet_realElements;
9682 sRefSet_free (aliases);
9689 ** function variables don't really work...
9692 if (!ctype_isFunction (ctype_realType (e2->typ)))
9696 checkInitTransfer (e1, e2);
9700 checkAssignTransfer (e1, e2);
9705 sRef fref = e2->sref;
9707 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
9708 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
9710 /* Need to typecheck the annotation on the parameters */
9712 if (ctype_isRealFunction (e1->typ)) {
9713 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
9714 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
9716 if (!uentryList_isMissingParams (e1p)
9717 && !uentryList_isMissingParams (e2p)
9718 && uentryList_size (e1p) > 0) {
9719 if (uentryList_size (e1p) == uentryList_size (e2p)) {
9722 uentryList_elements (e1p, el1) {
9725 el2 = uentryList_getN (e2p, n);
9727 uentry_checkMatchParam (el1, el2, n, e2);
9728 } end_uentryList_elements;
9734 if (isInit && sRef_isGlobal (e1->sref))
9740 updateAliases (e1, e2);
9742 // updateEnvironment (e1, e2);
9746 checkMacroParen (exprNode e)
9748 if (exprNode_isError (e) || e->kind == XPR_CAST)
9754 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
9758 message ("Macro parameter used without parentheses: %s",
9759 exprNode_unparse (e)),
9766 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
9770 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
9774 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
9781 ** if e2 is a parameter or global derived location which
9782 ** can be modified (that is, e2 is a mutable abstract type,
9783 ** or a derived pointer), then e1 can alias e2.
9785 ** e1 can alias everything which e2 can alias.
9787 ** Also, if e1 is guarded, remove from guard sets!
9790 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
9792 if (!context_inProtectVars ())
9795 ** depends on types of e1 and e2
9800 ctype t1 = exprNode_getType (e1);
9802 /* handle pointer sRefs, record fields, arrays, etc... */
9804 if (!ctype_isRealSU (t1))
9806 sRef_copyRealDerivedComplete (s1, s2);
9809 if (ctype_isMutable (t1) && sRef_isKnown (s1))
9811 usymtab_clearAlias (s1);
9812 usymtab_addMustAlias (s1, s2);
9815 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
9817 usymtab_unguard (s1);
9822 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
9824 if (exprNode_isDefined (e))
9826 e->loc = fileloc_update (e->loc, loc);
9830 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
9836 static void checkUniqueParams (exprNode fcn,
9837 /*@notnull@*/ exprNode current,
9839 int paramno, uentry ucurrent)
9842 sRef thisref = exprNode_getSref (current);
9845 ** Check if any argument could match this argument.
9848 exprNodeList_elements (args, icurrent)
9852 if (iparamno != paramno)
9854 sRef sr = exprNode_getSref (icurrent);
9856 if (sRef_similarRelaxed (thisref, sr))
9858 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
9863 ("Parameter %d (%s) to function %s is declared %s but "
9864 "is aliased by parameter %d (%s)",
9866 exprNode_unparse (current),
9867 exprNode_unparse (fcn),
9868 alkind_unparse (uentry_getAliasKind (ucurrent)),
9869 iparamno, exprNode_unparse (icurrent)),
9875 sRefSet aliases = usymtab_canAlias (sr);
9877 sRefSet_allElements (aliases, asr)
9879 if (ctype_isUnknown (sRef_getType (thisref)))
9881 sRef_setType (thisref, uentry_getType (ucurrent));
9884 if (sRef_similarRelaxed (thisref, asr))
9886 if (sRef_isExternal (asr))
9888 if (sRef_isLocalState (thisref))
9894 sRef base = sRef_getRootBase (asr);
9896 if (!sRef_similar (sRef_getBase (asr), thisref))
9898 if (sRef_isUnique (base) || sRef_isOnly (base)
9899 || sRef_isKept (base)
9900 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
9901 || (sRef_isAddress (thisref)
9902 && sRef_isLocalVar (sRef_getRootBase (thisref))))
9904 ; /* okay, no error */
9909 (FLG_MAYALIASUNIQUE,
9911 ("Parameter %d (%s) to function %s is declared %s but "
9912 "may be aliased externally by parameter %d (%s)",
9914 exprNode_unparse (current),
9915 exprNode_unparse (fcn),
9916 alkind_unparse (uentry_getAliasKind (ucurrent)),
9917 iparamno, exprNode_unparse (icurrent)),
9928 ("Parameter %d (%s) to function %s is declared %s but "
9929 "is aliased externally by parameter %d (%s) through "
9932 exprNode_unparse (current),
9933 exprNode_unparse (fcn),
9934 alkind_unparse (uentry_getAliasKind (ucurrent)),
9935 iparamno, exprNode_unparse (icurrent),
9936 sRef_unparse (asr)),
9940 } end_sRefSet_allElements;
9941 sRefSet_free (aliases);
9944 } end_exprNodeList_elements;
9947 long exprNode_getLongValue (exprNode e) {
9950 if (exprNode_hasValue (e)
9951 && multiVal_isInt (exprNode_getValue (e)))
9953 value = multiVal_forceInt (exprNode_getValue (e));
9963 fileloc exprNode_getfileloc (exprNode p_e)
9966 return fileloc_copy ( p_e->loc );
9968 return fileloc_undefined;
9971 fileloc exprNode_getNextSequencePoint (exprNode e)
9974 ** Returns the location of the sequence point following e.
9976 ** Only works for statements (for now).
9979 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
9980 lltok t = exprData_getUopTok (e->edata);
9981 return lltok_getLoc (t);
9984 // llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
9985 return fileloc_undefined;
9992 exprNode exprNode_fakeCopy (exprNode e)
9994 /*@-temptrans@*/ /*@-retalias@*/
9996 /*@=temptrans@*/ /*@=retalias@*/
9999 exprNode exprNode_createNew(ctype c)
10003 ret = exprNode_createPlain (c);