2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
28 # include <ctype.h> /* for isdigit */
29 # include "lclintMacros.nf"
31 # include "cgrammar.h"
32 # include "cgrammar_tokens.h"
34 # include "exprChecks.h"
35 # include "aliasChecks.h"
36 # include "exprNodeSList.h"
37 # include "exprData.i"
39 static bool exprNode_isEmptyStatement (exprNode p_e);
40 static /*@exposed@*/ exprNode exprNode_firstStatement (/*@returned@*/ exprNode p_e);
41 static bool exprNode_isFalseConstant (exprNode p_e) /*@*/ ;
42 static bool exprNode_isBlock (exprNode p_e);
43 static void checkGlobUse (uentry p_glob, bool p_isCall, /*@notnull@*/ exprNode p_e);
44 static void exprNode_addUse (exprNode p_e, sRef p_s);
45 static bool exprNode_matchArgType (ctype p_ct, exprNode p_e);
46 exprNode exprNode_fakeCopy (exprNode p_e) /*@*/ ;
47 static exprNode exprNode_statementError (/*@only@*/ exprNode p_e, /*@only@*/ lltok p_t);
48 static bool exprNode_matchTypes (exprNode p_e1, exprNode p_e2);
49 static void checkUniqueParams (exprNode p_fcn,
50 /*@notnull@*/ exprNode p_current, exprNodeList p_args,
51 int p_paramno, uentry p_ucurrent);
52 static void updateAliases (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2);
53 static void abstractOpError (ctype p_tr1, ctype p_tr2, lltok p_op,
54 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2,
55 fileloc p_loc1, fileloc p_loc2);
56 static ctype checkNumerics (ctype p_tr1, ctype p_tr2, ctype p_te1, ctype p_te2,
57 /*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, lltok p_op);
58 static void doAssign (/*@notnull@*/ exprNode p_e1, /*@notnull@*/ exprNode p_e2, bool p_isInit);
59 static void checkSafeUse (exprNode p_e, sRef p_s);
60 static void reflectNullTest (/*@notnull@*/ exprNode p_e, bool p_isnull);
61 static void checkMacroParen (exprNode p_e);
62 static exprNodeSList exprNode_flatten (/*@dependent@*/ exprNode p_e);
63 static void exprNode_checkSetAny (exprNode p_e, /*@dependent@*/ cstring p_name);
64 static void exprNode_checkUse (exprNode p_e, sRef p_s, fileloc p_loc);
65 static void exprNode_mergeUSs (exprNode p_res, exprNode p_other);
66 static void exprNode_mergeCondUSs (exprNode p_res, exprNode p_other1, exprNode p_other2);
67 static /*@only@*/ /*@notnull@*/ exprNode exprNode_fromIdentifierAux (/*@observer@*/ uentry p_c);
68 static void checkAnyCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn,
69 /*@dependent@*/ cstring p_fname,
70 uentryList p_pn, exprNodeList p_args,
71 bool p_hasMods, sRefSet p_mods, bool p_isSpec,
73 static void checkOneArg (uentry p_ucurrent, /*@notnull@*/ exprNode p_current,
74 /*@dependent@*/ exprNode p_fcn, bool p_isSpec, int p_argno, int p_totargs);
76 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode p_fcn, uentryList p_params, exprNodeList p_args);
78 static /*@only@*/ exprNode exprNode_effect (exprNode p_e)
79 /*@globals internalState@*/ ;
80 static /*@only@*/ cstring exprNode_doUnparse (exprNode p_e);
81 static /*@observer@*/ cstring exprNode_rootVarName (exprNode p_e);
82 static /*@exposed@*/ exprNode
83 exprNode_lastStatement (/*@returned@*/ exprNode p_e);
85 static /*@null@*/ sRef defref = sRef_undefined;
86 static /*@only@*/ exprNode mustExitNode = exprNode_undefined;
88 static int checkArgsReal (uentry p_fcn, /*@dependent@*/ exprNode p_f,
90 exprNodeList p_args, bool p_isIter, exprNode p_ret);
92 static bool inEffect = FALSE;
93 static int nowalloc = 0;
94 static int totalloc = 0;
95 static int maxalloc = 0;
97 static /*@only@*/ uentry regArg;
98 static /*@only@*/ uentry outArg;
99 static /*@only@*/ uentry outStringArg;
100 static /*@exposed@*/ sRef stdinRef;
101 static /*@exposed@*/ sRef stdoutRef;
102 static /*@only@*/ uentry csArg;
103 static /*@only@*/ uentry csOnlyArg;
104 static ctype cstringType;
105 static ctype ctypeType;
106 static ctype filelocType;
107 static bool initMod = FALSE;
110 ** must occur after library has been read
113 void exprNode_initMod (void)
114 /*@globals undef regArg, undef outArg, undef outStringArg,
115 undef csOnlyArg, undef csArg;
122 cstringType = ctype_unknown;
123 ctypeType = ctype_unknown;
124 filelocType = ctype_unknown;
126 defref = sRef_undefined;
128 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
130 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
133 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
135 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
138 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
140 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
143 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdin")))
145 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdin"));
147 else /* define stdin */
149 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdin"),
151 fileloc_getBuiltin (),
153 uentry_setHasNameError (ue);
154 ue = usymtab_supGlobalEntryReturn (ue);
157 stdinRef = sRef_makePointer (uentry_getSref (ue));
159 if (usymtab_existsGlob (cstring_makeLiteralTemp ("stdout")))
161 ue = usymtab_lookupGlob (cstring_makeLiteralTemp ("stdout"));
165 ue = uentry_makeVariable (cstring_makeLiteralTemp ("stdout"),
167 fileloc_getBuiltin (),
169 uentry_setHasNameError (ue);
170 ue = usymtab_supGlobalEntryReturn (ue);
173 stdoutRef = sRef_makePointer (uentry_getSref (ue));
175 tmp = idDecl_create (cstring_undefined, qtype_create (ctype_unknown));
177 regArg = uentry_makeParam (tmp, PARAMUNKNOWN);
180 qtype_addQual (qtype_create (ctype_makePointer (ctype_unknown)),
183 outArg = uentry_makeParam (tmp, PARAMUNKNOWN);
185 idDecl_setTyp (tmp, qtype_addQual (qtype_create (ctype_string),
188 outStringArg = uentry_makeParam (tmp, PARAMUNKNOWN);
190 idDecl_setTyp (tmp, qtype_addQual (qtype_addQual (qtype_create (cstringType),
192 qual_createNull ()));
194 csOnlyArg = uentry_makeParam (tmp, PARAMUNKNOWN);
196 idDecl_setTyp (tmp, qtype_addQual (qtype_create (cstringType), qual_createNull ()));
197 csArg = uentry_makeParam (tmp, PARAMUNKNOWN);
203 exprNode_destroyMod (void)
204 /*@globals killed regArg, killed outArg, killed outStringArg,
205 killed mustExitNode, initMod @*/
209 uentry_free (regArg);
210 uentry_free (outArg);
211 uentry_free (outStringArg);
213 exprNode_free (mustExitNode);
220 static void exprNode_resetSref (/*@notnull@*/ exprNode e)
225 exprNode exprNode_fakeCopy (exprNode e)
227 /*@-temptrans@*/ /*@-retalias@*/
229 /*@=temptrans@*/ /*@=retalias@*/
232 static bool isFlagKey (char key)
234 return (key == '-' || key == '+' || key == ' ' || key == '#');
237 static void exprNode_combineControl (/*@notnull@*/ exprNode ret,
238 /*@notnull@*/ exprNode ifclause,
239 /*@notnull@*/ exprNode elseclause)
241 ret->canBreak = ifclause->canBreak || elseclause->canBreak;
244 (ifclause->mustBreak || exprNode_mustEscape (ifclause))
245 && (elseclause->mustBreak || exprNode_mustEscape (elseclause));
247 ret->exitCode = exitkind_combine (ifclause->exitCode,
248 elseclause->exitCode);
253 ** For exprNode's returned by exprNode_effect.
256 static bool shallowKind (exprKind kind)
258 return (kind == XPR_STRINGLITERAL
259 || kind == XPR_NUMLIT
262 || kind == XPR_NODE);
266 exprNode_freeIniter (/*@only@*/ exprNode e)
268 if (!exprNode_isError (e))
273 sfree (e->edata->field);
277 exprNode_free (e->edata->op->b);
278 /*@-compdestroy@*/ sfree (e->edata->op); /*@=compdestroy@*/
282 llbug (message ("other: %s", exprNode_unparse (e)));
285 multiVal_free (e->val);
286 cstring_free (e->etext);
287 fileloc_free (e->loc);
288 sRefSet_free (e->uses);
289 sRefSet_free (e->sets);
290 sRefSet_free (e->msets);
291 guardSet_free (e->guards);
297 exprNode_freeShallow (/*@only@*/ exprNode e)
299 if (!exprNode_isError (e))
301 if (shallowKind (e->kind))
308 if (e->kind == XPR_EMPTY
309 || e->kind == XPR_BODY
310 || e->kind == XPR_STRINGLITERAL
311 || e->kind == XPR_NUMLIT
312 || e->kind == XPR_NODE
313 || e->kind == XPR_OFFSETOF
314 || e->kind == XPR_ALIGNOFT
315 || e->kind == XPR_ALIGNOF
316 || e->kind == XPR_SIZEOFT
317 || e->kind == XPR_SIZEOF)
319 /* don't free anything */
323 /* multiVal_free (e->val); */
324 cstring_free (e->etext);
325 fileloc_free (e->loc);
326 sRefSet_free (e->uses);
327 sRefSet_free (e->sets);
328 sRefSet_free (e->msets);
329 guardSet_free (e->guards);
330 exprData_freeShallow (e->edata, e->kind);
332 /*@-compdestroy@*/ sfree (e); /*@=compdestroy@*/
341 exprNode_free (exprNode e)
343 if (!exprNode_isError (e))
347 multiVal_free (e->val);
348 cstring_free (e->etext);
349 fileloc_free (e->loc);
350 sRefSet_free (e->uses);
351 sRefSet_free (e->sets);
352 sRefSet_free (e->msets);
353 guardSet_free (e->guards);
354 exprData_free (e->edata, e->kind);
364 exprNode_makeError ()
366 return exprNode_undefined;
369 static /*@out@*/ /*@only@*/ /*@notnull@*/ exprNode
372 exprNode ret = (exprNode) dmalloc (sizeof (*ret));
373 /* static int lastexpnodes = 0; */
378 if (nowalloc > maxalloc)
386 static /*@notnull@*/ /*@special@*/ exprNode
387 exprNode_createPlain (ctype c)
389 /*@post:isnull result->edata, result->loc, result->val, result->guards,
390 result->uses, result->sets, result->msets, result->etext @*/
393 exprNode e = exprNode_new ();
397 e->val = multiVal_undefined;
399 e->etext = cstring_undefined;
400 e->loc = fileloc_undefined;
401 e->guards = guardSet_undefined;
402 e->uses = sRefSet_undefined;
403 e->sets = sRefSet_undefined;
404 e->msets = sRefSet_undefined;
405 e->edata = exprData_undefined;
406 e->exitCode = XK_NEVERESCAPE;
408 e->mustBreak = FALSE;
409 e->isJumpPoint = FALSE;
410 e->environment = environmentTable_undefined;
411 e->requiresConstraints = constraintList_new();
412 e->ensuresConstraints = constraintList_new();
417 /*@observer@*/ exprNode exprNode_makeMustExit (void)
419 if (exprNode_isUndefined (mustExitNode))
421 mustExitNode = exprNode_createPlain (ctype_unknown);
422 mustExitNode->exitCode = XK_MUSTEXIT;
429 static /*@notnull@*/ /*@special@*/ exprNode exprNode_create (ctype c)
431 /*@post:isnull result->edata, result->guards, result->val,
432 result->uses, result->sets, result->msets@*/
435 exprNode e = exprNode_createPlain (c);
436 e->loc = fileloc_copy (g_currentloc);
440 static /*@notnull@*/ /*@special@*/ exprNode exprNode_createUnknown (void)
442 /*@post:isnull result->edata, result->guards,
443 result->uses, result->sets, result->msets@*/
446 return (exprNode_create (ctype_unknown));
449 static /*@notnull@*/ /*@special@*/ exprNode
450 exprNode_createLoc (ctype c, /*@keep@*/ fileloc loc)
452 /*@post:isnull result->edata, result->guards, result->val,
453 result->uses, result->sets, result->msets@*/
456 exprNode e = exprNode_createPlain (c);
462 exprNode_copySets (/*@special@*/ /*@notnull@*/ exprNode ret, exprNode e)
463 /*@defines ret->guards, ret->uses, ret->sets, ret->msets@*/
465 if (exprNode_isDefined (e))
467 ret->guards = guardSet_copy (e->guards);
468 ret->uses = sRefSet_newCopy (e->uses);
469 ret->sets = sRefSet_newCopy (e->sets);
470 ret->msets = sRefSet_newCopy (e->msets);
474 ret->guards = guardSet_undefined;
475 ret->uses = sRefSet_undefined;
476 ret->sets = sRefSet_undefined;
477 ret->msets = sRefSet_undefined;
481 static /*@notnull@*/ /*@special@*/ exprNode
482 exprNode_createPartialLocCopy (exprNode e, /*@only@*/ fileloc loc)
484 /*@post:isnull result->edata, result->etext@*/
487 exprNode ret = exprNode_new ();
489 if (exprNode_isError (e))
491 ret->typ = ctype_unknown;
492 ret->val = multiVal_undefined;
494 ret->guards = guardSet_undefined;
495 ret->uses = sRefSet_undefined;
496 ret->sets = sRefSet_undefined;
497 ret->msets = sRefSet_undefined;
502 ret->val = multiVal_copy (e->val);
504 ret->guards = guardSet_copy (e->guards);
505 ret->uses = sRefSet_newCopy (e->uses);
506 ret->sets = sRefSet_newCopy (e->sets);
507 ret->msets = sRefSet_newCopy (e->msets);
510 ret->kind = XPR_EMPTY;
512 ret->etext = cstring_undefined;
513 ret->exitCode = XK_NEVERESCAPE;
514 ret->canBreak = FALSE;
515 ret->mustBreak = FALSE;
516 ret->isJumpPoint = FALSE;
517 ret->edata = exprData_undefined;
523 static /*@notnull@*/ /*@special@*/ exprNode
524 exprNode_createPartialCopy (exprNode e)
526 /*@post:isnull result->edata, result->etext@*/
529 return (exprNode_createPartialLocCopy (e, fileloc_copy (exprNode_loc (e))));
532 static /*@notnull@*/ /*@special@*/ exprNode
533 exprNode_createPartialNVCopy (exprNode e)
535 /*@post:isnull result->edata, result->etext, result->val @*/
538 exprNode ret = exprNode_new ();
540 if (exprNode_isError (e))
542 ret->typ = ctype_unknown;
543 ret->loc = fileloc_undefined;
544 ret->guards = guardSet_undefined;
545 ret->uses = sRefSet_undefined;
546 ret->sets = sRefSet_undefined;
547 ret->msets = sRefSet_undefined;
552 ret->loc = fileloc_copy (e->loc);
553 ret->guards = guardSet_copy (e->guards);
554 ret->uses = sRefSet_newCopy (e->uses);
555 ret->sets = sRefSet_newCopy (e->sets);
556 ret->msets = sRefSet_newCopy (e->msets);
559 ret->val = multiVal_undefined;
560 ret->kind = XPR_EMPTY;
562 ret->etext = cstring_undefined;
563 ret->exitCode = XK_NEVERESCAPE;
564 ret->canBreak = FALSE;
565 ret->mustBreak = FALSE;
566 ret->isJumpPoint = FALSE;
567 ret->edata = exprData_undefined;
572 static /*@notnull@*/ /*@special@*/ exprNode
573 exprNode_createSemiCopy (exprNode e)
575 /*@post:isnull result->edata, result->etext, result->sets,
576 result->msets, result->uses, result->guards@*/
579 if (exprNode_isError (e))
581 return exprNode_createPlain (ctype_unknown);
585 exprNode ret = exprNode_new ();
588 ret->val = multiVal_copy (e->val);
589 ret->loc = fileloc_copy (e->loc);
590 ret->guards = guardSet_undefined;
591 ret->uses = sRefSet_undefined;
592 ret->sets = sRefSet_undefined;
593 ret->msets = sRefSet_undefined;
595 ret->kind = XPR_EMPTY;
597 ret->etext = cstring_undefined;
598 ret->exitCode = XK_NEVERESCAPE;
599 ret->canBreak = FALSE;
600 ret->mustBreak = FALSE;
601 ret->isJumpPoint = FALSE;
602 ret->edata = exprData_undefined;
609 exprNode_isNullValue (exprNode e)
611 if (exprNode_isDefined (e))
613 multiVal m = exprNode_getValue (e);
615 if (multiVal_isInt (m))
617 return (multiVal_forceInt (m) == 0);
625 exprNode_isUnknownConstant (/*@notnull@*/ exprNode e)
627 while (e->kind == XPR_PARENS)
629 e = exprData_getUopNode (e->edata);
630 llassert (exprNode_isDefined (e));
633 if (e->kind == XPR_CONST)
635 multiVal m = exprNode_getValue (e);
637 if (multiVal_isUnknown (m))
647 exprNode_numLiteral (ctype c, /*@temp@*/ cstring t,
648 /*@only@*/ fileloc loc, long val)
650 exprNode e = exprNode_createLoc (c, loc);
652 e->kind = XPR_NUMLIT;
654 llassert (multiVal_isUndefined (e->val));
655 e->val = multiVal_makeInt (val);
656 e->edata = exprData_makeLiteral (cstring_copy (t));
660 e->sref = sRef_makeUnknown ();
661 sRef_setDefNull (e->sref, e->loc);
664 DPRINTF (("Num lit: %s / %s", exprNode_unparse (e), ctype_unparse (exprNode_getType (e))));
669 exprNode_charLiteral (char c, cstring text, /*@only@*/ fileloc loc)
671 exprNode e = exprNode_createLoc (ctype_char, loc);
673 if (context_getFlag (FLG_CHARINTLITERAL))
675 e->typ = ctype_makeConj (ctype_char, ctype_int);
678 e->kind = XPR_NUMLIT;
679 e->val = multiVal_makeChar (c);
681 e->edata = exprData_makeLiteral (cstring_copy (text));
686 exprNode_floatLiteral (double d, ctype ct, cstring text, /*@only@*/ fileloc loc)
688 exprNode e = exprNode_createLoc (ct, loc);
690 e->kind = XPR_NUMLIT;
691 e->val = multiVal_makeDouble (d);
692 e->edata = exprData_makeLiteral (cstring_copy (text));
696 multiVal exprNode_getValue (exprNode e)
698 while (exprNode_isInParens (e)) {
699 if (e->edata != NULL) {
700 e = exprData_getUopNode (e->edata);
706 if (exprNode_isDefined (e)) {
709 return multiVal_undefined;
714 exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
716 exprNode e = exprNode_createLoc (ctype_string, loc);
717 int len = cstring_length (t) - 2;
718 char *ts = cstring_toCharsSafe (t);
719 char *s = cstring_toCharsSafe (cstring_create (len + 1));
721 if (context_getFlag (FLG_STRINGLITERALLEN))
723 if (len > context_getValue (FLG_STRINGLITERALLEN))
725 voptgenerror (FLG_STRINGLITERALLEN,
727 ("String literal length (%d) exceeds maximum "
730 context_getValue (FLG_STRINGLITERALLEN),
736 strncpy (s, ts+1, size_fromInt (len));
740 e->kind = XPR_STRINGLITERAL;
741 e->val = multiVal_makeString (cstring_fromCharsO (s));
742 e->edata = exprData_makeLiteral (t);
743 e->sref = sRef_makeType (ctype_string);
744 /* Start modifications */
745 /* This expr is null terminated, so we set the len and size */
746 sRef_setNullTerminatedState(e->sref);
748 TPRINTF("Len is set to : %d\n\n", strlen((char *)multiVal_forceString(e->val)));
749 TPRINTF("Size is set to : %d\n\n", strlen((char *)multiVal_forceString(e->val)));
750 TPRINTF("State is set to: %d\n\n", e->sref->bufinfo.bufstate);
752 sRef_setLen(e->sref, strlen((char *)multiVal_forceString(e->val)));
753 sRef_setSize(e->sref, strlen((char *)multiVal_forceString(e->val)));
755 if (context_getFlag (FLG_READONLYSTRINGS))
757 sRef_setAliasKind (e->sref, AK_STATIC, fileloc_undefined);
758 sRef_setExKind (e->sref, XO_OBSERVER, loc);
762 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
765 return (e); /* s released */
768 exprNode exprNode_fromUIO (cstring c)
770 fileloc loc = context_getSaveLocation ();
771 exprNode e = exprNode_createPlain (ctype_unknown);
775 if (fileloc_isUndefined (loc))
777 loc = fileloc_copy (g_currentloc);
780 e->loc = loc; /* save loc was mangled */
783 if (usymtab_exists (c))
785 uentry ue = usymtab_lookupEither (c);
787 if (uentry_isDatatype (ue)
788 && uentry_isSpecified (ue))
791 (message ("%q: Specified datatype %s used in code, but not defined. "
792 "(Cannot continue reasonably from this error.)",
793 fileloc_unparse (e->loc), c));
801 llassertprint (!usymtab_exists (c), ("Entry exists: %s", c));
804 ** was supercedeGlobalEntry...is this better?
807 if (!context_inIterEnd ())
809 if (context_inMacro ())
811 if (context_getFlag (FLG_UNRECOG))
815 message ("Unrecognized identifier in macro definition: %s", c), e->loc);
819 flagcode_recordSuppressed (FLG_UNRECOG);
825 (FLG_UNRECOG, message ("Unrecognized identifier: %s", c),
830 e->edata = exprData_makeId (uentry_makeUnrecognized (c, fileloc_copy (loc)));
832 /* No alias errors for unrecognized identifiers */
833 sRef_setAliasKind (e->sref, AK_ERROR, loc);
838 exprNode exprNode_createId (/*@observer@*/ uentry c)
840 if (uentry_isValid (c))
842 exprNode e = exprNode_new ();
844 e->typ = uentry_getType (c);
846 if (uentry_isFunction (c)
847 && !sRef_isLocalVar (uentry_getSref (c)))
849 e->sref = sRef_undefined;
853 e->sref = uentry_getSref (c);
856 if (sRef_isStateUnknown (e->sref) && uentry_isNonLocal (c))
858 sRef_setDefined (e->sref, fileloc_undefined);
862 ** yoikes! leaving this out was a heinous bug...that would have been
863 ** caught if i had lclint working first. gag!
866 e->etext = cstring_undefined;
868 if (uentry_isEitherConstant (c))
871 e->val = multiVal_copy (uentry_getConstantValue (c));
876 e->val = multiVal_unknown ();
879 e->edata = exprData_makeId (c);
880 e->loc = context_getSaveLocation ();
882 if (fileloc_isUndefined (e->loc))
884 fileloc_free (e->loc);
885 e->loc = fileloc_copy (g_currentloc);
888 e->guards = guardSet_new ();
889 e->sets = sRefSet_new ();
890 e->msets = sRefSet_new ();
891 e->uses = sRefSet_new ();
893 /*> missing fields, detected by lclint <*/
894 e->exitCode = XK_NEVERESCAPE;
895 e->isJumpPoint = FALSE;
897 e->mustBreak = FALSE;
903 return exprNode_createUnknown ();
907 /*@notnull@*/ exprNode
908 exprNode_fromIdentifier (/*@observer@*/ uentry c)
912 if (context_justPopped ()) /* watch out! c could be dead */
914 uentry ce = usymtab_lookupSafe (LastIdentifier ());
916 if (uentry_isValid (ce))
922 llbuglit ("Looks like Aunt Millie forgot to walk to dog again.");
926 ret = exprNode_fromIdentifierAux (c);
932 static /*@only@*/ /*@notnull@*/ exprNode
933 exprNode_fromIdentifierAux (/*@observer@*/ uentry c)
935 exprNode e = exprNode_createId (c);
938 uentry_setUsed (c, e->loc);
940 if (uentry_isVar (c) && sRef_isGlobal (sr))
942 checkGlobUse (c, FALSE, e);
949 exprNode_isZero (exprNode e)
951 if (exprNode_isDefined (e))
953 multiVal m = exprNode_getValue (e);
955 if (multiVal_isInt (m))
957 return (multiVal_forceInt (m) == 0);
965 exprNode_isNonNegative (exprNode e)
967 if (exprNode_isDefined (e))
969 multiVal m = exprNode_getValue (e);
971 if (multiVal_isInt (m))
973 return (multiVal_forceInt (m) >= 0);
981 ** a[x] - uses a but NOT a[]
982 ** result sref = a[] (set/use in assignment)
984 ** The syntax x[a] is also legal in C, and has the same
985 ** semantics. If ind is an array, and arr is an int, flip
990 exprNode_arrayFetch (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
993 ** error in arr, error propagates (no new messages)
994 ** error in ind, assume valid and continue
997 if (exprNode_isError (e1))
1000 return (exprNode_makeError ());
1006 ctype carr = exprNode_getType (e1);
1007 ctype crarr = ctype_realType (carr);
1010 ** this sets up funny aliasing, that leads to spurious
1011 ** lclint errors. Hence, the i2 comments.
1014 if (!ctype_isRealArray (crarr)
1015 && ctype_isRealNumeric (crarr)
1016 && !exprNode_isError (e2)
1017 && ctype_isRealAP (exprNode_getType (e2))) /* fetch like 3[a] */
1022 carr = exprNode_getType (arr);
1023 crarr = ctype_realType (carr);
1031 if (sRef_possiblyNull (arr->sref))
1033 if (!usymtab_isGuarded (arr->sref))
1035 if (optgenerror (FLG_NULLDEREF,
1036 message ("Index of %s pointer %q: %s",
1037 sRef_nullMessage (arr->sref),
1038 sRef_unparse (arr->sref),
1039 exprNode_unparse (arr)),
1042 sRef_showNullInfo (arr->sref);
1044 /* suppress future messages */
1045 sRef_setNullError (arr->sref);
1050 if (exprNode_isError (ind))
1052 if ((ctype_isArrayPtr (crarr)
1053 && !ctype_isFunction (crarr))
1054 || ctype_isUnknown (carr))
1056 exprNode ret = exprNode_createPartialCopy (arr);
1058 if (ctype_isKnown (carr))
1060 ret->typ = ctype_baseArrayPtr (crarr);
1064 ret->typ = ctype_unknown;
1067 ret->sref = sRef_makeArrayFetch (arr->sref);
1069 ret->kind = XPR_FETCH;
1072 ** Because of funny aliasing (when arr and ind are
1073 ** flipped) spurious errors would be reported here.
1076 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1077 checkSafeUse (ret, arr->sref);
1082 voptgenerror (FLG_TYPE,
1083 message ("Array fetch from non-array (%t): %s[%s]", carr,
1084 exprNode_unparse (e1), exprNode_unparse (e2)),
1086 exprNode_free (arr);
1087 return (exprNode_makeError ());
1092 if (!ctype_isForceRealInt (&(ind->typ)))
1094 ctype rt = ctype_realType (ind->typ);
1096 if (ctype_isChar (rt))
1100 message ("Array fetch using non-integer, %t: %s[%s]",
1102 exprNode_unparse (e1), exprNode_unparse (e2)),
1105 else if (ctype_isEnum (rt))
1109 message ("Array fetch using non-integer, %t: %s[%s]",
1111 exprNode_unparse (e1), exprNode_unparse (e2)),
1118 message ("Array fetch using non-integer, %t: %s[%s]",
1120 exprNode_unparse (e1), exprNode_unparse (e2)),
1124 multiVal_free (ind->val);
1125 ind->val = multiVal_unknown ();
1128 if (ctype_isArrayPtr (crarr) && !ctype_isFunction (crarr))
1130 exprNode ret = exprNode_createSemiCopy (arr);
1131 multiVal m = exprNode_getValue (ind);
1133 ret->typ = ctype_baseArrayPtr (crarr);
1134 ret->kind = XPR_FETCH;
1136 if (multiVal_isInt (m))
1138 int i = (int) multiVal_forceInt (m);
1140 if (sRef_isValid (arr->sref)) {
1141 ret->sref = sRef_makeArrayFetchKnown (arr->sref, i);
1143 ret->sref = sRef_undefined;
1148 ret->sref = sRef_makeArrayFetch (arr->sref);
1151 ret->sets = sRefSet_realNewUnion (arr->sets, ind->sets);
1152 ret->msets = sRefSet_realNewUnion (arr->msets, ind->msets);
1153 ret->uses = sRefSet_realNewUnion (arr->uses, ind->uses);
1155 /* (see comment on spurious errors above) */
1156 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1158 exprNode_checkUse (ret, ind->sref, ind->loc);
1159 exprNode_checkUse (ret, arr->sref, arr->loc);
1165 if (ctype_isUnknown (carr))
1167 exprNode ret = exprNode_createPartialCopy (arr);
1169 ret->kind = XPR_FETCH;
1170 ret->typ = ctype_unknown;
1171 ret->sets = sRefSet_union (ret->sets, ind->sets);
1172 ret->msets = sRefSet_union (ret->msets, ind->msets);
1173 ret->uses = sRefSet_union (ret->uses, ind->uses);
1175 /* (see comment on spurious errors above) */
1176 /*@i2@*/ ret->edata = exprData_makePair (arr, ind);
1178 exprNode_checkUse (ret, ind->sref, ind->loc);
1179 exprNode_checkUse (ret, arr->sref, arr->loc);
1186 message ("Array fetch from non-array (%t): %s[%s]", carr,
1187 exprNode_unparse (e1), exprNode_unparse (e2)),
1190 exprNode_free (arr);
1191 exprNode_free (ind);
1193 return (exprNode_makeError ());
1203 checkArgs (uentry fcn, /*@dependent@*/ exprNode f, ctype t,
1204 exprNodeList args, exprNode ret)
1206 return (checkArgsReal (fcn, f, ctype_argsFunction (t), args, FALSE, ret));
1210 ** checkPrintfArgs --- checks arguments for printf-like functions
1211 ** Arguments before ... have already been checked.
1212 ** The argument before the ... is a char *.
1213 ** argno is the format string argument.
1217 checkPrintfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1218 exprNodeList args, exprNode ret, int argno)
1221 ** the last argument before the elips is the format string
1226 int nargs = exprNodeList_size (args);
1227 uentryList params = uentry_getParams (fcn);
1231 ** These should be ensured by checkSpecialFunction
1234 llassert (uentryList_size (params) == argno + 1);
1235 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1237 a = exprNodeList_getN (args, argno - 1);
1238 formatloc = fileloc_copy (exprNode_loc (a));
1240 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1241 && exprNode_knownStringValue (a))
1243 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1244 char *code = format;
1247 nargs = exprNodeList_size (args);
1249 while ((code = strchr (code, '%')) != NULL)
1251 char *origcode = code;
1252 char key = *(++code);
1253 ctype modtype = ctype_int;
1254 bool modified = FALSE;
1256 fileloc_addColumn (formatloc, code - ocode);
1259 while (isFlagKey (key))
1262 fileloc_incColumn (formatloc);
1265 if (key == 'm') /* skipped in syslog */
1270 /* ignore field width */
1271 while (isdigit ((int) key) != 0)
1274 fileloc_incColumn (formatloc);
1277 /* ignore precision */
1281 fileloc_incColumn (formatloc);
1284 ** In printf, '*' means: read the next arg as an int for the
1285 ** field width. This seems to be missing from my copy of the
1286 ** standard x3.159-1989. Setion 4.9.6.1 refers to * (described
1287 ** later) but never does.
1292 ; /* don't do anything --- handle later */
1296 while (isdigit ((int) key) != 0)
1299 fileloc_incColumn (formatloc);
1306 modtype = ctype_sint; /* short */
1308 fileloc_incColumn (formatloc);
1310 else if (key == 'l' || key == 'L')
1312 modtype = ctype_lint; /* long */
1314 fileloc_incColumn (formatloc);
1316 if (key == 'l' || key == 'L') {
1317 modtype = ctype_llint; /* long long */
1319 fileloc_incColumn (formatloc);
1327 /* now, key = type of conversion to apply */
1329 fileloc_incColumn (formatloc);
1337 message ("No argument corresponding to %q format "
1338 "code %d (%%%h): \"%s\"",
1339 uentry_getName (fcn),
1341 cstring_fromChars (format)),
1344 if (fileloc_isDefined (formatloc)
1345 && context_getFlag (FLG_SHOWCOL))
1347 llgenindentmsg (cstring_makeLiteral ("Corresponding format code"),
1355 a = exprNodeList_getN (args, i);
1358 if (!exprNode_isError (a))
1364 case '*': /* int argument for fieldwidth */
1365 expecttype = ctype_int;
1366 *(--code) = '%'; /* convert it for next code */
1367 fileloc_subColumn (formatloc, 1);
1368 /*@switchbreak@*/ break;
1371 expecttype = ctype_combine (ctype_uint, modtype);
1372 /*@switchbreak@*/ break;
1374 case 'i': /* int argument */
1376 expecttype = ctype_combine (ctype_int, modtype);
1377 /*@switchbreak@*/ break;
1379 case 'x': /* unsigned int */
1381 expecttype = ctype_combine (ctype_uint, modtype);
1382 /*@switchbreak@*/ break;
1388 case 'f': /* double */
1389 expecttype = ctype_combine (ctype_double, modtype);
1390 /*@switchbreak@*/ break;
1392 case 'c': /* int converted to char (check its a char?) */
1393 expecttype = ctype_makeConj (ctype_char, ctype_uchar);
1394 /*@switchbreak@*/ break;
1396 case 's': /* string */
1397 expecttype = ctype_string;
1398 /*@switchbreak@*/ break;
1401 while (((key = *(++code)) != ']')
1404 fileloc_incColumn (formatloc);
1410 (message ("Bad character set format: %s",
1411 cstring_fromChars (origcode)));
1414 expecttype = ctype_string;
1415 /*@switchbreak@*/ break;
1417 case 'p': /* pointer */
1418 expecttype = ctype_makePointer (ctype_void);
1420 /*@switchbreak@*/ break;
1422 case 'n': /* pointer to int, modified by call! */
1423 expecttype = ctype_combine (ctype_makePointer (ctype_int), modtype);
1425 uentry_setDefState (regArg, SS_ALLOCATED); /* corresponds to out */
1426 /*@switchbreak@*/ break;
1428 case 'm': /* in a syslog, it doesn't consume an argument */
1429 /* should check we're really doing syslog */
1431 /*@switchbreak@*/ break;
1435 expecttype = ctype_unknown;
1439 message ("Unrecognized format code: %s",
1440 cstring_fromChars (origcode)),
1441 fileloc_isDefined (formatloc)
1442 ? formatloc : g_currentloc);
1444 /*@switchbreak@*/ break;
1447 if (!(exprNode_matchArgType (expecttype, a)))
1449 if (ctype_isVoidPointer (expecttype)
1450 && ctype_isRealAbstract (a->typ)
1451 && (context_getFlag (FLG_ABSTVOIDP)))
1457 if (llgenformattypeerror
1458 (expecttype, exprNode_undefined,
1460 message ("Format argument %d to %q (%%%h) expects "
1463 uentry_getName (fcn),
1465 a->typ, exprNode_unparse (a)),
1468 if (fileloc_isDefined (formatloc)
1469 && context_getFlag (FLG_SHOWCOL))
1472 (cstring_makeLiteral
1473 ("Corresponding format code"),
1480 uentry_setType (regArg, expecttype);
1481 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
1483 if (ctype_equal (expecttype, ctype_string))
1485 exprNode_checkUse (a, sRef_makePointer (a->sref), a->loc);
1488 uentry_setType (regArg, ctype_unknown);
1489 uentry_fixupSref (regArg);
1493 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1507 voptgenerror (FLG_TYPE,
1508 message ("Format string for %q has %d arg%p, given %d",
1509 uentry_getName (fcn), i - argno, nargs - argno),
1515 /* no checking possible for compile-time unknown format strings */
1518 fileloc_free (formatloc);
1522 checkScanfArgs (/*@notnull@*/ /*@dependent@*/ exprNode f, uentry fcn,
1523 exprNodeList args, exprNode ret, int argno)
1527 int nargs = exprNodeList_size (args);
1528 uentryList params = uentry_getParams (fcn);
1532 ** These should be ensured by checkSpecialFunction
1535 llassert (uentryList_size (params) == argno + 1);
1536 llassert (uentry_isElipsisMarker (uentryList_getN (params, argno)));
1538 a = exprNodeList_getN (args, argno - 1);
1539 formatloc = fileloc_copy (exprNode_loc (a));
1541 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1542 && exprNode_knownStringValue (a))
1544 char *format = cstring_toCharsSafe (multiVal_forceString (exprNode_getValue (a)));
1545 char *code = format;
1548 nargs = exprNodeList_size (args);
1550 while ((code = strchr (code, '%')) != NULL)
1552 char *origcode = code;
1553 char key = *(++code);
1554 ctype modtype = ctype_int;
1555 char modifier = '\0';
1556 bool modified = TRUE;
1557 bool ignore = FALSE;
1559 fileloc_addColumn (formatloc, code - ocode);
1562 ** this is based on ANSI standard library description of fscanf
1563 ** (from ANSI standard X3.159-1989, 4.9.6.1)
1566 /* '*' suppresses assignment (does not need match argument) */
1573 fileloc_incColumn (formatloc);
1576 /* ignore field width */
1577 while (isdigit ((int) key) != 0)
1580 fileloc_incColumn (formatloc);
1585 modtype = ctype_sint; /* short */
1587 fileloc_incColumn (formatloc);
1589 else if (key == 'l' || key == 'L')
1591 modtype = ctype_lint; /* long */
1595 fileloc_incColumn (formatloc);
1597 if (key == 'l' || key == 'L') {
1598 modtype = ctype_llint; /* long long */
1600 fileloc_incColumn (formatloc);
1608 /* now, key = type of conversion to apply */
1610 fileloc_incColumn (formatloc);
1624 message ("No argument corresponding to %q format "
1625 "code %d (%%%h): \"%s\"",
1626 uentry_getName (fcn),
1628 cstring_fromChars (format)),
1631 if (fileloc_isDefined (formatloc)
1632 && context_getFlag (FLG_SHOWCOL))
1635 (cstring_makeLiteral ("Corresponding format code"),
1643 a = exprNodeList_getN (args, i);
1646 if (!exprNode_isError (a))
1652 case '*': /* int argument for fieldwidth */
1653 expecttype = ctype_makePointer (ctype_int);
1654 *(--code) = '%'; /* convert it for next code */
1655 fileloc_subColumn (formatloc, 1);
1656 /*@switchbreak@*/ break;
1659 expecttype = ctype_makePointer (ctype_combine (ctype_uint, modtype));
1660 /*@switchbreak@*/ break;
1665 case 'X': /* unsigned int */
1666 expecttype = ctype_makePointer (ctype_combine (ctype_int, modtype));
1667 /*@switchbreak@*/ break;
1674 /* printf is double, scanf is float! */
1676 if (modifier == 'l')
1678 expecttype = ctype_makePointer (ctype_double);
1680 else if (modifier == 'L')
1682 expecttype = ctype_makePointer (ctype_ldouble);
1686 llassert (modifier == '\0');
1687 expecttype = ctype_makePointer (ctype_float);
1689 /*@switchbreak@*/ break;
1691 case 'c': /* int converted to char (check its a char?) */
1692 expecttype = ctype_makePointer (ctype_makeConj (ctype_char, ctype_uchar));
1693 /*@switchbreak@*/ break;
1695 case 's': /* string */
1696 expecttype = ctype_string;
1697 /*@switchbreak@*/ break;
1701 while (((key = *(++code)) != ']')
1704 fileloc_incColumn (formatloc);
1710 (message ("Bad character set format: %s",
1711 cstring_fromChars (origcode)));
1714 expecttype = ctype_string;
1715 /*@switchbreak@*/ break;
1717 case 'p': /* pointer */
1718 expecttype = ctype_unknown;
1720 /*@switchbreak@*/ break;
1722 case 'n': /* pointer to int, modified by call! */
1723 expecttype = ctype_makePointer (ctype_int);
1724 /*@switchbreak@*/ break;
1727 expecttype = ctype_unknown;
1731 message ("Unrecognized format code: %s",
1732 cstring_fromChars (origcode)),
1733 fileloc_isDefined (formatloc)
1734 ? formatloc : g_currentloc);
1736 /*@switchbreak@*/ break;
1739 if (!(exprNode_matchArgType (expecttype, a)))
1741 if (ctype_isVoidPointer (expecttype)
1742 && ctype_isRealAbstract (a->typ)
1743 && (context_getFlag (FLG_ABSTVOIDP)))
1749 if (modifier != '\0')
1751 if (llgenformattypeerror
1752 (expecttype, exprNode_undefined,
1754 message ("Format argument %d to %q (%%%h%h) expects "
1757 uentry_getName (fcn),
1760 a->typ, exprNode_unparse (a)),
1763 if (fileloc_isDefined (formatloc)
1764 && context_getFlag (FLG_SHOWCOL))
1767 (cstring_makeLiteral
1768 ("Corresponding format code"),
1776 if (llgenformattypeerror
1777 (expecttype, exprNode_undefined,
1779 message ("Format argument %d to %q (%%%h) expects "
1782 uentry_getName (fcn),
1784 a->typ, exprNode_unparse (a)),
1787 if (fileloc_isDefined (formatloc)
1788 && context_getFlag (FLG_SHOWCOL))
1791 (cstring_makeLiteral
1792 ("Corresponding format code"),
1800 uentry_setType (outArg, expecttype);
1801 checkOneArg (outArg, a, f, FALSE, i+1, nargs);
1802 uentry_setType (outArg, ctype_unknown);
1803 uentry_fixupSref (outArg);
1807 exprNode_checkCallModifyVal (a->sref, args, f, ret);
1812 /* a->sref = defref; */
1822 voptgenerror (FLG_TYPE,
1823 message ("Format string for %q has %d arg%p, given %d",
1824 uentry_getName (fcn), i - argno, nargs - argno),
1830 /* no checking possible for compile-time unknown format strings */
1833 fileloc_free (formatloc);
1837 checkMessageArgs (/*@notnull@*/ /*@dependent@*/ exprNode f,
1840 /*@unused@*/ int argno)
1843 ** the last argument before the elips is the format string
1846 int nargs = exprNodeList_size (args);
1851 a = exprNodeList_getN (args, argno - 1);
1852 formatloc = fileloc_copy (exprNode_loc (a));
1854 if (ctype_isUnknown (cstringType)) {
1855 if (usymtab_existsType (cstring_makeLiteralTemp ("cstring")))
1857 cstringType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("cstring"));
1861 if (ctype_isUnknown (ctypeType)) {
1862 if (usymtab_existsType (cstring_makeLiteralTemp ("ctype")))
1864 ctypeType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("ctype"));
1868 if (ctype_isUnknown (filelocType)) {
1869 if (usymtab_existsType (cstring_makeLiteralTemp ("fileloc")))
1871 filelocType = usymtab_lookupAbstractType (cstring_makeLiteralTemp ("fileloc"));
1875 if (exprNode_isDefined (a) && exprNode_isStringLiteral (a)
1876 && exprNode_knownStringValue (a))
1878 cstring format = multiVal_forceString (exprNode_getValue (a));
1879 char *code = cstring_toCharsSafe (format);
1882 nargs = exprNodeList_size (args);
1884 while ((code = strchr (code, '%')) != NULL)
1886 char *origcode = code;
1887 char key = *(++code);
1888 bool isOnly = FALSE;
1890 fileloc_addColumn (formatloc, code - ocode);
1892 while (key >= '0' && key <= '9')
1895 fileloc_incColumn (formatloc);
1899 fileloc_incColumn (formatloc);
1912 message ("Message missing format arg %d (%%%h): \"%s\"",
1913 i + 1, key, format),
1919 a = exprNodeList_getN (args, i);
1923 if (!exprNode_isError (a))
1927 /*@-loopswitchbreak@*/
1933 expecttype = ctype_char; break;
1935 expecttype = cstringType; break;
1937 expecttype = cstringType; isOnly = TRUE; break;
1939 expecttype = cstringType; isOnly = TRUE; break;
1940 case 'd': expecttype = ctype_int; break;
1941 case 'u': expecttype = ctype_uint; break;
1942 case 'w': expecttype = ctype_ulint; break;
1943 case 'f': expecttype = ctype_float; break;
1944 case 'b': expecttype = ctype_bool; break;
1945 case 't': expecttype = ctypeType; break;
1946 case 'l': expecttype = filelocType; break;
1947 case 'p': /* a wee bit of a hack methinks */
1948 expecttype = ctype_int;
1950 case 'r': expecttype = ctype_bool; break;
1952 expecttype = ctype_unknown;
1955 message ("Unrecognized format code: %s",
1956 cstring_fromChars (origcode)),
1957 fileloc_isDefined (formatloc)
1958 ? formatloc : g_currentloc);
1961 /*@=loopswitchbreak@*/
1963 if (!(exprNode_matchArgType (expecttype, a)))
1965 if (ctype_isVoidPointer (expecttype)
1966 && ctype_isRealAbstract (a->typ)
1967 && (context_getFlag (FLG_ABSTVOIDP)))
1973 if (llgenformattypeerror
1974 (expecttype, exprNode_undefined,
1976 message ("Format argument %d to %q (%%%h) expects "
1979 uentry_getName (fcn),
1981 a->typ, exprNode_unparse (a)),
1984 if (fileloc_isDefined (formatloc)
1985 && context_getFlag (FLG_SHOWCOL))
1988 (cstring_makeLiteral
1989 ("Corresponding format code"),
1996 if (ctype_equal (expecttype, cstringType))
2000 checkOneArg (csOnlyArg, a, f, FALSE, i+1, nargs);
2001 uentry_fixupSref (csOnlyArg);
2005 checkOneArg (csArg, a, f, FALSE, i+1, nargs);
2006 uentry_fixupSref (csArg);
2011 checkOneArg (regArg, a, f, FALSE, i+1, nargs);
2012 uentry_fixupSref (regArg);
2021 voptgenerror (FLG_TYPE,
2022 message ("Format string for %q has %d arg%p, given %d",
2023 uentry_getName (fcn), i - argno, nargs -argno),
2029 /* no checking possible for compile-time unknown format strings */
2032 fileloc_free (formatloc);
2036 checkExpressionDefinedAux (/*@notnull@*/ exprNode e1,
2037 /*@notnull@*/ exprNode e2,
2043 bool hadUncon = FALSE;
2045 if (sRef_isGlobal (sRef_getRootBase (e1->sref)) &&
2046 sRefSet_hasUnconstrained (sets2))
2049 (FLG_EVALORDERUNCON,
2051 ("Expression may have undefined behavior (%q used in right operand "
2052 "may set global variable %q used in left operand): %s %s %s",
2053 sRefSet_unparseUnconstrained (sets2),
2054 sRef_unparse (sRef_getRootBase (e1->sref)),
2055 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2059 if (sRef_isGlobal (sRef_getRootBase (e2->sref)) &&
2060 sRefSet_hasUnconstrained (sets1))
2063 (FLG_EVALORDERUNCON,
2065 ("Expression has undefined behavior (%q used in left operand "
2066 "may set global variable %q used in right operand): %s %s %s",
2067 sRefSet_unparseUnconstrained (sets1),
2068 sRef_unparse (e2->sref),
2069 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2073 sRefSet_realElements (e1->uses, sr)
2075 if (sRef_isMeaningful (sr) && sRefSet_member (sets2, sr))
2080 ("Expression has undefined behavior (left operand uses %q, "
2081 "modified by right operand): %s %s %s",
2083 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2086 } end_sRefSet_realElements;
2088 sRefSet_realElements (sets1, sr)
2090 if (sRef_isMeaningful (sr))
2092 if (sRef_same (sr, e2->sref))
2097 ("Expression has undefined behavior (value of right operand "
2098 "modified by left operand): %s %s %s",
2099 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2102 else if (sRefSet_member (e2->uses, sr))
2107 ("Expression has undefined behavior (left operand modifies %q, "
2108 "used by right operand): %s %s %s",
2110 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
2115 if (sRefSet_member (sets2, sr))
2117 if (sRef_isUnconstrained (sr))
2125 hadUncon = optgenerror
2126 (FLG_EVALORDERUNCON,
2128 ("Expression may have undefined behavior. Left operand "
2129 "calls %q; right operand calls %q. The unconstrained "
2130 "functions may modify global state used by "
2131 "the other operand): %s %s %s",
2132 sRefSet_unparseUnconstrained (sets1),
2133 sRefSet_unparseUnconstrained (sets2),
2134 exprNode_unparse (e1), lltok_unparse (op),
2135 exprNode_unparse (e2)),
2144 ("Expression has undefined behavior (both "
2145 "operands modify %q): %s %s %s",
2147 exprNode_unparse (e1),
2148 lltok_unparse (op), exprNode_unparse (e2)),
2154 } end_sRefSet_realElements;
2157 static void checkExpressionDefined (exprNode e1, exprNode e2, lltok op)
2159 bool hasError = FALSE;
2161 if (exprNode_isError (e1) || exprNode_isError (e2))
2166 if (sRefSet_member (e2->sets, e1->sref))
2168 if (e2->kind == XPR_CALL)
2174 hasError = optgenerror
2176 message ("Expression has undefined behavior "
2177 "(value of left operand is modified "
2178 "by right operand): %s %s %s",
2179 exprNode_unparse (e1), lltok_unparse (op),
2180 exprNode_unparse (e2)),
2185 if (context_getFlag (FLG_EVALORDERUNCON))
2187 if (sRefSet_member (e2->msets, e1->sref))
2189 if (e2->kind == XPR_CALL)
2195 hasError = optgenerror
2198 ("Expression has undefined behavior (value of left "
2199 "operand may be modified by right operand): %s %s %s",
2200 exprNode_unparse (e1), lltok_unparse (op),
2201 exprNode_unparse (e2)),
2209 checkExpressionDefinedAux (e1, e2, e1->sets, e2->sets, op, FLG_EVALORDER);
2211 if (context_maybeSet (FLG_EVALORDERUNCON))
2213 checkExpressionDefinedAux (e1, e2, e1->msets,
2214 e2->msets, op, FLG_EVALORDERUNCON);
2219 static void checkSequencing (exprNode p_f, exprNodeList p_args);
2222 checkArgsReal (uentry fcn, /*@dependent@*/ exprNode f, uentryList cl,
2223 exprNodeList args, bool isIter, exprNode ret)
2227 if (!exprNode_isError (f))
2229 if (!uentryList_isMissingParams (cl))
2231 int nargs = exprNodeList_size (args);
2232 int expectargs = uentryList_size (cl);
2236 if (expectargs == 0)
2244 message ("Iter %q invoked with %d args, "
2246 uentry_getName (fcn),
2254 message ("Function %s called with %d args, "
2256 exprNode_unparse (f), nargs),
2263 last = uentry_getType (uentryList_getN (cl, expectargs - 1));
2265 exprNodeList_reset (args);
2267 uentryList_elements (cl, current)
2269 ctype ct = uentry_getType (current);
2272 if (ctype_isElips (ct))
2275 ** do special checking for printf/scanf library functions
2277 ** this is kludgey code, just for handling the special case
2281 if (uentry_isPrintfLike (fcn))
2283 checkPrintfArgs (f, fcn, args, ret, i);
2286 else if (uentry_isScanfLike (fcn))
2288 checkScanfArgs (f, fcn, args, ret, i);
2291 else if (uentry_isMessageLike (fcn))
2293 checkMessageArgs (f, fcn, args, i);
2298 llassert (!uentry_isSpecialFunction (fcn));
2301 nargs = expectargs; /* avoid errors */
2306 if (i >= nargs) break;
2308 a = exprNodeList_current (args);
2309 exprNodeList_advance (args);
2313 if (exprNode_isError (a))
2320 probably necessary? I'm not sure about this one
2321 checkMacroParen (a);
2324 f->guards = guardSet_union (f->guards, a->guards);
2326 DPRINTF (("match arg: %s / %s", ctype_unparse (ct), ctype_unparse (a->typ)));
2328 if (!(exprNode_matchArgType (ct, a)))
2330 DPRINTF (("Args mismatch!"));
2332 if (ctype_isVoidPointer (ct)
2333 && (ctype_isPointer (a->typ)
2334 && (ctype_isRealAbstract (ctype_baseArrayPtr (a->typ)))))
2339 ("Pointer to abstract type (%t) used "
2341 "(arg %d to %q): %s",
2343 uentry_getName (fcn),
2344 exprNode_unparse (a)),
2352 (ct, exprNode_undefined,
2355 ("Iter %q expects arg %d to "
2356 "be %t gets %t: %s",
2357 uentry_getName (fcn),
2358 i, ct, a->typ, exprNode_unparse (a)),
2369 ("Function %q expects arg %d to be %t gets %t: %s",
2370 uentry_getName (fcn),
2371 i, ct, a->typ, exprNode_unparse (a)),
2374 DPRINTF (("Types: %s / %s",
2376 ctype_unparse (a->typ)));
2380 ** Clear null marker for abstract types.
2381 ** (It is not revealed, so suppress future messages.)
2384 if (ctype_isAbstract (a->typ))
2386 sRef_setNullUnknown (exprNode_getSref (a), a->loc);
2393 } end_uentryList_elements ;
2396 if (expectargs != nargs) /* note: not != since we may have ... */
2398 if (ctype_isElips (last))
2402 message ("Function %s called with %d args, expects at least %d",
2403 exprNode_unparse (f),
2404 nargs, expectargs - 1),
2413 message ("Iter %q invoked with %d args, expects %d",
2414 uentry_getName (fcn), nargs, expectargs),
2421 message ("Function %s called with %d args, expects %d",
2422 exprNode_unparse (f),
2435 ** Check for undefined code sequences in function arguments:
2437 ** one parameter sets something used by another parameter
2438 ** one parameter sets something set by another parameter
2442 checkSequencingOne (exprNode f, exprNodeList args,
2443 /*@notnull@*/ exprNode el, int argno)
2446 ** Do second loop, iff +undefunspec
2450 int numloops = context_maybeSet (FLG_EVALORDERUNCON) ? 2 : 1;
2452 for (checkloop = 0; checkloop < numloops; checkloop++)
2458 thissets = el->sets;
2462 llassert (checkloop == 1);
2463 thissets = el->msets;
2466 sRefSet_realElements (thissets, thisset)
2470 /*@access exprNodeList@*/
2471 for (j = 0; j < args->nelements; j++)
2473 exprNode jl = args->elements[j];
2474 int thisargno = j + 1;
2476 if (thisargno != argno && exprNode_isDefined (jl))
2478 sRefSet otheruses = jl->uses;
2480 if (sRef_isGlobal (sRef_getRootBase (jl->sref)) &&
2481 sRefSet_hasUnconstrained (thissets))
2484 (FLG_EVALORDERUNCON,
2487 ("%q used in argument %d may set "
2488 "global variable %q used by argument %d: %s(%q)",
2489 cstring_capitalizeFree (sRefSet_unparseUnconstrained (thissets)),
2492 sRef_unparse (sRef_getRootBase (jl->sref)),
2494 exprNode_unparse (f), exprNodeList_unparse (args)),
2498 if (sRefSet_member (otheruses, thisset))
2500 if (sRef_isUnconstrained (thisset))
2503 (FLG_EVALORDERUNCON,
2505 ("Unconstrained functions used in arguments %d (%q) "
2506 "and %d (%s) may modify "
2507 "or use global state in undefined way: %s(%q)",
2509 sRefSet_unparseUnconstrainedPlain (otheruses),
2511 sRef_unconstrainedName (thisset),
2512 exprNode_unparse (f),
2513 exprNodeList_unparse (args)),
2521 ("Argument %d modifies %q, used by argument %d "
2522 "(order of evaluation of actual parameters is "
2523 "undefined): %s(%q)",
2524 argno, sRef_unparse (thisset), thisargno,
2525 exprNode_unparse (f), exprNodeList_unparse (args)),
2531 sRefSet othersets = jl->sets;
2533 if (sRefSet_member (othersets, thisset))
2535 if (sRef_isUnconstrained (thisset))
2538 (FLG_EVALORDERUNCON,
2540 ("Unconstrained functions used in "
2541 "arguments %d (%q) and %d (%s) may modify "
2542 "or use global state in undefined way: %s(%q)",
2544 sRefSet_unparseUnconstrainedPlain (othersets),
2546 sRef_unconstrainedName (thisset),
2547 exprNode_unparse (f), exprNodeList_unparse (args)),
2555 ("Argument %d modifies %q, set by argument %d (order of"
2556 " evaluation of actual parameters is undefined): %s(%q)",
2557 argno, sRef_unparse (thisset), thisargno,
2558 exprNode_unparse (f), exprNodeList_unparse (args)),
2565 /*@noaccess exprNodeList@*/
2566 } end_sRefSet_realElements;
2571 checkSequencing (exprNode f, exprNodeList args)
2573 if (exprNodeList_size (args) > 1)
2578 /*@access exprNodeList*/
2580 for (i = 0; i < args->nelements; i++)
2582 el = args->elements[i];
2584 if (!exprNode_isError (el))
2586 checkSequencingOne (f, args, el, i + 1);
2589 /*@noaccess exprNodeList*/
2594 ** requires le = exprNode_getUentry (f)
2598 checkGlobMods (/*@notnull@*/ /*@dependent@*/ exprNode f,
2599 uentry le, exprNodeList args,
2600 /*@notnull@*/ exprNode ret, int specialArgs)
2602 bool isSpec = FALSE;
2603 bool hasMods = FALSE;
2605 globSet usesGlobs = globSet_undefined;
2606 sRefSet mods = sRefSet_undefined;
2607 bool freshMods = FALSE;
2608 uentryList params = uentryList_undefined;
2611 ** check globals and modifies
2616 if (!uentry_isValid (le))
2618 ctype fr = ctype_realType (f->typ);
2620 if (ctype_isFunction (fr))
2622 params = ctype_argsFunction (fr);
2626 params = uentryList_missingParams;
2629 if (!context_getFlag (FLG_MODNOMODS)
2630 && !context_getFlag (FLG_GLOBUNSPEC))
2632 checkUnspecCall (f, params, args);
2638 fname = uentry_rawName (le);
2642 if (uentry_isFunction (le))
2644 params = uentry_getParams (le);
2645 mods = uentry_getMods (le);
2646 hasMods = uentry_hasMods (le);
2647 usesGlobs = uentry_getGlobs (le);
2648 isSpec = uentry_isSpecified (le);
2650 else /* not a function */
2652 ctype ct = ctype_realType (uentry_getType (le));
2654 llassertprint (uentry_isVar (le) && ctype_isFunction (ct),
2655 ("checkModGlobs: uentry not a function: %s",
2656 uentry_unparse (le)));
2658 params = ctype_argsFunction (ct);
2668 globSet_allElements (usesGlobs, el)
2670 if (sRef_isValid (el))
2672 if (sRef_isInternalState (el) || sRef_isSystemState (el))
2674 context_usedGlobal (el);
2675 exprNode_checkUse (f, el, f->loc);
2677 if (context_checkInternalUse ())
2679 if (!context_globAccess (el))
2681 if (sRef_isSystemState (el)
2682 && !context_getFlag (FLG_MODFILESYSTEM))
2691 ("Called procedure %s may access %q, but "
2692 "globals list does not include globals %s",
2693 exprNode_unparse (f),
2695 cstring_makeLiteralTemp (sRef_isInternalState (el)
2703 else if (sRef_isNothing (el) || sRef_isSpecState (el))
2709 uentry gle = sRef_getUentry (el);
2710 sRef sr = sRef_updateSref (el);
2712 if (sRef_isUndefGlob (el))
2714 sRef_setDefined (sr, f->loc);
2715 exprNode_checkSet (f, sr);
2723 if (sRef_isAllocated (el))
2725 exprNode_checkSet (f, sr);
2729 if (sRef_isStateUndefined (sr))
2734 ("%s %q used by function undefined before call: %s",
2735 sRef_getScopeName (sr),
2737 exprNode_unparse (f)),
2739 sRef_setDefined (sr, f->loc);
2741 exprNode_checkUse (f, sr, f->loc);
2744 checkGlobUse (gle, TRUE, f);
2747 if (sRef_isKilledGlob (el))
2749 sRef_kill (sr, f->loc);
2750 context_usedGlobal (sr);
2754 } end_globSet_allElements;
2760 if (context_hasMods () || context_getFlag (FLG_MODNOMODS))
2762 sRefSet smods = sRefSet_undefined;
2765 ** NEED to check for modifies anything
2769 ** check each sRef that called function modifies (ml), is
2775 sRefSet_allElements (mods, s) /* s is something which may be modified */
2777 if (sRef_isKindSpecial (s))
2779 if (sRef_isSpecInternalState (s))
2781 if (context_getFlag (FLG_MODINTERNALSTRICT))
2783 exprNode_checkCallModifyVal (s, args, f, ret);
2787 sRefSet mmods = context_modList ();
2789 sRefSet_allElements (mmods, el)
2791 if (sRef_isInternalState (el))
2793 sRef_setModified (el);
2795 } end_sRefSet_allElements ;
2800 exprNode_checkCallModifyVal (s, args, f, ret);
2805 sRef rb = sRef_getRootBase (s);
2807 if (sRef_isGlobal (rb))
2809 context_usedGlobal (rb);
2812 if (sRef_isFileStatic (s)
2813 && !fileId_equal (fileloc_fileId (f->loc),
2814 fileloc_fileId (uentry_whereDefined (le))))
2816 smods = sRefSet_insert (smods, s);
2820 exprNode_checkCallModifyVal (s, args, f, ret);
2823 } end_sRefSet_allElements;
2828 ** Static elements in modifies set can have nasty consequences.
2829 ** (I think...have not been able to reproduce a possible bug.)
2832 if (!sRefSet_isDefined (smods))
2834 mods = sRefSet_newCopy (mods);
2837 sRefSet_allElements (smods, el)
2839 bool res = sRefSet_delete (mods, el);
2842 } end_sRefSet_allElements;
2844 sRefSet_free (smods);
2849 else if (sRefSet_isDefined (mods))
2850 { /* just check observers */
2853 sRefSet_allElements (mods, s) /* s is something which may be modified */
2855 sRef rb = sRef_getRootBase (s);
2859 if (sRef_isParam (rb))
2861 sRef b = sRef_fixBaseParam (s, args);
2863 if (sRef_isObserver (b))
2865 exprNode e = exprNodeList_nth (args, sRef_getParam (rb));
2869 message ("Function call may modify observer%q: %s",
2870 sRef_unparsePreOpt (b), exprNode_unparse (e)),
2873 sRef_showExpInfo (b);
2877 } end_sRefSet_allElements;
2881 if (!hasMods) /* no specified modifications */
2883 if (context_getFlag (FLG_MODOBSERVERUNCON))
2885 exprNodeList_elements (args, e)
2887 if (exprNode_isDefined (e))
2889 sRef s = exprNode_getSref (e);
2891 if (sRef_isObserver (s)
2892 && ctype_isMutable (sRef_getType (s)))
2895 (FLG_MODOBSERVERUNCON,
2897 ("Call to unconstrained function %s may modify observer%q: %s",
2898 exprNode_unparse (f),
2899 sRef_unparsePreOpt (s), exprNode_unparse (e)),
2902 sRef_showExpInfo (s);
2906 } end_exprNodeList_elements;
2911 checkAnyCall (f, fname, params, args, hasMods, mods, isSpec, specialArgs);
2913 ret->uses = sRefSet_union (ret->uses, f->uses);
2914 ret->sets = sRefSet_union (ret->sets, f->sets);
2915 ret->msets = sRefSet_union (ret->msets, f->msets);
2920 ** Spurious errors reported, because lclint can't tell
2921 ** mods must be fresh if freshMods is true.
2924 /*@i@*/ sRefSet_free (mods);
2930 void checkGlobUse (uentry glob, bool isCall, /*@notnull@*/ exprNode e)
2932 if (uentry_isVar (glob))
2934 if (context_inFunctionLike ())
2936 sRef sr = uentry_getSref (glob);
2938 context_usedGlobal (sr);
2940 if (context_checkGlobUse (glob))
2942 if (!context_globAccess (sr))
2948 message ("Called procedure %s may access %s %q",
2949 exprNode_unparse (e),
2950 sRef_unparseScope (sr),
2951 uentry_getName (glob)),
2958 message ("Undocumented use of %s %s",
2959 sRef_unparseScope (sr),
2960 exprNode_unparse (e)),
2969 llbug (message ("Global not variable: %q", uentry_unparse (glob)));
2973 static /*@only@*/ exprNode
2974 functionCallSafe (/*@only@*/ /*@notnull@*/ exprNode f,
2975 ctype t, /*@keep@*/ exprNodeList args)
2977 /* requires f is a non-error exprNode, with type function */
2978 cstring fname = exprNode_unparse (f);
2979 uentry le = exprNode_getUentry (f);
2980 exprNode ret = exprNode_createPartialCopy (f);
2985 ret->typ = ctype_returnValue (t);
2986 ret->kind = XPR_CALL;
2988 ret->edata = exprData_makeCall (f, args);
2991 ** Order of these steps is very important!
2993 ** Must check for argument dependencies before messing up uses and sets.
2996 if (context_getFlag (FLG_EVALORDER))
2998 exprNodeList_elements (args, current)
3000 if (exprNode_isDefined (current))
3002 exprNode_addUse (current, current->sref);
3004 } end_exprNodeList_elements;
3006 if (context_maybeSet (FLG_EVALORDER) || context_maybeSet (FLG_EVALORDERUNCON))
3008 checkSequencing (f, args);
3011 exprNodeList_elements (args, current)
3013 if (exprNode_isDefined (current) && sRef_isMeaningful (current->sref))
3015 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3017 } end_exprNodeList_elements ;
3020 special = checkArgs (le, f, t, args, ret);
3021 checkGlobMods (f, le, args, ret, special);
3025 if (uentry_isValid (le)
3026 && (uentry_isFunction (le)
3027 || (uentry_isVariable (le)
3028 && ctype_isFunction (uentry_getType (le)))))
3030 exitkind exk = uentry_getExitCode (le);
3032 /* f->typ is already set to the return type */
3034 ret->sref = uentry_returnedRef (le, args);
3036 if (uentry_isFunction (le) && exprNodeList_size (args) >= 1)
3038 qual nullPred = uentry_nullPred (le);
3040 if (qual_isTrueNull (nullPred))
3042 exprNode arg = exprNodeList_head (args);
3044 if (exprNode_isDefined (arg))
3046 ret->guards = guardSet_addFalseGuard (ret->guards, arg->sref);
3049 else if (qual_isFalseNull (nullPred))
3051 exprNode arg = exprNodeList_head (args);
3053 if (exprNode_isDefined (arg))
3055 ret->guards = guardSet_addTrueGuard (ret->guards, arg->sref);
3060 llassert (qual_isUnknown (nullPred));
3064 if (exitkind_isConditionalExit (exk))
3068 ** if (arg0) then { exit! } else { ; }
3070 ** if (arg0) then { ; } else { exit! }
3075 llassert (!exprNodeList_isEmpty (args));
3076 firstArg = exprNodeList_head (args);
3078 if (exprNode_isDefined (firstArg)
3079 && !guardSet_isEmpty (firstArg->guards))
3081 usymtab_trueBranch (guardSet_undefined);
3082 usymtab_altBranch (guardSet_undefined);
3084 if (exitkind_isTrueExit (exk))
3086 usymtab_popBranches (firstArg,
3087 exprNode_makeMustExit (),
3089 TRUE, TRUEEXITCLAUSE);
3093 usymtab_popBranches (firstArg,
3095 exprNode_makeMustExit (),
3096 TRUE, FALSEEXITCLAUSE);
3100 ret->exitCode = XK_MAYEXIT;
3102 else if (exitkind_mustExit (exk))
3104 ret->exitCode = XK_MUSTEXIT;
3106 else if (exitkind_couldExit (exk))
3108 ret->exitCode = XK_MAYEXIT;
3115 if (cstring_equalLit (fname, "exit"))
3117 if (exprNodeList_size (args) == 1)
3119 exprNode arg = exprNodeList_head (args);
3121 if (exprNode_isDefined (arg) && exprNode_knownIntValue (arg))
3123 long int val = multiVal_forceInt (exprNode_getValue (arg));
3130 ("Argument to exit has implementation defined behavior: %s",
3131 exprNode_unparse (arg)),
3132 exprNode_loc (arg));
3141 exprNode_checkSetAny (ret, uentry_rawName (le));
3148 ** this is yucky! should keep the uentry as part of exprNode!
3151 /*@observer@*/ uentry
3152 exprNode_getUentry (exprNode e)
3154 if (exprNode_isError (e))
3156 return uentry_undefined;
3160 cstring s = exprNode_rootVarName (e);
3161 uentry ue = usymtab_lookupSafe (s);
3168 exprNode_makeInitBlock (lltok brace, /*@only@*/ exprNodeList inits)
3170 exprNode ret = exprNode_createPlain (ctype_unknown);
3172 ret->kind = XPR_INITBLOCK;
3173 ret->edata = exprData_makeCall (exprNode_undefined, inits);
3174 ret->loc = fileloc_update (ret->loc, lltok_getLoc (brace));
3180 exprNode_functionCall (/*@only@*/ exprNode f, /*@only@*/ exprNodeList args)
3186 if (exprNode_isUndefined (f))
3189 exprNodeList_free (args);
3190 return exprNode_undefined;
3193 t = exprNode_getType (f);
3195 if (sRef_isLocalVar (f->sref))
3197 exprNode_checkUse (f, f->sref, f->loc);
3199 if (sRef_possiblyNull (f->sref))
3201 if (!usymtab_isGuarded (f->sref))
3203 if (optgenerror (FLG_NULLDEREF,
3204 message ("Function call using %s pointer %q",
3205 sRef_nullMessage (f->sref),
3206 sRef_unparse (f->sref)),
3209 sRef_showNullInfo (f->sref);
3210 sRef_setNullError (f->sref);
3218 if (ctype_isRealFunction (t))
3220 exprNode ret = functionCallSafe (f, t, args);
3224 else if (ctype_isUnknown (t))
3226 exprNode ret = exprNode_createPartialCopy (f);
3232 exprNodeList_elements (args, current)
3234 if (exprNode_isDefined (current))
3236 exprNode_checkUse (ret, current->sref, ret->loc);
3239 ** also, anything derivable from current->sref may be used
3242 exprNode_addUse (ret, sRef_makeDerived (current->sref));
3243 exprNode_mergeUSs (ret, current);
3245 } end_exprNodeList_elements;
3247 ret->edata = exprData_makeCall (f, args);
3248 ret->kind = XPR_CALL;
3250 tstring = cstring_copy (exprNode_unparse (f));
3252 cstring_markOwned (tstring);
3253 exprNode_checkSetAny (ret, tstring);
3259 voptgenerror (FLG_TYPE,
3260 message ("Call to non-function (type %t): %s", t,
3261 exprNode_unparse (f)),
3264 exprNodeList_free (args);
3266 return (exprNode_makeError ());
3271 exprNode_fieldAccess (/*@only@*/ exprNode s, /*@only@*/ cstring f)
3273 exprNode ret = exprNode_createPartialCopy (s);
3275 ret->kind = XPR_FACCESS;
3277 if (exprNode_isError (s))
3279 ret->edata = exprData_makeField (s, f);
3284 ctype t = exprNode_getType (s);
3285 ctype tr = ctype_realType (t);
3287 checkMacroParen (s);
3289 ret->edata = exprData_makeField (s, f);
3291 if (ctype_isStructorUnion (tr))
3293 uentry tf = uentryList_lookupField (ctype_getFields (tr), f);
3295 if (uentry_isUndefined (tf))
3297 voptgenerror (FLG_TYPE,
3298 message ("Access non-existent field %s of %t: %s", f, t,
3299 exprNode_unparse (ret)),
3306 uentry_setUsed (tf, exprNode_loc (ret));
3308 ret->typ = uentry_getType (tf);
3309 checkSafeUse (ret, s->sref);
3311 ret->sref = sRef_makeField (s->sref, uentry_rawName (tf));
3315 else /* isStructorUnion */
3317 if (ctype_isRealAbstract (tr))
3321 message ("Access field of abstract type (%t): %s.%s",
3322 t, exprNode_unparse (s), f),
3324 ret->typ = ctype_unknown;
3328 if (ctype_isKnown (tr))
3333 ("Access field of non-struct or union (%t): %s.%s",
3334 t, exprNode_unparse (s), f),
3337 ret->typ = ctype_unknown;
3341 cstring sn = cstring_copy (f);
3343 checkSafeUse (ret, s->sref);
3344 cstring_markOwned (sn);
3345 ret->sref = sRef_makeField (s->sref, sn);
3357 exprNode_addParens (/*@only@*/ lltok lpar, /*@only@*/ exprNode e)
3359 exprNode ret = exprNode_createPartialCopy (e);
3361 ret->loc = fileloc_update (ret->loc, lltok_getLoc (lpar));
3362 ret->kind = XPR_PARENS;
3363 ret->edata = exprData_makeUop (e, lpar);
3365 if (!exprNode_isError (e))
3367 ret->exitCode = e->exitCode;
3368 ret->canBreak = e->canBreak;
3369 ret->mustBreak = e->mustBreak;
3370 ret->isJumpPoint = e->isJumpPoint;
3371 ret->sref = e->sref;
3378 exprNode_arrowAccess (/*@only@*/ exprNode s, /*@only@*/ cstring f)
3380 exprNode ret = exprNode_createPartialCopy (s);
3382 ret->edata = exprData_makeField (s, f);
3383 ret->kind = XPR_ARROW;
3385 if (exprNode_isError (s))
3391 ctype t = exprNode_getType (s);
3392 ctype tr = ctype_realType (t);
3394 checkMacroParen (s);
3396 (void) ctype_fixArrayPtr (tr); /* REWRITE THIS */
3398 if (ctype_isRealPointer (tr))
3400 ctype b = ctype_realType (ctype_baseArrayPtr (tr));
3402 if (ctype_isStructorUnion (b))
3404 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
3406 if (sRef_isKnown (s->sref) && sRef_possiblyNull (s->sref))
3408 if (!usymtab_isGuarded (s->sref) && !context_inProtectVars ())
3412 message ("Arrow access from %s pointer%q: %s",
3413 sRef_nullMessage (s->sref),
3414 sRef_unparsePreOpt (s->sref),
3415 exprNode_unparse (ret)),
3418 sRef_showNullInfo (s->sref);
3419 sRef_setNullError (s->sref);
3424 if (uentry_isUndefined (fentry))
3428 message ("Access non-existent field %s of %t: %s",
3429 f, t, exprNode_unparse (ret)),
3431 ret->typ = ctype_unknown;
3438 ** was safeUse: shouldn't be safe!
3441 ** rec must be defined,
3442 ** *rec must be allocated
3443 ** rec->field need only be defined it if is an rvalue
3446 uentry_setUsed (fentry, exprNode_loc (ret));
3447 ret->typ = uentry_getType (fentry);
3449 exprNode_checkUse (ret, s->sref, s->loc);
3451 /* exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc); */
3452 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
3456 else /* Pointer to something that is not a struct or union*/
3458 if (ctype_isRealAbstract (tr))
3460 ctype xrt = ctype_forceRealType (tr);
3464 message ("Arrow access field of abstract type (%t): %s->%s",
3465 t, exprNode_unparse (s), f),
3469 ** Set the state correctly, as if the abstraction is broken.
3472 if (ctype_isRealPointer (xrt) &&
3473 (b = ctype_realType (ctype_baseArrayPtr (xrt)),
3474 ctype_isStructorUnion (b)))
3476 uentry fentry = uentryList_lookupField (ctype_getFields (b), f);
3477 ret->typ = uentry_getType (fentry);
3478 ret->sref = sRef_makeArrow (s->sref, uentry_rawName (fentry));
3482 ret->typ = ctype_unknown;
3483 ret->sref = sRef_undefined;
3486 else /* not a struct, union or abstract */
3488 if (ctype_isUnknown (tr)) {
3489 cstring sn = cstring_copy (f);
3491 DPRINTF (("Here: %s", exprNode_unparse (s)));
3493 exprNode_checkUse (ret, s->sref, s->loc);
3494 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
3496 cstring_markOwned (sn);
3497 ret->sref = sRef_makeArrow (s->sref, sn);
3499 ret->kind = XPR_ARROW;
3504 message ("Arrow access field of non-struct or union "
3505 "pointer (%t): %s->%s",
3506 t, exprNode_unparse (s), f),
3509 ret->typ = ctype_unknown;
3510 ret->sref = sRef_undefined;
3515 else /* its not a pointer */
3517 if (!ctype_isUnknown (tr))
3521 message ("Arrow access of non-pointer (%t): %s->%s",
3522 t, exprNode_unparse (s), f),
3525 ret->typ = ctype_unknown;
3526 ret->sref = sRef_undefined;
3530 cstring sn = cstring_copy (f);
3532 DPRINTF (("Here: %s", exprNode_unparse (s)));
3534 exprNode_checkUse (ret, s->sref, s->loc);
3535 exprNode_checkUse (ret, sRef_makePointer (s->sref), s->loc);
3537 cstring_markOwned (sn);
3538 ret->sref = sRef_makeArrow (s->sref, sn);
3540 ret->kind = XPR_ARROW;
3551 ** only postOp's in C: i++ and i--
3555 exprNode_postOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
3557 /* check modification also */
3558 /* cstring opname = lltok_unparse (op);*/
3560 exprNode ret = exprNode_createPartialCopy (e);
3562 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
3563 ret->kind = XPR_POSTOP;
3564 ret->edata = exprData_makeUop (e, op);
3566 if (!exprNode_isDefined (e))
3571 checkMacroParen (e);
3573 exprNode_checkUse (ret, e->sref, e->loc);
3574 exprNode_checkSet (ret, e->sref);
3576 t = exprNode_getType (e);
3578 if (sRef_isUnsafe (e->sref))
3580 voptgenerror (FLG_MACROPARAMS,
3581 message ("Operand of %s is macro parameter (non-functional): %s%s",
3582 lltok_unparse (op), exprNode_unparse (e), lltok_unparse (op)),
3584 sRef_makeSafe (e->sref);
3585 sRef_makeSafe (ret->sref);
3588 if (ctype_isForceRealNumeric (&t) || ctype_isRealAP (t))
3594 if (ctype_isRealAbstract (t))
3598 message ("Operand of %s is abstract type (%t): %s",
3599 lltok_unparse (op), t, exprNode_unparse (e)),
3606 message ("Operand of %s is non-numeric (%t): %s",
3607 lltok_unparse (op), t, exprNode_unparse (e)),
3610 ret->typ = ctype_unknown;
3613 /* if (ctype_isZero (t)) e->typ = ctype_int; */
3615 exprNode_checkModify (e, ret);
3617 /* added 7/11/2000 D.L */
3619 updateEnvironmentForPostOp (e);
3621 /* start modifications */
3622 /* added by Seejo on 4/16/2000 */
3624 /* Arithmetic operations on pointers wil modify the size/len/null terminated
3626 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
3628 ret->sref = sRef_copy (e->sref);
3631 if (lltok_getTok (op) == INC_OP) {
3632 if (sRef_getSize(e->sref) > 0) {
3634 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
3636 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
3637 /* Assumption: there is only 1 \0 in the buffer */
3638 /* This will not be correct if there are 2 \0's in the buffer */
3639 sRef_setNotNullTerminatedState(ret->sref);
3640 sRef_resetLen(ret->sref);
3642 sRef_setNullTerminatedState(ret->sref);
3643 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
3645 if (sRef_isNullTerminated (ret->sref))
3646 printf ("ret->sref is Null Terminated\n");
3647 else if (sRef_isPossiblyNullTerminated (ret->sref))
3648 printf ("ret->sref is Possibly Null Terminated\n");
3649 else if (sRef_isNotNullTerminated (ret->sref))
3650 printf ("ret->sref is Not Null Terminated\n");
3655 if (lltok_getTok (op) == DEC_OP) {
3656 if (sRef_getSize(e->sref) >= 0) {
3657 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
3658 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
3663 /* end modifications */
3669 exprNode_preOp (/*@only@*/ exprNode e, /*@only@*/ lltok op)
3671 bool checkMod = FALSE;
3673 int opid = lltok_getTok (op);
3674 exprNode ret = exprNode_createSemiCopy (e);
3676 exprNode_copySets (ret, e);
3678 multiVal_free (ret->val);
3679 ret->val = multiVal_undefined;
3680 ret->loc = fileloc_update (ret->loc, lltok_getLoc (op));
3681 ret->kind = XPR_PREOP;
3682 ret->edata = exprData_makeUop (e, op);
3684 if (exprNode_isError (e))
3689 checkMacroParen (e);
3691 te = exprNode_getType (e);
3692 tr = ctype_realType (te);
3694 if (opid != TAMPERSAND)
3696 exprNode_checkUse (ret, e->sref, e->loc);
3698 if (ctype_isRealAbstract (tr)
3699 && (!(ctype_isRealBool (te) && (opid == TEXCL))))
3701 if (optgenerror (FLG_ABSTRACT,
3702 message ("Operand of %s is abstract type (%t): %s",
3703 lltok_unparse (op), tr,
3704 exprNode_unparse (ret)),
3707 tr = te = ctype_unknown;
3708 ret->typ = ctype_unknown;
3709 sRef_setNullError (e->sref);
3717 case DEC_OP: /* should also check modification! */
3719 if (sRef_isMacroParamRef (e->sref))
3723 message ("Operand of %s is macro parameter (non-functional): %s",
3724 lltok_unparse (op), exprNode_unparse (ret)),
3729 exprNode_checkSet (ret, e->sref);
3732 if (ctype_isForceRealNumeric (&tr) || ctype_isRealAP (tr))
3737 if (context_msgStrictOps ())
3741 message ("Operand of %s is non-numeric (%t): %s",
3742 lltok_unparse (op), te, exprNode_unparse (ret)),
3745 ret->typ = ctype_int;
3748 /* start modifications */
3749 /* added by Seejo on 4/16/2000 */
3751 /* Arithmetic operations on pointers wil modify the size/len/null terminated
3753 if ((sRef_isPossiblyNullTerminated (e->sref)) || (sRef_isNullTerminated(e->sref))) {
3755 ret->sref = sRef_copy (e->sref);
3758 if (lltok_getTok (op) == INC_OP) {
3759 if (sRef_getSize(e->sref) > 0) {
3761 sRef_setSize (ret->sref, sRef_getSize(e->sref) - 1);
3763 if (sRef_getLen(e->sref) == 1) { /* i.e. the first character is \0 */
3764 /* Assumption: there is only 1 \0 in the buffer */
3765 /* This will not be correct if there are 2 \0's in the buffer */
3766 sRef_setNotNullTerminatedState(ret->sref);
3767 sRef_resetLen (ret->sref);
3769 sRef_setNullTerminatedState(ret->sref);
3770 sRef_setLen (ret->sref, sRef_getLen(e->sref) - 1);
3776 if (lltok_getTok (op) == DEC_OP) {
3777 if (sRef_getSize(e->sref) >= 0) {
3778 sRef_setSize (ret->sref, sRef_getSize(e->sref) + 1);
3779 sRef_setLen (ret->sref, sRef_getLen(e->sref) + 1);
3784 /* end modifications */
3791 if (ctype_isForceRealNumeric (&tr))
3795 ret->val = multiVal_invert (exprNode_getValue (e));
3799 ret->val = multiVal_copy (exprNode_getValue (e));
3804 if (context_msgStrictOps ())
3808 message ("Operand of %s is non-numeric (%t): %s",
3809 lltok_unparse (op), te, exprNode_unparse (ret)),
3813 ret->typ = ctype_int;
3817 case TEXCL: /* maybe this should be restricted */
3818 guardSet_flip (ret->guards);
3820 if (ctype_isRealBool (te))
3826 if (ctype_isRealPointer (tr))
3828 if (sRef_isKnown (e->sref))
3830 ret->guards = guardSet_addFalseGuard (ret->guards, e->sref);
3834 (FLG_BOOLOPS, FLG_PTRNEGATE,
3835 message ("Operand of %s is non-boolean (%t): %s",
3836 lltok_unparse (op), te, exprNode_unparse (ret)),
3843 message ("Operand of %s is non-boolean (%t): %s",
3844 lltok_unparse (op), te, exprNode_unparse (ret)),
3848 ret->typ = ctype_bool;
3853 if (ctype_isForceRealInt (&tr))
3858 if (context_msgStrictOps ())
3862 message ("Operand of %s is non-integer (%t): %s",
3863 lltok_unparse (op), te, exprNode_unparse (ret)),
3867 if (ctype_isInt (e->typ))
3873 ret->typ = ctype_int;
3879 ret->typ = ctype_makePointer (e->typ);
3881 if (sRef_isKnown (e->sref))
3883 ret->sref = sRef_makeAddress (e->sref);
3890 if (ctype_isAP (tr))
3892 ret->typ = ctype_baseArrayPtr (e->typ);
3896 if (ctype_isKnown (te))
3898 if (ctype_isFunction (te))
3904 message ("Dereference of function type (%t): %s",
3905 te, exprNode_unparse (ret)),
3910 voptgenerror (FLG_TYPE,
3911 message ("Dereference of non-pointer (%t): %s",
3912 te, exprNode_unparse (ret)),
3914 ret->typ = ctype_unknown;
3919 ret->typ = ctype_unknown;
3924 if (sRef_isKnown (e->sref))
3926 if (sRef_possiblyNull (e->sref))
3928 if (!usymtab_isGuarded (e->sref) && !context_inProtectVars ())
3932 message ("Dereference of %s pointer %q: %s",
3933 sRef_nullMessage (e->sref),
3934 sRef_unparse (e->sref),
3935 exprNode_unparse (ret)),
3938 sRef_showNullInfo (e->sref);
3939 sRef_setNotNull (e->sref, e->loc); /* suppress future messages */
3944 ret->sref = sRef_makePointer (e->sref);
3949 llbug (message ("exprNode_preOp: unhandled op: %s", lltok_unparse (op)));
3954 exprNode_checkModify (e, ret);
3961 ** any reason to disallow sizeof (abstract type) ?
3965 ** used by both sizeof
3969 ctype sizeof_resultType (void)
3971 static ctype sizet = ctype_unknown;
3973 if (ctype_isUnknown (sizet))
3975 if (usymtab_existsType (cstring_makeLiteralTemp ("size_t")))
3977 sizet = uentry_getAbstractType (usymtab_lookup (cstring_makeLiteralTemp ("size_t")));
3981 sizet = ctype_ulint;
3988 exprNode_sizeofType (/*@only@*/ qtype qt)
3990 exprNode ret = exprNode_create (sizeof_resultType ());
3991 ctype ct = qtype_getType (qt);
3993 ret->kind = XPR_SIZEOFT;
3994 ret->edata = exprData_makeSizeofType (qt);
3996 voptgenerror (FLG_SIZEOFTYPE,
3997 message ("Parameter to sizeof is type %s: %s",
3999 exprNode_unparse (ret)),
4006 exprNode_alignofType (/*@only@*/ qtype qt)
4008 exprNode ret = exprNode_create (sizeof_resultType ());
4009 ctype ct = qtype_getType (qt);
4011 ret->kind = XPR_ALIGNOFT;
4012 ret->edata = exprData_makeSizeofType (qt);
4014 voptgenerror (FLG_SIZEOFTYPE,
4015 message ("Parameter to alignof is type %s: %s",
4017 exprNode_unparse (ret)),
4023 exprNode exprNode_offsetof (qtype qt, cstringList s)
4025 exprNode ret = exprNode_create (sizeof_resultType ());
4026 ctype ct = qtype_getType (qt);
4028 ret->kind = XPR_OFFSETOF;
4029 ret->edata = exprData_makeOffsetof (qt, s);
4031 if (!ctype_isRealSU (ct))
4033 voptgenerror (FLG_TYPE,
4034 message ("First parameter to offsetof is not a "
4035 "struct or union type (type %s): %s",
4037 exprNode_unparse (ret)),
4044 cstringList_elements (s, el) {
4048 if (ctype_isUndefined (lt))
4052 else if (!ctype_isRealSU (lt))
4054 voptgenerror (FLG_TYPE,
4055 message ("Inner offsetof type is not a "
4056 "struct or union type (type %s before field %s): %s",
4057 ctype_unparse (lt), el,
4058 exprNode_unparse (ret)),
4064 fields = ctype_getFields (ctype_realType (lt));
4065 fld = uentryList_lookupField (fields, el);
4066 DPRINTF (("Try: %s / %s", ctype_unparse (lt), el));
4068 if (uentry_isUndefined (fld))
4070 if (ctype_equal (lt, ct)) {
4071 voptgenerror (FLG_TYPE,
4072 message ("Field %s in offsetof is not the "
4073 "name of a field of %s: %s",
4076 exprNode_unparse (ret)),
4079 voptgenerror (FLG_TYPE,
4080 message ("Deep field %s in offsetof is not the "
4081 "name of a field of %s: %s",
4084 exprNode_unparse (ret)),
4090 lt = uentry_getType (fld);
4093 } end_cstringList_elements;
4095 /* Should report error if its a bit field - behavior is undefined! */
4102 exprNode_sizeofExpr (/*@only@*/ exprNode e)
4106 if (exprNode_isUndefined (e))
4108 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4109 ret->edata = exprData_makeSingle (e);
4110 ret->typ = sizeof_resultType ();
4111 ret->kind = XPR_SIZEOF;
4115 uentry u = exprNode_getUentry (e);
4117 ret = exprNode_createPartialCopy (e);
4118 ret->edata = exprData_makeSingle (e);
4120 ret->typ = sizeof_resultType ();
4121 ret->kind = XPR_SIZEOF;
4123 if (uentry_isValid (u)
4124 && uentry_isRefParam (u)
4125 && ctype_isRealArray (uentry_getType (u)))
4128 (FLG_SIZEOFFORMALARRAY,
4129 message ("Parameter to sizeof is an array-type function parameter: %s",
4130 exprNode_unparse (ret)),
4136 ** sizeof (x) doesn't "really" use x
4143 exprNode_alignofExpr (/*@only@*/ exprNode e)
4147 if (exprNode_isUndefined (e))
4149 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (g_currentloc));
4153 ret = exprNode_createPartialCopy (e);
4156 ret->edata = exprData_makeSingle (e);
4157 ret->typ = sizeof_resultType ();
4158 ret->kind = XPR_ALIGNOF;
4161 ** sizeof (x) doesn't "really" use x
4168 exprNode_cast (/*@only@*/ lltok tok, /*@only@*/ exprNode e, /*@only@*/ qtype q)
4174 if (exprNode_isError (e))
4177 lltok_release (tok);
4178 return exprNode_undefined;
4181 checkMacroParen (e);
4183 c = qtype_getType (q);
4184 t = exprNode_getType (e);
4186 ret = exprNode_createPartialCopy (e);
4188 ret->loc = fileloc_update (ret->loc, lltok_getLoc (tok));
4190 ret->kind = XPR_CAST;
4191 ret->edata = exprData_makeCast (tok, e, q);
4193 if (ctype_isRealSU (ctype_getBaseType (sRef_getType (e->sref))))
4196 ** This is a bit of a hack to avoid a problem
4197 ** when the code does,
4198 ** (some other struct) x
4203 ret->sref = sRef_copy (e->sref);
4204 usymtab_addForceMustAlias (ret->sref, e->sref);
4205 sRef_setTypeFull (ret->sref, c);
4206 DPRINTF (("Cast: %s -> %s", sRef_unparseFull (e->sref),
4207 sRef_unparseFull (ret->sref)));
4211 ret->sref = e->sref;
4212 sRef_setTypeFull (ret->sref, c);
4213 DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
4220 ** void * <-> abstract * (if FLG_ABSTVOIDP)
4221 ** abstract * <-> void * (if FLG_ABSTVOIDP)
4224 if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
4228 else if (ctype_isRealAP (c)) /* casting to array or pointer */
4230 ctype bc = ctype_getBaseType (c);
4231 ctype bt = ctype_getBaseType (t);
4232 ctype rt = ctype_realType (t);
4234 if (ctype_isFunction (ctype_baseArrayPtr (ctype_realType (c)))
4235 && (ctype_isArrayPtr (rt)
4236 && !ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4240 message ("Cast from function pointer type (%t) to "
4241 "non-function pointer (%t): %s",
4242 c, t, exprNode_unparse (ret)),
4246 if (!ctype_isFunction (ctype_baseArrayPtr (c))
4247 && (ctype_isArrayPtr (rt)
4248 && ctype_isFunction (ctype_realType (ctype_baseArrayPtr (rt)))))
4252 message ("Cast from non-function pointer type (%t) to "
4253 "function pointer (%t): %s",
4254 c, t, exprNode_unparse (ret)),
4258 if (exprNode_isZero (e) && context_getFlag (FLG_ZEROPTR) &&
4259 !(ctype_isRealAbstract (bc)
4260 && context_hasAccess (ctype_typeId (bc))))
4262 ; /* okay to cast zero */
4266 if (ctype_isRealAbstract (bc)
4267 && !context_hasAccess (ctype_typeId (bc)))
4269 if (ctype_isVoidPointer (t) || ctype_isUnknown (t))
4273 message ("Cast to underlying abstract type %t: %s",
4274 c, exprNode_unparse (ret)),
4281 message ("Cast to underlying abstract type %t: %s",
4282 c, exprNode_unparse (ret)),
4287 if (ctype_isRealAbstract (bt)
4288 && !context_hasAccess (ctype_typeId (bt)))
4290 if (ctype_isUnknown (c) || ctype_isVoidPointer (c))
4294 message ("Cast from underlying abstract type %t: %s",
4295 t, exprNode_unparse (ret)),
4302 message ("Cast from underlying abstract type %t: %s",
4303 t, exprNode_unparse (ret)),
4311 ctype bt = ctype_realType (ctype_getBaseType (t));
4312 ctype bc = ctype_realType (ctype_getBaseType (c));
4314 if (ctype_isAbstract (bt) && !context_hasAccess (ctype_typeId (bt)))
4316 if (ctype_match (c, t))
4318 if (ctype_equal (c, t))
4322 message ("Redundant cast involving abstract type %t: %s",
4323 bt, exprNode_unparse (ret)),
4331 message ("Cast from abstract type %t: %s",
4332 bt, exprNode_unparse (ret)),
4337 if (ctype_isAbstract (bc)
4338 && !context_hasAccess (ctype_typeId (bc)))
4340 if (ctype_match (c, t))
4348 message ("Cast to abstract type %t: %s", bc,
4349 exprNode_unparse (ret)),
4355 if (ctype_isAbstract (c))
4357 if (sRef_isExposed (e->sref) || sRef_isOnly (e->sref))
4359 /* okay, cast exposed to abstract */
4360 sRef_clearExKindComplete (ret->sref, fileloc_undefined);
4364 if (ctype_isVisiblySharable (t)
4365 && sRef_isExternallyVisible (e->sref)
4366 && !(ctype_isAbstract (t)
4367 && context_hasAccess (ctype_typeId (t))))
4371 message ("Cast to abstract type from externally visible "
4372 "mutable storage exposes rep of %s: %s",
4374 exprNode_unparse (e)),
4384 evaluationOrderUndefined (lltok op)
4386 int opid = lltok_getTok (op);
4388 return (opid != AND_OP && opid != OR_OP);
4391 static bool checkIntegral (/*@notnull@*/ exprNode e1,
4392 /*@notnull@*/ exprNode e2,
4393 /*@notnull@*/ exprNode ret,
4398 ctype te1 = exprNode_getType (e1);
4399 ctype te2 = exprNode_getType (e2);
4401 ctype tr1 = ctype_realishType (te1);
4402 ctype tr2 = ctype_realishType (te2);
4404 if (ctype_isForceRealInt (&tr1) && ctype_isForceRealInt (&tr2))
4410 if (context_msgStrictOps ())
4412 if (!ctype_isInt (tr1) && !ctype_isInt (tr2))
4414 if (ctype_sameName (te1, te2))
4418 message ("Operands of %s are non-integer (%t): %s",
4419 lltok_unparse (op), te1,
4420 exprNode_unparse (ret)),
4427 message ("Operands of %s are non-integers (%t, %t): %s",
4428 lltok_unparse (op), te1, te2,
4429 exprNode_unparse (ret)),
4433 else if (!ctype_isInt (tr1))
4437 message ("Left operand of %s is non-integer (%t): %s",
4438 lltok_unparse (op), te1, exprNode_unparse (ret)),
4442 /* !ctype_isInt (te2) */
4446 message ("Right operand of %s is non-integer (%t): %s",
4447 lltok_unparse (op), te2, exprNode_unparse (ret)),
4457 ** returns exprNode representing e1 op e2
4459 ** uses msg if there are errors
4460 ** can be used for both assignment ops and regular ops
4465 static /*@only@*/ /*@notnull@*/ exprNode
4466 exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2,
4467 /*@keep@*/ lltok op)
4469 ctype te1, te2, tr1, tr2, tret;
4470 int opid = lltok_getTok (op);
4471 bool hasError = FALSE;
4474 if (exprNode_isError (e1))
4476 ret = exprNode_createPartialNVCopy (e2);
4480 ret = exprNode_createPartialNVCopy (e1);
4483 ret->val = multiVal_undefined;
4485 ret->edata = exprData_makeOp (e1, e2, op);
4487 if (exprNode_isError (e1) || exprNode_isError (e2))
4489 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
4490 || opid == EQ_OP || opid == NE_OP
4491 || opid == AND_OP || opid == OR_OP)
4493 ret->typ = ctype_bool;
4496 if (exprNode_isDefined (e1))
4498 exprNode_checkUse (ret, e1->sref, e1->loc);
4501 if (exprNode_isDefined (e2))
4503 exprNode_mergeUSs (ret, e2);
4504 exprNode_checkUse (ret, e2->sref, e2->loc);
4510 tret = ctype_unknown;
4511 te1 = exprNode_getType (e1);
4512 DPRINTF (("te1 = %s / %s", exprNode_unparse (e1), ctype_unparse (te1)));
4514 te2 = exprNode_getType (e2);
4516 tr1 = ctype_realishType (te1);
4517 tr2 = ctype_realishType (te2);
4521 ret->guards = guardSet_or (ret->guards, e2->guards);
4523 else if (opid == AND_OP)
4525 ret->guards = guardSet_and (ret->guards, e2->guards);
4532 if (opid == EQ_OP || opid == NE_OP)
4534 exprNode temp1 = e1, temp2 = e2;
4536 /* could do NULL == x */
4538 if (exprNode_isNullValue (e1) || exprNode_isUnknownConstant (e1))
4540 temp1 = e2; temp2 = e1;
4543 if (exprNode_isNullValue (temp2) || exprNode_isUnknownConstant (temp2))
4545 reflectNullTest (temp1, (opid == NE_OP));
4546 guardSet_free (ret->guards);
4547 ret->guards = guardSet_copy (temp1->guards);
4551 if (opid == TLT || opid == TGT || opid == LE_OP || opid == GE_OP
4552 || opid == EQ_OP || opid == NE_OP || opid == AND_OP || opid == OR_OP)
4557 if (anyAbstract (tr1, tr2) &&
4558 (!((ctype_isRealBool (te1) || ctype_isRealBool (te2)) &&
4559 (opid == AND_OP || opid == OR_OP
4560 || opid == EQ_OP || opid == NE_OP))))
4562 abstractOpError (tr1, tr2, op, e1, e2, e1->loc, e2->loc);
4564 else if (ctype_isUnknown (te1) || ctype_isUnknown (te2))
4566 /* unknown types, no comparisons possible */
4572 case TMULT: /* multiplication and division: */
4574 case MUL_ASSIGN: /* numeric, numeric -> numeric */
4575 case DIV_ASSIGN: /* */
4577 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4580 case TPLUS: /* addition and subtraction: */
4581 case TMINUS: /* pointer, int -> pointer */
4582 case SUB_ASSIGN: /* int, pointer -> pointer */
4583 case ADD_ASSIGN: /* numeric, numeric -> numeric */
4585 tr1 = ctype_fixArrayPtr (tr1);
4587 if ((ctype_isRealPointer (tr1) && !exprNode_isNullValue (e1))
4588 && (!ctype_isRealPointer (tr2) && ctype_isRealInt (tr2)))
4592 if (context_msgPointerArith ())
4596 message ("Pointer arithmetic (%t, %t): %s",
4597 te1, te2, exprNode_unparse (ret)),
4601 if (sRef_possiblyNull (e1->sref)
4602 && !usymtab_isGuarded (e1->sref))
4605 (FLG_NULLPOINTERARITH,
4606 message ("Pointer arithmetic involving possibly "
4607 "null pointer %s: %s",
4608 exprNode_unparse (e1),
4609 exprNode_unparse (ret)),
4613 ret->sref = sRef_copy (e1->sref);
4615 /* start modifications */
4616 /* added by Seejo on 4/16/2000 */
4618 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4620 if ((sRef_isPossiblyNullTerminated (e1->sref)) || (sRef_isNullTerminated(e1->sref))) {
4621 //if (sRef_isKnown (e->sref)) {
4622 //ret->sref = sRef_makeAddress (e->sref);
4627 added ugly fixed to stop
4628 program from crashing on point + int +int
4629 one day I'll fix this or ask Seejo wtf the codes supposed to do. */
4631 if (!multiVal_isInt (e2->val) )
4635 val = (int) multiVal_forceInt (e2->val);
4637 /* Operator : + or += */
4638 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4639 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
4640 val should not result in a
4641 size < 0 (size = 0 is ok !) */
4643 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
4645 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
4646 sRef_setNotNullTerminatedState(ret->sref);
4647 sRef_resetLen (ret->sref);
4649 sRef_setNullTerminatedState(ret->sref);
4650 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
4655 /* Operator : - or -= */
4656 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4657 if (sRef_getSize(e1->sref) >= 0) {
4658 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
4659 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
4664 /* end modifications */
4666 sRef_setNullError (ret->sref);
4669 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4670 ** since is points to storage that should not be deallocated
4671 ** through this pointer.
4674 if (sRef_isOnly (ret->sref)
4675 || sRef_isFresh (ret->sref))
4677 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4682 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
4683 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
4685 if (context_msgPointerArith ())
4689 message ("Pointer arithmetic (%t, %t): %s",
4690 te1, te2, exprNode_unparse (ret)),
4694 if (sRef_possiblyNull (e1->sref)
4695 && !usymtab_isGuarded (e1->sref))
4698 (FLG_NULLPOINTERARITH,
4699 message ("Pointer arithmetic involving possibly "
4700 "null pointer %s: %s",
4701 exprNode_unparse (e2),
4702 exprNode_unparse (ret)),
4706 ret->sref = sRef_copy (e2->sref);
4708 /* start modifications */
4709 /* added by Seejo on 4/16/2000 */
4711 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4714 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
4715 //if (sRef_isKnown (e->sref)) {
4716 //ret->sref = sRef_makeAddress (e->sref);
4719 int val = (int) multiVal_forceInt (e1->val);
4721 /* Operator : + or += */
4722 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4723 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
4724 val should not result in a
4725 size < 0 (size = 0 is ok !) */
4727 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
4729 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
4730 sRef_setNotNullTerminatedState(ret->sref);
4731 sRef_resetLen (ret->sref);
4733 sRef_setNullTerminatedState(ret->sref);
4734 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
4739 /* Operator : - or -= */
4740 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4741 if (sRef_getSize(e2->sref) >= 0) {
4742 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
4743 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
4748 /* end modifications */
4750 sRef_setNullError (ret->sref);
4753 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4754 ** since is points to storage that should not be deallocated
4755 ** through this pointer.
4758 if (sRef_isOnly (ret->sref)
4759 || sRef_isFresh (ret->sref)) {
4760 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4764 ret->sref = e2->sref;
4768 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4773 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
4777 case TAMPERSAND: /* bitwise & */
4779 case TCIRC: /* ^ (XOR) */
4784 bool reported = FALSE;
4785 flagcode code = FLG_BITWISEOPS;
4787 if (opid == LEFT_OP || opid == LEFT_ASSIGN
4788 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
4789 code = FLG_SHIFTSIGNED;
4792 if (!ctype_isUnsigned (tr1))
4794 if (exprNode_isNonNegative (e1)) {
4797 reported = optgenerror
4799 message ("Left operand of %s is not unsigned value (%t): %s",
4800 lltok_unparse (op), te1,
4801 exprNode_unparse (ret)),
4811 /* right need not be signed for shifts */
4812 if (code != FLG_SHIFTSIGNED
4813 && !ctype_isUnsigned (tr2))
4815 if (!exprNode_isNonNegative (e2)) {
4816 reported = optgenerror
4818 message ("Right operand of %s is not unsigned value (%t): %s",
4819 lltok_unparse (op), te2,
4820 exprNode_unparse (ret)),
4828 if (!checkIntegral (e1, e2, ret, op)) {
4829 te1 = ctype_unknown;
4833 DPRINTF (("Set: %s", ctype_unparse (te1)));
4836 ** tret is the widest type of te1 and te2
4839 tret = ctype_widest (te1, te2);
4844 if (checkIntegral (e1, e2, ret, op)) {
4847 tret = ctype_unknown;
4852 case TLT: /* comparisons */
4853 case TGT: /* numeric, numeric -> bool */
4854 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
4855 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
4858 bool fepsilon = FALSE;
4860 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
4865 if (opid == TLT || opid == TGT)
4867 uentry ue1 = exprNode_getUentry (e1);
4868 uentry ue2 = exprNode_getUentry (e2);
4871 ** FLT_EPSILON, etc. really is a variable, not
4875 if (uentry_isVariable (ue1))
4877 cstring uname = uentry_rawName (ue1);
4879 if (cstring_equalLit (uname, "FLT_EPSILON")
4880 || cstring_equalLit (uname, "DBL_EPSILON")
4881 || cstring_equalLit (uname, "LDBL_EPSILON"))
4887 if (uentry_isVariable (ue2))
4889 cstring uname = uentry_rawName (ue2);
4891 if (cstring_equalLit (uname, "FLT_EPSILON")
4892 || cstring_equalLit (uname, "DBL_EPSILON")
4893 || cstring_equalLit (uname, "LDBL_EPSILON"))
4902 ; /* Don't complain. */
4908 message ("Dangerous comparison involving %s types: %s",
4909 ctype_unparse (rtype),
4910 exprNode_unparse (ret)),
4919 ** Types should match.
4922 if (!exprNode_matchTypes (e1, e2))
4924 hasError = gentypeerror
4926 message ("Operands of %s have incompatible types (%t, %t): %s",
4927 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
4933 || (ctype_isForceRealNumeric (&tr1)
4934 && ctype_isForceRealNumeric (&tr2)) ||
4935 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
4941 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
4942 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
4946 message ("Comparison of pointer and numeric (%t, %t): %s",
4947 te1, te2, exprNode_unparse (ret)),
4952 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4957 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
4959 if ((opid == EQ_OP || opid == NE_OP) &&
4960 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
4963 ** is one a variable?
4966 if (uentry_isVariable (exprNode_getUentry (e1))
4967 || uentry_isVariable (exprNode_getUentry (e2)))
4970 ** comparisons with FALSE are okay
4973 if (exprNode_isFalseConstant (e1)
4974 || exprNode_isFalseConstant (e2))
4983 ("Use of %q with %s variables (risks inconsistency because "
4984 "of multiple true values): %s",
4985 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
4986 context_printBoolName (), exprNode_unparse (ret)),
4993 case AND_OP: /* bool, bool -> bool */
4996 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
5002 if (context_maybeSet (FLG_BOOLOPS))
5004 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
5006 if (ctype_sameName (te1, te2))
5010 message ("Operands of %s are non-boolean (%t): %s",
5011 lltok_unparse (op), te1,
5012 exprNode_unparse (ret)),
5020 ("Operands of %s are non-booleans (%t, %t): %s",
5021 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5025 else if (!ctype_isRealBool (te1))
5029 message ("Left operand of %s is non-boolean (%t): %s",
5030 lltok_unparse (op), te1, exprNode_unparse (ret)),
5033 else if (!ctype_isRealBool (te2))
5037 message ("Right operand of %s is non-boolean (%t): %s",
5038 lltok_unparse (op), te2, exprNode_unparse (ret)),
5051 (cstring_makeLiteral
5052 ("There has been a problem in the parser. This is due to a bug "
5053 "in either lclint, bison or gcc version 2.95 optimizations, "
5054 "but it has not been confirmed. Please try rebuidling LCLint "
5055 "without the -O<n> option."));
5060 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5063 exprNode_checkUse (ret, e1->sref, e1->loc);
5064 exprNode_mergeUSs (ret, e2);
5065 exprNode_checkUse (ret, e2->sref, e2->loc);
5071 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5072 /*@only@*/ lltok op)
5076 checkMacroParen (e1);
5077 checkMacroParen (e2);
5079 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5081 checkExpressionDefined (e1, e2, op);
5084 ret = exprNode_makeOp (e1, e2, op);
5089 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5092 ** This is somewhat bogus!
5094 ** Assigning to a nested observer in a non-observer datatype
5095 ** should not produce an error.
5098 sRef ref = exprNode_getSref (e1);
5100 DPRINTF (("Check assign mod: %s",
5101 sRef_unparseFull (ref)));
5103 if (sRef_isObserver (ref)
5104 || ((sRef_isFileStatic (ref) || sRef_isGlobal (ref))
5105 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5107 sRef base = sRef_getBase (ref);
5109 if (sRef_isValid (base) && sRef_isObserver (base))
5111 exprNode_checkModify (e1, ret);
5115 exprNode_checkModifyVal (e1, ret);
5120 exprNode_checkModify (e1, ret);
5125 exprNode_assign (/*@only@*/ exprNode e1,
5126 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5128 bool isalloc = FALSE;
5129 bool isjustalloc = FALSE;
5132 DPRINTF (("%s [%s] <- %s [%s]",
5133 exprNode_unparse (e1),
5134 ctype_unparse (e1->typ),
5135 exprNode_unparse (e2),
5136 ctype_unparse (e2->typ)));
5138 if (lltok_getTok (op) != TASSIGN)
5140 ret = exprNode_makeOp (e1, e2, op);
5144 ret = exprNode_createPartialCopy (e1);
5145 ret->kind = XPR_ASSIGN;
5146 ret->edata = exprData_makeOp (e1, e2, op);
5148 if (!exprNode_isError (e2))
5150 ret->sets = sRefSet_union (ret->sets, e2->sets);
5151 ret->msets = sRefSet_union (ret->msets, e2->msets);
5152 ret->uses = sRefSet_union (ret->uses, e2->uses);
5156 checkExpressionDefined (e1, e2, op);
5158 if (exprNode_isError (e1))
5160 if (!exprNode_isError (e2))
5162 ret->loc = fileloc_update (ret->loc, e2->loc);
5166 ret->loc = fileloc_update (ret->loc, g_currentloc);
5170 if (!exprNode_isError (e2))
5172 checkMacroParen (e2);
5175 if (exprNode_isDefined (e1))
5177 if (sRef_isMacroParamRef (e1->sref))
5179 if (context_inIterDef ())
5181 uentry ue = sRef_getUentry (e1->sref);
5183 if (uentry_isYield (ue))
5189 if (fileloc_isDefined (e1->loc))
5193 message ("Assignment to non-yield iter parameter: %q",
5194 sRef_unparse (e1->sref)),
5201 message ("Assignment to non-yield iter parameter: %q",
5202 sRef_unparse (e1->sref)),
5209 if (fileloc_isDefined (e1->loc))
5213 message ("Assignment to macro parameter: %q",
5214 sRef_unparse (e1->sref)),
5221 message ("Assignment to macro parameter: %q",
5222 sRef_unparse (e1->sref)),
5229 exprNode_checkAssignMod (e1, ret);
5232 if (exprNode_isDefined (e2))
5234 if (lltok_getTok (op) == TASSIGN)
5236 ctype te1 = exprNode_getType (e1);
5237 ctype te2 = exprNode_getType (e2);
5239 if (!ctype_forceMatch (te1, te2))
5241 if (exprNode_matchLiteral (te1, e2))
5249 message ("Assignment of %t to %t: %s %s %s",
5250 te2, te1, exprNode_unparse (e1),
5252 exprNode_unparse (e2)),
5258 exprNode_mergeUSs (ret, e2);
5259 exprNode_checkUse (ret, e2->sref, e2->loc);
5261 doAssign (e1, e2, FALSE);
5262 ret->sref = e1->sref;
5266 if (exprNode_isDefined (e2))
5268 exprNode_mergeUSs (ret, e2);
5269 exprNode_checkUse (ret, e2->sref, e2->loc);
5273 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5275 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5278 isjustalloc = sRef_isJustAllocated (e1->sref);
5279 isalloc = sRef_isAllocated (e1->sref);
5281 if (sRef_isField (e1->sref))
5283 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5285 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5287 exprNode_checkUse (ret, root, e1->loc);
5293 ** be careful! this defines e1->sref.
5296 if (!sRef_isMacroParamRef (e1->sref))
5298 exprNode_checkSet (ret, e1->sref);
5303 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5304 ? e2->loc : e1->loc);
5310 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5319 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5320 /*@keep@*/ exprNode elseclause)
5324 if (!exprNode_isError (pred))
5326 ret = exprNode_createPartialCopy (pred);
5327 checkMacroParen (pred);
5328 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
5330 if (!exprNode_isError (ifclause))
5332 checkMacroParen (ifclause); /* update macro counts! */
5334 if (!exprNode_isError (elseclause))
5336 checkMacroParen (elseclause);
5338 if (!exprNode_matchTypes (ifclause, elseclause))
5341 (exprNode_getType (ifclause),
5343 exprNode_getType (elseclause),
5345 message ("Conditional clauses are not of same type: "
5347 exprNode_unparse (ifclause),
5348 exprNode_getType (ifclause),
5349 exprNode_unparse (elseclause),
5350 exprNode_getType (elseclause)),
5353 ret->sref = sRef_undefined;
5354 ret->typ = ctype_unknown;
5359 /* for now...should merge the states */
5360 ret->sref = ifclause->sref;
5361 ret->typ = ifclause->typ;
5363 if (exprNode_isNullValue (ifclause))
5365 ret->typ = elseclause->typ;
5369 exprNode_checkUse (ret, pred->sref, pred->loc);
5370 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5371 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5373 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5378 ret->typ = ifclause->typ;
5380 exprNode_checkUse (pred, pred->sref, pred->loc);
5381 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5383 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
5388 if (!exprNode_isError (elseclause))
5390 ret->typ = elseclause->typ;
5392 exprNode_checkUse (pred, pred->sref, pred->loc);
5393 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5395 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5399 else /* pred is error */
5401 if (!exprNode_isError (ifclause))
5403 ret = exprNode_createSemiCopy (ifclause);
5405 checkMacroParen (ifclause); /* update macro counts! */
5407 if (!exprNode_isError (elseclause))
5409 checkMacroParen (elseclause);
5411 ret->typ = ifclause->typ;
5413 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
5416 (exprNode_getType (ifclause),
5418 exprNode_getType (elseclause),
5420 message ("Conditional clauses are not of same type: "
5422 exprNode_unparse (ifclause),
5423 exprNode_getType (ifclause),
5424 exprNode_unparse (elseclause),
5425 exprNode_getType (elseclause)),
5428 ret->typ = ctype_unknown;
5432 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5433 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5435 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5438 else if (!exprNode_isError (elseclause)) /* pred, if errors */
5440 ret = exprNode_createSemiCopy (ifclause);
5442 ret->typ = elseclause->typ;
5443 checkMacroParen (elseclause);
5445 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5446 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5448 else /* all errors! */
5450 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5454 ret->kind = XPR_COND;
5455 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
5457 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
5459 exprNode_combineControl (ret, ifclause, elseclause);
5466 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
5468 ctype totype = qtype_getType (qt);
5470 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
5474 ** check use of va_arg : <valist>, type -> type
5477 if (exprNode_isError (arg))
5482 targ = exprNode_getType (arg);
5485 ** arg should have be a pointer
5488 if (!ctype_isUA (targ) ||
5489 (!usymId_equal (ctype_typeId (targ),
5490 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
5494 message ("First argument to va_arg is not a va_list (type %t): %s",
5495 targ, exprNode_unparse (arg)),
5499 exprNode_checkSet (ret, arg->sref);
5503 ** return type is totype
5507 ret->kind = XPR_VAARG;
5508 ret->edata = exprData_makeCast (tok, arg, qt);
5513 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
5515 exprNode ret = exprNode_createPlain (ctype_undefined);
5516 ret->kind = XPR_LABEL;
5517 ret->edata = exprData_makeLiteral (label);
5518 ret->isJumpPoint = TRUE;
5520 return (ret); /* for now, ignore label */
5523 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
5525 if (exprNode_isDefined (stmt))
5527 stmt->isJumpPoint = TRUE;
5529 /* This prevent stray no return path errors, etc. */
5530 stmt->exitCode = XK_MUSTEXIT;
5536 bool exprNode_isDefaultMarker (exprNode e)
5538 if (exprNode_isDefined (e))
5540 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
5546 bool exprNode_isCaseMarker (exprNode e)
5548 if (exprNode_isDefined (e))
5550 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
5556 bool exprNode_isLabelMarker (exprNode e)
5558 if (exprNode_isDefined (e))
5560 return (e->kind == XPR_LABEL);
5566 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
5568 exprNode ret = exprNode_createPartialCopy (test);
5570 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5572 if (exprNode_isError (test)) {
5576 exprNode_checkUse (ret, test->sref, test->loc);
5578 usymtab_setExitCode (ret->exitCode);
5582 usymtab_setMustBreak ();
5585 ret->edata = exprData_makeSingle (test);
5586 ret->isJumpPoint = TRUE;
5592 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
5594 exprNode ret = exprNode_createPartialCopy (test);
5596 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5597 ret->edata = exprData_makePair (test, stmt);
5598 ret->isJumpPoint = TRUE;
5600 if (exprNode_isError (test))
5605 exprNode_checkUse (ret, test->sref, test->loc);
5607 if (exprNode_isError (stmt))
5612 exprNode_mergeUSs (ret, stmt);
5614 ret->exitCode = stmt->exitCode;
5615 ret->mustBreak = stmt->mustBreak;
5616 ret->canBreak = stmt->canBreak;
5618 usymtab_setExitCode (ret->exitCode);
5622 usymtab_setMustBreak ();
5629 /*@notnull@*/ /*@only@*/ exprNode
5630 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
5632 exprNode ret = exprNode_createTok (def);
5634 ret->isJumpPoint = TRUE;
5635 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
5640 exprNode_mayEscape (exprNode e)
5642 if (exprNode_isDefined (e))
5644 return exitkind_couldEscape (e->exitCode);
5650 exprNode_mustBreak (exprNode e)
5652 if (exprNode_isDefined (e))
5654 return e->mustBreak;
5660 exprNode_mustEscape (exprNode e)
5662 if (exprNode_isDefined (e))
5664 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
5671 exprNode_errorEscape (exprNode e)
5673 if (exprNode_isDefined (e))
5675 return exitkind_isError (e->exitCode);
5681 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
5683 exprNode ret = exprNode_createPartialCopy (e1);
5685 ret->edata = exprData_makePair (e1, e2);
5686 ret->kind = XPR_STMTLIST;
5688 if (exprNode_isDefined (e1))
5690 ret->isJumpPoint = e1->isJumpPoint;
5691 ret->canBreak = e1->canBreak;
5695 if (exprNode_isDefined (e2))
5697 ret->loc = fileloc_update (ret->loc, e2->loc);
5701 if (exprNode_isDefined (e2))
5703 ret->exitCode = e2->exitCode;
5704 ret->mustBreak = e2->mustBreak;
5705 if (e2->canBreak) ret->canBreak = TRUE;
5709 ** if e1 must return, then e2 is unreachable!
5712 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
5714 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
5715 && !(e2->isJumpPoint))
5717 if (context_getFlag (FLG_UNREACHABLE))
5721 if (e2->kind == XPR_STMT)
5723 nr = exprData_getUopNode (e2->edata);
5726 if ((nr->kind == XPR_TOK
5727 && lltok_isSemi (exprData_getTok (nr->edata))))
5729 /* okay to have unreachable ";" */
5730 ret->exitCode = XK_MUSTEXIT;
5731 ret->canBreak = TRUE;
5735 if (optgenerror (FLG_UNREACHABLE,
5736 message ("Unreachable code: %s",
5737 exprNode_unparseFirst (nr)),
5740 ret->isJumpPoint = TRUE;
5741 ret->mustBreak = FALSE;
5742 ret->exitCode = XK_ERROR;
5743 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
5747 ret->exitCode = XK_MUSTEXIT;
5748 ret->canBreak = TRUE;
5756 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
5759 ** We want a warning anytime we have:
5761 ** yyy; <<<- no break or return
5765 exprNode lastStmt = exprNode_lastStatement (e1);
5767 if (exprNode_isDefined (lastStmt)
5768 && !exprNode_mustEscape (lastStmt)
5769 && !exprNode_mustBreak (lastStmt)
5770 && !exprNode_isCaseMarker (lastStmt)
5771 && !exprNode_isDefaultMarker (lastStmt)
5772 && !exprNode_isLabelMarker (lastStmt))
5774 voptgenerror (FLG_CASEBREAK,
5776 ("Fall through case (no preceeding break)"),
5783 exprNode_mergeUSs (ret, e2);
5784 ret = exprNode_mergeEnvironments (ret, e1, e2);
5785 usymtab_setExitCode (ret->exitCode);
5789 usymtab_setMustBreak ();
5795 exprNode exprNode_createTok (/*@only@*/ lltok t)
5797 exprNode ret = exprNode_create (ctype_unknown);
5798 ret->kind = XPR_TOK;
5799 ret->edata = exprData_makeTok (t);
5803 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5805 if (!exprNode_isError (e))
5807 exprNode_checkStatement(e);
5810 return (exprNode_statementError (e, t));
5813 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5815 exprNode ret = exprNode_createPartialCopy (e);
5817 if (!exprNode_isError (e))
5819 if (e->kind != XPR_ASSIGN)
5821 exprNode_checkUse (ret, e->sref, e->loc);
5824 ret->exitCode = e->exitCode;
5825 ret->canBreak = e->canBreak;
5826 ret->mustBreak = e->mustBreak;
5829 ret->edata = exprData_makeUop (e, t);
5830 ret->kind = XPR_STMT;
5835 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
5837 if (!exprNode_isError (e))
5839 if (e->kind != XPR_ASSIGN)
5841 exprNode_checkUse (e, e->sref, e->loc);
5848 void exprNode_produceGuards (exprNode pred)
5850 if (!exprNode_isError (pred))
5852 if (ctype_isRealPointer (pred->typ))
5854 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
5857 exprNode_checkUse (pred, pred->sref, pred->loc);
5858 exprNode_resetSref (pred);
5862 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
5864 exprNode ret = exprNode_createPartialCopy (e);
5866 if (!exprNode_isError (e))
5868 ret->exitCode = e->exitCode;
5869 ret->canBreak = e->canBreak;
5870 ret->mustBreak = e->mustBreak;
5873 ret->edata = exprData_makeSingle (e);
5874 ret->kind = XPR_BLOCK;
5878 bool exprNode_isBlock (exprNode e)
5880 return (exprNode_isDefined (e)
5881 && ((e)->kind == XPR_BLOCK));
5884 bool exprNode_isAssign (exprNode e)
5886 if (exprNode_isDefined (e))
5888 return (e->kind == XPR_ASSIGN);
5894 bool exprNode_isEmptyStatement (exprNode e)
5896 return (exprNode_isDefined (e)
5897 && (e->kind == XPR_TOK)
5898 && (lltok_isSemi (exprData_getTok (e->edata))));
5901 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
5904 bool emptyErr = FALSE;
5906 if (context_maybeSet (FLG_IFEMPTY))
5908 if (exprNode_isEmptyStatement (tclause))
5910 emptyErr = optgenerror (FLG_IFEMPTY,
5912 ("Body of if statement is empty"),
5913 exprNode_loc (tclause));
5917 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
5919 if (exprNode_isDefined (tclause)
5920 && !exprNode_isBlock (tclause))
5922 voptgenerror (FLG_IFBLOCK,
5924 ("Body of if statement is not a block: %s",
5925 exprNode_unparse (tclause)),
5926 exprNode_loc (tclause));
5930 if (exprNode_isError (pred))
5932 if (exprNode_isError (tclause))
5934 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5938 ret = exprNode_createPartialCopy (tclause);
5943 if (exprNode_mustEscape (pred))
5947 message ("Predicate always exits: %s", exprNode_unparse (pred)),
5948 exprNode_loc (pred));
5951 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
5952 exprNode_checkUse (pred, pred->sref, pred->loc);
5954 if (!exprNode_isError (tclause))
5956 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
5959 ret = exprNode_createPartialCopy (pred);
5963 ret->edata = exprData_makePair (pred, tclause);
5965 ret->exitCode = XK_UNKNOWN;
5967 if (exprNode_isDefined (tclause))
5969 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
5970 ret->canBreak = tclause->canBreak;
5971 ret->sets = sRefSet_union (ret->sets, tclause->sets);
5972 ret->msets = sRefSet_union (ret->msets, tclause->msets);
5973 ret->uses = sRefSet_union (ret->uses, tclause->uses);
5976 ret->mustBreak = FALSE;
5981 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
5982 /*@only@*/ exprNode tclause,
5983 /*@only@*/ exprNode eclause)
5986 bool tEmptyErr = FALSE;
5987 bool eEmptyErr = FALSE;
5989 if (context_maybeSet (FLG_IFEMPTY))
5991 if (exprNode_isEmptyStatement (tclause))
5993 tEmptyErr = optgenerror
5996 ("Body of if clause of if statement is empty"),
5997 exprNode_loc (tclause));
6000 if (exprNode_isEmptyStatement (eclause))
6002 eEmptyErr = optgenerror
6005 ("Body of else clause of if statement is empty"),
6006 exprNode_loc (eclause));
6010 if (context_maybeSet (FLG_IFBLOCK))
6013 && exprNode_isDefined (tclause)
6014 && !exprNode_isBlock (tclause))
6016 voptgenerror (FLG_IFBLOCK,
6018 ("Body of if clause of if statement is not a block: %s",
6019 exprNode_unparse (tclause)),
6020 exprNode_loc (tclause));
6024 && exprNode_isDefined (eclause)
6025 && !exprNode_isBlock (eclause)
6026 && !(eclause->kind == XPR_IF)
6027 && !(eclause->kind == XPR_IFELSE))
6032 ("Body of else clause of if statement is not a block: %s",
6033 exprNode_unparse (eclause)),
6034 exprNode_loc (eclause));
6038 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6040 if (exprNode_isDefined (eclause)
6041 && (eclause->kind == XPR_IF))
6043 voptgenerror (FLG_ELSEIFCOMPLETE,
6044 message ("Incomplete else if logic (no final else): %s",
6045 exprNode_unparse (eclause)),
6046 exprNode_loc (eclause));
6050 if (exprNode_isError (pred))
6052 if (exprNode_isError (tclause))
6054 if (exprNode_isError (eclause))
6056 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6060 ret = exprNode_createPartialCopy (eclause);
6065 ret = exprNode_createPartialCopy (tclause);
6068 else /* pred is okay */
6070 ret = exprNode_createPartialCopy (pred);
6072 if (exprNode_mustEscape (pred))
6076 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6077 exprNode_loc (pred));
6080 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6081 exprNode_checkUse (ret, pred->sref, pred->loc);
6083 exprNode_mergeCondUSs (ret, tclause, eclause);
6086 ret->kind = XPR_IFELSE;
6087 ret->edata = exprData_makeCond (pred, tclause, eclause);
6089 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6091 exprNode_combineControl (ret, tclause, eclause);
6092 ret->loc = fileloc_update (ret->loc, eclause->loc);
6099 ** *allpaths <- TRUE iff all executions paths must go through the switch
6103 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6105 exprNodeSList el = exprNode_flatten (e);
6106 bool mustReturn = TRUE; /* find a branch that doesn't */
6107 bool thisReturn = FALSE;
6108 bool hasDefault = FALSE;
6109 bool hasAllMembers = FALSE;
6110 bool inSwitch = FALSE;
6111 bool isEnumSwitch = FALSE;
6112 bool canBreak = FALSE;
6113 bool fallThrough = FALSE;
6114 ctype ct = ctype_unknown;
6115 enumNameSList usedEnums;
6118 if (exprNode_isDefined (test))
6123 ttype = ctype_realType (ct);
6125 if (ctype_isEnum (ttype))
6127 isEnumSwitch = TRUE;
6128 enums = ctype_elist (ttype);
6129 usedEnums = enumNameSList_new ();
6133 exprNodeSList_elements (el, current)
6135 if (exprNode_isDefined (current))
6137 switch (current->kind)
6145 message ("Duplicate default cases in switch"),
6146 exprNode_loc (current));
6151 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6159 exprNode st = exprData_getSingle (current->edata);
6160 uentry ue = exprNode_getUentry (st);
6162 if (uentry_isValid (ue))
6164 cstring cname = uentry_rawName (ue);
6166 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6168 if (enumNameSList_member
6169 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6173 message ("Duplicate case in switch: %s",
6179 enumNameSList_addh (usedEnums, cname);
6186 message ("Case in switch not %s member: %s",
6187 ctype_unparse (ct), cname),
6194 if (inSwitch && !fallThrough)
6196 if (!thisReturn || canBreak)
6206 /*@switchbreak@*/ break;
6208 thisReturn = thisReturn || exprNode_mustEscape (current);
6209 canBreak = canBreak || current->canBreak;
6210 if (canBreak) fallThrough = FALSE;
6213 } end_exprNodeSList_elements;
6215 if (inSwitch) /* check the last one! */
6217 if (!thisReturn || canBreak)
6226 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6227 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6229 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6231 voptgenerror (FLG_MISSCASE,
6232 message ("Missing case%s in switch: %q",
6233 cstring_makeLiteralTemp
6234 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6235 enumNameSList_unparse (unused)),
6238 enumNameSList_free (unused);
6242 hasAllMembers = TRUE;
6246 enumNameSList_free (usedEnums);
6250 *allpaths = hasDefault;
6253 exprNodeSList_free (el);
6254 return ((hasDefault || hasAllMembers) && mustReturn);
6257 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6259 exprNode ret = exprNode_createPartialCopy (e);
6262 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6264 ret->kind = XPR_SWITCH;
6265 ret->edata = exprData_makePair (e, s);
6267 if (!exprNode_isError (s))
6269 exprNode fs = exprNode_firstStatement (s);
6270 ret->loc = fileloc_update (ret->loc, s->loc);
6272 if (exprNode_isUndefined (fs)
6273 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6274 || exprNode_isDefaultMarker (fs)) {
6277 voptgenerror (FLG_FIRSTCASE,
6279 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6284 if (!exprNode_isError (e))
6286 if (checkSwitchExpr (e, s, &allpaths))
6288 ret->exitCode = XK_MUSTRETURN;
6292 ret->exitCode = e->exitCode;
6295 ret->canBreak = e->canBreak;
6296 ret->mustBreak = e->mustBreak;
6300 ** exprNode.c:3883,32: Variable allpaths used before definition
6307 DPRINTF (("Context exit switch!"));
6308 context_exitSwitch (ret, allpaths);
6309 DPRINTF (("Context exit switch done!"));
6314 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6315 /*@notnull@*/ exprNode body)
6317 sRefSet tuses = test->uses;
6319 if (!sRefSet_isEmpty (test->uses))
6321 sRefSet sets = sRefSet_newCopy (body->sets);
6322 bool hasError = TRUE;
6323 bool innerState = FALSE;
6324 sRefSet tuncon = sRefSet_undefined;
6326 sets = sRefSet_union (sets, test->sets);
6327 sets = sRefSet_union (sets, body->msets);
6328 sets = sRefSet_union (sets, test->msets);
6330 sRefSet_allElements (tuses, el)
6332 if (sRef_isUnconstrained (el))
6334 tuncon = sRefSet_insert (tuncon, el);
6338 if (sRefSet_member (sets, el))
6345 if (sRef_isInternalState (el)
6346 || sRef_isFileStatic (sRef_getRootBase (el)))
6350 } end_sRefSet_allElements ;
6354 sRefSet suncon = sRefSet_undefined;
6355 bool sinner = FALSE;
6357 sRefSet_allElements (sets, el)
6359 if (sRef_isUnconstrained (el))
6361 suncon = sRefSet_insert (suncon, el);
6363 else if (sRef_isInternalState (el))
6371 } end_sRefSet_allElements ;
6373 if (sinner && innerState)
6377 else if (sRefSet_isEmpty (tuncon)
6378 && sRefSet_isEmpty (suncon))
6383 ("Suspected infinite loop. No value used in loop test (%q) "
6384 "is modified by test or loop body.",
6385 sRefSet_unparsePlain (tuses)),
6390 if (sRefSet_isEmpty (tuncon))
6394 message ("Suspected infinite loop. No condition values "
6395 "modified. Modification possible through "
6396 "unconstrained calls: %q",
6397 sRefSet_unparsePlain (suncon)),
6404 message ("Suspected infinite loop. No condition values "
6405 "modified. Possible undetected dependency through "
6406 "unconstrained calls in loop test: %q",
6407 sRefSet_unparsePlain (tuncon)),
6413 sRefSet_free (sets);
6417 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
6420 bool emptyErr = FALSE;
6422 // s = exprNode_generateConstraints (t);
6423 // printf("pred: %s\n", s);
6424 // s = exprNode_generateConstraints (b);
6425 //printf ("body: %s\n", s);
6426 //constraintList_print(b->constraints);
6428 if (context_maybeSet (FLG_WHILEEMPTY))
6430 if (exprNode_isEmptyStatement (b))
6432 emptyErr = optgenerror
6435 ("Body of while statement is empty"),
6440 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
6442 if (exprNode_isDefined (b)
6443 && !exprNode_isBlock (b))
6445 if (context_inIterDef ()
6446 && (b->kind == XPR_STMTLIST
6447 || b->kind == XPR_TOK))
6453 voptgenerror (FLG_WHILEBLOCK,
6455 ("Body of while statement is not a block: %s",
6456 exprNode_unparse (b)),
6462 if (exprNode_isError (t))
6464 if (exprNode_isError (b))
6466 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6470 ret = exprNode_createPartialCopy (b);
6477 ret = exprNode_createPartialCopy (t);
6479 llassert (t->kind == XPR_WHILEPRED);
6481 test = exprData_getSingle (t->edata);
6483 if (!exprNode_isError (b) && exprNode_isDefined (test))
6485 if (context_maybeSet (FLG_INFLOOPS)
6486 || context_maybeSet (FLG_INFLOOPSUNCON))
6489 ** check that some variable in the predicate is set by the body
6490 ** if the predicate uses any variables
6493 checkInfiniteLoop (test, b);
6496 exprNode_mergeUSs (ret, b);
6498 if (exprNode_isDefined (b))
6500 ret->exitCode = exitkind_makeConditional (b->exitCode);
6505 ret->edata = exprData_makePair (t, b);
6506 ret->kind = XPR_WHILE;
6508 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
6512 message ("Predicate always exits: %s", exprNode_unparse (t)),
6516 ret->exitCode = XK_NEVERESCAPE;
6519 ** If loop is infinite, and there is no break inside,
6520 ** exit code is never reach.
6523 if (exprNode_knownIntValue (t))
6525 if (!exprNode_isZero (t))
6527 if (exprNode_isDefined (b))
6531 /* Really, it means never reached. */
6532 ret->exitCode = XK_MUSTEXIT;
6542 ret->canBreak = FALSE;
6543 ret->mustBreak = FALSE;
6549 ** do { b } while (t);
6551 ** note: body passed as first argument
6554 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
6558 if (exprNode_isError (t))
6560 if (exprNode_isError (b))
6562 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6566 ret = exprNode_createPartialCopy (b);
6568 ret->exitCode = exitkind_makeConditional (b->exitCode);
6569 exprNode_checkUse (ret, b->sref, b->loc);
6570 ret->exitCode = b->exitCode;
6571 ret->canBreak = b->canBreak;
6572 ret->mustBreak = b->mustBreak;
6577 ret = exprNode_createPartialCopy (t);
6578 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
6580 if (!exprNode_isError (b))
6583 ** forgot the copy's --- why wasn't this detected??
6586 ret->sets = sRefSet_copy (ret->sets, b->sets);
6587 ret->msets = sRefSet_copy (ret->msets, b->msets);
6588 ret->uses = sRefSet_copy (ret->uses, b->uses);
6590 /* left this out --- causes and aliasing bug (infinite loop)
6591 should be detected?? */
6593 exprNode_checkUse (ret, b->sref, b->loc);
6594 exprNode_mergeUSs (ret, t);
6595 exprNode_checkUse (ret, t->sref, t->loc);
6597 ret->exitCode = b->exitCode;
6598 ret->canBreak = b->canBreak;
6599 ret->mustBreak = b->mustBreak;
6603 context_exitDoWhileClause (t);
6605 ret->kind = XPR_DOWHILE;
6606 ret->edata = exprData_makePair (t, b);
6610 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
6613 bool emptyErr = FALSE;
6615 if (context_maybeSet (FLG_FOREMPTY))
6617 if (exprNode_isEmptyStatement (body))
6619 emptyErr = optgenerror
6622 ("Body of for statement is empty"),
6623 exprNode_loc (body));
6627 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
6629 if (exprNode_isDefined (body)
6630 && !exprNode_isBlock (body))
6632 if (context_inIterDef ()
6633 && (body->kind == XPR_STMTLIST
6634 || body->kind == XPR_TOK))
6640 voptgenerror (FLG_FORBLOCK,
6642 ("Body of for statement is not a block: %s",
6643 exprNode_unparse (body)),
6644 exprNode_loc (body));
6650 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
6653 if (exprNode_isError (body))
6655 ret = exprNode_createPartialCopy (inc);
6659 ret = exprNode_createPartialCopy (body);
6661 ret->exitCode = exitkind_makeConditional (body->exitCode);
6663 exprNode_mergeUSs (inc, body);
6665 if (exprNode_isDefined (inc))
6669 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
6672 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
6673 exprNode_freeShallow (tmp);
6675 context_clearMessageAnnote ();
6676 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
6678 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
6679 exprNode_freeShallow (tmp);
6681 context_clearMessageAnnote ();
6683 ret->uses = sRefSet_copy (ret->uses, inc->uses);
6684 ret->sets = sRefSet_copy (ret->sets, inc->sets);
6685 ret->msets = sRefSet_copy (ret->msets, inc->msets);
6689 ret->kind = XPR_FOR;
6690 ret->edata = exprData_makePair (inc, body);
6692 if (exprNode_isDefined (inc)) {
6693 exprNode test = exprData_getTripleTest (inc->edata);
6695 if (exprNode_isUndefined (test)) {
6696 if (exprNode_isDefined (body)) {
6697 if (!body->canBreak) {
6698 /* Really, it means never reached. */
6699 ret->exitCode = XK_MUSTEXIT;
6709 ** for (init; test; inc)
6712 ** while (test) { body; inc; }
6714 ** Now: check use of init (may set vars for test)
6715 ** check use of test
6719 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
6723 if (exprNode_isError (pred)) return guardSet_undefined;
6725 llassert (pred->kind == XPR_FORPRED);
6727 test = exprData_getTripleTest (pred->edata);
6729 if (!exprNode_isError (test))
6731 return (test->guards);
6734 return guardSet_undefined;
6737 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
6739 exprNode ret = exprNode_createSemiCopy (test);
6741 if (exprNode_isDefined (test))
6743 exprNode_copySets (ret, test);
6744 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
6745 exprNode_checkUse (ret, test->sref, test->loc);
6747 exprNode_produceGuards (test);
6749 ret->guards = guardSet_copy (test->guards);
6752 ret->edata = exprData_makeSingle (test);
6753 ret->kind = XPR_WHILEPRED;
6757 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
6758 /*@only@*/ exprNode inc)
6763 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
6766 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
6768 if (!exprNode_isError (inc))
6770 ret = exprNode_createPartialCopy (inc);
6774 if (!exprNode_isError (init))
6776 ret = exprNode_createPartialCopy (init);
6778 else if (!exprNode_isError (test))
6780 ret = exprNode_createPartialCopy (test);
6784 ret = exprNode_createUnknown ();
6788 exprNode_mergeUSs (ret, init);
6790 if (exprNode_isDefined (init))
6792 exprNode_checkUse (ret, init->sref, init->loc);
6795 exprNode_mergeUSs (ret, test);
6797 if (exprNode_isDefined (test))
6799 exprNode_checkUse (ret, test->sref, test->loc);
6802 ret->kind = XPR_FORPRED;
6803 ret->edata = exprData_makeFor (init, test, inc);
6807 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
6809 exprNode ret = exprNode_createUnknown ();
6811 if (context_inMacro ())
6813 voptgenerror (FLG_MACROSTMT,
6814 message ("Macro %s uses goto (not functional)",
6815 context_inFunctionName ()),
6819 ret->kind = XPR_GOTO;
6820 ret->edata = exprData_makeLiteral (label);
6821 ret->mustBreak = TRUE;
6822 ret->exitCode = XK_GOTO;
6823 ret->canBreak = TRUE;
6827 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
6829 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6831 ret->kind = XPR_CONTINUE;
6832 ret->edata = exprData_makeTok (l);
6833 ret->canBreak = TRUE;
6834 ret->mustBreak = TRUE;
6836 if (qcontinue == QSAFEBREAK)
6840 else if (qcontinue == QINNERCONTINUE)
6842 if (!context_inDeepLoop ())
6845 (FLG_LOOPLOOPCONTINUE,
6846 cstring_makeLiteral ("Continue statement marked with innercontinue "
6847 "is not inside a nested loop"),
6848 exprNode_loc (ret));
6851 else if (qcontinue == BADTOK)
6853 if (context_inDeepLoop ())
6856 (FLG_LOOPLOOPCONTINUE,
6857 cstring_makeLiteral ("Continue statement in nested loop"),
6858 exprNode_loc (ret));
6863 llbuglit ("exprNode_continue: bad qcontinue");
6869 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
6871 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6872 clause breakClause = context_breakClause ();
6874 ret->kind = XPR_BREAK;
6875 ret->edata = exprData_makeTok (l);
6876 ret->canBreak = TRUE;
6877 ret->mustBreak = TRUE;
6879 if (breakClause == NOCLAUSE)
6883 cstring_makeLiteral ("Break not inside while, for or switch statement"),
6884 exprNode_loc (ret));
6888 if (bqual != BADTOK)
6895 if (breakClause == SWITCHCLAUSE)
6897 if (!context_inDeepSwitch ())
6899 voptgenerror (FLG_SYNTAX,
6901 ("Break preceded by innerbreak is not in a deep switch"),
6902 exprNode_loc (ret));
6907 if (!context_inDeepLoop ())
6909 voptgenerror (FLG_SYNTAX,
6911 ("Break preceded by innerbreak is not in a deep loop"),
6912 exprNode_loc (ret));
6917 if (breakClause == SWITCHCLAUSE)
6919 voptgenerror (FLG_SYNTAX,
6921 ("Break preceded by loopbreak is breaking a switch"),
6922 exprNode_loc (ret));
6926 if (breakClause != SWITCHCLAUSE)
6930 message ("Break preceded by switchbreak is breaking %s",
6931 cstring_makeLiteralTemp
6932 ((breakClause == WHILECLAUSE
6933 || breakClause == DOWHILECLAUSE) ? "a while loop"
6934 : (breakClause == FORCLAUSE) ? "a for loop"
6935 : (breakClause == ITERCLAUSE) ? "an iterator"
6937 exprNode_loc (ret));
6945 if (breakClause == SWITCHCLAUSE)
6947 clause nextBreakClause = context_nextBreakClause ();
6949 switch (nextBreakClause)
6951 case NOCLAUSE: break;
6957 (FLG_LOOPSWITCHBREAK,
6958 cstring_makeLiteral ("Break statement in switch inside loop"),
6959 exprNode_loc (ret));
6963 (FLG_SWITCHSWITCHBREAK,
6964 cstring_makeLiteral ("Break statement in switch inside switch"),
6965 exprNode_loc (ret));
6972 if (context_inDeepLoop ())
6976 cstring_makeLiteral ("Break statement in nested loop"),
6977 exprNode_loc (ret));
6981 if (context_inDeepLoopSwitch ())
6984 (FLG_SWITCHLOOPBREAK,
6985 cstring_makeLiteral ("Break statement in loop inside switch"),
6986 exprNode_loc (ret));
6996 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
6998 fileloc loc = lltok_getLoc (t);
6999 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
7001 context_returnFunction ();
7002 exprChecks_checkNullReturn (loc);
7004 ret->kind = XPR_NULLRETURN;
7005 ret->edata = exprData_makeTok (t);
7006 ret->exitCode = XK_MUSTRETURN;
7010 exprNode exprNode_return (/*@only@*/ exprNode e)
7014 if (exprNode_isError (e))
7016 ret = exprNode_createUnknown ();
7020 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7022 exprNode_checkUse (ret, e->sref, e->loc);
7023 exprNode_checkReturn (e);
7026 context_returnFunction ();
7027 ret->kind = XPR_RETURN;
7028 ret->edata = exprData_makeSingle (e);
7029 ret->exitCode = XK_MUSTRETURN;
7034 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7038 if (exprNode_isError (e1))
7040 if (exprNode_isError (e2))
7042 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
7046 ret = exprNode_createPartialCopy (e2);
7047 exprNode_checkUse (ret, e2->sref, e2->loc);
7048 ret->sref = e2->sref;
7053 ret = exprNode_createPartialCopy (e1);
7055 exprNode_checkUse (ret, e1->sref, e1->loc);
7057 if (!exprNode_isError (e2))
7059 exprNode_mergeUSs (ret, e2);
7060 exprNode_checkUse (ret, e2->sref, e2->loc);
7061 ret->sref = e2->sref;
7065 ret->kind = XPR_COMMA;
7066 ret->edata = exprData_makePair (e1, e2);
7068 if (exprNode_isDefined (e1))
7070 if (exprNode_isDefined (e2))
7074 if (exprNode_mustEscape (e1) || e1->mustBreak)
7078 message ("Second clause of comma expression is unreachable: %s",
7079 exprNode_unparse (e2)),
7083 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7084 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7085 ret->canBreak = e1->canBreak || e2->canBreak;
7089 if (exprNode_mustEscape (e1) || e1->mustBreak)
7093 message ("Second clause of comma expression is unreachable: %s",
7094 exprNode_unparse (e2)),
7098 ret->exitCode = e1->exitCode;
7099 ret->canBreak = e1->canBreak;
7104 if (exprNode_isDefined (e2))
7106 ret->exitCode = e2->exitCode;
7107 ret->mustBreak = e2->mustBreak;
7108 ret->canBreak = e2->canBreak;
7115 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7117 ctype t1 = exprNode_getType (el);
7118 ctype t2 = exprNode_getType (val);
7119 bool hasError = FALSE;
7121 if (ctype_isUnknown (t1))
7123 voptgenerror (FLG_IMPTYPE,
7124 message ("Variable has unknown (implicitly int) type: %s",
7125 exprNode_unparse (el)),
7129 el->typ = ctype_int;
7132 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7134 exprNodeList vals = exprData_getArgs (val->edata);
7136 if (ctype_isRealAP (t1))
7141 exprNodeList_elements (vals, oneval)
7143 cstring istring = message ("%d", i);
7146 (exprNode_fakeCopy (el),
7147 exprNode_numLiteral (ctype_int, istring,
7148 fileloc_copy (el->loc), i));
7150 if (exprNode_isDefined (newel))
7152 if (exprNodeList_size (vals) == 1
7153 && ctype_isString (exprNode_getType (oneval))
7154 && ctype_isChar (exprNode_getType (newel)))
7156 exprNode_freeIniter (newel);
7160 if (exprNode_checkOneInit (newel, oneval))
7165 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7168 (message ("Additional initialization errors "
7169 "for %s not reported",
7170 exprNode_unparse (el)),
7172 exprNode_freeIniter (newel);
7177 exprNode_freeIniter (newel);
7182 exprNode_freeIniter (newel);
7187 cstring_free (istring);
7190 } end_exprNodeList_elements;
7193 else if (ctype_isStruct (ctype_realType (t1)))
7195 uentryList fields = ctype_getFields (t1);
7198 if (uentryList_size (fields) != exprNodeList_size (vals))
7200 if (uentryList_size (fields) > exprNodeList_size (vals))
7202 hasError = optgenerror
7204 message ("Initializer block for "
7205 "%s has %d field%p, but %s has %d field%p: %q",
7206 exprNode_unparse (el),
7207 exprNodeList_size (vals),
7209 uentryList_size (fields),
7210 exprNodeList_unparse (vals)),
7215 hasError = optgenerror
7217 message ("Initializer block for "
7218 "%s has %d field%p, but %s has %d field%p: %q",
7219 exprNode_unparse (el),
7220 exprNodeList_size (vals),
7222 uentryList_size (fields),
7223 exprNodeList_unparse (vals)),
7229 exprNodeList_elements (vals, oneval)
7231 uentry thisfield = uentryList_getN (fields, i);
7233 exprNode_fieldAccess (exprNode_fakeCopy (el),
7234 uentry_getName (thisfield));
7236 if (exprNode_isDefined (newel))
7238 if (exprNode_checkOneInit (newel, oneval))
7243 exprNode_freeIniter (newel);
7247 } end_exprNodeList_elements;
7252 hasError = optgenerror
7254 message ("Initializer block used for "
7255 "%s where %t is expected: %s",
7256 exprNode_unparse (el), t1, exprNode_unparse (val)),
7262 if (exprNode_isDefined (val))
7264 doAssign (el, val, TRUE);
7266 if (!exprNode_matchType (t1, val))
7268 hasError = gentypeerror
7270 message ("Initial value of %s is type %t, "
7272 exprNode_unparse (el),
7273 t2, t1, exprNode_unparse (val)),
7282 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
7283 /*@only@*/ exprNode e)
7285 uentry ue = usymtab_lookup (idDecl_observeId (t));
7286 bool isUsed = uentry_isUsed (ue);
7287 exprNode ret = exprNode_fromIdentifierAux (ue);
7288 ctype ct = ctype_realishType (ret->typ);
7291 if (ctype_isUnknown (ct))
7293 voptgenerror (FLG_IMPTYPE,
7294 message ("Variable has unknown (implicitly int) type: %s",
7295 idDecl_getName (t)),
7296 exprNode_isDefined (e) ? exprNode_loc (e) : g_currentloc);
7301 if (exprNode_isError (e))
7303 e = exprNode_createUnknown ();
7306 /* error: assume initializer is defined */
7307 sRef_setDefined (ret->sref, loc);
7311 loc = exprNode_loc (e);
7316 ** was addSafeUse --- what's the problem?
7318 ** int x = 3, y = x ?
7321 exprNode_checkUse (ret, e->sref, e->loc);
7323 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
7325 exprNode lhs = exprNode_createId (ue);
7328 ** static storage should be undefined before initializing
7331 if (uentry_isStatic (ue))
7333 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
7336 (void) exprNode_checkOneInit (lhs, e);
7338 if (uentry_isStatic (ue))
7340 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
7343 exprNode_free (lhs);
7347 if (!exprNode_matchType (ct, e))
7349 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
7356 (exprNode_getType (e), e, exprNode_getType (ret), ret,
7358 ("Variable %s initialized to type %t, expects %t: %s",
7359 exprNode_unparse (ret), exprNode_getType (e),
7360 exprNode_getType (ret),
7361 exprNode_unparse (e)),
7367 if (uentry_isStatic (ue))
7369 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
7372 doAssign (ret, e, TRUE);
7374 if (uentry_isStatic (ue))
7376 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
7380 if (context_inIterDef ())
7382 /* should check if it is yield */
7383 uentry_setUsed (ue, loc);
7387 if (!isUsed) /* could be @unused@-qualified variable */
7389 uentry_setNotUsed (ue);
7393 ret->exitCode = XK_NEVERESCAPE;
7394 ret->mustBreak = FALSE;
7397 ** Must be before new kind is assigned!
7400 exprData_free (ret->edata, ret->kind);
7402 ret->kind = XPR_INIT;
7403 ret->edata = exprData_makeInit (t, e);
7404 exprNode_mergeUSs (ret, e);
7408 exprNode exprNode_iter (/*@observer@*/ uentry name,
7409 /*@only@*/ exprNodeList alist,
7410 /*@only@*/ exprNode body,
7411 /*@observer@*/ uentry end)
7416 llassert (uentry_isValid (name));
7418 uentry_setUsed (name, exprNode_loc (body));
7420 ret = exprNode_createPartialCopy (body);
7421 iname = uentry_getName (name);
7423 if (uentry_isInvalid (end))
7426 message ("Iter %s not balanced with end_%s", iname, iname));
7430 cstring ename = uentry_getName (end);
7432 if (!cstring_equalPrefix (ename, "end_"))
7434 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
7435 iname, iname, ename));
7439 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
7442 message ("Iter %s not balanced with end_%s: %s",
7443 iname, iname, ename));
7447 cstring_free (ename);
7450 context_exitIterClause (body);
7452 ret->kind = XPR_ITER;
7453 ret->edata = exprData_makeIter (name, alist, body, end);
7455 if (uentry_isIter (name))
7457 (void) checkArgsReal (name, body,
7458 uentry_getParams (name), alist, TRUE, ret);
7461 cstring_free (iname);
7467 exprNode_iterNewId (/*@only@*/ cstring s)
7469 exprNode e = exprNode_new ();
7470 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
7472 llassert (processingIterVars ());
7474 e->loc = context_getSaveLocation ();
7476 if (fileloc_isUndefined (e->loc))
7478 fileloc_free (e->loc);
7479 e->loc = fileloc_copy (g_currentloc);
7482 e->uses = sRefSet_new ();
7483 e->sets = sRefSet_new ();
7484 e->msets = sRefSet_new ();
7486 e->val = multiVal_unknown ();
7487 e->guards = guardSet_new ();
7489 e->isJumpPoint = FALSE;
7490 e->exitCode = XK_NEVERESCAPE;
7492 /*> missing fields, detected by lclint <*/
7493 e->canBreak = FALSE;
7494 e->mustBreak = FALSE;
7495 e->etext = cstring_undefined;
7497 if (uentry_isYield (ue))
7499 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
7500 fileloc_copy (e->loc),
7504 uue = usymtab_supEntrySrefReturn (uue);
7506 sr = uentry_getSref (uue);
7507 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
7508 sr = uentry_getSref (uue);
7509 sRef_setDefined (sr, e->loc);
7511 e->typ = uentry_getType (uue);
7513 e->edata = exprData_makeId (uue);
7514 uentry_setUsed (uue, g_currentloc);
7520 sRef_setGlobalScope ();
7521 uue = uentry_makeVariableLoc (s, ctype_unknown);
7523 e->typ = ctype_unknown;
7524 e->edata = exprData_makeId (uue);
7526 uentry_setUsed (uue, e->loc);
7527 uentry_setHasNameError (uue);
7529 if (context_getFlag (FLG_REPEATUNRECOG))
7531 uentry_markOwned (uue);
7535 usymtab_supGlobalEntry (uue);
7538 sRef_clearGlobalScope ();
7540 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
7550 exprNode_iterExpr (/*@returned@*/ exprNode e)
7552 if (!processingIterVars ())
7554 llcontbuglit ("checkIterParam: not in iter");
7558 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
7561 if (exprNode_isDefined (e))
7563 if (fileloc_isDefined (e->loc))
7567 message ("Yield parameter is not simple identifier: %s",
7568 exprNode_unparse (e)),
7575 message ("Yield parameter is not simple identifier: %s",
7576 exprNode_unparse (e)),
7586 exprNode_iterId (/*@observer@*/ uentry c)
7590 llassert (processingIterVars ());
7592 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
7595 if (uentry_isYield (ue))
7597 ctype ct = uentry_getType (ue);
7598 exprNode e = exprNode_createPlain (ct);
7599 cstring name = uentry_getName (c);
7600 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
7602 uentry_setUsed (ue, g_currentloc);
7603 uentry_setHasNameError (ue);
7605 cstring_free (name);
7608 e->edata = exprData_makeId (le);
7609 e->loc = context_getSaveLocation ();
7610 e->sref = uentry_getSref (le);
7612 usymtab_supEntrySref (le);
7614 if (!context_inHeader ())
7618 message ("Yield parameter shadows local declaration: %q",
7619 uentry_getName (c)),
7620 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
7622 uentry_showWhereDeclared (c);
7629 return (exprNode_fromIdentifierAux (c));
7632 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
7634 exprNode ret = exprNode_create (ctype_unknown);
7636 ret->kind = XPR_ITERCALL;
7637 ret->edata = exprData_makeIterCall (name, alist);
7639 if (uentry_isIter (name))
7641 uentryList params = uentry_getParams (name);
7643 if (context_inIterDef ()
7644 && uentryList_size (params) == exprNodeList_size (alist))
7648 exprNodeList_elements (alist, arg)
7650 uentry parg = uentryList_getN (params, i);
7652 if (uentry_isYield (parg))
7654 uentry ue = exprNode_getUentry (arg);
7656 if (uentry_isValid (ue))
7663 } end_exprNodeList_elements;
7666 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
7667 checkUnspecCall (ret, params, alist);
7673 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
7675 if (exprNode_isDefined (e))
7678 if (e->sref == defref) /*@noaccess sRef@*/
7681 e->sref = sRef_makeUnknown ();
7682 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
7693 return sRef_undefined;
7697 /*@observer@*/ cstring
7698 exprNode_unparseFirst (exprNode e)
7700 if (exprNode_isDefined (e))
7704 if (e->kind == XPR_STMTLIST
7705 || e->kind == XPR_COMMA || e->kind == XPR_COND)
7707 exprNode first = exprData_getPairA (e->edata);
7709 if (exprNode_isDefined (first))
7711 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
7715 return (cstring_makeLiteralTemp ("..."));
7719 ret = cstring_elide (exprNode_unparse (e), 20);
7720 cstring_markOwned (ret);
7726 return cstring_makeLiteralTemp ("<error>");
7730 /*@observer@*/ cstring
7731 exprNode_unparse (exprNode e)
7733 if (exprNode_isError (e))
7735 return cstring_makeLiteralTemp ("<error>");
7738 if (cstring_isDefined (e->etext))
7744 cstring ret = exprNode_doUnparse (e);
7746 /*@-modifies@*/ /* benevolent */
7753 /*@observer@*/ fileloc
7754 exprNode_loc (exprNode e)
7756 if (exprNode_isError (e))
7758 return (g_currentloc);
7767 ** executes exprNode e
7768 ** recursively rexecutes as though in original parse using
7769 ** information in e->edata
7772 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
7774 exprNodeList ret = exprNodeList_new ();
7776 exprNodeList_elements (e, current)
7778 exprNodeList_addh (ret, exprNode_effect (current));
7779 } end_exprNodeList_elements;
7784 static /*@only@*/ exprNode exprNode_effect (exprNode e)
7785 /*@globals internalState@*/
7787 bool innerEffect = inEffect;
7793 context_clearJustPopped ();
7795 if (exprNode_isError (e))
7797 ret = exprNode_undefined;
7802 ** Turn off expose and dependent transfer checking.
7803 ** Need to pass exposed internal nodes,
7804 ** [ copying would be a waste! ]
7805 ** [ Actually, I think I wasted a lot more time than its worth ]
7806 ** [ trying to do this. ]
7810 /*@-observertrans@*/
7811 /*@-dependenttrans@*/
7818 ret = exprNode_addParens (exprData_getUopTok (data),
7819 exprNode_effect (exprData_getUopNode (data)));
7822 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
7823 exprNode_effect (exprData_getOpB (data)),
7824 exprData_getOpTok (data));
7827 ret = exprNode_undefined;
7830 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
7831 exprNodeList_effect (exprData_getArgs (data)));
7844 cstring id = exprData_getId (data);
7845 uentry ue = usymtab_lookupSafe (id);
7847 ret = exprNode_fromIdentifierAux (ue);
7848 ret->loc = fileloc_update (ret->loc, e->loc);
7855 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
7856 exprNode_effect (exprData_getPairB (data)));
7859 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
7860 exprNode_effect (exprData_getOpB (data)),
7861 exprData_getOpTok (data));
7865 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
7866 exprData_getUopTok (data));
7869 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
7870 exprData_getUopTok (data));
7882 ret = exprNode_vaArg (exprData_getCastTok (data),
7883 exprNode_effect (exprData_getCastNode (data)),
7884 exprData_getCastType (data));
7888 ret = exprNode_cast (exprData_getCastTok (data),
7889 exprNode_effect (exprData_getCastNode (data)),
7890 exprData_getCastType (data));
7893 ret = exprNode_iterStart (exprData_getIterCallIter (data),
7895 (exprData_getIterCallArgs (data)));
7899 ret = exprNode_iter (exprData_getIterSname (data),
7900 exprNodeList_effect (exprData_getIterAlist (data)),
7901 exprNode_effect (exprData_getIterBody (data)),
7902 exprData_getIterEname (data));
7906 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
7907 exprNode_effect (exprData_getPairB (data)));
7911 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
7912 exprNode_effect (exprData_getTripleTest (data)),
7913 exprNode_effect (exprData_getTripleInc (data)));
7917 ret = exprNode_createTok (exprData_getTok (data));
7921 ret = exprNode_goto (exprData_getLiteral (data));
7922 ret->loc = fileloc_update (ret->loc, e->loc);
7926 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
7930 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
7934 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
7937 case XPR_NULLRETURN:
7938 ret = exprNode_nullReturn (exprData_getTok (data));
7942 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
7943 exprNode_effect (exprData_getPairB (data)));
7947 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
7948 exprNode_effect (exprData_getTripleTrue (data)),
7949 exprNode_effect (exprData_getTripleFalse (data)));
7952 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
7953 exprNode_effect (exprData_getPairB (data)));
7957 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
7958 exprNode_effect (exprData_getTripleTrue (data)),
7959 exprNode_effect (exprData_getTripleFalse (data)));
7962 ret = exprNode_whilePred (exprData_getSingle (data));
7966 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
7967 exprNode_effect (exprData_getPairB (data)));
7971 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
7972 exprNode_effect (exprData_getPairB (data)));
7976 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
7980 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
7981 exprData_getUopTok (data));
7985 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
7986 exprNode_effect (exprData_getPairB (data)));
7991 ret = exprNode_caseMarker
7992 (exprNode_effect (exprData_getSingle (data)),
7998 ret = exprNode_createTok (exprData_getTok (data));
8002 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
8003 exprNode_effect (exprData_getPairB (data)));
8007 ret = exprNode_makeInitialization
8008 (exprData_getInitId (data),
8009 exprNode_effect (exprData_getInitNode (data)));
8013 ret = exprNode_fieldAccess (exprNode_effect (exprData_getFieldNode (data)),
8014 cstring_copy (exprData_getFieldName (data)));
8018 ret = exprNode_arrowAccess (exprNode_effect (exprData_getFieldNode (data)),
8019 cstring_copy (exprData_getFieldName (data)));
8022 case XPR_STRINGLITERAL:
8036 /*@=observertrans@*/
8038 /*@=dependenttrans@*/
8049 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8054 if (exprNode_isError (e))
8056 return cstring_undefined;
8064 ret = exprNode_rootVarName (exprData_getUopNode (data));
8067 ret = exprNode_rootVarName (exprData_getOpA (data));
8071 ret = exprData_getId (data);
8096 case XPR_NULLRETURN:
8119 case XPR_STRINGLITERAL:
8120 ret = cstring_undefined;
8128 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8133 if (exprNode_isError (e))
8135 static /*@only@*/ cstring error = cstring_undefined;
8137 if (!cstring_isDefined (error))
8139 error = cstring_makeLiteral ("<error>");
8150 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8153 ret = message ("%s %s %s",
8154 exprNode_unparse (exprData_getOpA (data)),
8155 lltok_unparse (exprData_getOpTok (data)),
8156 exprNode_unparse (exprData_getOpB (data)));
8159 ret = message ("%s(%q)",
8160 exprNode_unparse (exprData_getFcn (data)),
8161 exprNodeList_unparse (exprData_getArgs (data)));
8164 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8167 ret = cstring_undefined;
8170 ret = message ("%s:", exprData_getId (data));
8174 ret = cstring_copy (exprData_getId (data));
8177 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8178 exprNode_unparse (exprData_getPairB (data)));
8181 ret = message ("<body>");
8184 ret = message ("%s %s %s",
8185 exprNode_unparse (exprData_getOpA (data)),
8186 lltok_unparse (exprData_getOpTok (data)),
8187 exprNode_unparse (exprData_getOpB (data)));
8191 ret = message ("%s%s",
8192 lltok_unparse (exprData_getUopTok (data)),
8193 exprNode_unparse (exprData_getUopNode (data)));
8197 ret = message ("%s%s",
8198 exprNode_unparse (exprData_getUopNode (data)),
8199 lltok_unparse (exprData_getUopTok (data)));
8203 ret = message ("offsetof(%s,%q)",
8204 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8205 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8209 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8213 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8217 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8221 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8225 ret = message ("va_arg(%s, %q)",
8226 exprNode_unparse (exprData_getCastNode (data)),
8227 qtype_unparse (exprData_getCastType (data)));
8231 ret = message ("%q(%q)",
8232 uentry_getName (exprData_getIterCallIter (data)),
8233 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8236 ret = message ("%q(%q) %s %q",
8237 uentry_getName (exprData_getIterSname (data)),
8238 exprNodeList_unparse (exprData_getIterAlist (data)),
8239 exprNode_unparse (exprData_getIterBody (data)),
8240 uentry_getName (exprData_getIterEname (data)));
8243 ret = message ("(%q)%s",
8244 qtype_unparse (exprData_getCastType (data)),
8245 exprNode_unparse (exprData_getCastNode (data)));
8249 ret = message ("%s %s",
8250 exprNode_unparse (exprData_getPairA (data)),
8251 exprNode_unparse (exprData_getPairB (data)));
8255 ret = message ("for (%s; %s; %s)",
8256 exprNode_unparse (exprData_getTripleInit (data)),
8257 exprNode_unparse (exprData_getTripleTest (data)),
8258 exprNode_unparse (exprData_getTripleInc (data)));
8262 ret = message ("goto %s", exprData_getLiteral (data));
8266 ret = cstring_makeLiteral ("continue");
8270 ret = cstring_makeLiteral ("break");
8274 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
8277 case XPR_NULLRETURN:
8278 ret = cstring_makeLiteral ("return");
8282 ret = message ("%s, %s",
8283 exprNode_unparse (exprData_getPairA (data)),
8284 exprNode_unparse (exprData_getPairB (data)));
8288 ret = message ("%s ? %s : %s",
8289 exprNode_unparse (exprData_getTriplePred (data)),
8290 exprNode_unparse (exprData_getTripleTrue (data)),
8291 exprNode_unparse (exprData_getTripleFalse (data)));
8294 ret = message ("if (%s) %s",
8295 exprNode_unparse (exprData_getPairA (data)),
8296 exprNode_unparse (exprData_getPairB (data)));
8300 ret = message ("if (%s) %s else %s",
8301 exprNode_unparse (exprData_getTriplePred (data)),
8302 exprNode_unparse (exprData_getTripleTrue (data)),
8303 exprNode_unparse (exprData_getTripleFalse (data)));
8306 ret = message ("while (%s) %s",
8307 exprNode_unparse (exprData_getPairA (data)),
8308 exprNode_unparse (exprData_getPairB (data)));
8312 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
8316 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
8320 ret = message ("do { %s } while (%s)",
8321 exprNode_unparse (exprData_getPairB (data)),
8322 exprNode_unparse (exprData_getPairA (data)));
8326 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
8330 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
8334 ret = message ("%s; %s",
8335 exprNode_unparse (exprData_getPairA (data)),
8336 exprNode_unparse (exprData_getPairB (data)));
8341 ret = cstring_makeLiteral ("default:");
8345 ret = message ("switch (%s) %s",
8346 exprNode_unparse (exprData_getPairA (data)),
8347 exprNode_unparse (exprData_getPairB (data)));
8352 ret = message ("case %s:",
8353 exprNode_unparse (exprData_getSingle (data)));
8357 ret = message ("%s = %s",
8358 idDecl_getName (exprData_getInitId (data)),
8359 exprNode_unparse (exprData_getInitNode (data)));
8363 ret = message ("%s.%s",
8364 exprNode_unparse (exprData_getFieldNode (data)),
8365 exprData_getFieldName (data));
8369 ret = message ("%s->%s",
8370 exprNode_unparse (exprData_getFieldNode (data)),
8371 exprData_getFieldName (data));
8374 case XPR_STRINGLITERAL:
8375 ret = cstring_copy (exprData_getLiteral (data));
8379 ret = cstring_copy (exprData_getLiteral (data));
8383 ret = cstring_makeLiteral ("<node>");
8391 exprNode_isCharLit (exprNode e)
8393 if (exprNode_isDefined (e))
8395 return (multiVal_isChar (exprNode_getValue (e)));
8404 exprNode_isNumLit (exprNode e)
8406 if (exprNode_isDefined (e))
8408 return (multiVal_isInt (exprNode_getValue (e)));
8417 exprNode_isFalseConstant (exprNode e)
8419 if (exprNode_isDefined (e))
8421 cstring s = exprNode_rootVarName (e);
8423 if (cstring_equal (s, context_getFalseName ()))
8433 exprNode_matchLiteral (ctype expected, exprNode e)
8435 if (exprNode_isDefined (e))
8437 multiVal m = exprNode_getValue (e);
8439 if (multiVal_isDefined (m))
8441 if (multiVal_isInt (m))
8443 long int val = multiVal_forceInt (m);
8445 if (ctype_isDirectBool (ctype_realishType (expected)))
8449 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
8457 if (ctype_isRealInt (expected))
8460 ** unsigned <- [ constant >= 0 is okay ]
8463 if (ctype_isUnsigned (expected))
8472 ** No checks on sizes of integers...maybe add
8476 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
8477 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
8478 bool_unparse (ctype_isInt (exprNode_getType (e)))));
8480 if (context_getFlag (FLG_NUMLITERAL)
8481 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
8487 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
8491 else if (ctype_isChar (expected))
8495 else if (ctype_isArrayPtr (expected))
8499 else if (ctype_isAnyFloat (expected))
8501 return (context_getFlag (FLG_NUMLITERAL));
8508 else if (multiVal_isDouble (m))
8510 if (ctype_isAnyFloat (expected))
8515 else if (multiVal_isChar (m))
8517 char val = multiVal_forceChar (m);
8519 if (ctype_isChar (expected))
8521 if (ctype_isUnsigned (expected) && ((int)val) < 0)
8542 exprNode_matchType (ctype expected, exprNode e)
8546 if (!exprNode_isDefined (e)) return TRUE;
8548 actual = ctype_realishType (exprNode_getType (e));
8550 if (ctype_match (ctype_realishType (expected), actual))
8555 llassert (!exprNode_isError (e));
8556 return (exprNode_matchLiteral (expected, e));
8560 exprNode_matchTypes (exprNode e1, exprNode e2)
8565 if (!exprNode_isDefined (e1)) return TRUE;
8566 if (!exprNode_isDefined (e2)) return TRUE;
8569 ** realish type --- keep bools, bools
8572 t1 = ctype_realishType (exprNode_getType (e1));
8573 t2 = ctype_realishType (exprNode_getType (e2));
8575 if (ctype_match (t1, t2))
8580 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
8588 exprNode_matchArgType (ctype ct, exprNode e)
8592 if (!exprNode_isDefined (e))
8597 et = ctype_realType (exprNode_getType (e));
8599 if (ctype_matchArg (ct, et)) return TRUE;
8601 llassert (!exprNode_isError (e));
8602 return (exprNode_matchLiteral (ct, e));
8605 static /*@only@*/ exprNodeSList
8606 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
8608 if (exprNode_isDefined (e))
8610 if (e->kind == XPR_STMTLIST)
8612 return (exprNodeSList_append
8613 (exprNode_flatten (exprData_getPairA (e->edata)),
8614 exprNode_flatten (exprData_getPairB (e->edata))));
8616 else if (e->kind == XPR_BLOCK)
8618 return (exprNode_flatten (exprData_getSingle (e->edata)));
8622 return (exprNodeSList_singleton (e));
8626 return exprNodeSList_new ();
8629 static /*@exposed@*/ exprNode
8630 exprNode_lastStatement (/*@returned@*/ exprNode e)
8632 if (exprNode_isDefined (e))
8634 if (e->kind == XPR_STMTLIST)
8636 exprNode b = exprData_getPairB (e->edata);
8638 if (exprNode_isDefined (b))
8640 return exprNode_lastStatement (b);
8644 return exprNode_lastStatement (exprData_getPairA (e->edata));
8647 else if (e->kind == XPR_BLOCK)
8649 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
8657 return exprNode_undefined;
8660 static /*@exposed@*/ exprNode
8661 exprNode_firstStatement (/*@returned@*/ exprNode e)
8663 if (exprNode_isDefined (e))
8665 if (e->kind == XPR_STMTLIST)
8667 exprNode b = exprData_getPairA (e->edata);
8669 if (exprNode_isDefined (b))
8671 return exprNode_firstStatement (b);
8675 return exprNode_firstStatement (exprData_getPairB (e->edata));
8678 else if (e->kind == XPR_BLOCK)
8680 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
8688 return exprNode_undefined;
8692 exprNode_mergeUSs (exprNode res, exprNode other)
8694 if (exprNode_isDefined (res) && exprNode_isDefined (other))
8696 res->msets = sRefSet_union (res->msets, other->msets);
8697 res->sets = sRefSet_union (res->sets, other->sets);
8698 res->uses = sRefSet_union (res->uses, other->uses);
8703 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
8705 if (exprNode_isDefined (res))
8707 if (exprNode_isDefined (other1))
8709 res->sets = sRefSet_union (res->sets, other1->sets);
8710 res->msets = sRefSet_union (res->msets, other1->msets);
8711 res->uses = sRefSet_union (res->uses, other1->uses);
8713 if (exprNode_isDefined (other2))
8715 res->sets = sRefSet_union (res->sets, other2->sets);
8716 res->msets = sRefSet_union (res->msets, other2->msets);
8717 res->uses = sRefSet_union (res->uses, other2->uses);
8725 ** Reports errors is s is not defined.
8729 exprNode_addUse (exprNode e, sRef s)
8731 if (exprNode_isDefined (e))
8733 e->uses = sRefSet_insert (e->uses, s);
8738 exprNode_checkUse (exprNode e, sRef s, fileloc loc)
8740 if (sRef_isKnown (s) && !sRef_isConst (s))
8743 ** need to check all outer types are useable
8746 DPRINTF (("Check use: %s / %s",
8747 exprNode_unparse (e), sRef_unparse (s)));
8749 exprNode_addUse (e, s);
8751 if (!context_inProtectVars ())
8754 ** only report the deepest error
8757 sRef errorRef = sRef_undefined;
8758 sRef lastRef = sRef_undefined;
8759 bool deadRef = FALSE;
8760 bool unuseable = FALSE;
8761 bool errorMaybe = FALSE;
8763 while (sRef_isValid (s) && sRef_isKnown (s))
8765 ynm readable = sRef_isReadable (s);
8767 if (!(ynm_toBoolStrict (readable)))
8769 if (ynm_isMaybe (readable))
8773 deadRef = sRef_isPossiblyDead (errorRef);
8774 unuseable = sRef_isUnuseable (errorRef);
8781 deadRef = sRef_isDead (errorRef);
8782 unuseable = sRef_isUnuseable (errorRef);
8786 if (!sRef_isPartial (s))
8788 sRef_setDefined (s, fileloc_undefined);
8792 s = sRef_getBaseSafe (s);
8795 if (sRef_isValid (errorRef))
8797 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
8798 && sRef_isPointer (errorRef))
8805 if (sRef_isThroughArrayFetch (errorRef))
8808 (FLG_STRICTUSERELEASED,
8809 message ("%q %q may be used after being released",
8810 sRef_unparseKindNamePlain (errorRef),
8811 sRef_unparse (errorRef)),
8814 sRef_showRefKilled (errorRef);
8816 if (sRef_isKept (errorRef))
8818 sRef_clearAliasState (errorRef, loc);
8824 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8828 message ("%q %q %qused after being released",
8829 sRef_unparseKindNamePlain (errorRef),
8830 sRef_unparse (errorRef),
8831 cstring_makeLiteral (errorMaybe
8835 sRef_showRefKilled (errorRef);
8837 if (sRef_isKept (errorRef))
8839 sRef_clearAliasState (errorRef, loc);
8848 message ("%q %q%qused in inconsistent state",
8849 sRef_unparseKindName (errorRef),
8850 sRef_unparseOpt (errorRef),
8851 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8854 sRef_showStateInconsistent (errorRef);
8859 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8863 message ("%q %q%qused before definition",
8864 sRef_unparseKindName (errorRef),
8865 sRef_unparseOpt (errorRef),
8866 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8870 sRef_setDefined (errorRef, loc);
8872 if (sRef_isAddress (errorRef))
8874 sRef_setDefined (sRef_getRootBase (errorRef), loc);
8876 } /* end is error */
8884 checkSafeUse (exprNode e, sRef s)
8886 if (exprNode_isDefined (e) && sRef_isKnown (s))
8888 e->uses = sRefSet_insert (e->uses, s);
8893 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
8895 if (exprNode_isDefined (e))
8897 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
8902 exprNode_checkSet (exprNode e, sRef s)
8904 sRef defines = sRef_undefined;
8906 if (sRef_isValid (s) && !sRef_isNothing (s))
8908 uentry ue = sRef_getBaseUentry (s);
8910 if (uentry_isValid (ue))
8912 uentry_setLset (ue);
8915 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
8917 voptgenerror (FLG_USEDEF,
8918 message ("Attempt to set unuseable storage: %q",
8923 if (sRef_isMeaningful (s))
8926 if (sRef_isDead (s))
8928 sRef base = sRef_getBaseSafe (s);
8930 if (sRef_isValid (base)
8931 && sRef_isDead (base))
8933 sRef_setPartial (s, exprNode_loc (e));
8936 defines = s; /* okay - modifies for only param */
8938 else if (sRef_isPartial (s))
8940 sRef eref = exprNode_getSref (e);
8942 if (!sRef_isPartial (eref))
8945 ** should do something different here???
8948 sRef_setDefinedComplete (eref, exprNode_loc (e));
8952 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
8955 if (sRef_isMeaningful (eref))
8964 else if (sRef_isAllocated (s))
8966 sRef eref = exprNode_getSref (e);
8969 if (!sRef_isAllocated (eref))
8971 sRef_setDefinedComplete (eref, exprNode_loc (e));
8975 sRef base = sRef_getBaseSafe (eref);
8977 if (sRef_isValid (base))
8979 sRef_setPdefined (base, exprNode_loc (e));
8987 sRef_setDefinedNCComplete (s, exprNode_loc (e));
8992 else /* not meaningful...but still need to insert it */
8998 if (exprNode_isDefined (e) && sRef_isValid (defines))
9000 e->sets = sRefSet_insert (e->sets, defines);
9005 exprNode_checkMSet (exprNode e, sRef s)
9007 if (sRef_isValid (s) && !sRef_isNothing (s))
9009 uentry ue = sRef_getBaseUentry (s);
9011 if (uentry_isValid (ue))
9013 uentry_setLset (ue);
9016 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9018 voptgenerror (FLG_USEDEF,
9019 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9023 if (sRef_isMeaningful (s))
9025 sRef_setDefinedComplete (s, exprNode_loc (e));
9028 if (exprNode_isDefined (e))
9030 e->msets = sRefSet_insert (e->msets, s);
9036 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9038 checkAnyCall (fcn, cstring_undefined, params, args,
9039 FALSE, sRefSet_undefined, FALSE, 0);
9043 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9044 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9048 if (uentry_isYield (ucurrent))
9050 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9051 exprNode_checkSet (current, current->sref);
9055 if (uentry_isSefParam (ucurrent))
9057 sRefSet sets = current->sets;
9058 sRef ref = exprNode_getSref (current);
9060 if (sRef_isMacroParamRef (ref))
9062 uentry ue = sRef_getUentry (ref);
9064 if (!uentry_isSefParam (ue))
9069 ("Parameter %d to %s is declared sef, but "
9070 "the argument is a macro parameter declared "
9072 argno, exprNode_unparse (fcn),
9073 exprNode_unparse (current)),
9074 exprNode_loc (current));
9078 if (!sRefSet_isEmpty (sets))
9080 sRefSet reported = sRefSet_undefined;
9082 sRefSet_realElements (current->sets, el)
9084 if (sRefSet_isSameNameMember (reported, el))
9086 ; /* don't report again */
9090 if (sRef_isUnconstrained (el))
9095 ("Parameter %d to %s is declared sef, but "
9096 "the argument calls unconstrained function %s "
9097 "(no guarantee it will not modify something): %s",
9098 argno, exprNode_unparse (fcn),
9099 sRef_unconstrainedName (el),
9100 exprNode_unparse (current)),
9101 exprNode_loc (current));
9108 ("Parameter %d to %s is declared sef, but "
9109 "the argument may modify %q: %s",
9110 argno, exprNode_unparse (fcn),
9112 exprNode_unparse (current)),
9113 exprNode_loc (current));
9116 } end_sRefSet_realElements;
9120 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9121 exprNode_mergeUSs (fcn, current);
9126 checkAnyCall (/*@dependent@*/ exprNode fcn,
9127 /*@dependent@*/ cstring fname,
9130 bool hasMods, sRefSet mods,
9135 int nargs = exprNodeList_size (args);
9140 ** concat all args ud's to f, add each arg sref as a use unless
9141 ** it was specified as "out", in which case it is a def.
9144 uentryList_reset (pn);
9149 ** if paramn is only or unique, no other arg may alias argn
9152 exprNodeList_elements (args, current)
9156 if (exprNode_isDefined (current))
9158 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9160 uentry ucurrent = uentryList_current (pn);
9162 if (specialArgs == 0
9163 || (paramno < specialArgs))
9165 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9167 if (context_maybeSet (FLG_ALIASUNIQUE))
9169 if (uentry_isOnly (ucurrent)
9170 || uentry_isUnique (ucurrent))
9172 checkUniqueParams (fcn, current, args,
9178 else /* uentry is undefined */
9180 if (specialArgs == 0)
9182 exprNode_checkUseParam (current);
9185 exprNode_mergeUSs (fcn, current);
9188 uentryList_advanceSafe (pn);
9189 } end_exprNodeList_elements;
9195 sRefSet_allElements (mods, s)
9198 sRef rb = sRef_getRootBase (s);
9200 if (sRef_isGlobal (rb))
9202 context_usedGlobal (rb);
9205 fb = sRef_fixBaseParam (s, args);
9207 if (!sRef_isMacroParamRef (fb))
9209 if (sRef_isNothing (fb))
9215 if (sRef_isValid (fb))
9217 uentry ue = sRef_getBaseUentry (s);
9219 if (uentry_isValid (ue))
9221 uentry_setLset (ue);
9225 fcn->sets = sRefSet_insert (fcn->sets, fb);
9228 sRef_clearDerivedComplete (s);
9229 } end_sRefSet_allElements;
9235 if (context_hasMods ())
9237 if (context_maybeSet (FLG_MODUNCON))
9241 message ("Undetected modification possible "
9242 "from call to unconstrained function %s: %s",
9244 exprNode_unparse (fcn)),
9245 exprNode_loc (fcn));
9250 if (context_maybeSet (FLG_MODUNCONNOMODS)
9251 && !(context_inIterDef () || context_inIterEnd ()))
9254 (FLG_MODUNCONNOMODS,
9255 message ("Undetected modification possible "
9256 "from call to unconstrained function %s: %s",
9258 exprNode_unparse (fcn)),
9259 exprNode_loc (fcn));
9263 exprNode_checkSetAny (fcn, fname);
9267 void exprNode_checkUseParam (exprNode current)
9269 if (exprNode_isDefined (current))
9271 exprNode_checkUse (current, current->sref, current->loc);
9276 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
9277 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9282 if (!ctype_match (tr1, tr2))
9284 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
9285 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
9293 message ("Incompatible types for %s (%s, %s): %s %s %s",
9295 ctype_unparse (te1),
9296 ctype_unparse (te2),
9297 exprNode_unparse (e1), lltok_unparse (op),
9298 exprNode_unparse (e2)),
9301 ret = ctype_unknown;
9305 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
9307 ret = ctype_resolveNumerics (tr1, tr2);
9309 else if (!context_msgStrictOps ())
9311 if (ctype_isPointer (tr1))
9313 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
9317 else if (ctype_isInt (tr2))
9323 ret = ctype_unknown;
9326 else if (ctype_isPointer (tr2))
9328 if (ctype_isPointer (tr1))
9332 else if (ctype_isInt (tr1))
9338 ret = ctype_unknown;
9343 ret = ctype_resolveNumerics (tr1, tr2);
9348 int opid = lltok_getTok (op);
9349 bool comparop = (opid == EQ_OP || opid == NE_OP
9350 || opid == TLT || opid == TGT
9351 || opid == LE_OP || opid == GE_OP);
9353 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
9356 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
9357 || (ctype_isBool (tr1) && ctype_isBool (tr2))
9358 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
9364 if (ctype_sameName (te1, te2))
9368 message ("Operands of %s are non-numeric (%t): %s %s %s",
9369 lltok_unparse (op), te1,
9370 exprNode_unparse (e1), lltok_unparse (op),
9371 exprNode_unparse (e2)),
9378 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
9379 lltok_unparse (op), te1, te2,
9380 exprNode_unparse (e1), lltok_unparse (op),
9381 exprNode_unparse (e2)),
9386 else if (!ctype_isNumeric (tr1))
9390 message ("Right operand of %s is non-numeric (%t): %s %s %s",
9391 lltok_unparse (op), te1,
9392 exprNode_unparse (e1), lltok_unparse (op),
9393 exprNode_unparse (e2)),
9398 if (!ctype_isNumeric (tr2))
9402 message ("Left operand of %s is non-numeric (%t): %s %s %s",
9403 lltok_unparse (op), te2,
9404 exprNode_unparse (e1), lltok_unparse (op),
9405 exprNode_unparse (e2)),
9410 ret = ctype_unknown;
9418 abstractOpError (ctype tr1, ctype tr2, lltok op,
9419 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9420 fileloc loc1, fileloc loc2)
9422 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
9424 if (ctype_match (tr1, tr2))
9428 message ("Operands of %s are abstract type (%t): %s %s %s",
9429 lltok_unparse (op), tr1,
9430 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9437 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
9438 lltok_unparse (op), tr1, tr2,
9439 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9443 else if (ctype_isRealAbstract (tr1))
9447 message ("Left operand of %s is abstract type (%t): %s %s %s",
9448 lltok_unparse (op), tr1,
9449 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9454 if (ctype_isRealAbstract (tr2))
9458 message ("Right operand of %s is abstract type (%t): %s %s %s",
9459 lltok_unparse (op), tr2,
9460 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9469 ** requies e1 and e2 and not error exprNode's.
9473 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
9474 ** the rep of the abstract type is exposed.
9476 ** The order is very important:
9478 ** check rep expose (move into check transfer)
9484 ** This isn't really a sensible procedure, but the indententation
9485 ** was getting too deep.
9489 checkOneRepExpose (sRef ysr, sRef base,
9490 /*@notnull@*/ exprNode e1,
9491 /*@notnull@*/ exprNode e2, ctype ct,
9494 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
9495 || sRef_isOwned (ysr) || sRef_isExposed (ysr)))
9497 if (sRef_isAnyParam (base) && !sRef_isExposed (base))
9499 if (sRef_isIReference (ysr))
9501 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9506 ("Assignment of mutable component of parameter %q "
9507 "to component of abstract "
9508 "type %s exposes rep: %s = %s",
9509 sRef_unparse (base),
9511 exprNode_unparse (e1), exprNode_unparse (e2)),
9519 ("Assignment of mutable component of parameter %q "
9520 "(through alias %q) to component of abstract "
9521 "type %s exposes rep: %s = %s",
9522 sRef_unparse (base),
9523 sRef_unparse (e2->sref),
9525 exprNode_unparse (e1), exprNode_unparse (e2)),
9531 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9535 message ("Assignment of mutable parameter %q "
9536 "to component of abstract type %s "
9537 "exposes rep: %s = %s",
9538 sRef_unparse (base),
9540 exprNode_unparse (e1),
9541 exprNode_unparse (e2)),
9548 message ("Assignment of mutable parameter %q "
9549 "(through alias %q) to "
9550 "component of abstract type %s exposes "
9552 sRef_unparse (base),
9553 sRef_unparse (e2->sref),
9555 exprNode_unparse (e1),
9556 exprNode_unparse (e2)),
9562 if (sRef_isGlobal (s2b))
9564 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9568 message ("Assignment of global %q "
9570 "abstract type %s exposes rep: %s = %s",
9571 sRef_unparse (base),
9573 exprNode_unparse (e1), exprNode_unparse (e2)),
9580 message ("Assignment of global %q (through alias %q) "
9582 "abstract type %s exposes rep: %s = %s",
9583 sRef_unparse (base),
9584 sRef_unparse (e2->sref),
9586 exprNode_unparse (e1), exprNode_unparse (e2)),
9594 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
9596 if (ctype_isRealFunction (exprNode_getType (e1))
9597 && !ctype_isRealPointer (exprNode_getType (e1)))
9601 message ("Invalid left-hand side of assignment (function type %s): %s",
9602 ctype_unparse (exprNode_getType (e1)),
9603 exprNode_unparse (e1)),
9607 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
9609 ctype t2 = exprNode_getType (e2);
9610 sRef sr = sRef_getRootBase (e1->sref);
9611 ctype ct = sRef_getType (sr);
9613 if (ctype_isAbstract (t2)
9614 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
9616 /* it is immutable, okay to reference */
9620 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
9622 sRef s2b = sRef_getRootBase (e2->sref);
9624 sRef s1b = sRef_getRootBase (s1);
9627 aliases = usymtab_canAlias (e2->sref);
9629 if (!sRef_similar (s2b, s1b)
9630 && !sRef_isExposed (s1)
9631 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
9633 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
9634 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
9635 && !sRef_isExposed (s2b))
9637 if (sRef_isIReference (e2->sref))
9642 ("Assignment of mutable component of parameter %q "
9643 "to component of abstract type %s exposes rep: %s = %s",
9646 exprNode_unparse (e1), exprNode_unparse (e2)),
9653 message ("Assignment of mutable parameter %q to "
9654 "component of abstract type %s exposes rep: %s = %s",
9657 exprNode_unparse (e1), exprNode_unparse (e2)),
9662 if (sRef_isGlobal (s2b))
9666 message ("Assignment of global %q to component of "
9667 "abstract type %s exposes rep: %s = %s",
9670 exprNode_unparse (e1), exprNode_unparse (e2)),
9674 sRefSet_realElements (aliases, ysr)
9676 sRef base = sRef_getRootBase (ysr);
9678 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
9679 || sRef_sameName (base, s1b))
9681 ; /* error already reported or same sref */
9685 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
9687 } end_sRefSet_realElements;
9689 sRefSet_free (aliases);
9696 ** function variables don't really work...
9699 if (!ctype_isFunction (ctype_realType (e2->typ)))
9703 checkInitTransfer (e1, e2);
9707 checkAssignTransfer (e1, e2);
9712 sRef fref = e2->sref;
9714 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
9715 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
9717 /* Need to typecheck the annotation on the parameters */
9719 if (ctype_isRealFunction (e1->typ)) {
9720 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
9721 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
9723 if (!uentryList_isMissingParams (e1p)
9724 && !uentryList_isMissingParams (e2p)
9725 && uentryList_size (e1p) > 0) {
9726 if (uentryList_size (e1p) == uentryList_size (e2p)) {
9729 uentryList_elements (e1p, el1) {
9732 el2 = uentryList_getN (e2p, n);
9734 uentry_checkMatchParam (el1, el2, n, e2);
9735 } end_uentryList_elements;
9741 if (isInit && sRef_isGlobal (e1->sref))
9747 updateAliases (e1, e2);
9749 updateEnvironment (e1, e2);
9753 checkMacroParen (exprNode e)
9755 if (exprNode_isError (e) || e->kind == XPR_CAST)
9761 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
9765 message ("Macro parameter used without parentheses: %s",
9766 exprNode_unparse (e)),
9773 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
9777 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
9781 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
9788 ** if e2 is a parameter or global derived location which
9789 ** can be modified (that is, e2 is a mutable abstract type,
9790 ** or a derived pointer), then e1 can alias e2.
9792 ** e1 can alias everything which e2 can alias.
9794 ** Also, if e1 is guarded, remove from guard sets!
9797 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
9799 if (!context_inProtectVars ())
9802 ** depends on types of e1 and e2
9807 ctype t1 = exprNode_getType (e1);
9809 /* handle pointer sRefs, record fields, arrays, etc... */
9811 if (!ctype_isRealSU (t1))
9813 sRef_copyRealDerivedComplete (s1, s2);
9816 if (ctype_isMutable (t1) && sRef_isKnown (s1))
9818 usymtab_clearAlias (s1);
9819 usymtab_addMustAlias (s1, s2);
9822 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
9824 usymtab_unguard (s1);
9829 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
9831 if (exprNode_isDefined (e))
9833 e->loc = fileloc_update (e->loc, loc);
9837 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
9843 static void checkUniqueParams (exprNode fcn,
9844 /*@notnull@*/ exprNode current,
9846 int paramno, uentry ucurrent)
9849 sRef thisref = exprNode_getSref (current);
9852 ** Check if any argument could match this argument.
9855 exprNodeList_elements (args, icurrent)
9859 if (iparamno != paramno)
9861 sRef sr = exprNode_getSref (icurrent);
9863 if (sRef_similarRelaxed (thisref, sr))
9865 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
9870 ("Parameter %d (%s) to function %s is declared %s but "
9871 "is aliased by parameter %d (%s)",
9873 exprNode_unparse (current),
9874 exprNode_unparse (fcn),
9875 alkind_unparse (uentry_getAliasKind (ucurrent)),
9876 iparamno, exprNode_unparse (icurrent)),
9882 sRefSet aliases = usymtab_canAlias (sr);
9884 sRefSet_allElements (aliases, asr)
9886 if (ctype_isUnknown (sRef_getType (thisref)))
9888 sRef_setType (thisref, uentry_getType (ucurrent));
9891 if (sRef_similarRelaxed (thisref, asr))
9893 if (sRef_isExternal (asr))
9895 if (sRef_isLocalState (thisref))
9901 sRef base = sRef_getRootBase (asr);
9903 if (!sRef_similar (sRef_getBase (asr), thisref))
9905 if (sRef_isUnique (base) || sRef_isOnly (base)
9906 || sRef_isKept (base)
9907 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
9908 || (sRef_isAddress (thisref)
9909 && sRef_isLocalVar (sRef_getRootBase (thisref))))
9911 ; /* okay, no error */
9916 (FLG_MAYALIASUNIQUE,
9918 ("Parameter %d (%s) to function %s is declared %s but "
9919 "may be aliased externally by parameter %d (%s)",
9921 exprNode_unparse (current),
9922 exprNode_unparse (fcn),
9923 alkind_unparse (uentry_getAliasKind (ucurrent)),
9924 iparamno, exprNode_unparse (icurrent)),
9935 ("Parameter %d (%s) to function %s is declared %s but "
9936 "is aliased externally by parameter %d (%s) through "
9939 exprNode_unparse (current),
9940 exprNode_unparse (fcn),
9941 alkind_unparse (uentry_getAliasKind (ucurrent)),
9942 iparamno, exprNode_unparse (icurrent),
9943 sRef_unparse (asr)),
9947 } end_sRefSet_allElements;
9948 sRefSet_free (aliases);
9951 } end_exprNodeList_elements;
9954 long exprNode_getLongValue (exprNode e) {
9957 if (exprNode_hasValue (e)
9958 && multiVal_isInt (exprNode_getValue (e)))
9960 value = multiVal_forceInt (exprNode_getValue (e));
9970 fileloc exprNode_getfileloc (exprNode p_e)
9973 return fileloc_copy ( p_e->loc );
9975 return fileloc_undefined;
9978 fileloc exprNode_getNextSequencePoint (exprNode e)
9981 ** Returns the location of the sequence point following e.
9983 ** Only works for statements (for now).
9986 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
9987 lltok t = exprData_getUopTok (e->edata);
9988 return lltok_getLoc (t);
9991 // llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
9992 return fileloc_undefined;