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);
4625 int val = (int) multiVal_forceInt (e2->val);
4627 /* Operator : + or += */
4628 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4629 if (sRef_getSize(e1->sref) >= val) {/* Incrementing the pointer by
4630 val should not result in a
4631 size < 0 (size = 0 is ok !) */
4633 sRef_setSize (ret->sref, sRef_getSize(e1->sref) - val);
4635 if (sRef_getLen(e1->sref) == val) { /* i.e. the character at posn val is \0 */
4636 sRef_setNotNullTerminatedState(ret->sref);
4637 sRef_resetLen (ret->sref);
4639 sRef_setNullTerminatedState(ret->sref);
4640 sRef_setLen (ret->sref, sRef_getLen(e1->sref) - val);
4645 /* Operator : - or -= */
4646 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4647 if (sRef_getSize(e1->sref) >= 0) {
4648 sRef_setSize (ret->sref, sRef_getSize(e1->sref) + val);
4649 sRef_setLen (ret->sref, sRef_getLen(e1->sref) + val);
4654 /* end modifications */
4656 sRef_setNullError (ret->sref);
4659 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4660 ** since is points to storage that should not be deallocated
4661 ** through this pointer.
4664 if (sRef_isOnly (ret->sref)
4665 || sRef_isFresh (ret->sref))
4667 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4672 else if ((!ctype_isRealPointer(tr1) && ctype_isRealInt (tr1))
4673 && (ctype_isRealPointer (tr2) && !exprNode_isNullValue (e2)))
4675 if (context_msgPointerArith ())
4679 message ("Pointer arithmetic (%t, %t): %s",
4680 te1, te2, exprNode_unparse (ret)),
4684 if (sRef_possiblyNull (e1->sref)
4685 && !usymtab_isGuarded (e1->sref))
4688 (FLG_NULLPOINTERARITH,
4689 message ("Pointer arithmetic involving possibly "
4690 "null pointer %s: %s",
4691 exprNode_unparse (e2),
4692 exprNode_unparse (ret)),
4696 ret->sref = sRef_copy (e2->sref);
4698 /* start modifications */
4699 /* added by Seejo on 4/16/2000 */
4701 /* Arithmetic operations on pointers wil modify the size/len/null terminated
4704 if ((sRef_isPossiblyNullTerminated (e2->sref)) || (sRef_isNullTerminated(e2->sref))) {
4705 //if (sRef_isKnown (e->sref)) {
4706 //ret->sref = sRef_makeAddress (e->sref);
4709 int val = (int) multiVal_forceInt (e1->val);
4711 /* Operator : + or += */
4712 if ((lltok_getTok (op) == TPLUS) || (lltok_getTok(op) == ADD_ASSIGN)) {
4713 if (sRef_getSize(e2->sref) >= val) {/* Incrementing the pointer by
4714 val should not result in a
4715 size < 0 (size = 0 is ok !) */
4717 sRef_setSize (ret->sref, sRef_getSize(e2->sref) - val);
4719 if (sRef_getLen(e2->sref) == val) { /* i.e. the character at posn val is \0 */
4720 sRef_setNotNullTerminatedState(ret->sref);
4721 sRef_resetLen (ret->sref);
4723 sRef_setNullTerminatedState(ret->sref);
4724 sRef_setLen (ret->sref, sRef_getLen(e2->sref) - val);
4729 /* Operator : - or -= */
4730 if ((lltok_getTok (op) == TMINUS) || (lltok_getTok (op) == SUB_ASSIGN)) {
4731 if (sRef_getSize(e2->sref) >= 0) {
4732 sRef_setSize (ret->sref, sRef_getSize(e2->sref) + val);
4733 sRef_setLen (ret->sref, sRef_getLen(e2->sref) + val);
4738 /* end modifications */
4740 sRef_setNullError (ret->sref);
4743 ** Fixed for 2.2c: the alias state of ptr + int is dependent,
4744 ** since is points to storage that should not be deallocated
4745 ** through this pointer.
4748 if (sRef_isOnly (ret->sref)
4749 || sRef_isFresh (ret->sref)) {
4750 sRef_setAliasKind (ret->sref, AK_DEPENDENT, exprNode_loc (ret));
4754 ret->sref = e2->sref;
4758 tret = checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4763 case LEFT_ASSIGN: /* Shifts: should be unsigned values */
4767 case TAMPERSAND: /* bitwise & */
4769 case TCIRC: /* ^ (XOR) */
4774 bool reported = FALSE;
4775 flagcode code = FLG_BITWISEOPS;
4777 if (opid == LEFT_OP || opid == LEFT_ASSIGN
4778 || opid == RIGHT_OP || opid == RIGHT_ASSIGN) {
4779 code = FLG_SHIFTSIGNED;
4782 if (!ctype_isUnsigned (tr1))
4784 if (exprNode_isNonNegative (e1)) {
4787 reported = optgenerror
4789 message ("Left operand of %s is not unsigned value (%t): %s",
4790 lltok_unparse (op), te1,
4791 exprNode_unparse (ret)),
4801 /* right need not be signed for shifts */
4802 if (code != FLG_SHIFTSIGNED
4803 && !ctype_isUnsigned (tr2))
4805 if (!exprNode_isNonNegative (e2)) {
4806 reported = optgenerror
4808 message ("Right operand of %s is not unsigned value (%t): %s",
4809 lltok_unparse (op), te2,
4810 exprNode_unparse (ret)),
4818 if (!checkIntegral (e1, e2, ret, op)) {
4819 te1 = ctype_unknown;
4823 DPRINTF (("Set: %s", ctype_unparse (te1)));
4826 ** tret is the widest type of te1 and te2
4829 tret = ctype_widest (te1, te2);
4834 if (checkIntegral (e1, e2, ret, op)) {
4837 tret = ctype_unknown;
4842 case TLT: /* comparisons */
4843 case TGT: /* numeric, numeric -> bool */
4844 if ((ctype_isReal (tr1) && !ctype_isInt (tr1))
4845 || (ctype_isReal (tr2) && !ctype_isInt (tr2)))
4848 bool fepsilon = FALSE;
4850 if (!ctype_isReal (rtype) || ctype_isInt (rtype))
4855 if (opid == TLT || opid == TGT)
4857 uentry ue1 = exprNode_getUentry (e1);
4858 uentry ue2 = exprNode_getUentry (e2);
4861 ** FLT_EPSILON, etc. really is a variable, not
4865 if (uentry_isVariable (ue1))
4867 cstring uname = uentry_rawName (ue1);
4869 if (cstring_equalLit (uname, "FLT_EPSILON")
4870 || cstring_equalLit (uname, "DBL_EPSILON")
4871 || cstring_equalLit (uname, "LDBL_EPSILON"))
4877 if (uentry_isVariable (ue2))
4879 cstring uname = uentry_rawName (ue2);
4881 if (cstring_equalLit (uname, "FLT_EPSILON")
4882 || cstring_equalLit (uname, "DBL_EPSILON")
4883 || cstring_equalLit (uname, "LDBL_EPSILON"))
4892 ; /* Don't complain. */
4898 message ("Dangerous comparison involving %s types: %s",
4899 ctype_unparse (rtype),
4900 exprNode_unparse (ret)),
4909 ** Types should match.
4912 if (!exprNode_matchTypes (e1, e2))
4914 hasError = gentypeerror
4916 message ("Operands of %s have incompatible types (%t, %t): %s",
4917 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
4923 || (ctype_isForceRealNumeric (&tr1)
4924 && ctype_isForceRealNumeric (&tr2)) ||
4925 (ctype_isRealPointer (tr1) && ctype_isRealPointer (tr2)))
4931 if ((ctype_isRealNumeric (tr1) && ctype_isRealPointer (tr2)) ||
4932 (ctype_isRealPointer (tr1) && ctype_isRealNumeric (tr2)))
4936 message ("Comparison of pointer and numeric (%t, %t): %s",
4937 te1, te2, exprNode_unparse (ret)),
4942 (void) checkNumerics (tr1, tr2, te1, te2, e1, e2, op);
4947 /* EQ_OP should NOT be used with booleans (unless one is FALSE) */
4949 if ((opid == EQ_OP || opid == NE_OP) &&
4950 ctype_isDirectBool (tr1) && ctype_isDirectBool (tr2))
4953 ** is one a variable?
4956 if (uentry_isVariable (exprNode_getUentry (e1))
4957 || uentry_isVariable (exprNode_getUentry (e2)))
4960 ** comparisons with FALSE are okay
4963 if (exprNode_isFalseConstant (e1)
4964 || exprNode_isFalseConstant (e2))
4973 ("Use of %q with %s variables (risks inconsistency because "
4974 "of multiple true values): %s",
4975 cstring_makeLiteral ((opid == EQ_OP) ? "==" : "!="),
4976 context_printBoolName (), exprNode_unparse (ret)),
4983 case AND_OP: /* bool, bool -> bool */
4986 if (ctype_isForceRealBool (&tr1) && ctype_isForceRealBool (&tr2))
4992 if (context_maybeSet (FLG_BOOLOPS))
4994 if (!ctype_isRealBool (te1) && !ctype_isRealBool (te2))
4996 if (ctype_sameName (te1, te2))
5000 message ("Operands of %s are non-boolean (%t): %s",
5001 lltok_unparse (op), te1,
5002 exprNode_unparse (ret)),
5010 ("Operands of %s are non-booleans (%t, %t): %s",
5011 lltok_unparse (op), te1, te2, exprNode_unparse (ret)),
5015 else if (!ctype_isRealBool (te1))
5019 message ("Left operand of %s is non-boolean (%t): %s",
5020 lltok_unparse (op), te1, exprNode_unparse (ret)),
5023 else if (!ctype_isRealBool (te2))
5027 message ("Right operand of %s is non-boolean (%t): %s",
5028 lltok_unparse (op), te2, exprNode_unparse (ret)),
5041 (cstring_makeLiteral
5042 ("There has been a problem in the parser. This is due to a bug "
5043 "in either lclint, bison or gcc version 2.95 optimizations, "
5044 "but it has not been confirmed. Please try rebuidling LCLint "
5045 "without the -O<n> option."));
5050 DPRINTF (("Return type: %s", ctype_unparse (tret)));
5053 exprNode_checkUse (ret, e1->sref, e1->loc);
5054 exprNode_mergeUSs (ret, e2);
5055 exprNode_checkUse (ret, e2->sref, e2->loc);
5061 exprNode_op (/*@only@*/ exprNode e1, /*@keep@*/ exprNode e2,
5062 /*@only@*/ lltok op)
5066 checkMacroParen (e1);
5067 checkMacroParen (e2);
5069 if (evaluationOrderUndefined (op) && context_maybeSet (FLG_EVALORDER))
5071 checkExpressionDefined (e1, e2, op);
5074 ret = exprNode_makeOp (e1, e2, op);
5079 void exprNode_checkAssignMod (exprNode e1, exprNode ret)
5082 ** This is somewhat bogus!
5084 ** Assigning to a nested observer in a non-observer datatype
5085 ** should not produce an error.
5088 sRef ref = exprNode_getSref (e1);
5090 DPRINTF (("Check assign mod: %s",
5091 sRef_unparseFull (ref)));
5093 if (sRef_isObserver (ref)
5094 || ((sRef_isFileStatic (ref) || sRef_isGlobal (ref))
5095 && ctype_isArray (ctype_realType (sRef_getType (ref)))))
5097 sRef base = sRef_getBase (ref);
5099 if (sRef_isValid (base) && sRef_isObserver (base))
5101 exprNode_checkModify (e1, ret);
5105 exprNode_checkModifyVal (e1, ret);
5110 exprNode_checkModify (e1, ret);
5115 exprNode_assign (/*@only@*/ exprNode e1,
5116 /*@only@*/ exprNode e2, /*@only@*/ lltok op)
5118 bool isalloc = FALSE;
5119 bool isjustalloc = FALSE;
5122 DPRINTF (("%s [%s] <- %s [%s]",
5123 exprNode_unparse (e1),
5124 ctype_unparse (e1->typ),
5125 exprNode_unparse (e2),
5126 ctype_unparse (e2->typ)));
5128 if (lltok_getTok (op) != TASSIGN)
5130 ret = exprNode_makeOp (e1, e2, op);
5134 ret = exprNode_createPartialCopy (e1);
5135 ret->kind = XPR_ASSIGN;
5136 ret->edata = exprData_makeOp (e1, e2, op);
5138 if (!exprNode_isError (e2))
5140 ret->sets = sRefSet_union (ret->sets, e2->sets);
5141 ret->msets = sRefSet_union (ret->msets, e2->msets);
5142 ret->uses = sRefSet_union (ret->uses, e2->uses);
5146 checkExpressionDefined (e1, e2, op);
5148 if (exprNode_isError (e1))
5150 if (!exprNode_isError (e2))
5152 ret->loc = fileloc_update (ret->loc, e2->loc);
5156 ret->loc = fileloc_update (ret->loc, g_currentloc);
5160 if (!exprNode_isError (e2))
5162 checkMacroParen (e2);
5165 if (exprNode_isDefined (e1))
5167 if (sRef_isMacroParamRef (e1->sref))
5169 if (context_inIterDef ())
5171 uentry ue = sRef_getUentry (e1->sref);
5173 if (uentry_isYield (ue))
5179 if (fileloc_isDefined (e1->loc))
5183 message ("Assignment to non-yield iter parameter: %q",
5184 sRef_unparse (e1->sref)),
5191 message ("Assignment to non-yield iter parameter: %q",
5192 sRef_unparse (e1->sref)),
5199 if (fileloc_isDefined (e1->loc))
5203 message ("Assignment to macro parameter: %q",
5204 sRef_unparse (e1->sref)),
5211 message ("Assignment to macro parameter: %q",
5212 sRef_unparse (e1->sref)),
5219 exprNode_checkAssignMod (e1, ret);
5222 if (exprNode_isDefined (e2))
5224 if (lltok_getTok (op) == TASSIGN)
5226 ctype te1 = exprNode_getType (e1);
5227 ctype te2 = exprNode_getType (e2);
5229 if (!ctype_forceMatch (te1, te2))
5231 if (exprNode_matchLiteral (te1, e2))
5239 message ("Assignment of %t to %t: %s %s %s",
5240 te2, te1, exprNode_unparse (e1),
5242 exprNode_unparse (e2)),
5248 exprNode_mergeUSs (ret, e2);
5249 exprNode_checkUse (ret, e2->sref, e2->loc);
5251 doAssign (e1, e2, FALSE);
5252 ret->sref = e1->sref;
5256 if (exprNode_isDefined (e2))
5258 exprNode_mergeUSs (ret, e2);
5259 exprNode_checkUse (ret, e2->sref, e2->loc);
5263 if (sRef_isPointer (e1->sref) && !sRef_isMacroParamRef (e1->sref))
5265 exprNode_checkUse (ret, sRef_getBase (e1->sref), e1->loc);
5268 isjustalloc = sRef_isJustAllocated (e1->sref);
5269 isalloc = sRef_isAllocated (e1->sref);
5271 if (sRef_isField (e1->sref))
5273 sRef root = sRef_getRootBase (sRef_getBase (e1->sref));
5275 if (!sRef_isAllocated (root) && !sRef_isMacroParamRef (root))
5277 exprNode_checkUse (ret, root, e1->loc);
5283 ** be careful! this defines e1->sref.
5286 if (!sRef_isMacroParamRef (e1->sref))
5288 exprNode_checkSet (ret, e1->sref);
5293 sRef_setAllocatedComplete (e1->sref, exprNode_isDefined (e2)
5294 ? e2->loc : e1->loc);
5300 sRef_setAllocatedShallowComplete (e1->sref, exprNode_loc (e2));
5309 exprNode_cond (/*@keep@*/ exprNode pred, /*@keep@*/ exprNode ifclause,
5310 /*@keep@*/ exprNode elseclause)
5314 if (!exprNode_isError (pred))
5316 ret = exprNode_createPartialCopy (pred);
5317 checkMacroParen (pred);
5318 exprNode_checkPred (cstring_makeLiteralTemp ("conditional"), pred);
5320 if (!exprNode_isError (ifclause))
5322 checkMacroParen (ifclause); /* update macro counts! */
5324 if (!exprNode_isError (elseclause))
5326 checkMacroParen (elseclause);
5328 if (!exprNode_matchTypes (ifclause, elseclause))
5331 (exprNode_getType (ifclause),
5333 exprNode_getType (elseclause),
5335 message ("Conditional clauses are not of same type: "
5337 exprNode_unparse (ifclause),
5338 exprNode_getType (ifclause),
5339 exprNode_unparse (elseclause),
5340 exprNode_getType (elseclause)),
5343 ret->sref = sRef_undefined;
5344 ret->typ = ctype_unknown;
5349 /* for now...should merge the states */
5350 ret->sref = ifclause->sref;
5351 ret->typ = ifclause->typ;
5353 if (exprNode_isNullValue (ifclause))
5355 ret->typ = elseclause->typ;
5359 exprNode_checkUse (ret, pred->sref, pred->loc);
5360 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5361 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5363 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5368 ret->typ = ifclause->typ;
5370 exprNode_checkUse (pred, pred->sref, pred->loc);
5371 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5373 exprNode_mergeCondUSs (ret, ifclause, exprNode_undefined);
5378 if (!exprNode_isError (elseclause))
5380 ret->typ = elseclause->typ;
5382 exprNode_checkUse (pred, pred->sref, pred->loc);
5383 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5385 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5389 else /* pred is error */
5391 if (!exprNode_isError (ifclause))
5393 ret = exprNode_createSemiCopy (ifclause);
5395 checkMacroParen (ifclause); /* update macro counts! */
5397 if (!exprNode_isError (elseclause))
5399 checkMacroParen (elseclause);
5401 ret->typ = ifclause->typ;
5403 if (!ctype_forceMatch (ifclause->typ, elseclause->typ))
5406 (exprNode_getType (ifclause),
5408 exprNode_getType (elseclause),
5410 message ("Conditional clauses are not of same type: "
5412 exprNode_unparse (ifclause),
5413 exprNode_getType (ifclause),
5414 exprNode_unparse (elseclause),
5415 exprNode_getType (elseclause)),
5418 ret->typ = ctype_unknown;
5422 exprNode_checkUse (ifclause, ifclause->sref, ifclause->loc);
5423 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5425 exprNode_mergeCondUSs (ret, ifclause, elseclause);
5428 else if (!exprNode_isError (elseclause)) /* pred, if errors */
5430 ret = exprNode_createSemiCopy (ifclause);
5432 ret->typ = elseclause->typ;
5433 checkMacroParen (elseclause);
5435 exprNode_checkUse (elseclause, elseclause->sref, elseclause->loc);
5436 exprNode_mergeCondUSs (ret, exprNode_undefined, elseclause);
5438 else /* all errors! */
5440 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5444 ret->kind = XPR_COND;
5445 ret->edata = exprData_makeCond (pred, ifclause, elseclause);
5447 if (exprNode_isDefined (ifclause) && exprNode_isDefined (elseclause))
5449 exprNode_combineControl (ret, ifclause, elseclause);
5456 exprNode_vaArg (/*@only@*/ lltok tok, /*@only@*/ exprNode arg, /*@only@*/ qtype qt)
5458 ctype totype = qtype_getType (qt);
5460 exprNode_createPartialLocCopy (arg, fileloc_copy (lltok_getLoc (tok)));
5464 ** check use of va_arg : <valist>, type -> type
5467 if (exprNode_isError (arg))
5472 targ = exprNode_getType (arg);
5475 ** arg should have be a pointer
5478 if (!ctype_isUA (targ) ||
5479 (!usymId_equal (ctype_typeId (targ),
5480 usymtab_getTypeId (cstring_makeLiteralTemp ("va_list")))))
5484 message ("First argument to va_arg is not a va_list (type %t): %s",
5485 targ, exprNode_unparse (arg)),
5489 exprNode_checkSet (ret, arg->sref);
5493 ** return type is totype
5497 ret->kind = XPR_VAARG;
5498 ret->edata = exprData_makeCast (tok, arg, qt);
5503 exprNode exprNode_labelMarker (/*@only@*/ cstring label)
5505 exprNode ret = exprNode_createPlain (ctype_undefined);
5506 ret->kind = XPR_LABEL;
5507 ret->edata = exprData_makeLiteral (label);
5508 ret->isJumpPoint = TRUE;
5510 return (ret); /* for now, ignore label */
5513 exprNode exprNode_notReached (/*@returned@*/ exprNode stmt)
5515 if (exprNode_isDefined (stmt))
5517 stmt->isJumpPoint = TRUE;
5519 /* This prevent stray no return path errors, etc. */
5520 stmt->exitCode = XK_MUSTEXIT;
5526 bool exprNode_isDefaultMarker (exprNode e)
5528 if (exprNode_isDefined (e))
5530 return (e->kind == XPR_DEFAULT || e->kind == XPR_FTDEFAULT);
5536 bool exprNode_isCaseMarker (exprNode e)
5538 if (exprNode_isDefined (e))
5540 return (e->kind == XPR_FTCASE || e->kind == XPR_CASE);
5546 bool exprNode_isLabelMarker (exprNode e)
5548 if (exprNode_isDefined (e))
5550 return (e->kind == XPR_LABEL);
5556 exprNode exprNode_caseMarker (/*@only@*/ exprNode test, bool fallThrough)
5558 exprNode ret = exprNode_createPartialCopy (test);
5560 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5562 if (exprNode_isError (test)) {
5566 exprNode_checkUse (ret, test->sref, test->loc);
5568 usymtab_setExitCode (ret->exitCode);
5572 usymtab_setMustBreak ();
5575 ret->edata = exprData_makeSingle (test);
5576 ret->isJumpPoint = TRUE;
5582 exprNode exprNode_caseStatement (/*@only@*/ exprNode test, /*@only@*/ exprNode stmt, bool fallThrough)
5584 exprNode ret = exprNode_createPartialCopy (test);
5586 ret->kind = fallThrough ? XPR_FTCASE : XPR_CASE;
5587 ret->edata = exprData_makePair (test, stmt);
5588 ret->isJumpPoint = TRUE;
5590 if (exprNode_isError (test))
5595 exprNode_checkUse (ret, test->sref, test->loc);
5597 if (exprNode_isError (stmt))
5602 exprNode_mergeUSs (ret, stmt);
5604 ret->exitCode = stmt->exitCode;
5605 ret->mustBreak = stmt->mustBreak;
5606 ret->canBreak = stmt->canBreak;
5608 usymtab_setExitCode (ret->exitCode);
5612 usymtab_setMustBreak ();
5619 /*@notnull@*/ /*@only@*/ exprNode
5620 exprNode_defaultMarker (/*@only@*/ lltok def, bool fallThrough)
5622 exprNode ret = exprNode_createTok (def);
5624 ret->isJumpPoint = TRUE;
5625 ret->kind = fallThrough ? XPR_FTDEFAULT : XPR_DEFAULT;
5630 exprNode_mayEscape (exprNode e)
5632 if (exprNode_isDefined (e))
5634 return exitkind_couldEscape (e->exitCode);
5640 exprNode_mustBreak (exprNode e)
5642 if (exprNode_isDefined (e))
5644 return e->mustBreak;
5650 exprNode_mustEscape (exprNode e)
5652 if (exprNode_isDefined (e))
5654 return exitkind_mustEscape (e->exitCode) || exprNode_mustBreak (e);
5661 exprNode_errorEscape (exprNode e)
5663 if (exprNode_isDefined (e))
5665 return exitkind_isError (e->exitCode);
5671 exprNode exprNode_concat (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
5673 exprNode ret = exprNode_createPartialCopy (e1);
5675 ret->edata = exprData_makePair (e1, e2);
5676 ret->kind = XPR_STMTLIST;
5678 if (exprNode_isDefined (e1))
5680 ret->isJumpPoint = e1->isJumpPoint;
5681 ret->canBreak = e1->canBreak;
5685 if (exprNode_isDefined (e2))
5687 ret->loc = fileloc_update (ret->loc, e2->loc);
5691 if (exprNode_isDefined (e2))
5693 ret->exitCode = e2->exitCode;
5694 ret->mustBreak = e2->mustBreak;
5695 if (e2->canBreak) ret->canBreak = TRUE;
5699 ** if e1 must return, then e2 is unreachable!
5702 if (exprNode_isDefined (e1) && exprNode_isDefined (e2))
5704 if ((exprNode_mustEscape (e1) || exprNode_mustBreak (e1))
5705 && !(e2->isJumpPoint))
5707 if (context_getFlag (FLG_UNREACHABLE))
5711 if (e2->kind == XPR_STMT)
5713 nr = exprData_getUopNode (e2->edata);
5716 if ((nr->kind == XPR_TOK
5717 && lltok_isSemi (exprData_getTok (nr->edata))))
5719 /* okay to have unreachable ";" */
5720 ret->exitCode = XK_MUSTEXIT;
5721 ret->canBreak = TRUE;
5725 if (optgenerror (FLG_UNREACHABLE,
5726 message ("Unreachable code: %s",
5727 exprNode_unparseFirst (nr)),
5730 ret->isJumpPoint = TRUE;
5731 ret->mustBreak = FALSE;
5732 ret->exitCode = XK_ERROR;
5733 DPRINTF (("Jump point: %s", exprNode_unparse (ret)));
5737 ret->exitCode = XK_MUSTEXIT;
5738 ret->canBreak = TRUE;
5746 if ((e2->kind == XPR_CASE || e2->kind == XPR_DEFAULT))
5749 ** We want a warning anytime we have:
5751 ** yyy; <<<- no break or return
5755 exprNode lastStmt = exprNode_lastStatement (e1);
5757 if (exprNode_isDefined (lastStmt)
5758 && !exprNode_mustEscape (lastStmt)
5759 && !exprNode_mustBreak (lastStmt)
5760 && !exprNode_isCaseMarker (lastStmt)
5761 && !exprNode_isDefaultMarker (lastStmt)
5762 && !exprNode_isLabelMarker (lastStmt))
5764 voptgenerror (FLG_CASEBREAK,
5766 ("Fall through case (no preceeding break)"),
5773 exprNode_mergeUSs (ret, e2);
5774 ret = exprNode_mergeEnvironments (ret, e1, e2);
5775 usymtab_setExitCode (ret->exitCode);
5779 usymtab_setMustBreak ();
5785 exprNode exprNode_createTok (/*@only@*/ lltok t)
5787 exprNode ret = exprNode_create (ctype_unknown);
5788 ret->kind = XPR_TOK;
5789 ret->edata = exprData_makeTok (t);
5793 exprNode exprNode_statement (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5795 if (!exprNode_isError (e))
5797 exprNode_checkStatement(e);
5800 return (exprNode_statementError (e, t));
5803 static exprNode exprNode_statementError (/*@only@*/ exprNode e, /*@only@*/ lltok t)
5805 exprNode ret = exprNode_createPartialCopy (e);
5807 if (!exprNode_isError (e))
5809 if (e->kind != XPR_ASSIGN)
5811 exprNode_checkUse (ret, e->sref, e->loc);
5814 ret->exitCode = e->exitCode;
5815 ret->canBreak = e->canBreak;
5816 ret->mustBreak = e->mustBreak;
5819 ret->edata = exprData_makeUop (e, t);
5820 ret->kind = XPR_STMT;
5825 exprNode exprNode_checkExpr (/*@returned@*/ exprNode e)
5827 if (!exprNode_isError (e))
5829 if (e->kind != XPR_ASSIGN)
5831 exprNode_checkUse (e, e->sref, e->loc);
5838 void exprNode_produceGuards (exprNode pred)
5840 if (!exprNode_isError (pred))
5842 if (ctype_isRealPointer (pred->typ))
5844 pred->guards = guardSet_addTrueGuard (pred->guards, pred->sref);
5847 exprNode_checkUse (pred, pred->sref, pred->loc);
5848 exprNode_resetSref (pred);
5852 exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
5854 exprNode ret = exprNode_createPartialCopy (e);
5856 if (!exprNode_isError (e))
5858 ret->exitCode = e->exitCode;
5859 ret->canBreak = e->canBreak;
5860 ret->mustBreak = e->mustBreak;
5863 ret->edata = exprData_makeSingle (e);
5864 ret->kind = XPR_BLOCK;
5868 bool exprNode_isBlock (exprNode e)
5870 return (exprNode_isDefined (e)
5871 && ((e)->kind == XPR_BLOCK));
5874 bool exprNode_isAssign (exprNode e)
5876 if (exprNode_isDefined (e))
5878 return (e->kind == XPR_ASSIGN);
5884 bool exprNode_isEmptyStatement (exprNode e)
5886 return (exprNode_isDefined (e)
5887 && (e->kind == XPR_TOK)
5888 && (lltok_isSemi (exprData_getTok (e->edata))));
5891 exprNode exprNode_if (/*@only@*/ exprNode pred, /*@only@*/ exprNode tclause)
5894 bool emptyErr = FALSE;
5896 if (context_maybeSet (FLG_IFEMPTY))
5898 if (exprNode_isEmptyStatement (tclause))
5900 emptyErr = optgenerror (FLG_IFEMPTY,
5902 ("Body of if statement is empty"),
5903 exprNode_loc (tclause));
5907 if (!emptyErr && context_maybeSet (FLG_IFBLOCK))
5909 if (exprNode_isDefined (tclause)
5910 && !exprNode_isBlock (tclause))
5912 voptgenerror (FLG_IFBLOCK,
5914 ("Body of if statement is not a block: %s",
5915 exprNode_unparse (tclause)),
5916 exprNode_loc (tclause));
5920 if (exprNode_isError (pred))
5922 if (exprNode_isError (tclause))
5924 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
5928 ret = exprNode_createPartialCopy (tclause);
5933 if (exprNode_mustEscape (pred))
5937 message ("Predicate always exits: %s", exprNode_unparse (pred)),
5938 exprNode_loc (pred));
5941 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
5942 exprNode_checkUse (pred, pred->sref, pred->loc);
5944 if (!exprNode_isError (tclause))
5946 exprNode_mergeCondUSs (pred, tclause, exprNode_undefined);
5949 ret = exprNode_createPartialCopy (pred);
5953 ret->edata = exprData_makePair (pred, tclause);
5955 ret->exitCode = XK_UNKNOWN;
5957 if (exprNode_isDefined (tclause))
5959 ret->exitCode = exitkind_makeConditional (tclause->exitCode);
5960 ret->canBreak = tclause->canBreak;
5961 ret->sets = sRefSet_union (ret->sets, tclause->sets);
5962 ret->msets = sRefSet_union (ret->msets, tclause->msets);
5963 ret->uses = sRefSet_union (ret->uses, tclause->uses);
5966 ret->mustBreak = FALSE;
5971 exprNode exprNode_ifelse (/*@only@*/ exprNode pred,
5972 /*@only@*/ exprNode tclause,
5973 /*@only@*/ exprNode eclause)
5976 bool tEmptyErr = FALSE;
5977 bool eEmptyErr = FALSE;
5979 if (context_maybeSet (FLG_IFEMPTY))
5981 if (exprNode_isEmptyStatement (tclause))
5983 tEmptyErr = optgenerror
5986 ("Body of if clause of if statement is empty"),
5987 exprNode_loc (tclause));
5990 if (exprNode_isEmptyStatement (eclause))
5992 eEmptyErr = optgenerror
5995 ("Body of else clause of if statement is empty"),
5996 exprNode_loc (eclause));
6000 if (context_maybeSet (FLG_IFBLOCK))
6003 && exprNode_isDefined (tclause)
6004 && !exprNode_isBlock (tclause))
6006 voptgenerror (FLG_IFBLOCK,
6008 ("Body of if clause of if statement is not a block: %s",
6009 exprNode_unparse (tclause)),
6010 exprNode_loc (tclause));
6014 && exprNode_isDefined (eclause)
6015 && !exprNode_isBlock (eclause)
6016 && !(eclause->kind == XPR_IF)
6017 && !(eclause->kind == XPR_IFELSE))
6022 ("Body of else clause of if statement is not a block: %s",
6023 exprNode_unparse (eclause)),
6024 exprNode_loc (eclause));
6028 if (context_maybeSet (FLG_ELSEIFCOMPLETE))
6030 if (exprNode_isDefined (eclause)
6031 && (eclause->kind == XPR_IF))
6033 voptgenerror (FLG_ELSEIFCOMPLETE,
6034 message ("Incomplete else if logic (no final else): %s",
6035 exprNode_unparse (eclause)),
6036 exprNode_loc (eclause));
6040 if (exprNode_isError (pred))
6042 if (exprNode_isError (tclause))
6044 if (exprNode_isError (eclause))
6046 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6050 ret = exprNode_createPartialCopy (eclause);
6055 ret = exprNode_createPartialCopy (tclause);
6058 else /* pred is okay */
6060 ret = exprNode_createPartialCopy (pred);
6062 if (exprNode_mustEscape (pred))
6066 message ("Predicate always exits: %s", exprNode_unparse (pred)),
6067 exprNode_loc (pred));
6070 exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
6071 exprNode_checkUse (ret, pred->sref, pred->loc);
6073 exprNode_mergeCondUSs (ret, tclause, eclause);
6076 ret->kind = XPR_IFELSE;
6077 ret->edata = exprData_makeCond (pred, tclause, eclause);
6079 if (exprNode_isDefined (tclause) && exprNode_isDefined (eclause))
6081 exprNode_combineControl (ret, tclause, eclause);
6082 ret->loc = fileloc_update (ret->loc, eclause->loc);
6089 ** *allpaths <- TRUE iff all executions paths must go through the switch
6093 checkSwitchExpr (exprNode test, /*@dependent@*/ exprNode e, /*@out@*/ bool *allpaths)
6095 exprNodeSList el = exprNode_flatten (e);
6096 bool mustReturn = TRUE; /* find a branch that doesn't */
6097 bool thisReturn = FALSE;
6098 bool hasDefault = FALSE;
6099 bool hasAllMembers = FALSE;
6100 bool inSwitch = FALSE;
6101 bool isEnumSwitch = FALSE;
6102 bool canBreak = FALSE;
6103 bool fallThrough = FALSE;
6104 ctype ct = ctype_unknown;
6105 enumNameSList usedEnums;
6108 if (exprNode_isDefined (test))
6113 ttype = ctype_realType (ct);
6115 if (ctype_isEnum (ttype))
6117 isEnumSwitch = TRUE;
6118 enums = ctype_elist (ttype);
6119 usedEnums = enumNameSList_new ();
6123 exprNodeSList_elements (el, current)
6125 if (exprNode_isDefined (current))
6127 switch (current->kind)
6135 message ("Duplicate default cases in switch"),
6136 exprNode_loc (current));
6141 if (current->kind == XPR_DEFAULT || current->kind == XPR_FTDEFAULT)
6149 exprNode st = exprData_getSingle (current->edata);
6150 uentry ue = exprNode_getUentry (st);
6152 if (uentry_isValid (ue))
6154 cstring cname = uentry_rawName (ue);
6156 if (enumNameList_member (/*@-usedef@*/enums/*@=usedef@*/, cname))
6158 if (enumNameSList_member
6159 (/*@-usedef@*/usedEnums/*@=usedef@*/, cname))
6163 message ("Duplicate case in switch: %s",
6169 enumNameSList_addh (usedEnums, cname);
6176 message ("Case in switch not %s member: %s",
6177 ctype_unparse (ct), cname),
6184 if (inSwitch && !fallThrough)
6186 if (!thisReturn || canBreak)
6196 /*@switchbreak@*/ break;
6198 thisReturn = thisReturn || exprNode_mustEscape (current);
6199 canBreak = canBreak || current->canBreak;
6200 if (canBreak) fallThrough = FALSE;
6203 } end_exprNodeSList_elements;
6205 if (inSwitch) /* check the last one! */
6207 if (!thisReturn || canBreak)
6216 && (enumNameSList_size (/*@-usedef@*/usedEnums/*@=usedef@*/) !=
6217 enumNameList_size (/*@-usedef@*/enums/*@=usedef@*/)))
6219 enumNameSList unused = enumNameSList_subtract (enums, usedEnums);
6221 voptgenerror (FLG_MISSCASE,
6222 message ("Missing case%s in switch: %q",
6223 cstring_makeLiteralTemp
6224 ((enumNameSList_size (unused) > 1) ? "s" : ""),
6225 enumNameSList_unparse (unused)),
6228 enumNameSList_free (unused);
6232 hasAllMembers = TRUE;
6236 enumNameSList_free (usedEnums);
6240 *allpaths = hasDefault;
6243 exprNodeSList_free (el);
6244 return ((hasDefault || hasAllMembers) && mustReturn);
6247 exprNode exprNode_switch (/*@only@*/ exprNode e, /*@only@*/ exprNode s)
6249 exprNode ret = exprNode_createPartialCopy (e);
6252 DPRINTF (("Switch: %s", exprNode_unparse (s)));
6254 ret->kind = XPR_SWITCH;
6255 ret->edata = exprData_makePair (e, s);
6257 if (!exprNode_isError (s))
6259 exprNode fs = exprNode_firstStatement (s);
6260 ret->loc = fileloc_update (ret->loc, s->loc);
6262 if (exprNode_isUndefined (fs)
6263 || exprNode_isCaseMarker (fs) || exprNode_isLabelMarker (fs)
6264 || exprNode_isDefaultMarker (fs)) {
6267 voptgenerror (FLG_FIRSTCASE,
6269 ("Statement after switch is not a case: %s", exprNode_unparse (fs)),
6274 if (!exprNode_isError (e))
6276 if (checkSwitchExpr (e, s, &allpaths))
6278 ret->exitCode = XK_MUSTRETURN;
6282 ret->exitCode = e->exitCode;
6285 ret->canBreak = e->canBreak;
6286 ret->mustBreak = e->mustBreak;
6290 ** exprNode.c:3883,32: Variable allpaths used before definition
6297 DPRINTF (("Context exit switch!"));
6298 context_exitSwitch (ret, allpaths);
6299 DPRINTF (("Context exit switch done!"));
6304 static void checkInfiniteLoop (/*@notnull@*/ exprNode test,
6305 /*@notnull@*/ exprNode body)
6307 sRefSet tuses = test->uses;
6309 if (!sRefSet_isEmpty (test->uses))
6311 sRefSet sets = sRefSet_newCopy (body->sets);
6312 bool hasError = TRUE;
6313 bool innerState = FALSE;
6314 sRefSet tuncon = sRefSet_undefined;
6316 sets = sRefSet_union (sets, test->sets);
6317 sets = sRefSet_union (sets, body->msets);
6318 sets = sRefSet_union (sets, test->msets);
6320 sRefSet_allElements (tuses, el)
6322 if (sRef_isUnconstrained (el))
6324 tuncon = sRefSet_insert (tuncon, el);
6328 if (sRefSet_member (sets, el))
6335 if (sRef_isInternalState (el)
6336 || sRef_isFileStatic (sRef_getRootBase (el)))
6340 } end_sRefSet_allElements ;
6344 sRefSet suncon = sRefSet_undefined;
6345 bool sinner = FALSE;
6347 sRefSet_allElements (sets, el)
6349 if (sRef_isUnconstrained (el))
6351 suncon = sRefSet_insert (suncon, el);
6353 else if (sRef_isInternalState (el))
6361 } end_sRefSet_allElements ;
6363 if (sinner && innerState)
6367 else if (sRefSet_isEmpty (tuncon)
6368 && sRefSet_isEmpty (suncon))
6373 ("Suspected infinite loop. No value used in loop test (%q) "
6374 "is modified by test or loop body.",
6375 sRefSet_unparsePlain (tuses)),
6380 if (sRefSet_isEmpty (tuncon))
6384 message ("Suspected infinite loop. No condition values "
6385 "modified. Modification possible through "
6386 "unconstrained calls: %q",
6387 sRefSet_unparsePlain (suncon)),
6394 message ("Suspected infinite loop. No condition values "
6395 "modified. Possible undetected dependency through "
6396 "unconstrained calls in loop test: %q",
6397 sRefSet_unparsePlain (tuncon)),
6403 sRefSet_free (sets);
6407 exprNode exprNode_while (/*@keep@*/ exprNode t, /*@keep@*/ exprNode b)
6410 bool emptyErr = FALSE;
6412 s = exprNode_generateConstraints (t);
6413 // printf("pred: %s\n", s);
6414 s = exprNode_generateConstraints (b);
6415 //printf ("body: %s\n", s);
6416 //constraintList_print(b->constraints);
6418 if (context_maybeSet (FLG_WHILEEMPTY))
6420 if (exprNode_isEmptyStatement (b))
6422 emptyErr = optgenerror
6425 ("Body of while statement is empty"),
6430 if (!emptyErr && context_maybeSet (FLG_WHILEBLOCK))
6432 if (exprNode_isDefined (b)
6433 && !exprNode_isBlock (b))
6435 if (context_inIterDef ()
6436 && (b->kind == XPR_STMTLIST
6437 || b->kind == XPR_TOK))
6443 voptgenerror (FLG_WHILEBLOCK,
6445 ("Body of while statement is not a block: %s",
6446 exprNode_unparse (b)),
6452 if (exprNode_isError (t))
6454 if (exprNode_isError (b))
6456 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6460 ret = exprNode_createPartialCopy (b);
6467 ret = exprNode_createPartialCopy (t);
6469 llassert (t->kind == XPR_WHILEPRED);
6471 test = exprData_getSingle (t->edata);
6473 if (!exprNode_isError (b) && exprNode_isDefined (test))
6475 if (context_maybeSet (FLG_INFLOOPS)
6476 || context_maybeSet (FLG_INFLOOPSUNCON))
6479 ** check that some variable in the predicate is set by the body
6480 ** if the predicate uses any variables
6483 checkInfiniteLoop (test, b);
6486 exprNode_mergeUSs (ret, b);
6488 if (exprNode_isDefined (b))
6490 ret->exitCode = exitkind_makeConditional (b->exitCode);
6495 ret->edata = exprData_makePair (t, b);
6496 ret->kind = XPR_WHILE;
6498 if (exprNode_isDefined (t) && exprNode_mustEscape (t))
6502 message ("Predicate always exits: %s", exprNode_unparse (t)),
6506 ret->exitCode = XK_NEVERESCAPE;
6509 ** If loop is infinite, and there is no break inside,
6510 ** exit code is never reach.
6513 if (exprNode_knownIntValue (t))
6515 if (!exprNode_isZero (t))
6517 if (exprNode_isDefined (b))
6521 /* Really, it means never reached. */
6522 ret->exitCode = XK_MUSTEXIT;
6532 ret->canBreak = FALSE;
6533 ret->mustBreak = FALSE;
6539 ** do { b } while (t);
6541 ** note: body passed as first argument
6544 exprNode exprNode_doWhile (/*@only@*/ exprNode b, /*@only@*/ exprNode t)
6548 if (exprNode_isError (t))
6550 if (exprNode_isError (b))
6552 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
6556 ret = exprNode_createPartialCopy (b);
6558 ret->exitCode = exitkind_makeConditional (b->exitCode);
6559 exprNode_checkUse (ret, b->sref, b->loc);
6560 ret->exitCode = b->exitCode;
6561 ret->canBreak = b->canBreak;
6562 ret->mustBreak = b->mustBreak;
6567 ret = exprNode_createPartialCopy (t);
6568 exprNode_checkPred (cstring_makeLiteralTemp ("while"), t);
6570 if (!exprNode_isError (b))
6573 ** forgot the copy's --- why wasn't this detected??
6576 ret->sets = sRefSet_copy (ret->sets, b->sets);
6577 ret->msets = sRefSet_copy (ret->msets, b->msets);
6578 ret->uses = sRefSet_copy (ret->uses, b->uses);
6580 /* left this out --- causes and aliasing bug (infinite loop)
6581 should be detected?? */
6583 exprNode_checkUse (ret, b->sref, b->loc);
6584 exprNode_mergeUSs (ret, t);
6585 exprNode_checkUse (ret, t->sref, t->loc);
6587 ret->exitCode = b->exitCode;
6588 ret->canBreak = b->canBreak;
6589 ret->mustBreak = b->mustBreak;
6593 context_exitDoWhileClause (t);
6595 ret->kind = XPR_DOWHILE;
6596 ret->edata = exprData_makePair (t, b);
6600 exprNode exprNode_for (/*@keep@*/ exprNode inc, /*@keep@*/ exprNode body)
6603 bool emptyErr = FALSE;
6605 if (context_maybeSet (FLG_FOREMPTY))
6607 if (exprNode_isEmptyStatement (body))
6609 emptyErr = optgenerror
6612 ("Body of for statement is empty"),
6613 exprNode_loc (body));
6617 if (!emptyErr && context_maybeSet (FLG_FORBLOCK))
6619 if (exprNode_isDefined (body)
6620 && !exprNode_isBlock (body))
6622 if (context_inIterDef ()
6623 && (body->kind == XPR_STMTLIST
6624 || body->kind == XPR_TOK))
6630 voptgenerror (FLG_FORBLOCK,
6632 ("Body of for statement is not a block: %s",
6633 exprNode_unparse (body)),
6634 exprNode_loc (body));
6640 ** for ud purposes: (alreadly) init -> test -> (now) LOOP: body + inc + test
6643 if (exprNode_isError (body))
6645 ret = exprNode_createPartialCopy (inc);
6649 ret = exprNode_createPartialCopy (body);
6651 ret->exitCode = exitkind_makeConditional (body->exitCode);
6653 exprNode_mergeUSs (inc, body);
6655 if (exprNode_isDefined (inc))
6659 context_setMessageAnnote (cstring_makeLiteral ("in post loop increment"));
6662 tmp = exprNode_effect (exprData_getTripleInc (inc->edata));
6663 exprNode_freeShallow (tmp);
6665 context_clearMessageAnnote ();
6666 context_setMessageAnnote (cstring_makeLiteral ("in post loop test"));
6668 tmp = exprNode_effect (exprData_getTripleTest (inc->edata));
6669 exprNode_freeShallow (tmp);
6671 context_clearMessageAnnote ();
6673 ret->uses = sRefSet_copy (ret->uses, inc->uses);
6674 ret->sets = sRefSet_copy (ret->sets, inc->sets);
6675 ret->msets = sRefSet_copy (ret->msets, inc->msets);
6679 ret->kind = XPR_FOR;
6680 ret->edata = exprData_makePair (inc, body);
6682 if (exprNode_isDefined (inc)) {
6683 exprNode test = exprData_getTripleTest (inc->edata);
6685 if (exprNode_isUndefined (test)) {
6686 if (exprNode_isDefined (body)) {
6687 if (!body->canBreak) {
6688 /* Really, it means never reached. */
6689 ret->exitCode = XK_MUSTEXIT;
6699 ** for (init; test; inc)
6702 ** while (test) { body; inc; }
6704 ** Now: check use of init (may set vars for test)
6705 ** check use of test
6709 /*@observer@*/ guardSet exprNode_getForGuards (exprNode pred)
6713 if (exprNode_isError (pred)) return guardSet_undefined;
6715 llassert (pred->kind == XPR_FORPRED);
6717 test = exprData_getTripleTest (pred->edata);
6719 if (!exprNode_isError (test))
6721 return (test->guards);
6724 return guardSet_undefined;
6727 exprNode exprNode_whilePred (/*@only@*/ exprNode test)
6729 exprNode ret = exprNode_createSemiCopy (test);
6731 if (exprNode_isDefined (test))
6733 exprNode_copySets (ret, test);
6734 exprNode_checkPred (cstring_makeLiteralTemp ("while"), test);
6735 exprNode_checkUse (ret, test->sref, test->loc);
6737 exprNode_produceGuards (test);
6739 ret->guards = guardSet_copy (test->guards);
6742 ret->edata = exprData_makeSingle (test);
6743 ret->kind = XPR_WHILEPRED;
6747 exprNode exprNode_forPred (/*@only@*/ exprNode init, /*@only@*/ exprNode test,
6748 /*@only@*/ exprNode inc)
6753 ** for ud purposes: init -> test -> LOOP: [ body, inc ]
6756 exprNode_checkPred (cstring_makeLiteralTemp ("for"), test);
6758 if (!exprNode_isError (inc))
6760 ret = exprNode_createPartialCopy (inc);
6764 if (!exprNode_isError (init))
6766 ret = exprNode_createPartialCopy (init);
6768 else if (!exprNode_isError (test))
6770 ret = exprNode_createPartialCopy (test);
6774 ret = exprNode_createUnknown ();
6778 exprNode_mergeUSs (ret, init);
6780 if (exprNode_isDefined (init))
6782 exprNode_checkUse (ret, init->sref, init->loc);
6785 exprNode_mergeUSs (ret, test);
6787 if (exprNode_isDefined (test))
6789 exprNode_checkUse (ret, test->sref, test->loc);
6792 ret->kind = XPR_FORPRED;
6793 ret->edata = exprData_makeFor (init, test, inc);
6797 /*@notnull@*/ /*@only@*/ exprNode exprNode_goto (/*@only@*/ cstring label)
6799 exprNode ret = exprNode_createUnknown ();
6801 if (context_inMacro ())
6803 voptgenerror (FLG_MACROSTMT,
6804 message ("Macro %s uses goto (not functional)",
6805 context_inFunctionName ()),
6809 ret->kind = XPR_GOTO;
6810 ret->edata = exprData_makeLiteral (label);
6811 ret->mustBreak = TRUE;
6812 ret->exitCode = XK_GOTO;
6813 ret->canBreak = TRUE;
6817 exprNode exprNode_continue (/*@only@*/ lltok l, int qcontinue)
6819 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6821 ret->kind = XPR_CONTINUE;
6822 ret->edata = exprData_makeTok (l);
6823 ret->canBreak = TRUE;
6824 ret->mustBreak = TRUE;
6826 if (qcontinue == QSAFEBREAK)
6830 else if (qcontinue == QINNERCONTINUE)
6832 if (!context_inDeepLoop ())
6835 (FLG_LOOPLOOPCONTINUE,
6836 cstring_makeLiteral ("Continue statement marked with innercontinue "
6837 "is not inside a nested loop"),
6838 exprNode_loc (ret));
6841 else if (qcontinue == BADTOK)
6843 if (context_inDeepLoop ())
6846 (FLG_LOOPLOOPCONTINUE,
6847 cstring_makeLiteral ("Continue statement in nested loop"),
6848 exprNode_loc (ret));
6853 llbuglit ("exprNode_continue: bad qcontinue");
6859 exprNode exprNode_break (/*@only@*/ lltok l, int bqual)
6861 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (lltok_getLoc (l)));
6862 clause breakClause = context_breakClause ();
6864 ret->kind = XPR_BREAK;
6865 ret->edata = exprData_makeTok (l);
6866 ret->canBreak = TRUE;
6867 ret->mustBreak = TRUE;
6869 if (breakClause == NOCLAUSE)
6873 cstring_makeLiteral ("Break not inside while, for or switch statement"),
6874 exprNode_loc (ret));
6878 if (bqual != BADTOK)
6885 if (breakClause == SWITCHCLAUSE)
6887 if (!context_inDeepSwitch ())
6889 voptgenerror (FLG_SYNTAX,
6891 ("Break preceded by innerbreak is not in a deep switch"),
6892 exprNode_loc (ret));
6897 if (!context_inDeepLoop ())
6899 voptgenerror (FLG_SYNTAX,
6901 ("Break preceded by innerbreak is not in a deep loop"),
6902 exprNode_loc (ret));
6907 if (breakClause == SWITCHCLAUSE)
6909 voptgenerror (FLG_SYNTAX,
6911 ("Break preceded by loopbreak is breaking a switch"),
6912 exprNode_loc (ret));
6916 if (breakClause != SWITCHCLAUSE)
6920 message ("Break preceded by switchbreak is breaking %s",
6921 cstring_makeLiteralTemp
6922 ((breakClause == WHILECLAUSE
6923 || breakClause == DOWHILECLAUSE) ? "a while loop"
6924 : (breakClause == FORCLAUSE) ? "a for loop"
6925 : (breakClause == ITERCLAUSE) ? "an iterator"
6927 exprNode_loc (ret));
6935 if (breakClause == SWITCHCLAUSE)
6937 clause nextBreakClause = context_nextBreakClause ();
6939 switch (nextBreakClause)
6941 case NOCLAUSE: break;
6947 (FLG_LOOPSWITCHBREAK,
6948 cstring_makeLiteral ("Break statement in switch inside loop"),
6949 exprNode_loc (ret));
6953 (FLG_SWITCHSWITCHBREAK,
6954 cstring_makeLiteral ("Break statement in switch inside switch"),
6955 exprNode_loc (ret));
6962 if (context_inDeepLoop ())
6966 cstring_makeLiteral ("Break statement in nested loop"),
6967 exprNode_loc (ret));
6971 if (context_inDeepLoopSwitch ())
6974 (FLG_SWITCHLOOPBREAK,
6975 cstring_makeLiteral ("Break statement in loop inside switch"),
6976 exprNode_loc (ret));
6986 exprNode exprNode_nullReturn (/*@only@*/ lltok t)
6988 fileloc loc = lltok_getLoc (t);
6989 exprNode ret = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
6991 context_returnFunction ();
6992 exprChecks_checkNullReturn (loc);
6994 ret->kind = XPR_NULLRETURN;
6995 ret->edata = exprData_makeTok (t);
6996 ret->exitCode = XK_MUSTRETURN;
7000 exprNode exprNode_return (/*@only@*/ exprNode e)
7004 if (exprNode_isError (e))
7006 ret = exprNode_createUnknown ();
7010 ret = exprNode_createLoc (ctype_unknown, fileloc_copy (e->loc));
7012 exprNode_checkUse (ret, e->sref, e->loc);
7013 exprNode_checkReturn (e);
7016 context_returnFunction ();
7017 ret->kind = XPR_RETURN;
7018 ret->edata = exprData_makeSingle (e);
7019 ret->exitCode = XK_MUSTRETURN;
7024 exprNode exprNode_comma (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2)
7028 if (exprNode_isError (e1))
7030 if (exprNode_isError (e2))
7032 ret = exprNode_createLoc (ctype_unknown, g_currentloc);
7036 ret = exprNode_createPartialCopy (e2);
7037 exprNode_checkUse (ret, e2->sref, e2->loc);
7038 ret->sref = e2->sref;
7043 ret = exprNode_createPartialCopy (e1);
7045 exprNode_checkUse (ret, e1->sref, e1->loc);
7047 if (!exprNode_isError (e2))
7049 exprNode_mergeUSs (ret, e2);
7050 exprNode_checkUse (ret, e2->sref, e2->loc);
7051 ret->sref = e2->sref;
7055 ret->kind = XPR_COMMA;
7056 ret->edata = exprData_makePair (e1, e2);
7058 if (exprNode_isDefined (e1))
7060 if (exprNode_isDefined (e2))
7064 if (exprNode_mustEscape (e1) || e1->mustBreak)
7068 message ("Second clause of comma expression is unreachable: %s",
7069 exprNode_unparse (e2)),
7073 ret->exitCode = exitkind_combine (e1->exitCode, e2->exitCode);
7074 ret->mustBreak = e1->mustBreak || e2->mustBreak;
7075 ret->canBreak = e1->canBreak || e2->canBreak;
7079 if (exprNode_mustEscape (e1) || e1->mustBreak)
7083 message ("Second clause of comma expression is unreachable: %s",
7084 exprNode_unparse (e2)),
7088 ret->exitCode = e1->exitCode;
7089 ret->canBreak = e1->canBreak;
7094 if (exprNode_isDefined (e2))
7096 ret->exitCode = e2->exitCode;
7097 ret->mustBreak = e2->mustBreak;
7098 ret->canBreak = e2->canBreak;
7105 static bool exprNode_checkOneInit (/*@notnull@*/ exprNode el, exprNode val)
7107 ctype t1 = exprNode_getType (el);
7108 ctype t2 = exprNode_getType (val);
7109 bool hasError = FALSE;
7111 if (ctype_isUnknown (t1))
7113 voptgenerror (FLG_IMPTYPE,
7114 message ("Variable has unknown (implicitly int) type: %s",
7115 exprNode_unparse (el)),
7119 el->typ = ctype_int;
7122 if (exprNode_isDefined (val) && val->kind == XPR_INITBLOCK)
7124 exprNodeList vals = exprData_getArgs (val->edata);
7126 if (ctype_isRealAP (t1))
7131 exprNodeList_elements (vals, oneval)
7133 cstring istring = message ("%d", i);
7136 (exprNode_fakeCopy (el),
7137 exprNode_numLiteral (ctype_int, istring,
7138 fileloc_copy (el->loc), i));
7140 if (exprNode_isDefined (newel))
7142 if (exprNodeList_size (vals) == 1
7143 && ctype_isString (exprNode_getType (oneval))
7144 && ctype_isChar (exprNode_getType (newel)))
7146 exprNode_freeIniter (newel);
7150 if (exprNode_checkOneInit (newel, oneval))
7155 if (nerrors > 3 && exprNodeList_size (vals) > 6)
7158 (message ("Additional initialization errors "
7159 "for %s not reported",
7160 exprNode_unparse (el)),
7162 exprNode_freeIniter (newel);
7167 exprNode_freeIniter (newel);
7172 exprNode_freeIniter (newel);
7177 cstring_free (istring);
7180 } end_exprNodeList_elements;
7183 else if (ctype_isStruct (ctype_realType (t1)))
7185 uentryList fields = ctype_getFields (t1);
7188 if (uentryList_size (fields) != exprNodeList_size (vals))
7190 if (uentryList_size (fields) > exprNodeList_size (vals))
7192 hasError = optgenerror
7194 message ("Initializer block for "
7195 "%s has %d field%p, but %s has %d field%p: %q",
7196 exprNode_unparse (el),
7197 exprNodeList_size (vals),
7199 uentryList_size (fields),
7200 exprNodeList_unparse (vals)),
7205 hasError = optgenerror
7207 message ("Initializer block for "
7208 "%s has %d field%p, but %s has %d field%p: %q",
7209 exprNode_unparse (el),
7210 exprNodeList_size (vals),
7212 uentryList_size (fields),
7213 exprNodeList_unparse (vals)),
7219 exprNodeList_elements (vals, oneval)
7221 uentry thisfield = uentryList_getN (fields, i);
7223 exprNode_fieldAccess (exprNode_fakeCopy (el),
7224 uentry_getName (thisfield));
7226 if (exprNode_isDefined (newel))
7228 if (exprNode_checkOneInit (newel, oneval))
7233 exprNode_freeIniter (newel);
7237 } end_exprNodeList_elements;
7242 hasError = optgenerror
7244 message ("Initializer block used for "
7245 "%s where %t is expected: %s",
7246 exprNode_unparse (el), t1, exprNode_unparse (val)),
7252 if (exprNode_isDefined (val))
7254 doAssign (el, val, TRUE);
7256 if (!exprNode_matchType (t1, val))
7258 hasError = gentypeerror
7260 message ("Initial value of %s is type %t, "
7262 exprNode_unparse (el),
7263 t2, t1, exprNode_unparse (val)),
7272 exprNode exprNode_makeInitialization (/*@only@*/ idDecl t,
7273 /*@only@*/ exprNode e)
7275 uentry ue = usymtab_lookup (idDecl_observeId (t));
7276 bool isUsed = uentry_isUsed (ue);
7277 exprNode ret = exprNode_fromIdentifierAux (ue);
7278 ctype ct = ctype_realishType (ret->typ);
7281 if (ctype_isUnknown (ct))
7283 voptgenerror (FLG_IMPTYPE,
7284 message ("Variable has unknown (implicitly int) type: %s",
7285 idDecl_getName (t)),
7286 exprNode_isDefined (e) ? exprNode_loc (e) : g_currentloc);
7291 if (exprNode_isError (e))
7293 e = exprNode_createUnknown ();
7296 /* error: assume initializer is defined */
7297 sRef_setDefined (ret->sref, loc);
7301 loc = exprNode_loc (e);
7306 ** was addSafeUse --- what's the problem?
7308 ** int x = 3, y = x ?
7311 exprNode_checkUse (ret, e->sref, e->loc);
7313 if (ctype_isUnknown (e->typ) && uentry_isValid (ue))
7315 exprNode lhs = exprNode_createId (ue);
7318 ** static storage should be undefined before initializing
7321 if (uentry_isStatic (ue))
7323 sRef_setDefState (lhs->sref, SS_PARTIAL, fileloc_undefined);
7326 (void) exprNode_checkOneInit (lhs, e);
7328 if (uentry_isStatic (ue))
7330 sRef_setDefState (lhs->sref, SS_DEFINED, fileloc_undefined);
7333 exprNode_free (lhs);
7337 if (!exprNode_matchType (ct, e))
7339 if (exprNode_isZero (e) && ctype_isArrayPtr (ct))
7346 (exprNode_getType (e), e, exprNode_getType (ret), ret,
7348 ("Variable %s initialized to type %t, expects %t: %s",
7349 exprNode_unparse (ret), exprNode_getType (e),
7350 exprNode_getType (ret),
7351 exprNode_unparse (e)),
7357 if (uentry_isStatic (ue))
7359 sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
7362 doAssign (ret, e, TRUE);
7364 if (uentry_isStatic (ue))
7366 sRef_setDefState (ret->sref, SS_DEFINED, fileloc_undefined);
7370 if (context_inIterDef ())
7372 /* should check if it is yield */
7373 uentry_setUsed (ue, loc);
7377 if (!isUsed) /* could be @unused@-qualified variable */
7379 uentry_setNotUsed (ue);
7383 ret->exitCode = XK_NEVERESCAPE;
7384 ret->mustBreak = FALSE;
7387 ** Must be before new kind is assigned!
7390 exprData_free (ret->edata, ret->kind);
7392 ret->kind = XPR_INIT;
7393 ret->edata = exprData_makeInit (t, e);
7394 exprNode_mergeUSs (ret, e);
7398 exprNode exprNode_iter (/*@observer@*/ uentry name,
7399 /*@only@*/ exprNodeList alist,
7400 /*@only@*/ exprNode body,
7401 /*@observer@*/ uentry end)
7406 llassert (uentry_isValid (name));
7408 uentry_setUsed (name, exprNode_loc (body));
7410 ret = exprNode_createPartialCopy (body);
7411 iname = uentry_getName (name);
7413 if (uentry_isInvalid (end))
7416 message ("Iter %s not balanced with end_%s", iname, iname));
7420 cstring ename = uentry_getName (end);
7422 if (!cstring_equalPrefix (ename, "end_"))
7424 llerror (FLG_ITER, message ("Iter %s not balanced with end_%s: %s",
7425 iname, iname, ename));
7429 if (!cstring_equal (iname, cstring_suffix (ename, 4)))
7432 message ("Iter %s not balanced with end_%s: %s",
7433 iname, iname, ename));
7437 cstring_free (ename);
7440 context_exitIterClause (body);
7442 ret->kind = XPR_ITER;
7443 ret->edata = exprData_makeIter (name, alist, body, end);
7445 if (uentry_isIter (name))
7447 (void) checkArgsReal (name, body,
7448 uentry_getParams (name), alist, TRUE, ret);
7451 cstring_free (iname);
7457 exprNode_iterNewId (/*@only@*/ cstring s)
7459 exprNode e = exprNode_new ();
7460 uentry ue = uentryList_getN (uentry_getParams (getCurrentIter ()), iterParamNo ());
7462 llassert (processingIterVars ());
7464 e->loc = context_getSaveLocation ();
7466 if (fileloc_isUndefined (e->loc))
7468 fileloc_free (e->loc);
7469 e->loc = fileloc_copy (g_currentloc);
7472 e->uses = sRefSet_new ();
7473 e->sets = sRefSet_new ();
7474 e->msets = sRefSet_new ();
7476 e->val = multiVal_unknown ();
7477 e->guards = guardSet_new ();
7479 e->isJumpPoint = FALSE;
7480 e->exitCode = XK_NEVERESCAPE;
7482 /*> missing fields, detected by lclint <*/
7483 e->canBreak = FALSE;
7484 e->mustBreak = FALSE;
7485 e->etext = cstring_undefined;
7487 if (uentry_isYield (ue))
7489 uentry uue = uentry_makeVariable (s, uentry_getType (ue),
7490 fileloc_copy (e->loc),
7494 uue = usymtab_supEntrySrefReturn (uue);
7496 sr = uentry_getSref (uue);
7497 sRef_mergeStateQuiet (sr, uentry_getSref (ue));
7498 sr = uentry_getSref (uue);
7499 sRef_setDefined (sr, e->loc);
7501 e->typ = uentry_getType (uue);
7503 e->edata = exprData_makeId (uue);
7504 uentry_setUsed (uue, g_currentloc);
7510 sRef_setGlobalScope ();
7511 uue = uentry_makeVariableLoc (s, ctype_unknown);
7513 e->typ = ctype_unknown;
7514 e->edata = exprData_makeId (uue);
7516 uentry_setUsed (uue, e->loc);
7517 uentry_setHasNameError (uue);
7519 if (context_getFlag (FLG_REPEATUNRECOG))
7521 uentry_markOwned (uue);
7525 usymtab_supGlobalEntry (uue);
7528 sRef_clearGlobalScope ();
7530 voptgenerror (FLG_UNRECOG, message ("Unrecognized identifier: %s", s),
7540 exprNode_iterExpr (/*@returned@*/ exprNode e)
7542 if (!processingIterVars ())
7544 llcontbuglit ("checkIterParam: not in iter");
7548 if (uentry_isYield (uentryList_getN (uentry_getParams (getCurrentIter ()),
7551 if (exprNode_isDefined (e))
7553 if (fileloc_isDefined (e->loc))
7557 message ("Yield parameter is not simple identifier: %s",
7558 exprNode_unparse (e)),
7565 message ("Yield parameter is not simple identifier: %s",
7566 exprNode_unparse (e)),
7576 exprNode_iterId (/*@observer@*/ uentry c)
7580 llassert (processingIterVars ());
7582 ue = uentryList_getN (uentry_getParams (getCurrentIter ()),
7585 if (uentry_isYield (ue))
7587 ctype ct = uentry_getType (ue);
7588 exprNode e = exprNode_createPlain (ct);
7589 cstring name = uentry_getName (c);
7590 uentry le = uentry_makeVariable (name, ct, fileloc_undefined, FALSE);
7592 uentry_setUsed (ue, g_currentloc);
7593 uentry_setHasNameError (ue);
7595 cstring_free (name);
7598 e->edata = exprData_makeId (le);
7599 e->loc = context_getSaveLocation ();
7600 e->sref = uentry_getSref (le);
7602 usymtab_supEntrySref (le);
7604 if (!context_inHeader ())
7608 message ("Yield parameter shadows local declaration: %q",
7609 uentry_getName (c)),
7610 fileloc_isDefined (e->loc) ? e->loc : g_currentloc))
7612 uentry_showWhereDeclared (c);
7619 return (exprNode_fromIdentifierAux (c));
7622 exprNode exprNode_iterStart (/*@observer@*/ uentry name, /*@only@*/ exprNodeList alist)
7624 exprNode ret = exprNode_create (ctype_unknown);
7626 ret->kind = XPR_ITERCALL;
7627 ret->edata = exprData_makeIterCall (name, alist);
7629 if (uentry_isIter (name))
7631 uentryList params = uentry_getParams (name);
7633 if (context_inIterDef ()
7634 && uentryList_size (params) == exprNodeList_size (alist))
7638 exprNodeList_elements (alist, arg)
7640 uentry parg = uentryList_getN (params, i);
7642 if (uentry_isYield (parg))
7644 uentry ue = exprNode_getUentry (arg);
7646 if (uentry_isValid (ue))
7653 } end_exprNodeList_elements;
7656 (void) checkArgsReal (name, ret, params, alist, TRUE, ret);
7657 checkUnspecCall (ret, params, alist);
7663 /*@exposed@*/ sRef exprNode_getSref (exprNode e)
7665 if (exprNode_isDefined (e))
7668 if (e->sref == defref) /*@noaccess sRef@*/
7671 e->sref = sRef_makeUnknown ();
7672 sRef_setAliasKind (e->sref, AK_ERROR, fileloc_undefined);
7683 return sRef_undefined;
7687 /*@observer@*/ cstring
7688 exprNode_unparseFirst (exprNode e)
7690 if (exprNode_isDefined (e))
7694 if (e->kind == XPR_STMTLIST
7695 || e->kind == XPR_COMMA || e->kind == XPR_COND)
7697 exprNode first = exprData_getPairA (e->edata);
7699 if (exprNode_isDefined (first))
7701 return (exprNode_unparseFirst (exprData_getPairA (e->edata)));
7705 return (cstring_makeLiteralTemp ("..."));
7709 ret = cstring_elide (exprNode_unparse (e), 20);
7710 cstring_markOwned (ret);
7716 return cstring_makeLiteralTemp ("<error>");
7720 /*@observer@*/ cstring
7721 exprNode_unparse (exprNode e)
7723 if (exprNode_isError (e))
7725 return cstring_makeLiteralTemp ("<error>");
7728 if (cstring_isDefined (e->etext))
7734 cstring ret = exprNode_doUnparse (e);
7736 /*@-modifies@*/ /* benevolent */
7743 /*@observer@*/ fileloc
7744 exprNode_loc (exprNode e)
7746 if (exprNode_isError (e))
7748 return (g_currentloc);
7757 ** executes exprNode e
7758 ** recursively rexecutes as though in original parse using
7759 ** information in e->edata
7762 static /*@only@*/ exprNodeList exprNodeList_effect (exprNodeList e)
7764 exprNodeList ret = exprNodeList_new ();
7766 exprNodeList_elements (e, current)
7768 exprNodeList_addh (ret, exprNode_effect (current));
7769 } end_exprNodeList_elements;
7774 static /*@only@*/ exprNode exprNode_effect (exprNode e)
7775 /*@globals internalState@*/
7777 bool innerEffect = inEffect;
7783 context_clearJustPopped ();
7785 if (exprNode_isError (e))
7787 ret = exprNode_undefined;
7792 ** Turn off expose and dependent transfer checking.
7793 ** Need to pass exposed internal nodes,
7794 ** [ copying would be a waste! ]
7795 ** [ Actually, I think I wasted a lot more time than its worth ]
7796 ** [ trying to do this. ]
7800 /*@-observertrans@*/
7801 /*@-dependenttrans@*/
7808 ret = exprNode_addParens (exprData_getUopTok (data),
7809 exprNode_effect (exprData_getUopNode (data)));
7812 ret = exprNode_assign (exprNode_effect (exprData_getOpA (data)),
7813 exprNode_effect (exprData_getOpB (data)),
7814 exprData_getOpTok (data));
7817 ret = exprNode_undefined;
7820 ret = exprNode_functionCall (exprNode_effect (exprData_getFcn (data)),
7821 exprNodeList_effect (exprData_getArgs (data)));
7834 cstring id = exprData_getId (data);
7835 uentry ue = usymtab_lookupSafe (id);
7837 ret = exprNode_fromIdentifierAux (ue);
7838 ret->loc = fileloc_update (ret->loc, e->loc);
7845 ret = exprNode_arrayFetch (exprNode_effect (exprData_getPairA (data)),
7846 exprNode_effect (exprData_getPairB (data)));
7849 ret = exprNode_op (exprNode_effect (exprData_getOpA (data)),
7850 exprNode_effect (exprData_getOpB (data)),
7851 exprData_getOpTok (data));
7855 ret = exprNode_postOp (exprNode_effect (exprData_getUopNode (data)),
7856 exprData_getUopTok (data));
7859 ret = exprNode_preOp (exprNode_effect (exprData_getUopNode (data)),
7860 exprData_getUopTok (data));
7872 ret = exprNode_vaArg (exprData_getCastTok (data),
7873 exprNode_effect (exprData_getCastNode (data)),
7874 exprData_getCastType (data));
7878 ret = exprNode_cast (exprData_getCastTok (data),
7879 exprNode_effect (exprData_getCastNode (data)),
7880 exprData_getCastType (data));
7883 ret = exprNode_iterStart (exprData_getIterCallIter (data),
7885 (exprData_getIterCallArgs (data)));
7889 ret = exprNode_iter (exprData_getIterSname (data),
7890 exprNodeList_effect (exprData_getIterAlist (data)),
7891 exprNode_effect (exprData_getIterBody (data)),
7892 exprData_getIterEname (data));
7896 ret = exprNode_for (exprNode_effect (exprData_getPairA (data)),
7897 exprNode_effect (exprData_getPairB (data)));
7901 ret = exprNode_forPred (exprNode_effect (exprData_getTripleInit (data)),
7902 exprNode_effect (exprData_getTripleTest (data)),
7903 exprNode_effect (exprData_getTripleInc (data)));
7907 ret = exprNode_createTok (exprData_getTok (data));
7911 ret = exprNode_goto (exprData_getLiteral (data));
7912 ret->loc = fileloc_update (ret->loc, e->loc);
7916 ret = exprNode_continue (exprData_getTok (data), QSAFEBREAK);
7920 ret = exprNode_break (exprData_getTok (data), QSAFEBREAK);
7924 ret = exprNode_return (exprNode_effect (exprData_getSingle (data)));
7927 case XPR_NULLRETURN:
7928 ret = exprNode_nullReturn (exprData_getTok (data));
7932 ret = exprNode_comma (exprNode_effect (exprData_getPairA (data)),
7933 exprNode_effect (exprData_getPairB (data)));
7937 ret = exprNode_cond (exprNode_effect (exprData_getTriplePred (data)),
7938 exprNode_effect (exprData_getTripleTrue (data)),
7939 exprNode_effect (exprData_getTripleFalse (data)));
7942 ret = exprNode_if (exprNode_effect (exprData_getPairA (data)),
7943 exprNode_effect (exprData_getPairB (data)));
7947 ret = exprNode_ifelse (exprNode_effect (exprData_getTriplePred (data)),
7948 exprNode_effect (exprData_getTripleTrue (data)),
7949 exprNode_effect (exprData_getTripleFalse (data)));
7952 ret = exprNode_whilePred (exprData_getSingle (data));
7956 ret = exprNode_while (exprNode_effect (exprData_getPairA (data)),
7957 exprNode_effect (exprData_getPairB (data)));
7961 ret = exprNode_doWhile (exprNode_effect (exprData_getPairA (data)),
7962 exprNode_effect (exprData_getPairB (data)));
7966 ret = exprNode_makeBlock (exprNode_effect (exprData_getSingle (data)));
7970 ret = exprNode_statement (exprNode_effect (exprData_getUopNode (data)),
7971 exprData_getUopTok (data));
7975 ret = exprNode_concat (exprNode_effect (exprData_getPairA (data)),
7976 exprNode_effect (exprData_getPairB (data)));
7981 ret = exprNode_caseMarker
7982 (exprNode_effect (exprData_getSingle (data)),
7988 ret = exprNode_createTok (exprData_getTok (data));
7992 ret = exprNode_switch (exprNode_effect (exprData_getPairA (data)),
7993 exprNode_effect (exprData_getPairB (data)));
7997 ret = exprNode_makeInitialization
7998 (exprData_getInitId (data),
7999 exprNode_effect (exprData_getInitNode (data)));
8003 ret = exprNode_fieldAccess (exprNode_effect (exprData_getFieldNode (data)),
8004 cstring_copy (exprData_getFieldName (data)));
8008 ret = exprNode_arrowAccess (exprNode_effect (exprData_getFieldNode (data)),
8009 cstring_copy (exprData_getFieldName (data)));
8012 case XPR_STRINGLITERAL:
8026 /*@=observertrans@*/
8028 /*@=dependenttrans@*/
8039 static /*@observer@*/ cstring exprNode_rootVarName (exprNode e)
8044 if (exprNode_isError (e))
8046 return cstring_undefined;
8054 ret = exprNode_rootVarName (exprData_getUopNode (data));
8057 ret = exprNode_rootVarName (exprData_getOpA (data));
8061 ret = exprData_getId (data);
8086 case XPR_NULLRETURN:
8109 case XPR_STRINGLITERAL:
8110 ret = cstring_undefined;
8118 static /*@only@*/ cstring exprNode_doUnparse (exprNode e)
8123 if (exprNode_isError (e))
8125 static /*@only@*/ cstring error = cstring_undefined;
8127 if (!cstring_isDefined (error))
8129 error = cstring_makeLiteral ("<error>");
8140 ret = message ("(%s)", exprNode_unparse (exprData_getUopNode (e->edata)));
8143 ret = message ("%s %s %s",
8144 exprNode_unparse (exprData_getOpA (data)),
8145 lltok_unparse (exprData_getOpTok (data)),
8146 exprNode_unparse (exprData_getOpB (data)));
8149 ret = message ("%s(%q)",
8150 exprNode_unparse (exprData_getFcn (data)),
8151 exprNodeList_unparse (exprData_getArgs (data)));
8154 ret = message ("{ %q }", exprNodeList_unparse (exprData_getArgs (data)));
8157 ret = cstring_undefined;
8160 ret = message ("%s:", exprData_getId (data));
8164 ret = cstring_copy (exprData_getId (data));
8167 ret = message ("%s[%s]", exprNode_unparse (exprData_getPairA (data)),
8168 exprNode_unparse (exprData_getPairB (data)));
8171 ret = message ("<body>");
8174 ret = message ("%s %s %s",
8175 exprNode_unparse (exprData_getOpA (data)),
8176 lltok_unparse (exprData_getOpTok (data)),
8177 exprNode_unparse (exprData_getOpB (data)));
8181 ret = message ("%s%s",
8182 lltok_unparse (exprData_getUopTok (data)),
8183 exprNode_unparse (exprData_getUopNode (data)));
8187 ret = message ("%s%s",
8188 exprNode_unparse (exprData_getUopNode (data)),
8189 lltok_unparse (exprData_getUopTok (data)));
8193 ret = message ("offsetof(%s,%q)",
8194 ctype_unparse (qtype_getType (exprData_getOffsetType (data))),
8195 cstringList_unparseSep (exprData_getOffsetName (data), cstring_makeLiteralTemp (".")));
8199 ret = message ("sizeof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8203 ret = message ("sizeof(%s)", exprNode_unparse (exprData_getSingle (data)));
8207 ret = message ("alignof(%s)", ctype_unparse (qtype_getType (exprData_getType (data))));
8211 ret = message ("alignof(%s)", exprNode_unparse (exprData_getSingle (data)));
8215 ret = message ("va_arg(%s, %q)",
8216 exprNode_unparse (exprData_getCastNode (data)),
8217 qtype_unparse (exprData_getCastType (data)));
8221 ret = message ("%q(%q)",
8222 uentry_getName (exprData_getIterCallIter (data)),
8223 exprNodeList_unparse (exprData_getIterCallArgs (data)));
8226 ret = message ("%q(%q) %s %q",
8227 uentry_getName (exprData_getIterSname (data)),
8228 exprNodeList_unparse (exprData_getIterAlist (data)),
8229 exprNode_unparse (exprData_getIterBody (data)),
8230 uentry_getName (exprData_getIterEname (data)));
8233 ret = message ("(%q)%s",
8234 qtype_unparse (exprData_getCastType (data)),
8235 exprNode_unparse (exprData_getCastNode (data)));
8239 ret = message ("%s %s",
8240 exprNode_unparse (exprData_getPairA (data)),
8241 exprNode_unparse (exprData_getPairB (data)));
8245 ret = message ("for (%s; %s; %s)",
8246 exprNode_unparse (exprData_getTripleInit (data)),
8247 exprNode_unparse (exprData_getTripleTest (data)),
8248 exprNode_unparse (exprData_getTripleInc (data)));
8252 ret = message ("goto %s", exprData_getLiteral (data));
8256 ret = cstring_makeLiteral ("continue");
8260 ret = cstring_makeLiteral ("break");
8264 ret = message ("return %s", exprNode_unparse (exprData_getSingle (data)));
8267 case XPR_NULLRETURN:
8268 ret = cstring_makeLiteral ("return");
8272 ret = message ("%s, %s",
8273 exprNode_unparse (exprData_getPairA (data)),
8274 exprNode_unparse (exprData_getPairB (data)));
8278 ret = message ("%s ? %s : %s",
8279 exprNode_unparse (exprData_getTriplePred (data)),
8280 exprNode_unparse (exprData_getTripleTrue (data)),
8281 exprNode_unparse (exprData_getTripleFalse (data)));
8284 ret = message ("if (%s) %s",
8285 exprNode_unparse (exprData_getPairA (data)),
8286 exprNode_unparse (exprData_getPairB (data)));
8290 ret = message ("if (%s) %s else %s",
8291 exprNode_unparse (exprData_getTriplePred (data)),
8292 exprNode_unparse (exprData_getTripleTrue (data)),
8293 exprNode_unparse (exprData_getTripleFalse (data)));
8296 ret = message ("while (%s) %s",
8297 exprNode_unparse (exprData_getPairA (data)),
8298 exprNode_unparse (exprData_getPairB (data)));
8302 ret = cstring_copy (exprNode_unparse (exprData_getSingle (data)));
8306 ret = cstring_copy (lltok_unparse (exprData_getTok (data)));
8310 ret = message ("do { %s } while (%s)",
8311 exprNode_unparse (exprData_getPairB (data)),
8312 exprNode_unparse (exprData_getPairA (data)));
8316 ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
8320 ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
8324 ret = message ("%s; %s",
8325 exprNode_unparse (exprData_getPairA (data)),
8326 exprNode_unparse (exprData_getPairB (data)));
8331 ret = cstring_makeLiteral ("default:");
8335 ret = message ("switch (%s) %s",
8336 exprNode_unparse (exprData_getPairA (data)),
8337 exprNode_unparse (exprData_getPairB (data)));
8342 ret = message ("case %s:",
8343 exprNode_unparse (exprData_getSingle (data)));
8347 ret = message ("%s = %s",
8348 idDecl_getName (exprData_getInitId (data)),
8349 exprNode_unparse (exprData_getInitNode (data)));
8353 ret = message ("%s.%s",
8354 exprNode_unparse (exprData_getFieldNode (data)),
8355 exprData_getFieldName (data));
8359 ret = message ("%s->%s",
8360 exprNode_unparse (exprData_getFieldNode (data)),
8361 exprData_getFieldName (data));
8364 case XPR_STRINGLITERAL:
8365 ret = cstring_copy (exprData_getLiteral (data));
8369 ret = cstring_copy (exprData_getLiteral (data));
8373 ret = cstring_makeLiteral ("<node>");
8381 exprNode_isCharLit (exprNode e)
8383 if (exprNode_isDefined (e))
8385 return (multiVal_isChar (exprNode_getValue (e)));
8394 exprNode_isNumLit (exprNode e)
8396 if (exprNode_isDefined (e))
8398 return (multiVal_isInt (exprNode_getValue (e)));
8407 exprNode_isFalseConstant (exprNode e)
8409 if (exprNode_isDefined (e))
8411 cstring s = exprNode_rootVarName (e);
8413 if (cstring_equal (s, context_getFalseName ()))
8423 exprNode_matchLiteral (ctype expected, exprNode e)
8425 if (exprNode_isDefined (e))
8427 multiVal m = exprNode_getValue (e);
8429 if (multiVal_isDefined (m))
8431 if (multiVal_isInt (m))
8433 long int val = multiVal_forceInt (m);
8435 if (ctype_isDirectBool (ctype_realishType (expected)))
8439 return FALSE; /* really?! return TRUE; allow use of 0 for FALSE */
8447 if (ctype_isRealInt (expected))
8450 ** unsigned <- [ constant >= 0 is okay ]
8453 if (ctype_isUnsigned (expected))
8462 ** No checks on sizes of integers...maybe add
8466 DPRINTF (("Here: %s => %s", exprNode_unparse (e), ctype_unparse (expected)));
8467 DPRINTF (("Type: %s / %s", ctype_unparse (exprNode_getType (e)),
8468 bool_unparse (ctype_isInt (exprNode_getType (e)))));
8470 if (context_getFlag (FLG_NUMLITERAL)
8471 && (ctype_isRegularInt (exprNode_getType (e)) || val == 0)) {
8477 return FALSE; /* evs 2000-05-17: previously, always returned TRUE */
8481 else if (ctype_isChar (expected))
8485 else if (ctype_isArrayPtr (expected))
8489 else if (ctype_isAnyFloat (expected))
8491 return (context_getFlag (FLG_NUMLITERAL));
8498 else if (multiVal_isDouble (m))
8500 if (ctype_isAnyFloat (expected))
8505 else if (multiVal_isChar (m))
8507 char val = multiVal_forceChar (m);
8509 if (ctype_isChar (expected))
8511 if (ctype_isUnsigned (expected) && ((int)val) < 0)
8532 exprNode_matchType (ctype expected, exprNode e)
8536 if (!exprNode_isDefined (e)) return TRUE;
8538 actual = ctype_realishType (exprNode_getType (e));
8540 if (ctype_match (ctype_realishType (expected), actual))
8545 llassert (!exprNode_isError (e));
8546 return (exprNode_matchLiteral (expected, e));
8550 exprNode_matchTypes (exprNode e1, exprNode e2)
8555 if (!exprNode_isDefined (e1)) return TRUE;
8556 if (!exprNode_isDefined (e2)) return TRUE;
8559 ** realish type --- keep bools, bools
8562 t1 = ctype_realishType (exprNode_getType (e1));
8563 t2 = ctype_realishType (exprNode_getType (e2));
8565 if (ctype_match (t1, t2))
8570 return (exprNode_matchLiteral (t1, e2) || exprNode_matchLiteral (t2, e1));
8578 exprNode_matchArgType (ctype ct, exprNode e)
8582 if (!exprNode_isDefined (e))
8587 et = ctype_realType (exprNode_getType (e));
8589 if (ctype_matchArg (ct, et)) return TRUE;
8591 llassert (!exprNode_isError (e));
8592 return (exprNode_matchLiteral (ct, e));
8595 static /*@only@*/ exprNodeSList
8596 exprNode_flatten (/*@dependent@*/ exprNode e) /*@*/
8598 if (exprNode_isDefined (e))
8600 if (e->kind == XPR_STMTLIST)
8602 return (exprNodeSList_append
8603 (exprNode_flatten (exprData_getPairA (e->edata)),
8604 exprNode_flatten (exprData_getPairB (e->edata))));
8606 else if (e->kind == XPR_BLOCK)
8608 return (exprNode_flatten (exprData_getSingle (e->edata)));
8612 return (exprNodeSList_singleton (e));
8616 return exprNodeSList_new ();
8619 static /*@exposed@*/ exprNode
8620 exprNode_lastStatement (/*@returned@*/ exprNode e)
8622 if (exprNode_isDefined (e))
8624 if (e->kind == XPR_STMTLIST)
8626 exprNode b = exprData_getPairB (e->edata);
8628 if (exprNode_isDefined (b))
8630 return exprNode_lastStatement (b);
8634 return exprNode_lastStatement (exprData_getPairA (e->edata));
8637 else if (e->kind == XPR_BLOCK)
8639 return (exprNode_lastStatement (exprData_getSingle (e->edata)));
8647 return exprNode_undefined;
8650 static /*@exposed@*/ exprNode
8651 exprNode_firstStatement (/*@returned@*/ exprNode e)
8653 if (exprNode_isDefined (e))
8655 if (e->kind == XPR_STMTLIST)
8657 exprNode b = exprData_getPairA (e->edata);
8659 if (exprNode_isDefined (b))
8661 return exprNode_firstStatement (b);
8665 return exprNode_firstStatement (exprData_getPairB (e->edata));
8668 else if (e->kind == XPR_BLOCK)
8670 return (exprNode_firstStatement (exprData_getSingle (e->edata)));
8678 return exprNode_undefined;
8682 exprNode_mergeUSs (exprNode res, exprNode other)
8684 if (exprNode_isDefined (res) && exprNode_isDefined (other))
8686 res->msets = sRefSet_union (res->msets, other->msets);
8687 res->sets = sRefSet_union (res->sets, other->sets);
8688 res->uses = sRefSet_union (res->uses, other->uses);
8693 exprNode_mergeCondUSs (exprNode res, exprNode other1, exprNode other2)
8695 if (exprNode_isDefined (res))
8697 if (exprNode_isDefined (other1))
8699 res->sets = sRefSet_union (res->sets, other1->sets);
8700 res->msets = sRefSet_union (res->msets, other1->msets);
8701 res->uses = sRefSet_union (res->uses, other1->uses);
8703 if (exprNode_isDefined (other2))
8705 res->sets = sRefSet_union (res->sets, other2->sets);
8706 res->msets = sRefSet_union (res->msets, other2->msets);
8707 res->uses = sRefSet_union (res->uses, other2->uses);
8715 ** Reports errors is s is not defined.
8719 exprNode_addUse (exprNode e, sRef s)
8721 if (exprNode_isDefined (e))
8723 e->uses = sRefSet_insert (e->uses, s);
8728 exprNode_checkUse (exprNode e, sRef s, fileloc loc)
8730 if (sRef_isKnown (s) && !sRef_isConst (s))
8733 ** need to check all outer types are useable
8736 DPRINTF (("Check use: %s / %s",
8737 exprNode_unparse (e), sRef_unparse (s)));
8739 exprNode_addUse (e, s);
8741 if (!context_inProtectVars ())
8744 ** only report the deepest error
8747 sRef errorRef = sRef_undefined;
8748 sRef lastRef = sRef_undefined;
8749 bool deadRef = FALSE;
8750 bool unuseable = FALSE;
8751 bool errorMaybe = FALSE;
8753 while (sRef_isValid (s) && sRef_isKnown (s))
8755 ynm readable = sRef_isReadable (s);
8757 if (!(ynm_toBoolStrict (readable)))
8759 if (ynm_isMaybe (readable))
8763 deadRef = sRef_isPossiblyDead (errorRef);
8764 unuseable = sRef_isUnuseable (errorRef);
8771 deadRef = sRef_isDead (errorRef);
8772 unuseable = sRef_isUnuseable (errorRef);
8776 if (!sRef_isPartial (s))
8778 sRef_setDefined (s, fileloc_undefined);
8782 s = sRef_getBaseSafe (s);
8785 if (sRef_isValid (errorRef))
8787 if (sRef_isValid (lastRef) && sRef_isField (lastRef)
8788 && sRef_isPointer (errorRef))
8795 if (sRef_isThroughArrayFetch (errorRef))
8798 (FLG_STRICTUSERELEASED,
8799 message ("%q %q may be used after being released",
8800 sRef_unparseKindNamePlain (errorRef),
8801 sRef_unparse (errorRef)),
8804 sRef_showRefKilled (errorRef);
8806 if (sRef_isKept (errorRef))
8808 sRef_clearAliasState (errorRef, loc);
8814 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8818 message ("%q %q %qused after being released",
8819 sRef_unparseKindNamePlain (errorRef),
8820 sRef_unparse (errorRef),
8821 cstring_makeLiteral (errorMaybe
8825 sRef_showRefKilled (errorRef);
8827 if (sRef_isKept (errorRef))
8829 sRef_clearAliasState (errorRef, loc);
8838 message ("%q %q%qused in inconsistent state",
8839 sRef_unparseKindName (errorRef),
8840 sRef_unparseOpt (errorRef),
8841 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8844 sRef_showStateInconsistent (errorRef);
8849 DPRINTF (("HERE: %s", sRef_unparse (errorRef)));
8853 message ("%q %q%qused before definition",
8854 sRef_unparseKindName (errorRef),
8855 sRef_unparseOpt (errorRef),
8856 cstring_makeLiteral (errorMaybe ? "may be " : "")),
8860 sRef_setDefined (errorRef, loc);
8862 if (sRef_isAddress (errorRef))
8864 sRef_setDefined (sRef_getRootBase (errorRef), loc);
8866 } /* end is error */
8874 checkSafeUse (exprNode e, sRef s)
8876 if (exprNode_isDefined (e) && sRef_isKnown (s))
8878 e->uses = sRefSet_insert (e->uses, s);
8883 exprNode_checkSetAny (exprNode e, /*@dependent@*/ cstring name)
8885 if (exprNode_isDefined (e))
8887 e->sets = sRefSet_insert (e->sets, sRef_makeUnconstrained (name));
8892 exprNode_checkSet (exprNode e, sRef s)
8894 sRef defines = sRef_undefined;
8896 if (sRef_isValid (s) && !sRef_isNothing (s))
8898 uentry ue = sRef_getBaseUentry (s);
8900 if (uentry_isValid (ue))
8902 uentry_setLset (ue);
8905 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
8907 voptgenerror (FLG_USEDEF,
8908 message ("Attempt to set unuseable storage: %q",
8913 if (sRef_isMeaningful (s))
8916 if (sRef_isDead (s))
8918 sRef base = sRef_getBaseSafe (s);
8920 if (sRef_isValid (base)
8921 && sRef_isDead (base))
8923 sRef_setPartial (s, exprNode_loc (e));
8926 defines = s; /* okay - modifies for only param */
8928 else if (sRef_isPartial (s))
8930 sRef eref = exprNode_getSref (e);
8932 if (!sRef_isPartial (eref))
8935 ** should do something different here???
8938 sRef_setDefinedComplete (eref, exprNode_loc (e));
8942 sRef_setPartialDefinedComplete (eref, exprNode_loc (e));
8945 if (sRef_isMeaningful (eref))
8954 else if (sRef_isAllocated (s))
8956 sRef eref = exprNode_getSref (e);
8959 if (!sRef_isAllocated (eref))
8961 sRef_setDefinedComplete (eref, exprNode_loc (e));
8965 sRef base = sRef_getBaseSafe (eref);
8967 if (sRef_isValid (base))
8969 sRef_setPdefined (base, exprNode_loc (e));
8977 sRef_setDefinedNCComplete (s, exprNode_loc (e));
8982 else /* not meaningful...but still need to insert it */
8988 if (exprNode_isDefined (e) && sRef_isValid (defines))
8990 e->sets = sRefSet_insert (e->sets, defines);
8995 exprNode_checkMSet (exprNode e, sRef s)
8997 if (sRef_isValid (s) && !sRef_isNothing (s))
8999 uentry ue = sRef_getBaseUentry (s);
9001 if (uentry_isValid (ue))
9003 uentry_setLset (ue);
9006 if (!ynm_toBoolStrict (sRef_isWriteable (s)))
9008 voptgenerror (FLG_USEDEF,
9009 message ("Attempt to set unuseable storage: %q", sRef_unparse (s)),
9013 if (sRef_isMeaningful (s))
9015 sRef_setDefinedComplete (s, exprNode_loc (e));
9018 if (exprNode_isDefined (e))
9020 e->msets = sRefSet_insert (e->msets, s);
9026 checkUnspecCall (/*@notnull@*/ /*@dependent@*/ exprNode fcn, uentryList params, exprNodeList args)
9028 checkAnyCall (fcn, cstring_undefined, params, args,
9029 FALSE, sRefSet_undefined, FALSE, 0);
9033 checkOneArg (uentry ucurrent, /*@notnull@*/ exprNode current,
9034 /*@dependent@*/ exprNode fcn, bool isSpec, int argno, int totargs)
9038 if (uentry_isYield (ucurrent))
9040 sRef_setDefined (exprNode_getSref (current), exprNode_loc (current));
9041 exprNode_checkSet (current, current->sref);
9045 if (uentry_isSefParam (ucurrent))
9047 sRefSet sets = current->sets;
9048 sRef ref = exprNode_getSref (current);
9050 if (sRef_isMacroParamRef (ref))
9052 uentry ue = sRef_getUentry (ref);
9054 if (!uentry_isSefParam (ue))
9059 ("Parameter %d to %s is declared sef, but "
9060 "the argument is a macro parameter declared "
9062 argno, exprNode_unparse (fcn),
9063 exprNode_unparse (current)),
9064 exprNode_loc (current));
9068 if (!sRefSet_isEmpty (sets))
9070 sRefSet reported = sRefSet_undefined;
9072 sRefSet_realElements (current->sets, el)
9074 if (sRefSet_isSameNameMember (reported, el))
9076 ; /* don't report again */
9080 if (sRef_isUnconstrained (el))
9085 ("Parameter %d to %s is declared sef, but "
9086 "the argument calls unconstrained function %s "
9087 "(no guarantee it will not modify something): %s",
9088 argno, exprNode_unparse (fcn),
9089 sRef_unconstrainedName (el),
9090 exprNode_unparse (current)),
9091 exprNode_loc (current));
9098 ("Parameter %d to %s is declared sef, but "
9099 "the argument may modify %q: %s",
9100 argno, exprNode_unparse (fcn),
9102 exprNode_unparse (current)),
9103 exprNode_loc (current));
9106 } end_sRefSet_realElements;
9110 checkPassTransfer (current, ucurrent, isSpec, fcn, argno, totargs);
9111 exprNode_mergeUSs (fcn, current);
9116 checkAnyCall (/*@dependent@*/ exprNode fcn,
9117 /*@dependent@*/ cstring fname,
9120 bool hasMods, sRefSet mods,
9125 int nargs = exprNodeList_size (args);
9130 ** concat all args ud's to f, add each arg sref as a use unless
9131 ** it was specified as "out", in which case it is a def.
9134 uentryList_reset (pn);
9139 ** if paramn is only or unique, no other arg may alias argn
9142 exprNodeList_elements (args, current)
9146 if (exprNode_isDefined (current))
9148 if ((!uentryList_isUndefined (pn) && !uentryList_isFinished (pn)))
9150 uentry ucurrent = uentryList_current (pn);
9152 if (specialArgs == 0
9153 || (paramno < specialArgs))
9155 checkOneArg (ucurrent, current, fcn, isSpec, paramno, nargs);
9157 if (context_maybeSet (FLG_ALIASUNIQUE))
9159 if (uentry_isOnly (ucurrent)
9160 || uentry_isUnique (ucurrent))
9162 checkUniqueParams (fcn, current, args,
9168 else /* uentry is undefined */
9170 if (specialArgs == 0)
9172 exprNode_checkUseParam (current);
9175 exprNode_mergeUSs (fcn, current);
9178 uentryList_advanceSafe (pn);
9179 } end_exprNodeList_elements;
9185 sRefSet_allElements (mods, s)
9188 sRef rb = sRef_getRootBase (s);
9190 if (sRef_isGlobal (rb))
9192 context_usedGlobal (rb);
9195 fb = sRef_fixBaseParam (s, args);
9197 if (!sRef_isMacroParamRef (fb))
9199 if (sRef_isNothing (fb))
9205 if (sRef_isValid (fb))
9207 uentry ue = sRef_getBaseUentry (s);
9209 if (uentry_isValid (ue))
9211 uentry_setLset (ue);
9215 fcn->sets = sRefSet_insert (fcn->sets, fb);
9218 sRef_clearDerivedComplete (s);
9219 } end_sRefSet_allElements;
9225 if (context_hasMods ())
9227 if (context_maybeSet (FLG_MODUNCON))
9231 message ("Undetected modification possible "
9232 "from call to unconstrained function %s: %s",
9234 exprNode_unparse (fcn)),
9235 exprNode_loc (fcn));
9240 if (context_maybeSet (FLG_MODUNCONNOMODS)
9241 && !(context_inIterDef () || context_inIterEnd ()))
9244 (FLG_MODUNCONNOMODS,
9245 message ("Undetected modification possible "
9246 "from call to unconstrained function %s: %s",
9248 exprNode_unparse (fcn)),
9249 exprNode_loc (fcn));
9253 exprNode_checkSetAny (fcn, fname);
9257 void exprNode_checkUseParam (exprNode current)
9259 if (exprNode_isDefined (current))
9261 exprNode_checkUse (current, current->sref, current->loc);
9266 checkNumerics (ctype tr1, ctype tr2, ctype te1, ctype te2,
9267 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9272 if (!ctype_match (tr1, tr2))
9274 if ((ctype_isRealInt (tr1) || ctype_isReal (tr1)) &&
9275 (ctype_isRealInt (tr2) || ctype_isReal (tr2)))
9283 message ("Incompatible types for %s (%s, %s): %s %s %s",
9285 ctype_unparse (te1),
9286 ctype_unparse (te2),
9287 exprNode_unparse (e1), lltok_unparse (op),
9288 exprNode_unparse (e2)),
9291 ret = ctype_unknown;
9295 if (ctype_isForceRealNumeric (&tr1) && ctype_isForceRealNumeric (&tr2))
9297 ret = ctype_resolveNumerics (tr1, tr2);
9299 else if (!context_msgStrictOps ())
9301 if (ctype_isPointer (tr1))
9303 if (ctype_isPointer (tr2) && !exprNode_isNullValue (e2))
9307 else if (ctype_isInt (tr2))
9313 ret = ctype_unknown;
9316 else if (ctype_isPointer (tr2))
9318 if (ctype_isPointer (tr1))
9322 else if (ctype_isInt (tr1))
9328 ret = ctype_unknown;
9333 ret = ctype_resolveNumerics (tr1, tr2);
9338 int opid = lltok_getTok (op);
9339 bool comparop = (opid == EQ_OP || opid == NE_OP
9340 || opid == TLT || opid == TGT
9341 || opid == LE_OP || opid == GE_OP);
9343 if (!ctype_isNumeric (tr1) && !ctype_isNumeric (tr2))
9346 && ((ctype_isEnum (tr1) && ctype_isEnum (tr2))
9347 || (ctype_isBool (tr1) && ctype_isBool (tr2))
9348 || (ctype_isChar (tr1) && ctype_isChar (tr2))))
9354 if (ctype_sameName (te1, te2))
9358 message ("Operands of %s are non-numeric (%t): %s %s %s",
9359 lltok_unparse (op), te1,
9360 exprNode_unparse (e1), lltok_unparse (op),
9361 exprNode_unparse (e2)),
9368 message ("Operands of %s are non-numerics (%t, %t): %s %s %s",
9369 lltok_unparse (op), te1, te2,
9370 exprNode_unparse (e1), lltok_unparse (op),
9371 exprNode_unparse (e2)),
9376 else if (!ctype_isNumeric (tr1))
9380 message ("Right operand of %s is non-numeric (%t): %s %s %s",
9381 lltok_unparse (op), te1,
9382 exprNode_unparse (e1), lltok_unparse (op),
9383 exprNode_unparse (e2)),
9388 if (!ctype_isNumeric (tr2))
9392 message ("Left operand of %s is non-numeric (%t): %s %s %s",
9393 lltok_unparse (op), te2,
9394 exprNode_unparse (e1), lltok_unparse (op),
9395 exprNode_unparse (e2)),
9400 ret = ctype_unknown;
9408 abstractOpError (ctype tr1, ctype tr2, lltok op,
9409 /*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2,
9410 fileloc loc1, fileloc loc2)
9412 if (ctype_isRealAbstract (tr1) && ctype_isRealAbstract (tr2))
9414 if (ctype_match (tr1, tr2))
9418 message ("Operands of %s are abstract type (%t): %s %s %s",
9419 lltok_unparse (op), tr1,
9420 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9427 message ("Operands of %s are abstract types (%t, %t): %s %s %s",
9428 lltok_unparse (op), tr1, tr2,
9429 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9433 else if (ctype_isRealAbstract (tr1))
9437 message ("Left operand of %s is abstract type (%t): %s %s %s",
9438 lltok_unparse (op), tr1,
9439 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9444 if (ctype_isRealAbstract (tr2))
9448 message ("Right operand of %s is abstract type (%t): %s %s %s",
9449 lltok_unparse (op), tr2,
9450 exprNode_unparse (e1), lltok_unparse (op), exprNode_unparse (e2)),
9459 ** requies e1 and e2 and not error exprNode's.
9463 ** If e1 is a component of an abstract type, and e2 is mutable and client-visible,
9464 ** the rep of the abstract type is exposed.
9466 ** The order is very important:
9468 ** check rep expose (move into check transfer)
9474 ** This isn't really a sensible procedure, but the indententation
9475 ** was getting too deep.
9479 checkOneRepExpose (sRef ysr, sRef base,
9480 /*@notnull@*/ exprNode e1,
9481 /*@notnull@*/ exprNode e2, ctype ct,
9484 if (!(sRef_isOnly (ysr) || sRef_isKeep (ysr)
9485 || sRef_isOwned (ysr) || sRef_isExposed (ysr)))
9487 if (sRef_isAnyParam (base) && !sRef_isExposed (base))
9489 if (sRef_isIReference (ysr))
9491 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9496 ("Assignment of mutable component of parameter %q "
9497 "to component of abstract "
9498 "type %s exposes rep: %s = %s",
9499 sRef_unparse (base),
9501 exprNode_unparse (e1), exprNode_unparse (e2)),
9509 ("Assignment of mutable component of parameter %q "
9510 "(through alias %q) to component of abstract "
9511 "type %s exposes rep: %s = %s",
9512 sRef_unparse (base),
9513 sRef_unparse (e2->sref),
9515 exprNode_unparse (e1), exprNode_unparse (e2)),
9521 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9525 message ("Assignment of mutable parameter %q "
9526 "to component of abstract type %s "
9527 "exposes rep: %s = %s",
9528 sRef_unparse (base),
9530 exprNode_unparse (e1),
9531 exprNode_unparse (e2)),
9538 message ("Assignment of mutable parameter %q "
9539 "(through alias %q) to "
9540 "component of abstract type %s exposes "
9542 sRef_unparse (base),
9543 sRef_unparse (e2->sref),
9545 exprNode_unparse (e1),
9546 exprNode_unparse (e2)),
9552 if (sRef_isGlobal (s2b))
9554 if (sRef_sameName (base, sRef_getRootBase (e2->sref)))
9558 message ("Assignment of global %q "
9560 "abstract type %s exposes rep: %s = %s",
9561 sRef_unparse (base),
9563 exprNode_unparse (e1), exprNode_unparse (e2)),
9570 message ("Assignment of global %q (through alias %q) "
9572 "abstract type %s exposes rep: %s = %s",
9573 sRef_unparse (base),
9574 sRef_unparse (e2->sref),
9576 exprNode_unparse (e1), exprNode_unparse (e2)),
9584 doAssign (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2, bool isInit)
9586 if (ctype_isRealFunction (exprNode_getType (e1))
9587 && !ctype_isRealPointer (exprNode_getType (e1)))
9591 message ("Invalid left-hand side of assignment (function type %s): %s",
9592 ctype_unparse (exprNode_getType (e1)),
9593 exprNode_unparse (e1)),
9597 if (context_getFlag (FLG_ASSIGNEXPOSE) && ctype_isMutable (e2->typ))
9599 ctype t2 = exprNode_getType (e2);
9600 sRef sr = sRef_getRootBase (e1->sref);
9601 ctype ct = sRef_getType (sr);
9603 if (ctype_isAbstract (t2)
9604 && !(uentry_isMutableDatatype (usymtab_getTypeEntry (ctype_typeId (t2)))))
9606 /* it is immutable, okay to reference */
9610 if (ctype_isAbstract (ct) && sRef_isIReference (e1->sref))
9612 sRef s2b = sRef_getRootBase (e2->sref);
9614 sRef s1b = sRef_getRootBase (s1);
9617 aliases = usymtab_canAlias (e2->sref);
9619 if (!sRef_similar (s2b, s1b)
9620 && !sRef_isExposed (s1)
9621 && !(sRef_isOnly (s2b) || sRef_isKeep (s2b) || sRef_isExposed (s2b)))
9623 if (sRef_isAnyParam (s2b) && !sRef_isOnly (s2b)
9624 && !sRef_isOwned (s2b) && !sRef_isKeep (s2b)
9625 && !sRef_isExposed (s2b))
9627 if (sRef_isIReference (e2->sref))
9632 ("Assignment of mutable component of parameter %q "
9633 "to component of abstract type %s exposes rep: %s = %s",
9636 exprNode_unparse (e1), exprNode_unparse (e2)),
9643 message ("Assignment of mutable parameter %q to "
9644 "component of abstract type %s exposes rep: %s = %s",
9647 exprNode_unparse (e1), exprNode_unparse (e2)),
9652 if (sRef_isGlobal (s2b))
9656 message ("Assignment of global %q to component of "
9657 "abstract type %s exposes rep: %s = %s",
9660 exprNode_unparse (e1), exprNode_unparse (e2)),
9664 sRefSet_realElements (aliases, ysr)
9666 sRef base = sRef_getRootBase (ysr);
9668 if (sRef_similar (ysr, s2b) || sRef_similar (s1b, base)
9669 || sRef_sameName (base, s1b))
9671 ; /* error already reported or same sref */
9675 checkOneRepExpose (ysr, base, e1, e2, ct, s2b);
9677 } end_sRefSet_realElements;
9679 sRefSet_free (aliases);
9686 ** function variables don't really work...
9689 if (!ctype_isFunction (ctype_realType (e2->typ)))
9693 checkInitTransfer (e1, e2);
9697 checkAssignTransfer (e1, e2);
9702 sRef fref = e2->sref;
9704 sRef_setDefState (e1->sref, sRef_getDefState (fref), e1->loc);
9705 sRef_setNullState (e1->sref, sRef_getNullState (fref), e1->loc);
9707 /* Need to typecheck the annotation on the parameters */
9709 if (ctype_isRealFunction (e1->typ)) {
9710 uentryList e1p = ctype_argsFunction (ctype_realType (e1->typ));
9711 uentryList e2p = ctype_argsFunction (ctype_realType (e2->typ));
9713 if (!uentryList_isMissingParams (e1p)
9714 && !uentryList_isMissingParams (e2p)
9715 && uentryList_size (e1p) > 0) {
9716 if (uentryList_size (e1p) == uentryList_size (e2p)) {
9719 uentryList_elements (e1p, el1) {
9722 el2 = uentryList_getN (e2p, n);
9724 uentry_checkMatchParam (el1, el2, n, e2);
9725 } end_uentryList_elements;
9731 if (isInit && sRef_isGlobal (e1->sref))
9737 updateAliases (e1, e2);
9739 updateEnvironment (e1, e2);
9743 checkMacroParen (exprNode e)
9745 if (exprNode_isError (e) || e->kind == XPR_CAST)
9751 if (sRef_isUnsafe (e->sref) && !exprNode_isInParens (e))
9755 message ("Macro parameter used without parentheses: %s",
9756 exprNode_unparse (e)),
9763 reflectNullTest (/*@notnull@*/ exprNode e, bool isnull)
9767 e->guards = guardSet_addTrueGuard (e->guards, e->sref);
9771 e->guards = guardSet_addFalseGuard (e->guards, e->sref);
9778 ** if e2 is a parameter or global derived location which
9779 ** can be modified (that is, e2 is a mutable abstract type,
9780 ** or a derived pointer), then e1 can alias e2.
9782 ** e1 can alias everything which e2 can alias.
9784 ** Also, if e1 is guarded, remove from guard sets!
9787 static void updateAliases (/*@notnull@*/ exprNode e1, /*@notnull@*/ exprNode e2)
9789 if (!context_inProtectVars ())
9792 ** depends on types of e1 and e2
9797 ctype t1 = exprNode_getType (e1);
9799 /* handle pointer sRefs, record fields, arrays, etc... */
9801 if (!ctype_isRealSU (t1))
9803 sRef_copyRealDerivedComplete (s1, s2);
9806 if (ctype_isMutable (t1) && sRef_isKnown (s1))
9808 usymtab_clearAlias (s1);
9809 usymtab_addMustAlias (s1, s2);
9812 if (sRef_possiblyNull (s1) && usymtab_isGuarded (s1))
9814 usymtab_unguard (s1);
9819 exprNode exprNode_updateLocation (/*@returned@*/ exprNode e, /*@temp@*/ fileloc loc)
9821 if (exprNode_isDefined (e))
9823 e->loc = fileloc_update (e->loc, loc);
9827 e = exprNode_createLoc (ctype_unknown, fileloc_copy (loc));
9833 static void checkUniqueParams (exprNode fcn,
9834 /*@notnull@*/ exprNode current,
9836 int paramno, uentry ucurrent)
9839 sRef thisref = exprNode_getSref (current);
9842 ** Check if any argument could match this argument.
9845 exprNodeList_elements (args, icurrent)
9849 if (iparamno != paramno)
9851 sRef sr = exprNode_getSref (icurrent);
9853 if (sRef_similarRelaxed (thisref, sr))
9855 if (!sRef_isConst (thisref) && !sRef_isConst (sr))
9860 ("Parameter %d (%s) to function %s is declared %s but "
9861 "is aliased by parameter %d (%s)",
9863 exprNode_unparse (current),
9864 exprNode_unparse (fcn),
9865 alkind_unparse (uentry_getAliasKind (ucurrent)),
9866 iparamno, exprNode_unparse (icurrent)),
9872 sRefSet aliases = usymtab_canAlias (sr);
9874 sRefSet_allElements (aliases, asr)
9876 if (ctype_isUnknown (sRef_getType (thisref)))
9878 sRef_setType (thisref, uentry_getType (ucurrent));
9881 if (sRef_similarRelaxed (thisref, asr))
9883 if (sRef_isExternal (asr))
9885 if (sRef_isLocalState (thisref))
9891 sRef base = sRef_getRootBase (asr);
9893 if (!sRef_similar (sRef_getBase (asr), thisref))
9895 if (sRef_isUnique (base) || sRef_isOnly (base)
9896 || sRef_isKept (base)
9897 || (sRef_isAddress (asr) && sRef_isLocalVar (base))
9898 || (sRef_isAddress (thisref)
9899 && sRef_isLocalVar (sRef_getRootBase (thisref))))
9901 ; /* okay, no error */
9906 (FLG_MAYALIASUNIQUE,
9908 ("Parameter %d (%s) to function %s is declared %s but "
9909 "may be aliased externally by parameter %d (%s)",
9911 exprNode_unparse (current),
9912 exprNode_unparse (fcn),
9913 alkind_unparse (uentry_getAliasKind (ucurrent)),
9914 iparamno, exprNode_unparse (icurrent)),
9925 ("Parameter %d (%s) to function %s is declared %s but "
9926 "is aliased externally by parameter %d (%s) through "
9929 exprNode_unparse (current),
9930 exprNode_unparse (fcn),
9931 alkind_unparse (uentry_getAliasKind (ucurrent)),
9932 iparamno, exprNode_unparse (icurrent),
9933 sRef_unparse (asr)),
9937 } end_sRefSet_allElements;
9938 sRefSet_free (aliases);
9941 } end_exprNodeList_elements;
9944 long exprNode_getLongValue (exprNode e) {
9947 if (exprNode_hasValue (e)
9948 && multiVal_isInt (exprNode_getValue (e)))
9950 value = multiVal_forceInt (exprNode_getValue (e));
9960 fileloc exprNode_getfileloc (exprNode p_e)
9963 return fileloc_copy ( p_e->loc );
9965 return fileloc_undefined;
9968 fileloc exprNode_getNextSequencePoint (exprNode e)
9971 ** Returns the location of the sequence point following e.
9973 ** Only works for statements (for now).
9976 if (exprNode_isDefined (e) && e->kind == XPR_STMT) {
9977 lltok t = exprData_getUopTok (e->edata);
9978 return lltok_getLoc (t);
9981 // llcontbug (message ("Cannot get next sequence point: %s", exprNode_unparse (e)));
9982 return fileloc_undefined;