2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
31 # include "lclintMacros.nf"
33 # include "cgrammar.h"
36 # include "usymtab_interface.h"
39 # include "structNames.h"
40 # include "nameChecks.h"
43 # include "sgrammar_tokens.h"
45 # include "cgrammar_tokens.h"
49 ** Lots of variables are needed because of interactions with the
50 ** parser. This is easier than restructuring the grammar so the
51 ** right values are available in the right place.
55 static /*@only@*/ constraintList implicitFcnConstraints = NULL;
58 //static constraintList fcnPreConditions = NULL;
60 static void clabstract_prepareFunction (uentry p_e) /*@modifies p_e@*/ ;
61 static bool fcnNoGlobals = FALSE;
62 static bool ProcessingVars = FALSE;
63 static bool ProcessingParams = FALSE;
64 static bool ProcessingGlobals = FALSE;
65 static bool ProcessingTypedef = FALSE;
66 static bool ProcessingIterVars = FALSE;
67 static /*@only@*/ qtype processingType = qtype_undefined;
68 static uentry currentIter = uentry_undefined;
69 static /*@dependent@*/ uentryList saveParamList; /* for old style functions */
70 static /*@owned@*/ uentry saveFunction = uentry_undefined;
71 static int saveIterParamNo;
72 static idDecl fixStructDecl (/*@returned@*/ idDecl p_d);
73 static void checkTypeDecl (uentry p_e, ctype p_rep);
74 static /*@dependent@*/ fileloc saveStoreLoc = fileloc_undefined;
75 static storageClassCode storageClass = SCNONE;
76 static void declareEnumList (/*@temp@*/ enumNameList p_el, ctype p_c, fileloc p_loc);
77 static void resetGlobals (void);
78 static /*@null@*/ qual specialFunctionCode;
79 static bool argsUsed = FALSE;
81 extern void clabstract_initMod ()
83 specialFunctionCode = qual_createUnknown ();
84 DPRINTF (("Initialized: %s", qual_unparse (specialFunctionCode)));
87 static bool hasSpecialCode (void)
89 return (!qual_isUnknown (specialFunctionCode));
92 extern void setArgsUsed (void)
98 cstring_makeLiteral ("Multiple ARGSUSED comments for one function"),
105 static void reflectArgsUsed (uentry ue)
109 if (uentry_isFunction (ue))
111 uentryList params = uentry_getParams (ue);
113 uentryList_elements (params, el)
115 uentry_setUsed (el, fileloc_undefined);
116 } end_uentryList_elements ;
123 extern void setSpecialFunction (qual qu)
125 if (!qual_isUnknown (specialFunctionCode))
127 voptgenerror (FLG_SYNTAX,
128 message ("Multiple special function codes: %s, %s "
129 "(first code is ignored)",
130 qual_unparse (specialFunctionCode),
135 specialFunctionCode = qu;
138 static void reflectSpecialCode (uentry ue)
140 if (qual_isUnknown (specialFunctionCode)) {
142 } else if (qual_isPrintfLike (specialFunctionCode)) {
143 uentry_setPrintfLike (ue);
144 } else if (qual_isScanfLike (specialFunctionCode)) {
145 uentry_setScanfLike (ue);
146 } else if (qual_isMessageLike (specialFunctionCode)) {
147 uentry_setMessageLike (ue);
152 specialFunctionCode = qual_createUnknown ();
155 static void resetStorageClass (void)
157 qtype_free (processingType);
158 processingType = qtype_undefined;
159 storageClass = SCNONE;
162 static void reflectStorageClass (uentry u)
164 if (storageClass == SCSTATIC)
166 uentry_setStatic (u);
168 else if (storageClass == SCEXTERN)
170 uentry_setExtern (u);
174 ; /* no storage class */
181 saveStoreLoc = g_currentloc;
184 void setFunctionNoGlobals (void)
189 static void reflectGlobalQualifiers (sRef sr, qualList quals)
191 DPRINTF (("Reflect global qualifiers: %s / %s",
192 sRef_unparseFull (sr), qualList_unparse (quals)));
194 qualList_elements (quals, qel)
196 if (qual_isGlobalQual (qel)) /* undef, killed */
198 sstate oldstate = sRef_getDefState (sr);
199 sstate defstate = sstate_fromQual (qel);
201 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
202 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
204 defstate = SS_UNDEFKILLED;
211 sRef_setDefState (sr, defstate, fileloc_undefined);
212 DPRINTF (("State: %s", sRef_unparseFull (sr)));
214 else if (qual_isAllocQual (qel)) /* out, partial, reldef, etc. */
216 ctype realType = sRef_getType (sr);
217 sstate defstate = sstate_fromQual (qel);
219 if (qual_isRelDef (qel))
221 ; /* okay anywhere */
225 if (!ctype_isAP (realType)
226 && !ctype_isSU (realType)
227 && !ctype_isUnknown (realType)
228 && !ctype_isAbstract (sRef_getType (sr)))
232 message ("Qualifier %s used on non-pointer or struct: %q",
233 qual_unparse (qel), sRef_unparse (sr)));
238 sRef_setDefState (sr, defstate, fileloc_undefined);
240 else if (qual_isNull (qel))
242 sRef_setNullState (sr, NS_POSNULL, fileloc_undefined);
244 else if (qual_isRelNull (qel))
246 sRef_setNullState (sr, NS_RELNULL, fileloc_undefined);
248 else if (qual_isNotNull (qel))
250 sRef_setNullState (sr, NS_MNOTNULL, fileloc_undefined);
254 if (qual_isCQual (qel))
261 message ("Qualifier %s cannot be used in a globals list",
262 qual_unparse (qel)));
265 } end_qualList_elements;
268 sRef clabstract_createGlobal (sRef sr, qualList quals)
272 if (sRef_isValid (sr))
274 res = sRef_copy (sr);
275 DPRINTF (("Reflecting quals: %s / %s", sRef_unparse (sr), qualList_unparse (quals)));
276 reflectGlobalQualifiers (res, quals);
277 DPRINTF (("==> %s", sRef_unparseFull (res)));
281 res = sRef_undefined;
284 qualList_free (quals);
288 extern void declareCIter (cstring name, /*@owned@*/ uentryList params)
292 ue = uentry_makeIter (name,
293 ctype_makeFunction (ctype_void, params),
294 fileloc_copy (g_currentloc));
296 usymtab_supEntry (uentry_makeEndIter (name, fileloc_copy (g_currentloc)));
297 ue = usymtab_supGlobalEntryReturn (ue);
300 extern void nextIterParam (void)
302 llassert (ProcessingIterVars);
306 extern int iterParamNo (void)
308 llassert (ProcessingIterVars);
309 return saveIterParamNo;
313 ** yucky hacks to put it in the right place
317 makeCurrentParam (idDecl t)
321 saveStoreLoc = fileloc_undefined;
323 /* param number unknown */
325 ue = uentry_makeParam (t, 0);
330 declareUnnamedEnum (enumNameList el)
332 ctype ret = usymtab_enumEnumNameListType (el);
336 if (ctype_isDefined (ret))
339 e = uentry_makeEnumTagLoc (ctype_enumTag (rt), ret);
341 reflectStorageClass (e);
342 usymtab_supGlobalEntry (e);
344 declareEnumList (el, ret, g_currentloc);
345 enumNameList_free (el);
349 ctype ct = ctype_createEnum (fakeTag (), el);
351 e = uentry_makeEnumTagLoc (ctype_enumTag (ctype_realType (ct)), ct);
352 reflectStorageClass (e);
354 e = usymtab_supGlobalEntryReturn (e);
355 rt = uentry_getAbstractType (e);
356 declareEnumList (el, ct, g_currentloc);
363 declareEnum (cstring ename, enumNameList el)
368 llassert (cstring_isDefined (ename));
370 cet = ctype_createEnum (ename, el);
371 e = uentry_makeEnumTagLoc (ename, cet);
372 reflectStorageClass (e);
373 e = usymtab_supGlobalEntryReturn (e);
374 cet = uentry_getType (e);
375 declareEnumList (el, cet, uentry_whereLast (e));
376 return (uentry_getAbstractType (e));
380 declareEnumList (enumNameList el, ctype c, fileloc loc)
382 bool boolnames = FALSE;
383 bool othernames = FALSE;
385 (void) context_getSaveLocation (); /* undefine it */
387 if (context_maybeSet (FLG_NUMENUMMEMBERS))
389 int maxnum = context_getValue (FLG_NUMENUMMEMBERS);
390 int num = enumNameList_size (el);
396 message ("Enumerator %s declared with %d members (limit is set to %d)",
397 ctype_unparse (c), num, maxnum),
402 enumNameList_elements (el, e)
404 uentry ue = usymtab_lookupExposeGlob (e);
405 ctype ct = uentry_getType (ue);
407 llassert (uentry_isEnumConstant (ue));
409 if (ctype_isUnknown (ct))
411 uentry_setType (ue, c);
415 if (cstring_equal (e, context_getFalseName ())
416 || cstring_equal (e, context_getTrueName ()))
422 message ("Enumerator mixes boolean name (%s) with "
425 uentry_whereLast (ue)))
432 uentry_setType (ue, ctype_bool);
433 DPRINTF (("Set type: %s / %s",
434 uentry_unparse (ue), ctype_unparse (ctype_bool)));
442 message ("Enumerator mixes boolean names (%s, %s) with "
443 "non-boolean name: %s",
444 context_getTrueName (),
445 context_getFalseName (),
447 uentry_whereLast (ue)))
456 if (!ctype_match (c, ct))
458 if (ctype_isDirectBool (ct))
460 if (cstring_equal (e, context_getFalseName ())
461 || cstring_equal (e, context_getTrueName ()))
463 DPRINTF (("Here we are!"));
469 message ("Enumerator member %s declared with "
470 "inconsistent type: %s",
471 e, ctype_unparse (c)),
472 uentry_whereLast (ue)))
474 uentry_showWhereSpecifiedExtra
475 (ue, cstring_copy (ctype_unparse (ct)));
483 message ("Enumerator member %s declared with "
484 "inconsistent type: %s",
485 e, ctype_unparse (c)),
486 uentry_whereLast (ue)))
488 uentry_showWhereSpecifiedExtra
489 (ue, cstring_copy (ctype_unparse (ct)));
494 } end_enumNameList_elements;
497 static /*@dependent@*/ uentryList currentParamList;
499 /*drl added 3-28-2001*/
500 /* this function takes a list of paramentar and generates a list
502 Currently the only constraints gnerated are MaxSet(p) >= 0 for all pointers
505 void setImplictfcnConstraints (void)
510 params = currentParamList;
512 if (constraintList_isDefined(implicitFcnConstraints) )
513 constraintList_free(implicitFcnConstraints);
515 implicitFcnConstraints = constraintList_makeNew();
517 uentryList_elements (params, el)
519 DPRINTF((message("setImplictfcnConstraints doing: %s", uentry_unparse(el) ) ));
521 s = uentry_getSref(el);
522 if (sRef_isReference (s) )
524 DPRINTF((message ("%s is a pointer", sRef_unparse(s) ) ));
528 DPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) ));
531 chagned this is MaxSet(s) == 0 to MaxSet(s) >= 0 */
533 c = constraint_makeSRefWriteSafeInt (s, 0);
534 // constraint_makeSRefSetBufferSize (s, 0);
535 implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c);
537 end_uentryList_elements;
541 /*@observer@*/ constraintList getImplicitFcnConstraints (void)
543 return implicitFcnConstraints;
546 void setCurrentParams (/*@dependent@*/ uentryList ue)
548 currentParamList = ue;
551 void clearCurrentParams (void)
553 currentParamList = uentryList_undefined;
557 ** requires: uentry_isFunction (e)
558 ** parameter names for current function are in currentParamList
561 static void enterFunctionParams (uentryList params)
565 uentryList_elements (params, current)
567 if (uentry_hasName (current))
569 uentry_setParamNo (current, paramno);
570 usymtab_supEntry (uentry_copy (current));
574 } end_uentryList_elements;
578 extern void enterParamsTemp (void)
580 usymtab_enterScope ();
581 enterFunctionParams (currentParamList);
584 extern void exitParamsTemp (void)
586 usymtab_quietPlainExitScope ();
589 static /*@exposed@*/ uentry clabstract_globalDeclareFunction (idDecl tid)
591 ctype deftype = idDecl_getCtype (tid);
595 DPRINTF (("Global function: %s", idDecl_unparse (tid)));
597 if (ctype_isFunction (deftype))
599 rettype = ctype_getReturnType (deftype);
603 rettype = ctype_unknown;
607 ** check has been moved here...
610 if (ctype_isFunction (idDecl_getCtype (tid)))
612 ue = uentry_makeIdFunction (tid);
613 reflectSpecialCode (ue);
614 reflectArgsUsed (ue);
618 llparseerror (message ("Inconsistent function declaration: %q",
619 idDecl_unparse (tid)));
621 tid = idDecl_replaceCtype
622 (tid, ctype_makeFunction (ctype_unknown, uentryList_undefined));
623 ue = uentry_makeIdFunction (tid);
626 reflectStorageClass (ue);
627 uentry_checkParams (ue);
629 DPRINTF (("Supercede function: %s", uentry_unparseFull (ue)));
631 ue = usymtab_supGlobalEntryReturn (ue);
632 DPRINTF (("After supercede function: %s", uentry_unparseFull (ue)));
634 DPRINTF (("Enter function: %s", uentry_unparseFull (ue)));
635 context_enterFunction (ue);
636 enterFunctionParams (uentry_getParams (ue));
638 resetStorageClass ();
639 DPRINTF (("Function: %s", uentry_unparseFull (ue)));
644 ** for now, no type checking
645 ** (must check later though!)
648 static /*@only@*/ uentry globalDeclareOldStyleFunction (idDecl tid)
653 ** check has been moved here...
656 if (cstring_equalLit (idDecl_observeId (tid), "main"))
658 context_setFlagTemp (FLG_MAINTYPE, FALSE);
661 ue = uentry_makeIdFunction (tid);
662 reflectStorageClass (ue);
663 reflectSpecialCode (ue);
664 reflectArgsUsed (ue);
665 uentry_setDefined (ue, g_currentloc);
666 uentry_checkParams (ue);
667 resetStorageClass ();
669 /* context_enterOldStyleScope (); */
674 static void oldStyleDeclareFunction (/*@only@*/ uentry e)
676 uentryList params = saveParamList;
677 ctype rt = uentry_getType (e);
679 llassert (ctype_isFunction (rt));
681 if (uentry_hasStateClauseList (e)
682 || uentry_hasConditions (e))
684 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
685 fileloc_unparse (g_currentloc), uentry_unparse (e)));
688 e = usymtab_supGlobalEntryReturn (e);
690 context_enterFunction (e);
691 enterFunctionParams (params);
692 saveParamList = uentryList_undefined;
693 resetStorageClass ();
696 static void oldStyleCompleteFunction (/*@only@*/ uentry e)
698 uentryList params = saveParamList;
699 ctype rt = uentry_getType (e);
701 llassert (ctype_isFunction (rt));
703 if (uentry_hasStateClauseList (e)
704 || uentry_hasConditions (e))
706 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
707 fileloc_unparse (g_currentloc), uentry_unparse (e)));
710 e = usymtab_supGlobalEntryReturn (e);
712 context_completeOldStyleFunction (e);
713 enterFunctionParams (params);
714 saveParamList = uentryList_undefined;
715 resetStorageClass ();
718 void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
722 DPRINTF (("Declare function: %s", idDecl_unparse (tid)));
724 if (ProcessingParams)
726 ue = globalDeclareOldStyleFunction (tid);
728 DPRINTF (("Set save function: %s", uentry_unparseFull (ue)));
732 saveFunction = uentry_undefined;
734 if (context_inRealFunction ())
736 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
738 llparseerror (message ("Function declared inside function: %q",
739 idDecl_unparse (tid)));
741 context_quietExitFunction ();
742 ue = usymtab_supEntryReturn (ue);
746 if (context_inInnerScope ())
748 llparseerror (message ("Declaration in inner context: %q",
749 idDecl_unparse (tid)));
751 sRef_setGlobalScope ();
752 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
754 ue = usymtab_supGlobalEntryReturn (ue);
755 sRef_clearGlobalScope ();
759 ue = clabstract_globalDeclareFunction (tid);
766 resetStorageClass ();
770 void declareStaticFunction (idDecl tid) /*@globals undef saveFunction; @*/
774 DPRINTF (("Declare static funciton: %s", idDecl_unparse (tid)));
776 if (ProcessingParams)
778 ue = globalDeclareOldStyleFunction (tid);
783 saveFunction = uentry_undefined;
785 if (context_inRealFunction ())
787 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
789 llparseerror (message ("Function declared inside function: %q",
790 idDecl_unparse (tid)));
792 context_quietExitFunction ();
793 ue = usymtab_supEntryReturn (ue);
797 if (context_inInnerScope ())
799 llparseerror (message ("Declaration in inner context: %q",
800 idDecl_unparse (tid)));
802 sRef_setGlobalScope ();
803 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
805 ue = usymtab_supGlobalEntryReturn (ue);
806 sRef_clearGlobalScope ();
810 ctype deftype = idDecl_getCtype (tid);
813 if (ctype_isFunction (deftype))
815 rettype = ctype_getReturnType (deftype);
819 rettype = ctype_unknown;
823 ** check has been moved here...
826 if (ctype_isFunction (idDecl_getCtype (tid)))
828 ue = uentry_makeIdFunction (tid);
829 reflectSpecialCode (ue);
830 reflectArgsUsed (ue);
834 llparseerror (message ("Inconsistent function declaration: %q",
835 idDecl_unparse (tid)));
837 tid = idDecl_replaceCtype
838 (tid, ctype_makeFunction (ctype_unknown, uentryList_undefined));
839 ue = uentry_makeIdFunction (tid);
842 reflectStorageClass (ue);
843 uentry_setStatic (ue);
845 uentry_checkParams (ue);
847 DPRINTF (("Sub global entry: %s", uentry_unparse (ue)));
848 ue = usymtab_supGlobalEntryReturn (ue);
850 context_enterFunction (ue);
851 enterFunctionParams (uentry_getParams (ue));
852 resetStorageClass ();
859 resetStorageClass ();
864 checkTypeDecl (uentry e, ctype rep)
866 cstring n = uentry_getName (e);
868 DPRINTF (("Check type decl: %s", uentry_unparseFull (e)));
870 if (cstring_equal (context_getBoolName (), n))
872 ctype rrep = ctype_realType (rep);
875 ** for abstract enum types, we need to fix the enum members:
876 ** they should have the abstract type, not the rep type.
879 if (ctype_isEnum (ctype_realType (rrep)))
881 enumNameList el = ctype_elist (rrep);
883 enumNameList_elements (el, ye)
885 if (usymtab_existsGlob (ye))
887 uentry ue = usymtab_lookupSafe (ye);
888 uentry_setType (ue, ctype_bool);
891 if (cstring_equal (context_getTrueName (), ye)
892 || cstring_equal (context_getFalseName (), ye))
900 message ("Member of boolean enumerated type definition "
901 "does not match name set to represent TRUE "
904 message ("Use -boolfalse and -booltrue to set the "
905 "name of false and true boolean values."),
906 uentry_whereDefined (e));
908 } end_enumNameList_elements;
912 if (usymtab_exists (n))
914 usymId llm = usymtab_getId (n);
915 uentry le = usymtab_getTypeEntry (llm);
917 uentry_setDeclared (e, g_currentloc);
918 uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le), stateInfo_currentLoc ()));
920 DPRINTF (("Here we are: %s / %s",
921 n, context_getBoolName ()));
923 if (uentry_isAbstractDatatype (le))
925 ctype rrep = ctype_realType (rep);
927 DPRINTF (("Abstract type: %s", uentry_unparseFull (le)));
930 ** for abstract enum types, we need to fix the enum members:
931 ** they should have the abstract type, not the rep type.
934 if (ctype_isEnum (ctype_realType (rrep)))
936 ctype at = uentry_getAbstractType (le);
937 enumNameList el = ctype_elist (rrep);
939 enumNameList_elements (el, ye)
941 if (usymtab_existsGlob (ye))
943 uentry ue = usymtab_lookupSafe (ye);
945 llassert (uentry_isEitherConstant (ue));
946 llassertprint (ctype_match (uentry_getType (ue), rrep),
947 ("Bad enum: %s / %s",
949 ctype_unparse (rrep)));
951 uentry_setType (ue, at);
953 } end_enumNameList_elements;
956 if (uentry_isMutableDatatype (le))
958 /* maybe more complicated if abstract and immutable ? */
960 if (!ctype_isRealPointer (rep) && !ctype_isRealAbstract (rep))
964 message ("Mutable abstract type %s declared without pointer "
965 "indirection: %s (violates assignment semantics)",
966 n, ctype_unparse (rep)),
967 uentry_whereDefined (e));
969 uentry_setMutable (e);
976 fileloc fl = uentry_whereDeclared (e);
978 if (context_getFlag (FLG_LIKELYBOOL)
979 && !context_getFlag (FLG_BOOLINT))
981 if ((cstring_equalLit (n, "BOOL")
982 || cstring_equalLit (n, "Bool")
983 || cstring_equalLit (n, "bool")
984 || cstring_equalLit (n, "boolean")
985 || cstring_equalLit (n, "Boolean")
986 || cstring_equalLit (n, "BOOLEAN"))
987 && !(cstring_equal (n, context_getBoolName ())))
989 if (context_setBoolName ()) {
992 message ("Type %s is probably meant as a boolean type, but does "
993 "not match the boolean type name \"%s\".",
995 context_getBoolName ()),
1000 message ("Type %s is probably meant as a boolean type, "
1001 "but the boolean type name is not set. "
1002 "Use -booltype %s to set it.",
1009 if (!uentry_isStatic (e)
1010 && !ctype_isFunction (uentry_getType (e))
1011 && !fileloc_isLib (fl)
1012 && !fileloc_isImport (fl)
1013 && fileloc_isHeader (fl))
1015 voptgenerror (FLG_EXPORTTYPE,
1016 message ("Type exported, but not specified: %s\n", n),
1025 fixUentryList (idDeclList tl, qtype q)
1027 uentryList f = uentryList_new ();
1029 idDeclList_elements (tl, i)
1031 if (idDecl_isDefined (i))
1037 (void) idDecl_fixBase (i, q);
1040 ** implicit annotations
1043 (void) fixStructDecl (i);
1045 ue = uentry_makeIdVariable (i);
1046 rt = ctype_realType (uentry_getType (ue));
1049 ** where is this here???
1051 if (ctype_isArray (rt) || ctype_isSU (rt))
1053 sRef_setAllocated (uentry_getSref (ue), uentry_whereDefined (ue));
1059 if (uentry_isValid (old = uentryList_lookupField (f, uentry_rawName (ue))))
1061 if (optgenerror (FLG_SYNTAX,
1062 message ("Field name reused: %s", uentry_rawName (ue)),
1063 uentry_whereDefined (ue)))
1065 llgenmsg (message ("Previous use of %s", uentry_rawName (ue)),
1066 uentry_whereDefined (old));
1070 f = uentryList_add (f, ue);
1072 } end_idDeclList_elements;
1074 idDeclList_free (tl);
1079 ** This is a hack to support unnamed struct/union fields as done by
1080 ** Microsoft VC++. It is not supported by the ANSI standard.
1082 ** The inner fields are added to the outer structure. This is meaningful
1083 ** for nesting structs inside unions, but lclint does no related
1088 fixUnnamedDecl (qtype q)
1090 ctype ct = ctype_realType (qtype_getType (q));
1092 if (ctype_isStruct (ct) || ctype_isUnion (ct))
1094 uentryList res = ctype_getFields (ct);
1096 return (uentryList_copy (res));
1103 return uentryList_undefined;
1106 void setStorageClass (storageClassCode sc)
1112 setProcessingIterVars (uentry iter)
1114 ProcessingIterVars = TRUE;
1116 saveIterParamNo = 0;
1120 setProcessingGlobalsList ()
1122 ProcessingGlobals = TRUE;
1123 fcnNoGlobals = FALSE;
1126 static bool ProcessingGlobMods = FALSE;
1129 setProcessingGlobMods ()
1131 ProcessingGlobMods = TRUE;
1135 clearProcessingGlobMods ()
1137 ProcessingGlobMods = FALSE;
1141 isProcessingGlobMods ()
1143 return (ProcessingGlobMods);
1146 static void resetGlobals (void)
1148 ProcessingGlobals = FALSE;
1149 fcnNoGlobals = FALSE;
1153 unsetProcessingGlobals ()
1155 ProcessingGlobals = FALSE;
1159 setProcessingVars (/*@only@*/ qtype q)
1161 ProcessingVars = TRUE;
1162 qtype_free (processingType);
1167 setGenericParamList (/*@dependent@*/ uentryList pm)
1169 ProcessingParams = TRUE;
1174 setProcessingTypedef (qtype q)
1176 ProcessingTypedef = TRUE;
1178 qtype_free (processingType);
1183 unsetProcessingVars ()
1185 resetStorageClass ();
1186 ProcessingVars = FALSE;
1190 oldStyleDoneParams ()
1192 if (ProcessingParams)
1194 if (uentry_isInvalid (saveFunction))
1196 llbuglit ("unsetProcessingVars: no saved function\n");
1200 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1201 uentryList params = uentryList_copy (saveParamList);
1202 ctype ct2 = ctype_makeFunction (ct, params);
1204 uentry_setType (saveFunction, ct2);
1205 ProcessingParams = FALSE;
1207 oldStyleCompleteFunction (saveFunction);
1208 saveFunction = uentry_undefined;
1215 ** If the paramlist used a type name, we could be here.
1218 llfatalerror (message ("%q: Old-style function parameter list uses a "
1219 "type name.", fileloc_unparse (g_currentloc)));
1226 if (uentry_isValid (saveFunction))
1229 ** old style declaration
1232 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1235 DPRINTF (("save function: %s", uentry_unparseFull (saveFunction)));
1237 uentryList_elements (saveParamList, current)
1239 uentry_setType (current, ctype_int); /* all params are ints */
1240 } end_uentryList_elements;
1242 ct2 = ctype_makeParamsFunction (ct, uentryList_copy (saveParamList));
1244 uentry_setType (saveFunction, ct2);
1245 ProcessingParams = FALSE;
1247 oldStyleDeclareFunction (saveFunction);
1248 saveFunction = uentry_undefined;
1252 void clabstract_declareType (/*@only@*/ exprNodeList decls, /*@only@*/ warnClause warn)
1254 llassert (ProcessingTypedef);
1256 if (warnClause_isDefined (warn))
1258 exprNodeList_elements (decls, el)
1260 uentry ue = exprNode_getUentry (el);
1261 cstring uname = uentry_getName (ue);
1263 DPRINTF (("Entry: %s", exprNode_unparse (el)));
1266 ** Need to lookup again to make sure we have the right one...
1269 ue = usymtab_lookupGlob (uname);
1271 llassert (uentry_isValid (ue));
1272 llassert (uentry_isDatatype (ue));
1274 DPRINTF (("Warning for %s: %s",
1275 uentry_unparse (ue), warnClause_unparse (warn)));
1277 uentry_addWarning (ue, warnClause_copy (warn));
1278 } end_exprNodeList_elements;
1281 warnClause_free (warn);
1282 exprNodeList_free (decls);
1283 unsetProcessingTypedef ();
1287 unsetProcessingTypedef ()
1289 ProcessingTypedef = FALSE;
1292 void checkConstant (qtype t, idDecl id)
1296 id = idDecl_fixBase (id, t);
1297 e = uentry_makeIdConstant (id);
1299 reflectStorageClass (e);
1300 resetStorageClass ();
1302 DPRINTF (("Constant: %s", uentry_unparseFull (e)));
1303 usymtab_supGlobalEntry (e);
1306 void checkValueConstant (qtype t, idDecl id, exprNode e)
1310 id = idDecl_fixBase (id, t);
1311 ue = uentry_makeIdConstant (id);
1312 reflectStorageClass (ue);
1313 resetStorageClass ();
1315 if (exprNode_isDefined (e))
1317 if (!exprNode_matchType (uentry_getType (ue), e))
1320 (exprNode_getType (e), e,
1321 uentry_getType (ue), exprNode_undefined,
1322 message ("Constant %q initialized to type %t, expects %t: %s",
1323 uentry_getName (ue),
1324 exprNode_getType (e),
1325 uentry_getType (ue),
1326 exprNode_unparse (e)),
1331 if (exprNode_hasValue (e))
1333 uentry_mergeConstantValue (ue, multiVal_copy (exprNode_getValue (e)));
1337 DPRINTF (("No value: %s", exprNode_unparse (e)));
1342 DPRINTF (("Constant value: %s", uentry_unparseFull (ue)));
1343 usymtab_supGlobalEntry (ue);
1346 void processNamedDecl (idDecl t)
1348 if (qtype_isUndefined (processingType))
1350 llparseerror (message ("No type before declaration name: %q", idDecl_unparse (t)));
1352 processingType = qtype_create (ctype_unknown);
1355 t = idDecl_fixBase (t, processingType);
1357 DPRINTF (("Declare: %s", idDecl_unparse (t)));
1359 if (ProcessingGlobals)
1361 cstring id = idDecl_getName (t);
1362 uentry ue = usymtab_lookupSafe (id);
1364 if (!uentry_isValid (ue))
1366 llerror (FLG_UNRECOG,
1367 message ("Variable used in globals list is undeclared: %s", id));
1371 if (!ctype_match (uentry_getType (ue), idDecl_getCtype (t)))
1375 message ("Variable %s used in globals list declared %s, "
1377 id, ctype_unparse (uentry_getType (ue)),
1378 ctype_unparse (idDecl_getCtype (t))),
1383 sRef sr = sRef_copy (uentry_getSref (ue));
1384 reflectGlobalQualifiers (sr, idDecl_getQuals (t));
1388 else if (ProcessingVars)
1393 ct = ctype_realType (idDecl_getCtype (t));
1395 if (ProcessingParams)
1397 cstring id = idDecl_getName (t);
1398 int paramno = uentryList_lookupRealName (saveParamList, id);
1402 uentry cparam = uentryList_getN (saveParamList, paramno);
1404 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1405 uentry_setType (cparam, idDecl_getCtype (t));
1406 uentry_reflectQualifiers (cparam, idDecl_getQuals (t));
1407 uentry_setDeclaredOnly (cparam, context_getSaveLocation ());
1408 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1413 (message ("Old style declaration uses unlisted parameter: %s",
1421 if (context_inIterDef ())
1423 cstring pname = makeParam (idDecl_observeId (t));
1424 uentry p = usymtab_lookupSafe (pname);
1426 cstring_free (pname);
1428 if (uentry_isYield (p))
1430 e = uentry_makeParam (t, sRef_getParam (uentry_getSref (p)));
1431 uentry_checkYieldParam (p, e);
1432 usymtab_supEntrySref (e);
1437 if ((hasSpecialCode () || argsUsed)
1438 && ctype_isFunction (idDecl_getCtype (t)))
1440 e = uentry_makeIdFunction (t);
1441 reflectSpecialCode (e);
1442 reflectArgsUsed (e);
1446 e = uentry_makeIdVariable (t);
1449 loc = uentry_whereDeclared (e);
1452 if (context_inGlobalScope ())
1454 uentry_checkParams was here!
1458 if (ctype_isFunction (uentry_getType (e)))
1460 clabstract_prepareFunction (e);
1463 DPRINTF (("Superceding... %s", uentry_unparseFull (e)));
1464 e = usymtab_supEntrySrefReturn (e);
1465 DPRINTF (("After superceding... %s", uentry_unparseFull (e)));
1467 if (uentry_isExtern (e) && !context_inGlobalScope ())
1471 message ("Declaration using extern inside function scope: %q",
1472 uentry_unparse (e)),
1475 uentry_setDefined (e, fileloc_getExternal ());
1476 sRef_setDefined (uentry_getSref (e), fileloc_getExternal ());
1479 if (uentry_isFunction (e))
1481 if (!context_inXHFile ())
1483 checkParamNames (e);
1487 if (uentry_isVar (e) && uentry_isCheckedUnknown (e))
1489 sRef sr = uentry_getSref (e);
1491 if (sRef_isLocalVar (sr))
1493 if (context_getFlag (FLG_IMPCHECKMODINTERNALS))
1495 uentry_setCheckMod (e);
1499 uentry_setUnchecked (e);
1502 else if (sRef_isFileStatic (sr))
1504 if (context_getFlag (FLG_IMPCHECKEDSTRICTSTATICS))
1506 uentry_setCheckedStrict (e);
1508 else if (context_getFlag (FLG_IMPCHECKEDSTATICS))
1510 uentry_setChecked (e);
1512 else if (context_getFlag (FLG_IMPCHECKMODSTATICS))
1514 uentry_setCheckMod (e);
1521 else /* real global */
1523 llassert (sRef_isRealGlobal (sr));
1525 if (context_getFlag (FLG_IMPCHECKEDSTRICTGLOBALS))
1527 uentry_setCheckedStrict (e);
1529 else if (context_getFlag (FLG_IMPCHECKEDGLOBALS))
1531 uentry_setChecked (e);
1533 else if (context_getFlag (FLG_IMPCHECKMODGLOBALS))
1535 uentry_setCheckMod (e);
1545 else if (ProcessingTypedef)
1547 ctype ct = idDecl_getCtype (t);
1550 DPRINTF (("Processing typedef: %s", ctype_unparse (ct)));
1552 e = uentry_makeIdDatatype (t);
1554 if (cstring_equal (idDecl_getName (t), context_getBoolName ())) {
1555 ctype rt = ctype_realType (ct);
1557 if (ctype_isEnum (rt)) {
1560 if (!(ctype_isInt (rt)
1561 || ctype_isUnknown (rt)
1562 || ctype_isChar (rt))) {
1565 message ("Boolean type %s defined using non-standard type %s (integral, char or enum type expected)",
1566 context_getBoolName (),
1567 ctype_unparse (ct)),
1568 uentry_whereLast (e));
1572 uentry_setType (e, ct);
1576 reflectStorageClass (e);
1577 checkTypeDecl (e, ct);
1579 e = usymtab_supReturnTypeEntry (e);
1583 llparseerror (message ("Suspect missing struct or union keyword: %q",
1584 idDecl_unparse (t)));
1590 ** moved from grammar
1593 static idDecl fixStructDecl (/*@returned@*/ idDecl d)
1595 if (ctype_isVisiblySharable (idDecl_getCtype (d))
1596 && context_getFlag (FLG_STRUCTIMPONLY))
1598 if (!qualList_hasAliasQualifier (idDecl_getQuals (d)))
1600 if (qualList_hasExposureQualifier (idDecl_getQuals (d)))
1602 idDecl_addQual (d, qual_createDependent ());
1606 idDecl_addQual (d, qual_createImpOnly ());
1615 declareUnnamedStruct (/*@only@*/ uentryList f)
1617 DPRINTF (("Unnamed struct: %s", uentryList_unparse (f)));
1619 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1621 int num = uentryList_size (f);
1622 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1627 (FLG_NUMSTRUCTFIELDS,
1628 message ("Structure declared with %d fields "
1629 "(limit is set to %d)",
1635 return (ctype_createUnnamedStruct (f));
1639 declareUnnamedUnion (/*@only@*/ uentryList f)
1641 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1643 int num = uentryList_size (f);
1644 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1649 (FLG_NUMSTRUCTFIELDS,
1650 message ("Union declared with %d fields "
1651 "(limit is set to %d)",
1657 return (ctype_createUnnamedUnion (f));
1660 ctype declareStruct (cstring id, /*@only@*/ uentryList f)
1664 int num = uentryList_size (f);
1666 DPRINTF (("Declare struct: %s / %s", id, uentryList_unparse (f)));
1668 ct = ctype_createStruct (cstring_copy (id), f);
1670 DPRINTF (("Ctype: %s", ctype_unparse (ct)));
1672 ue = uentry_makeStructTagLoc (id, ct);
1674 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
1676 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1678 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1683 (FLG_NUMSTRUCTFIELDS,
1684 message ("Structure %q declared with %d fields "
1685 "(limit is set to %d)",
1686 uentry_getName (ue), num, max),
1687 uentry_whereLast (ue));
1691 return (usymtab_supTypeEntry (ue));
1694 ctype declareUnion (cstring id, uentryList f)
1698 int num = uentryList_size (f);
1700 ct = ctype_createUnion (cstring_copy (id), f);
1701 ue = uentry_makeUnionTagLoc (id, ct);
1703 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1705 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1710 (FLG_NUMSTRUCTFIELDS,
1711 message ("Union %q declared with %d fields "
1712 "(limit is set to %d)",
1713 uentry_getName (ue), num, max),
1714 uentry_whereLast (ue));
1718 return (usymtab_supTypeEntry (ue));
1721 ctype handleStruct (/*@only@*/ cstring id)
1723 if (usymtab_existsStructTag (id))
1725 ctype ct = uentry_getAbstractType (usymtab_lookupStructTag (id));
1732 return (ctype_createForwardStruct (id));
1736 ctype handleUnion (/*@only@*/ cstring id)
1738 if (usymtab_existsUnionTag (id))
1740 ctype ret = uentry_getAbstractType (usymtab_lookupUnionTag (id));
1746 return (ctype_createForwardUnion (id));
1751 handleEnum (cstring id)
1753 if (usymtab_existsEnumTag (id))
1755 ctype ret = uentry_getAbstractType (usymtab_lookupEnumTag (id));
1761 return (declareEnum (id, enumNameList_new ()));
1765 bool processingIterVars (void)
1767 return ProcessingIterVars;
1770 uentry getCurrentIter (void)
1775 static bool flipOldStyle = FALSE;
1776 static bool flipNewStyle = TRUE;
1778 void setFlipOldStyle () { flipOldStyle = TRUE; }
1779 bool isFlipOldStyle () { return flipOldStyle; }
1780 bool isNewStyle () { return flipNewStyle; }
1781 void setNewStyle () { flipNewStyle = TRUE; }
1783 /*@dependent@*/ uentryList handleParamIdList (/*@dependent@*/ uentryList params)
1788 ** this is a really YUCKY hack to handle old style
1792 voptgenerror (FLG_OLDSTYLE,
1793 cstring_makeLiteral ("Old style function declaration"),
1796 DPRINTF (("Handle old style params: %s", uentryList_unparseFull (params)));
1798 uentryList_elements (params, current)
1800 uentry_setParam (current);
1801 uentry_setSref (current, sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (uentry_whereLast (current))));
1803 } end_uentryList_elements;
1805 setGenericParamList (params);
1806 g_expectingTypeName = TRUE;
1811 /*@dependent@*/ uentryList handleParamTypeList (/*@returned@*/ uentryList params)
1815 uentryList_fixMissingNames (params);
1817 voptgenerror (FLG_OLDSTYLE,
1818 cstring_makeLiteral ("Old style function declaration."),
1821 setGenericParamList (params);
1822 flipOldStyle = FALSE;
1823 g_expectingTypeName = TRUE;
1832 ctype c = ctype_unknown;
1833 cstring id = cstring_makeLiteral ("va_alist");
1836 if (ProcessingParams)
1838 int i = uentryList_lookupRealName (saveParamList, id);
1842 fileloc loc = context_getSaveLocation ();
1843 e = uentry_makeVariableSrefParam (id, c, loc, sRef_makeParam (i, c, stateInfo_makeLoc (loc)));
1847 e = uentry_undefined; /* suppress gcc message */
1848 llfatalerrorLoc (cstring_makeLiteral ("va_dcl used without va_alist"));
1853 llerror (FLG_SYNTAX, cstring_makeLiteral ("va_dcl used outside of function declaration"));
1854 e = uentry_makeVariableLoc (id, c);
1858 uentry_setUsed (e, g_currentloc);
1859 usymtab_supEntrySref (e);
1862 /*@exposed@*/ sRef modListPointer (/*@exposed@*/ sRef s)
1864 ctype ct = sRef_getType (s);
1865 ctype rt = ctype_realType (ct);
1867 if (ctype_isAP (rt))
1869 if (context_inHeader () && ctype_isAbstract (ct))
1874 ("Modifies clause in header file dereferences abstract "
1875 "type %s (interface modifies clause should not depend "
1876 "on or expose type representation): %q",
1882 return (sRef_constructPointer (s));
1886 if (ctype_isKnown (rt))
1890 message ("Implementation modifies clause dereferences non-pointer (type %s): %q",
1900 /*@exposed@*/ sRef modListFieldAccess (sRef s, cstring f)
1902 ctype ct = sRef_getType (s);
1903 ctype rt = ctype_realType (ct);
1905 if (ctype_isStructorUnion (rt))
1907 uentry tf = uentryList_lookupField (ctype_getFields (rt), f);
1909 if (uentry_isUndefined (tf))
1911 voptgenerror (FLG_TYPE,
1912 message ("Modifies list accesses non-existent "
1913 "field %s of %t: %q", f, ct,
1918 return sRef_undefined;
1922 if (ctype_isAbstract (ct) && context_inHeader ())
1927 ("Modifies clause in header file accesses abstract "
1928 "type %s (interface modifies clause should not depend "
1929 "on or expose type representation): %q",
1936 cstring_markOwned (f);
1937 return (sRef_makeField (s, f));
1943 message ("Modifies clause dereferences non-pointer (type %s): %q",
1953 /*@dependent@*/ sRef clabstract_unrecognizedGlobal (cstring s)
1955 if (cstring_equalLit (s, "nothing"))
1957 return sRef_makeNothing ();
1959 else if (cstring_equalLit (s, "internalState"))
1961 return sRef_makeInternalState ();
1963 else if (cstring_equalLit (s, "fileSystem")
1964 || cstring_equalLit (s, "systemState"))
1966 return sRef_makeSystemState ();
1972 message ("Unrecognized identifier in globals list: %s", s),
1975 return sRef_undefined;
1979 /*@exposed@*/ sRef modListArrowAccess (sRef s, cstring f)
1981 ctype ct = sRef_getType (s);
1982 ctype rt = ctype_realType (ct);
1984 if (ctype_isRealPointer (rt))
1986 ctype b = ctype_baseArrayPtr (rt);
1987 ctype rb = ctype_realType (b);
1989 if (ctype_isStructorUnion (rb))
1991 uentry tf = uentryList_lookupField (ctype_getFields (rb), f);
1993 if (uentry_isUndefined (tf))
1995 voptgenerror (FLG_TYPE,
1996 message ("Modifies list arrow accesses non-existent "
1997 "field %s of %t: %q", f, b,
2002 return sRef_undefined;
2006 if (context_inHeader ())
2008 if (ctype_isAbstract (b))
2013 ("Modifies clause in header file arrow accesses abstract "
2014 "type %s (interface modifies clause should not depend "
2015 "on or expose type representation): %q",
2023 if (ctype_isAbstract (ct))
2028 ("Modifies clause in header file arrow accesses abstract "
2029 "type %s (interface modifies clause should not depend "
2030 "on or expose type representation): %q",
2038 cstring_markOwned (f);
2039 return (sRef_makeArrow (s, f));
2045 message ("Modifies clause arrow accesses pointer to "
2046 "non-structure (type %s): %q",
2056 message ("Modifies clause arrow accesses non-pointer (type %s): %q",
2066 sRef checkStateClausesId (uentry ue)
2068 cstring s = uentry_rawName (ue);
2070 if (sRef_isFileOrGlobalScope (uentry_getSref (ue)))
2074 message ("Global variable %s used special clause. (Global variables "
2075 "are not recognized in special clauses. If there is "
2076 "sufficient interest in support for this, it may be "
2077 "added to a future release. Send mail to "
2078 "lclint@cs.virginia.edu.)",
2082 return sRef_undefined;
2086 if (cstring_equalLit (s, "result"))
2090 message ("Special clause list uses %s which is a variable and has special "
2091 "meaning in a modifies list. (Special meaning assumed.)", s),
2094 uentry_showWhereDeclared (ue);
2098 return uentry_getSref (ue);
2104 don;t know what the real date is...
2110 based on checkSpecClausesId
2114 sRef checkbufferConstraintClausesId (uentry ue)
2116 cstring s = uentry_rawName (ue);
2118 if (cstring_equalLit (s, "result"))
2122 message ("Function clause list uses %s which is a variable and has special "
2123 "meaning in a modifies list. (Special meaning assumed.)", s),
2126 uentry_showWhereDeclared (ue);
2130 DPRINTF (("constrant id: %s", uentry_unparseFull (ue)));
2131 return sRef_saveCopy (uentry_getSref (ue)); /*@i523 why the saveCopy? */
2134 void checkModifiesId (uentry ue)
2136 cstring s = uentry_rawName (ue);
2138 if (cstring_equalLit (s, "nothing")
2139 || cstring_equalLit (s, "internalState")
2140 || cstring_equalLit (s, "systemState")
2141 || (cstring_equalLit (s, "fileSystem")))
2145 message ("Modifies list uses %s which is a variable and has special "
2146 "meaning in a modifies list. (Special meaning assumed.)", s),
2149 uentry_showWhereDeclared (ue);
2154 /*@exposed@*/ sRef fixModifiesId (cstring s)
2157 cstring pname = makeParam (s);
2158 uentry ue = usymtab_lookupSafe (pname);
2160 cstring_free (pname);
2162 if (cstring_equalLit (s, "nothing"))
2164 ret = sRef_makeNothing ();
2166 else if (cstring_equalLit (s, "internalState"))
2168 ret = sRef_makeInternalState ();
2170 else if (cstring_equalLit (s, "fileSystem")
2171 || cstring_equalLit (s, "systemState"))
2173 ret = sRef_makeSystemState ();
2177 ret = sRef_undefined;
2180 if (sRef_isValid (ret))
2182 if (uentry_isValid (ue))
2186 message ("Modifies list uses %s which is a parameter and has special "
2187 "meaning in a modifies list. (Special meaning assumed.)", s),
2193 if (uentry_isValid (ue))
2195 ret = uentry_getSref (ue);
2199 fileloc loc = fileloc_decColumn (g_currentloc, cstring_length (s));
2200 ret = sRef_undefined;
2204 message ("Unrecognized identifier in modifies comment: %s", s),
2214 sRef fixStateClausesId (cstring s)
2217 cstring pname = makeParam (s);
2218 uentry ue = usymtab_lookupSafe (pname);
2220 cstring_free (pname);
2222 if (cstring_equalLit (s, "result"))
2224 ret = sRef_makeResult (ctype_unknown);
2228 ret = sRef_undefined;
2231 if (sRef_isValid (ret))
2233 if (uentry_isValid (ue))
2237 message ("Function clause uses %s which is a parameter and has special "
2238 "meaning in a function clause. (Special meaning assumed.)", s),
2244 if (uentry_isValid (ue))
2246 ret = uentry_getSref (ue);
2248 if (sRef_isFileOrGlobalScope (ret))
2252 message ("Global variable %s used in function clause. (Global variables "
2253 "are not recognized in function clauses. If there is "
2254 "sufficient interest in support for this, it may be "
2255 "added to a future release. Send mail to "
2256 "lclint@cs.virginia.edu.)",
2260 ret = sRef_undefined;
2265 fileloc loc = fileloc_decColumn (g_currentloc, cstring_length (s));
2266 ret = sRef_undefined;
2270 message ("Unrecognized identifier in function clause: %s", s),
2280 sRef modListArrayFetch (/*@exposed@*/ sRef s, /*@unused@*/ sRef mexp)
2282 ctype ct = sRef_getType (s);
2283 ctype rt = ctype_realType (ct);
2285 if (ctype_isAP (rt))
2287 if (context_inHeader () && ctype_isAbstract (ct))
2292 ("Modifies clause in header file indexes abstract "
2293 "type %s (interface modifies clause should not depend "
2294 "on or expose type representation): %q",
2300 return (sRef_makeAnyArrayFetch (s));
2307 ("Implementation modifies clause uses array fetch on non-array (type %s): %q",
2308 ctype_unparse (ct), sRef_unparse (s)),
2314 static void clabstract_prepareFunction (uentry e)
2316 uentry_checkParams (e);
2317 DPRINTF (("After prepare: %s", uentry_unparseFull (e)));
2320 sRef clabstract_checkGlobal (exprNode e)
2323 llassert (exprNode_isInitializer (e));
2325 s = exprNode_getSref (e);
2326 DPRINTF (("Initializer: %s -> %s", exprNode_unparse (e), sRef_unparse (s)));
2329 return sRef_copy (s);