2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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 splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
31 # include "splintMacros.nf"
33 # include "cgrammar.h"
34 # include "usymtab_interface.h"
36 # include "structNames.h"
37 # include "nameChecks.h"
39 # include "cscannerHelp.h"
42 # include "sgrammar_tokens.h"
44 # include "cgrammar_tokens.h"
48 ** Lots of variables are needed because of interactions with the
49 ** parser. This is easier than restructuring the grammar so the
50 ** right values are available in the right place.
54 static /*@only@*/ constraintList implicitFcnConstraints = NULL;
56 static void clabstract_prepareFunction (uentry p_e) /*@modifies p_e@*/ ;
57 static bool fcnNoGlobals = FALSE;
58 static void processVariable (/*@temp@*/ idDecl p_t) /*@modifies internalState@*/ ;
60 static bool s_processingVars = FALSE;
61 static bool s_processingParams = FALSE;
62 static bool s_processingGlobals = FALSE;
63 static bool s_processingTypedef = FALSE;
64 static bool s_processingIterVars = FALSE;
65 static /*@only@*/ qtype processingType = qtype_undefined;
66 static uentry currentIter = uentry_undefined;
67 static /*@dependent@*/ uentryList saveParamList; /* for old style functions */
68 static /*@owned@*/ uentry saveFunction = uentry_undefined;
69 static int saveIterParamNo;
70 static idDecl fixStructDecl (/*@returned@*/ idDecl p_d);
71 static void checkTypeDecl (uentry p_e, ctype p_rep);
72 static /*@dependent@*/ fileloc saveStoreLoc = fileloc_undefined;
73 static storageClassCode storageClass = SCNONE;
74 static void declareEnumList (/*@temp@*/ enumNameList p_el, ctype p_c, fileloc p_loc);
75 static void resetGlobals (void);
76 static /*@null@*/ qual specialFunctionCode;
77 static bool argsUsed = FALSE;
79 extern void clabstract_initMod ()
81 specialFunctionCode = qual_createUnknown ();
82 DPRINTF (("Initialized: %s", qual_unparse (specialFunctionCode)));
85 static bool hasSpecialCode (void)
87 return (!qual_isUnknown (specialFunctionCode));
90 extern void setArgsUsed (void)
96 cstring_makeLiteral ("Multiple ARGSUSED comments for one function"),
103 static void reflectArgsUsed (uentry ue)
107 if (uentry_isFunction (ue))
109 uentryList params = uentry_getParams (ue);
111 uentryList_elements (params, el)
113 uentry_setUsed (el, fileloc_undefined);
114 } end_uentryList_elements ;
121 extern void setSpecialFunction (qual qu)
123 if (!qual_isUnknown (specialFunctionCode))
125 voptgenerror (FLG_SYNTAX,
126 message ("Multiple special function codes: %s, %s "
127 "(first code is ignored)",
128 qual_unparse (specialFunctionCode),
133 specialFunctionCode = qu;
136 static void reflectSpecialCode (uentry ue)
138 if (qual_isUnknown (specialFunctionCode)) {
140 } else if (qual_isPrintfLike (specialFunctionCode)) {
141 uentry_setPrintfLike (ue);
142 } else if (qual_isScanfLike (specialFunctionCode)) {
143 uentry_setScanfLike (ue);
144 } else if (qual_isMessageLike (specialFunctionCode)) {
145 uentry_setMessageLike (ue);
150 specialFunctionCode = qual_createUnknown ();
153 static void resetStorageClass (void)
155 qtype_free (processingType);
156 processingType = qtype_undefined;
157 storageClass = SCNONE;
160 static void reflectStorageClass (uentry u)
162 if (storageClass == SCSTATIC)
164 uentry_setStatic (u);
166 else if (storageClass == SCEXTERN)
168 uentry_setExtern (u);
172 ; /* no storage class */
179 saveStoreLoc = g_currentloc;
182 void setFunctionNoGlobals (void)
187 static void reflectGlobalQualifiers (sRef sr, qualList quals)
189 DPRINTF (("Reflect global qualifiers: %s / %s",
190 sRef_unparseFull (sr), qualList_unparse (quals)));
192 qualList_elements (quals, qel)
194 if (qual_isGlobalQual (qel)) /* undef, killed */
196 sstate oldstate = sRef_getDefState (sr);
197 sstate defstate = sstate_fromQual (qel);
199 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
200 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
202 defstate = SS_UNDEFKILLED;
209 sRef_setDefState (sr, defstate, fileloc_undefined);
210 DPRINTF (("State: %s", sRef_unparseFull (sr)));
212 else if (qual_isAllocQual (qel)) /* out, partial, reldef, etc. */
214 ctype realType = sRef_getType (sr);
215 sstate defstate = sstate_fromQual (qel);
217 if (qual_isRelDef (qel))
219 ; /* okay anywhere */
223 if (!ctype_isAP (realType)
224 && !ctype_isSU (realType)
225 && !ctype_isUnknown (realType)
226 && !ctype_isAbstract (sRef_getType (sr)))
230 message ("Qualifier %s used on non-pointer or struct: %q",
231 qual_unparse (qel), sRef_unparse (sr)));
236 sRef_setDefState (sr, defstate, fileloc_undefined);
238 else if (qual_isNull (qel))
240 sRef_setNullState (sr, NS_POSNULL, fileloc_undefined);
242 else if (qual_isRelNull (qel))
244 sRef_setNullState (sr, NS_RELNULL, fileloc_undefined);
246 else if (qual_isNotNull (qel))
248 sRef_setNullState (sr, NS_MNOTNULL, fileloc_undefined);
252 if (qual_isCQual (qel))
259 message ("Qualifier %s cannot be used in a globals list",
260 qual_unparse (qel)));
263 } end_qualList_elements;
266 sRef clabstract_createGlobal (sRef sr, qualList quals)
270 if (sRef_isValid (sr))
272 res = sRef_copy (sr);
273 DPRINTF (("Reflecting quals: %s / %s", sRef_unparse (sr), qualList_unparse (quals)));
274 reflectGlobalQualifiers (res, quals);
275 DPRINTF (("==> %s", sRef_unparseFull (res)));
279 res = sRef_undefined;
282 qualList_free (quals);
286 extern void declareCIter (cstring name, /*@owned@*/ uentryList params)
290 ue = uentry_makeIter (name,
291 ctype_makeFunction (ctype_void, params),
292 fileloc_copy (g_currentloc));
294 usymtab_supEntry (uentry_makeEndIter (name, fileloc_copy (g_currentloc)));
295 ue = usymtab_supGlobalEntryReturn (ue);
298 extern void nextIterParam (void)
300 llassert (s_processingIterVars);
304 extern int iterParamNo (void)
306 llassert (s_processingIterVars);
307 return saveIterParamNo;
311 ** yucky hacks to put it in the right place
315 makeCurrentParam (idDecl t)
319 saveStoreLoc = fileloc_undefined;
321 /* param number unknown */
323 ue = uentry_makeParam (t, 0);
328 declareUnnamedEnum (enumNameList el)
330 ctype ret = usymtab_enumEnumNameListType (el);
334 if (ctype_isDefined (ret))
337 e = uentry_makeEnumTagLoc (ctype_enumTag (rt), ret);
339 reflectStorageClass (e);
340 usymtab_supGlobalEntry (e);
342 declareEnumList (el, ret, g_currentloc);
343 enumNameList_free (el);
347 ctype ct = ctype_createEnum (fakeTag (), el);
349 e = uentry_makeEnumTagLoc (ctype_enumTag (ctype_realType (ct)), ct);
350 reflectStorageClass (e);
352 e = usymtab_supGlobalEntryReturn (e);
353 rt = uentry_getAbstractType (e);
354 declareEnumList (el, ct, g_currentloc);
361 declareEnum (cstring ename, enumNameList el)
366 llassert (cstring_isDefined (ename));
368 cet = ctype_createEnum (ename, el);
369 e = uentry_makeEnumTagLoc (ename, cet);
370 reflectStorageClass (e);
371 e = usymtab_supGlobalEntryReturn (e);
372 cet = uentry_getType (e);
373 declareEnumList (el, cet, uentry_whereLast (e));
374 return (uentry_getAbstractType (e));
378 declareEnumList (enumNameList el, ctype c, fileloc loc)
380 bool boolnames = FALSE;
381 bool othernames = FALSE;
383 (void) context_getSaveLocation (); /* undefine it */
385 if (context_maybeSet (FLG_NUMENUMMEMBERS))
387 int maxnum = context_getValue (FLG_NUMENUMMEMBERS);
388 int num = enumNameList_size (el);
394 message ("Enumerator %s declared with %d members (limit is set to %d)",
395 ctype_unparse (c), num, maxnum),
400 enumNameList_elements (el, e)
402 uentry ue = usymtab_lookupExposeGlob (e);
403 ctype ct = uentry_getType (ue);
405 llassert (uentry_isEnumConstant (ue));
407 if (ctype_isUnknown (ct))
409 uentry_setType (ue, c);
413 if (cstring_equal (e, context_getFalseName ())
414 || cstring_equal (e, context_getTrueName ()))
420 message ("Enumerator mixes boolean name (%s) with "
423 uentry_whereLast (ue)))
430 uentry_setType (ue, ctype_bool);
431 DPRINTF (("Set type: %s / %s",
432 uentry_unparse (ue), ctype_unparse (ctype_bool)));
440 message ("Enumerator mixes boolean names (%s, %s) with "
441 "non-boolean name: %s",
442 context_getTrueName (),
443 context_getFalseName (),
445 uentry_whereLast (ue)))
454 if (!ctype_match (c, ct))
456 if (ctype_isDirectBool (ct))
458 if (cstring_equal (e, context_getFalseName ())
459 || cstring_equal (e, context_getTrueName ()))
461 DPRINTF (("Here we are!"));
467 message ("Enumerator member %s declared with "
468 "inconsistent type: %s",
469 e, ctype_unparse (c)),
470 uentry_whereLast (ue)))
472 uentry_showWhereSpecifiedExtra
473 (ue, cstring_copy (ctype_unparse (ct)));
481 message ("Enumerator member %s declared with "
482 "inconsistent type: %s",
483 e, ctype_unparse (c)),
484 uentry_whereLast (ue)))
486 uentry_showWhereSpecifiedExtra
487 (ue, cstring_copy (ctype_unparse (ct)));
492 } end_enumNameList_elements;
495 static /*@dependent@*/ uentryList currentParamList;
497 /*drl added 3-28-2002*/
498 /* this function takes a list of paramentar and generates a list
502 /* drl modified 10/23/2002
504 The current semantics are generated constraints of the form MaxSet(p) >= 0 and MaxRead(p) >= 0 for all pointers
505 unless the @out@ annotation has been applied to a parameter, then we only want to generate maxSet(p) > = 0
508 void setImplicitfcnConstraints (void)
513 params = currentParamList;
515 if (constraintList_isDefined (implicitFcnConstraints))
517 constraintList_free (implicitFcnConstraints);
520 implicitFcnConstraints = constraintList_makeNew();
522 uentryList_elements (params, el)
524 DPRINTF (("setImplicitfcnConstraints doing: %s", uentry_unparse(el)));
526 if (uentry_isVariable (el))
528 s = uentry_getSref(el);
530 if (sRef_isReference (s))
532 DPRINTF((message ("%s is a pointer", sRef_unparse(s) ) ));
534 chagned this from MaxSet(s) == 0 to MaxSet(s) >= 0 */
535 c = constraint_makeSRefWriteSafeInt (s, 0);
537 implicitFcnConstraints = constraintList_add (implicitFcnConstraints , c);
539 /*drl 10/23/2002 added support for out*/
541 if (!uentry_isOut(el))
543 c = constraint_makeSRefReadSafeInt (s, 0);
544 implicitFcnConstraints = constraintList_add (implicitFcnConstraints , c);
549 DPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) ));
551 } /*end uentry_isVariable*/
552 else if (uentry_isElipsisMarker (el) )
554 /* just ignore these*/
561 I'm not sure if this is possible though
565 } end_uentryList_elements;
569 /*@observer@*/ constraintList getImplicitFcnConstraints (void)
571 return implicitFcnConstraints;
574 void setCurrentParams (/*@dependent@*/ uentryList ue)
576 currentParamList = ue;
579 void clearCurrentParams (void)
581 currentParamList = uentryList_undefined;
585 ** requires: uentry_isFunction (e)
586 ** parameter names for current function are in currentParamList
589 static void enterFunctionParams (uentryList params)
593 uentryList_elements (params, current)
595 if (uentry_hasName (current))
597 uentry_setParamNo (current, paramno);
598 usymtab_supEntry (uentry_copy (current));
602 } end_uentryList_elements;
606 extern void enterParamsTemp (void)
608 usymtab_enterScope ();
609 enterFunctionParams (currentParamList);
612 extern void exitParamsTemp (void)
614 usymtab_quietPlainExitScope ();
617 static /*@exposed@*/ uentry clabstract_globalDeclareFunction (idDecl tid)
619 ctype deftype = idDecl_getCtype (tid);
623 DPRINTF (("Global function: %s", idDecl_unparse (tid)));
625 if (ctype_isFunction (deftype))
627 rettype = ctype_getReturnType (deftype);
631 rettype = ctype_unknown;
635 ** check has been moved here...
638 if (ctype_isFunction (idDecl_getCtype (tid)))
640 ue = uentry_makeIdFunction (tid);
641 reflectSpecialCode (ue);
642 reflectArgsUsed (ue);
643 reflectStorageClass (ue);
644 uentry_checkParams (ue);
646 DPRINTF (("Supercede function: %s", uentry_unparseFull (ue)));
648 ue = usymtab_supGlobalEntryReturn (ue);
649 DPRINTF (("After supercede function: %s", uentry_unparseFull (ue)));
651 DPRINTF (("Enter function: %s", uentry_unparseFull (ue)));
652 context_enterFunction (ue);
653 enterFunctionParams (uentry_getParams (ue));
655 resetStorageClass ();
656 DPRINTF (("Function: %s", uentry_unparseFull (ue)));
661 llparseerror (message ("Non-function declaration: %q",
662 idDecl_unparse (tid)));
663 return (uentry_undefined);
668 ** for now, no type checking
669 ** (must check later though!)
672 static /*@only@*/ uentry globalDeclareOldStyleFunction (idDecl tid)
677 ** check has been moved here...
680 if (cstring_equalLit (idDecl_observeId (tid), "main"))
682 context_setFlagTemp (FLG_MAINTYPE, FALSE);
685 ue = uentry_makeIdFunction (tid);
686 reflectStorageClass (ue);
687 reflectSpecialCode (ue);
688 reflectArgsUsed (ue);
689 uentry_setDefined (ue, g_currentloc);
690 uentry_checkParams (ue);
691 resetStorageClass ();
693 /* context_enterOldStyleScope (); */
698 static void oldStyleDeclareFunction (/*@only@*/ uentry e)
700 uentryList params = saveParamList;
701 ctype rt = uentry_getType (e);
703 llassert (ctype_isFunction (rt));
705 if (uentry_hasStateClauseList (e)
706 || uentry_hasConditions (e))
708 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
709 fileloc_unparse (g_currentloc), uentry_unparse (e)));
712 e = usymtab_supGlobalEntryReturn (e);
714 context_enterFunction (e);
715 enterFunctionParams (params);
716 saveParamList = uentryList_undefined;
717 resetStorageClass ();
720 static void oldStyleCompleteFunction (/*@only@*/ uentry e)
722 uentryList params = saveParamList;
723 ctype rt = uentry_getType (e);
725 llassert (ctype_isFunction (rt));
727 if (uentry_hasStateClauseList (e)
728 || uentry_hasConditions (e))
730 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
731 fileloc_unparse (g_currentloc), uentry_unparse (e)));
734 e = usymtab_supGlobalEntryReturn (e);
736 context_completeOldStyleFunction (e);
737 enterFunctionParams (params);
738 saveParamList = uentryList_undefined;
739 resetStorageClass ();
742 void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
746 DPRINTF (("Declare function: %s", idDecl_unparse (tid)));
748 if (ctype_isUnknown (idDecl_getCtype (tid)))
751 ** No type, its really a plain name (int) declaration
754 voptgenerror (FLG_IMPTYPE,
755 message ("No type before declaration name (implicit int type): %q",
756 idDecl_unparse (tid)),
758 tid = idDecl_replaceCtype (tid, ctype_int);
759 processVariable (tid);
760 saveFunction = uentry_undefined;
764 if (s_processingParams)
766 ue = globalDeclareOldStyleFunction (tid);
768 DPRINTF (("Set save function: %s", uentry_unparseFull (ue)));
772 saveFunction = uentry_undefined;
774 if (context_inRealFunction ())
776 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
778 llparseerror (message ("Function declared inside function: %q",
779 idDecl_unparse (tid)));
781 context_quietExitFunction ();
782 ue = usymtab_supEntryReturn (ue);
786 if (context_inInnerScope ())
788 llparseerror (message ("Declaration in inner context: %q",
789 idDecl_unparse (tid)));
791 sRef_setGlobalScope ();
792 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
794 ue = usymtab_supGlobalEntryReturn (ue);
795 sRef_clearGlobalScope ();
799 ue = clabstract_globalDeclareFunction (tid);
806 resetStorageClass ();
812 void declareStaticFunction (idDecl tid) /*@globals undef saveFunction; @*/
816 DPRINTF (("Declare static funciton: %s", idDecl_unparse (tid)));
818 if (s_processingParams)
820 ue = globalDeclareOldStyleFunction (tid);
825 saveFunction = uentry_undefined;
827 if (context_inRealFunction ())
829 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
831 llparseerror (message ("Function declared inside function: %q",
832 idDecl_unparse (tid)));
834 context_quietExitFunction ();
835 ue = usymtab_supEntryReturn (ue);
839 if (context_inInnerScope ())
841 llparseerror (message ("Declaration in inner context: %q",
842 idDecl_unparse (tid)));
844 sRef_setGlobalScope ();
845 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
847 ue = usymtab_supGlobalEntryReturn (ue);
848 sRef_clearGlobalScope ();
852 ctype deftype = idDecl_getCtype (tid);
855 if (ctype_isFunction (deftype))
857 rettype = ctype_getReturnType (deftype);
861 rettype = ctype_unknown;
865 ** check has been moved here...
868 if (ctype_isFunction (idDecl_getCtype (tid)))
870 ue = uentry_makeIdFunction (tid);
871 reflectSpecialCode (ue);
872 reflectArgsUsed (ue);
876 DPRINTF (("Here we are!"));
877 llparseerror (message ("Inconsistent function declaration: %q",
878 idDecl_unparse (tid)));
880 tid = idDecl_replaceCtype
881 (tid, ctype_makeFunction (ctype_unknown, uentryList_undefined));
882 ue = uentry_makeIdFunction (tid);
885 reflectStorageClass (ue);
886 uentry_setStatic (ue);
888 uentry_checkParams (ue);
890 DPRINTF (("Sub global entry: %s", uentry_unparse (ue)));
891 ue = usymtab_supGlobalEntryReturn (ue);
893 context_enterFunction (ue);
894 enterFunctionParams (uentry_getParams (ue));
895 resetStorageClass ();
902 resetStorageClass ();
907 checkTypeDecl (uentry e, ctype rep)
909 cstring n = uentry_getName (e);
911 DPRINTF (("Check type decl: %s", uentry_unparseFull (e)));
913 if (cstring_equal (context_getBoolName (), n))
915 ctype rrep = ctype_realType (rep);
918 ** for abstract enum types, we need to fix the enum members:
919 ** they should have the abstract type, not the rep type.
922 if (ctype_isEnum (ctype_realType (rrep)))
924 enumNameList el = ctype_elist (rrep);
926 enumNameList_elements (el, ye)
928 if (usymtab_existsGlob (ye))
930 uentry ue = usymtab_lookupSafe (ye);
931 uentry_setType (ue, ctype_bool);
934 if (cstring_equal (context_getTrueName (), ye)
935 || cstring_equal (context_getFalseName (), ye))
943 message ("Member of boolean enumerated type definition "
944 "does not match name set to represent true "
947 message ("Use -boolfalse and -booltrue to set the "
948 "name of false and true boolean values."),
949 uentry_whereDefined (e));
951 } end_enumNameList_elements;
955 if (usymtab_exists (n))
957 usymId llm = usymtab_getId (n);
958 uentry le = usymtab_getTypeEntry (typeId_fromUsymId (llm));
960 uentry_setDeclared (e, g_currentloc);
961 uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le), stateInfo_currentLoc ()));
963 DPRINTF (("Here we are: %s / %s",
964 n, context_getBoolName ()));
966 if (uentry_isAbstractDatatype (le))
968 ctype rrep = ctype_realType (rep);
970 DPRINTF (("Abstract type: %s", uentry_unparseFull (le)));
973 ** for abstract enum types, we need to fix the enum members:
974 ** they should have the abstract type, not the rep type.
977 if (ctype_isEnum (ctype_realType (rrep)))
979 ctype at = uentry_getAbstractType (le);
980 enumNameList el = ctype_elist (rrep);
982 enumNameList_elements (el, ye)
984 if (usymtab_existsGlob (ye))
986 uentry ue = usymtab_lookupSafe (ye);
988 llassert (uentry_isEitherConstant (ue));
990 /* evans 2002-04-22 */
991 if (ctype_isBool (uentry_getType (ue)))
994 ** If set using -booltrue or -boolfalse, don't change the type.
999 llassertprint (ctype_match (uentry_getType (ue), rrep),
1000 ("Bad enum: %s / %s",
1001 uentry_unparse (ue),
1002 ctype_unparse (rrep)));
1004 uentry_setType (ue, at);
1007 } end_enumNameList_elements;
1010 if (uentry_isMutableDatatype (le))
1012 /* maybe more complicated if abstract and immutable ? */
1014 if (!ctype_isRealPointer (rep) && !ctype_isRealAbstract (rep))
1018 message ("Mutable abstract type %s declared without pointer "
1019 "indirection: %s (violates assignment semantics)",
1020 n, ctype_unparse (rep)),
1021 uentry_whereDefined (e));
1023 uentry_setMutable (e);
1030 fileloc fl = uentry_whereDeclared (e);
1032 if (context_getFlag (FLG_LIKELYBOOL)
1033 && !context_getFlag (FLG_BOOLINT))
1035 if ((cstring_equalLit (n, "BOOL")
1036 || cstring_equalLit (n, "Bool")
1037 || cstring_equalLit (n, "bool")
1038 || cstring_equalLit (n, "boolean")
1039 || cstring_equalLit (n, "Boolean")
1040 || cstring_equalLit (n, "BOOLEAN"))
1041 && !(cstring_equal (n, context_getBoolName ())))
1043 if (context_setBoolName ()) {
1046 message ("Type %s is probably meant as a boolean type, but does "
1047 "not match the boolean type name \"%s\".",
1049 context_getBoolName ()),
1054 message ("Type %s is probably meant as a boolean type, "
1055 "but the boolean type name is not set. "
1056 "Use -booltype %s to set it.",
1063 if (!uentry_isStatic (e)
1064 && !ctype_isFunction (uentry_getType (e))
1065 && !fileloc_isLib (fl)
1066 && !fileloc_isImport (fl)
1067 && fileloc_isHeader (fl))
1069 voptgenerror (FLG_EXPORTTYPE,
1070 message ("Type exported, but not specified: %s\n", n),
1079 fixUentryList (idDeclList tl, qtype q)
1081 uentryList f = uentryList_new ();
1083 idDeclList_elements (tl, i)
1085 if (idDecl_isDefined (i))
1091 (void) idDecl_fixBase (i, q);
1094 ** implicit annotations
1097 (void) fixStructDecl (i);
1099 ue = uentry_makeIdVariable (i);
1100 rt = ctype_realType (uentry_getType (ue));
1103 ** where is this here???
1105 if (ctype_isArray (rt) || ctype_isSU (rt))
1107 sRef_setAllocated (uentry_getSref (ue), uentry_whereDefined (ue));
1113 if (uentry_isValid (old = uentryList_lookupField (f, uentry_rawName (ue))))
1115 if (optgenerror (FLG_SYNTAX,
1116 message ("Field name reused: %s", uentry_rawName (ue)),
1117 uentry_whereDefined (ue)))
1119 llgenmsg (message ("Previous use of %s", uentry_rawName (ue)),
1120 uentry_whereDefined (old));
1124 f = uentryList_add (f, ue);
1126 } end_idDeclList_elements;
1128 idDeclList_free (tl);
1133 ** This is a hack to support unnamed struct/union fields as done by
1134 ** Microsoft VC++. It is not supported by the ANSI standard.
1136 ** The inner fields are added to the outer structure. This is meaningful
1137 ** for nesting structs inside unions, but Splint does no related
1142 fixUnnamedDecl (qtype q)
1144 ctype ct = ctype_realType (qtype_getType (q));
1146 if (ctype_isStruct (ct) || ctype_isUnion (ct))
1148 return uentryList_single (uentry_makeUnnamedVariable (ct));
1150 else if (ctype_isEnum (ct))
1152 /* evans 2002-02-05: nothing to do for unnamed enum lists */
1153 return uentryList_undefined;
1159 message ("Type name in field declarations: %s", qtype_unparse (q)),
1163 return uentryList_undefined;
1166 void setStorageClass (storageClassCode sc)
1172 setProcessingIterVars (uentry iter)
1174 s_processingIterVars = TRUE;
1176 saveIterParamNo = 0;
1180 setProcessingGlobalsList ()
1182 s_processingGlobals = TRUE;
1183 fcnNoGlobals = FALSE;
1186 static bool ProcessingGlobMods = FALSE;
1189 setProcessingGlobMods ()
1191 ProcessingGlobMods = TRUE;
1195 clearProcessingGlobMods ()
1197 ProcessingGlobMods = FALSE;
1201 isProcessingGlobMods ()
1203 return (ProcessingGlobMods);
1206 static void resetGlobals (void)
1208 s_processingGlobals = FALSE;
1209 fcnNoGlobals = FALSE;
1213 unsetProcessingGlobals ()
1215 s_processingGlobals = FALSE;
1219 setProcessingVars (/*@only@*/ qtype q)
1221 s_processingVars = TRUE;
1222 qtype_free (processingType);
1227 setGenericParamList (/*@dependent@*/ uentryList pm)
1229 s_processingParams = TRUE;
1234 setProcessingTypedef (qtype q)
1236 s_processingTypedef = TRUE;
1238 qtype_free (processingType);
1243 unsetProcessingVars ()
1245 resetStorageClass ();
1246 s_processingVars = FALSE;
1250 oldStyleDoneParams ()
1252 if (s_processingParams)
1254 if (uentry_isInvalid (saveFunction))
1256 llbuglit ("unsetProcessingVars: no saved function\n");
1260 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1261 uentryList params = uentryList_copy (saveParamList);
1262 ctype ct2 = ctype_makeFunction (ct, params);
1264 uentry_setType (saveFunction, ct2);
1265 s_processingParams = FALSE;
1267 oldStyleCompleteFunction (saveFunction);
1268 saveFunction = uentry_undefined;
1275 ** If the paramlist used a type name, we could be here.
1278 llfatalerror (message ("%q: Old-style function parameter list uses a "
1279 "type name.", fileloc_unparse (g_currentloc)));
1286 if (uentry_isValid (saveFunction))
1289 ** old style declaration
1292 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1295 DPRINTF (("save function: %s", uentry_unparseFull (saveFunction)));
1297 uentryList_elements (saveParamList, current)
1299 uentry_setType (current, ctype_int); /* all params are ints */
1300 } end_uentryList_elements;
1302 ct2 = ctype_makeParamsFunction (ct, uentryList_copy (saveParamList));
1304 uentry_setType (saveFunction, ct2);
1305 s_processingParams = FALSE;
1307 oldStyleDeclareFunction (saveFunction);
1308 saveFunction = uentry_undefined;
1312 void clabstract_declareType (/*@only@*/ exprNodeList decls, /*@only@*/ warnClause warn)
1314 llassert (s_processingTypedef);
1316 DPRINTF (("Declare type: %s", exprNodeList_unparse (decls)));
1318 if (warnClause_isDefined (warn))
1320 DPRINTF (("Has a warn clause!"));
1321 DPRINTF (("Warn: %s", warnClause_unparse (warn)));
1323 exprNodeList_elements (decls, el)
1325 uentry ue = exprNode_getUentry (el);
1326 cstring uname = uentry_getName (ue);
1328 DPRINTF (("Entry: %s", exprNode_unparse (el)));
1331 ** Need to lookup again to make sure we have the right one...
1334 ue = usymtab_lookupExposeGlob (uname);
1336 llassert (uentry_isValid (ue));
1337 llassert (uentry_isDatatype (ue));
1339 DPRINTF (("Warning for %s: %s",
1340 uentry_unparse (ue), warnClause_unparse (warn)));
1342 uentry_addWarning (ue, warnClause_copy (warn));
1343 DPRINTF (("After add warning: %s", uentry_unparseFull (ue)));
1344 cstring_free (uname);
1345 } end_exprNodeList_elements;
1348 warnClause_free (warn);
1349 exprNodeList_free (decls);
1350 unsetProcessingTypedef ();
1354 unsetProcessingTypedef ()
1356 s_processingTypedef = FALSE;
1359 void checkConstant (qtype t, idDecl id)
1363 id = idDecl_fixBase (id, t);
1364 e = uentry_makeIdConstant (id);
1366 reflectStorageClass (e);
1367 resetStorageClass ();
1369 DPRINTF (("Constant: %s", uentry_unparseFull (e)));
1370 usymtab_supGlobalEntry (e);
1373 void checkValueConstant (qtype t, idDecl id, exprNode e)
1377 id = idDecl_fixBase (id, t);
1378 ue = uentry_makeIdConstant (id);
1379 reflectStorageClass (ue);
1380 resetStorageClass ();
1382 if (exprNode_isDefined (e))
1384 if (!exprNode_matchType (uentry_getType (ue), e))
1387 (exprNode_getType (e), e,
1388 uentry_getType (ue), exprNode_undefined,
1389 message ("Constant %q initialized to type %t, expects %t: %s",
1390 uentry_getName (ue),
1391 exprNode_getType (e),
1392 uentry_getType (ue),
1393 exprNode_unparse (e)),
1398 if (exprNode_hasValue (e))
1400 uentry_mergeConstantValue (ue, multiVal_copy (exprNode_getValue (e)));
1404 DPRINTF (("No value: %s", exprNode_unparse (e)));
1409 DPRINTF (("Constant value: %s", uentry_unparseFull (ue)));
1410 usymtab_supGlobalEntry (ue);
1413 static void processVariable (idDecl t)
1418 ct = ctype_realType (idDecl_getCtype (t));
1420 if (s_processingParams)
1422 cstring id = idDecl_getName (t);
1423 int paramno = uentryList_lookupRealName (saveParamList, id);
1427 uentry cparam = uentryList_getN (saveParamList, paramno);
1429 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1430 uentry_setType (cparam, idDecl_getCtype (t));
1431 uentry_reflectQualifiers (cparam, idDecl_getQuals (t));
1432 uentry_setDeclaredOnly (cparam, context_getSaveLocation ());
1433 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1438 (message ("Old style declaration uses unlisted parameter: %s",
1446 if (context_inIterDef ())
1448 cstring pname = makeParam (idDecl_observeId (t));
1449 uentry p = usymtab_lookupSafe (pname);
1451 cstring_free (pname);
1453 if (uentry_isYield (p))
1455 e = uentry_makeParam (t, sRef_getParam (uentry_getSref (p)));
1456 uentry_checkYieldParam (p, e);
1457 usymtab_supEntrySref (e);
1462 if ((hasSpecialCode () || argsUsed)
1463 && ctype_isFunction (idDecl_getCtype (t)))
1465 e = uentry_makeIdFunction (t);
1466 reflectSpecialCode (e);
1467 reflectArgsUsed (e);
1471 e = uentry_makeIdVariable (t);
1474 loc = uentry_whereDeclared (e);
1477 if (context_inGlobalScope ())
1479 uentry_checkParams was here!
1483 if (ctype_isFunction (uentry_getType (e)))
1485 clabstract_prepareFunction (e);
1488 DPRINTF (("Superceding... %s", uentry_unparseFull (e)));
1489 e = usymtab_supEntrySrefReturn (e);
1490 DPRINTF (("After superceding... %s", uentry_unparseFull (e)));
1492 if (uentry_isExtern (e) && !context_inGlobalScope ())
1496 message ("Declaration using extern inside function scope: %q",
1497 uentry_unparse (e)),
1500 uentry_setDefined (e, fileloc_getExternal ());
1501 sRef_setDefined (uentry_getSref (e), fileloc_getExternal ());
1504 if (uentry_isFunction (e))
1506 if (!context_inXHFile ())
1508 checkParamNames (e);
1512 if (uentry_isVar (e) && uentry_isCheckedUnknown (e))
1514 sRef sr = uentry_getSref (e);
1516 if (sRef_isLocalVar (sr))
1518 if (context_getFlag (FLG_IMPCHECKMODINTERNALS))
1520 uentry_setCheckMod (e);
1524 uentry_setUnchecked (e);
1527 else if (sRef_isFileStatic (sr))
1529 if (context_getFlag (FLG_IMPCHECKEDSTRICTSTATICS))
1531 uentry_setCheckedStrict (e);
1533 else if (context_getFlag (FLG_IMPCHECKEDSTATICS))
1535 uentry_setChecked (e);
1537 else if (context_getFlag (FLG_IMPCHECKMODSTATICS))
1539 uentry_setCheckMod (e);
1546 else /* real global */
1548 llassert (sRef_isRealGlobal (sr));
1550 if (context_getFlag (FLG_IMPCHECKEDSTRICTGLOBALS))
1552 uentry_setCheckedStrict (e);
1554 else if (context_getFlag (FLG_IMPCHECKEDGLOBALS))
1556 uentry_setChecked (e);
1558 else if (context_getFlag (FLG_IMPCHECKMODGLOBALS))
1560 uentry_setCheckMod (e);
1571 void processNamedDecl (idDecl t)
1573 if (qtype_isUndefined (processingType))
1575 processingType = qtype_create (ctype_int);
1576 t = idDecl_fixBase (t, processingType);
1578 voptgenerror (FLG_IMPTYPE,
1579 message ("No type before declaration name (implicit int type): %q",
1580 idDecl_unparse (t)),
1585 t = idDecl_fixBase (t, processingType);
1588 DPRINTF (("Declare: %s", idDecl_unparse (t)));
1590 if (s_processingGlobals)
1592 cstring id = idDecl_getName (t);
1593 uentry ue = usymtab_lookupSafe (id);
1595 if (!uentry_isValid (ue))
1597 llerror (FLG_UNRECOG,
1598 message ("Variable used in globals list is undeclared: %s", id));
1602 if (!ctype_match (uentry_getType (ue), idDecl_getCtype (t)))
1606 message ("Variable %s used in globals list declared %s, "
1608 id, ctype_unparse (uentry_getType (ue)),
1609 ctype_unparse (idDecl_getCtype (t))),
1614 sRef sr = sRef_copy (uentry_getSref (ue));
1615 reflectGlobalQualifiers (sr, idDecl_getQuals (t));
1619 else if (s_processingVars)
1621 processVariable (t);
1623 else if (s_processingTypedef)
1625 ctype ct = idDecl_getCtype (t);
1628 DPRINTF (("Processing typedef: %s", ctype_unparse (ct)));
1630 e = uentry_makeIdDatatype (t);
1632 if (cstring_equal (idDecl_getName (t), context_getBoolName ())) {
1633 ctype rt = ctype_realType (ct);
1635 if (ctype_isEnum (rt)) {
1638 if (!(ctype_isInt (rt)
1639 || ctype_isUnknown (rt)
1640 || ctype_isChar (rt))) {
1643 message ("Boolean type %s defined using non-standard type %s (integral, char or enum type expected)",
1644 context_getBoolName (),
1645 ctype_unparse (ct)),
1646 uentry_whereLast (e));
1650 uentry_setType (e, ct);
1654 reflectStorageClass (e);
1655 checkTypeDecl (e, ct);
1657 e = usymtab_supReturnTypeEntry (e);
1661 llparseerror (message ("Suspect missing struct or union keyword: %q",
1662 idDecl_unparse (t)));
1668 ** moved from grammar
1671 static idDecl fixStructDecl (/*@returned@*/ idDecl d)
1673 if (ctype_isVisiblySharable (idDecl_getCtype (d))
1674 && context_getFlag (FLG_STRUCTIMPONLY))
1676 if (!qualList_hasAliasQualifier (idDecl_getQuals (d)))
1678 if (qualList_hasExposureQualifier (idDecl_getQuals (d)))
1680 idDecl_addQual (d, qual_createDependent ());
1684 idDecl_addQual (d, qual_createImpOnly ());
1693 declareUnnamedStruct (/*@only@*/ uentryList f)
1695 DPRINTF (("Unnamed struct: %s", uentryList_unparse (f)));
1697 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1699 int num = uentryList_size (f);
1700 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1705 (FLG_NUMSTRUCTFIELDS,
1706 message ("Structure declared with %d fields "
1707 "(limit is set to %d)",
1713 return (ctype_createUnnamedStruct (f));
1717 declareUnnamedUnion (/*@only@*/ uentryList f)
1719 DPRINTF (("Unnamed union: %s", uentryList_unparse (f)));
1721 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1723 int num = uentryList_size (f);
1724 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1729 (FLG_NUMSTRUCTFIELDS,
1730 message ("Union declared with %d fields "
1731 "(limit is set to %d)",
1737 return (ctype_createUnnamedUnion (f));
1740 ctype declareStruct (cstring id, /*@only@*/ uentryList f)
1744 int num = uentryList_size (f);
1746 DPRINTF (("Declare struct: %s / %s [%d]", id, uentryList_unparse (f),
1747 uentryList_size (f)));
1749 ct = ctype_createStruct (cstring_copy (id), f);
1751 DPRINTF (("Ctype: %s", ctype_unparse (ct)));
1753 ue = uentry_makeStructTagLoc (id, ct);
1755 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
1757 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1759 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1764 (FLG_NUMSTRUCTFIELDS,
1765 message ("Structure %q declared with %d fields "
1766 "(limit is set to %d)",
1767 uentry_getName (ue), num, max),
1768 uentry_whereLast (ue));
1772 return (usymtab_supTypeEntry (ue));
1775 ctype declareUnion (cstring id, uentryList f)
1779 int num = uentryList_size (f);
1781 ct = ctype_createUnion (cstring_copy (id), f);
1782 ue = uentry_makeUnionTagLoc (id, ct);
1784 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1786 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1791 (FLG_NUMSTRUCTFIELDS,
1792 message ("Union %q declared with %d fields "
1793 "(limit is set to %d)",
1794 uentry_getName (ue), num, max),
1795 uentry_whereLast (ue));
1799 return (usymtab_supTypeEntry (ue));
1802 ctype handleStruct (/*@only@*/ cstring id)
1804 if (usymtab_existsStructTag (id))
1806 ctype ct = uentry_getAbstractType (usymtab_lookupStructTag (id));
1813 return (ctype_createForwardStruct (id));
1817 ctype handleUnion (/*@only@*/ cstring id)
1819 if (usymtab_existsUnionTag (id))
1821 ctype ret = uentry_getAbstractType (usymtab_lookupUnionTag (id));
1827 return (ctype_createForwardUnion (id));
1832 handleEnum (cstring id)
1834 if (usymtab_existsEnumTag (id))
1836 ctype ret = uentry_getAbstractType (usymtab_lookupEnumTag (id));
1842 return (ctype_createForwardEnum (id));
1846 bool processingIterVars (void)
1848 return s_processingIterVars;
1851 uentry getCurrentIter (void)
1856 static bool flipOldStyle = FALSE;
1857 static bool flipNewStyle = TRUE;
1859 void setFlipOldStyle () { flipOldStyle = TRUE; }
1860 bool isFlipOldStyle () { return flipOldStyle; }
1861 bool isNewStyle () { return flipNewStyle; }
1862 void setNewStyle () { flipNewStyle = TRUE; }
1864 /*@dependent@*/ uentryList handleParamIdList (/*@dependent@*/ uentryList params)
1869 ** this is a really YUCKY hack to handle old style
1873 voptgenerror (FLG_OLDSTYLE,
1874 cstring_makeLiteral ("Old style function declaration"),
1877 DPRINTF (("Handle old style params: %s", uentryList_unparseFull (params)));
1879 uentryList_elements (params, current)
1881 uentry_setParam (current);
1882 uentry_setSref (current, sRef_makeParam
1883 (paramno, ctype_unknown,
1884 stateInfo_makeLoc (uentry_whereLast (current), SA_DECLARED)));
1886 } end_uentryList_elements;
1888 setGenericParamList (params);
1889 cscannerHelp_setExpectingTypeName ();
1894 /*@dependent@*/ uentryList handleParamTypeList (/*@returned@*/ uentryList params)
1898 uentryList_fixMissingNames (params);
1900 voptgenerror (FLG_OLDSTYLE,
1901 cstring_makeLiteral ("Old style function declaration."),
1904 setGenericParamList (params);
1905 flipOldStyle = FALSE;
1906 cscannerHelp_setExpectingTypeName ();
1915 ctype c = ctype_unknown;
1916 cstring id = cstring_makeLiteral ("va_alist");
1919 if (s_processingParams)
1921 int i = uentryList_lookupRealName (saveParamList, id);
1925 fileloc loc = context_getSaveLocation ();
1926 e = uentry_makeVariableSrefParam
1928 sRef_makeParam (i, c, stateInfo_makeLoc (loc, SA_DECLARED)));
1932 e = uentry_undefined; /* suppress gcc message */
1933 llfatalerrorLoc (cstring_makeLiteral ("va_dcl used without va_alist"));
1938 llerror (FLG_SYNTAX, cstring_makeLiteral ("va_dcl used outside of function declaration"));
1939 e = uentry_makeVariableLoc (id, c);
1943 uentry_setUsed (e, g_currentloc);
1944 usymtab_supEntrySref (e);
1947 /*@exposed@*/ sRef modListPointer (/*@exposed@*/ sRef s)
1949 ctype ct = sRef_getType (s);
1950 ctype rt = ctype_realType (ct);
1952 if (ctype_isAP (rt))
1954 if (context_inHeader () && ctype_isAbstract (ct))
1959 ("Modifies clause in header file dereferences abstract "
1960 "type %s (interface modifies clause should not depend "
1961 "on or expose type representation): %q",
1967 return (sRef_constructPointer (s));
1971 if (ctype_isKnown (rt))
1975 message ("Implementation modifies clause dereferences non-pointer (type %s): %q",
1985 /*@exposed@*/ sRef modListFieldAccess (sRef s, cstring f)
1987 ctype ct = sRef_getType (s);
1988 ctype rt = ctype_realType (ct);
1990 if (ctype_isStructorUnion (rt))
1992 uentry tf = uentryList_lookupField (ctype_getFields (rt), f);
1994 if (uentry_isUndefined (tf))
1996 voptgenerror (FLG_TYPE,
1997 message ("Modifies list accesses non-existent "
1998 "field %s of %t: %q", f, ct,
2003 return sRef_undefined;
2007 if (ctype_isAbstract (ct) && context_inHeader ())
2012 ("Modifies clause in header file accesses abstract "
2013 "type %s (interface modifies clause should not depend "
2014 "on or expose type representation): %q",
2021 cstring_markOwned (f);
2022 return (sRef_makeField (s, f));
2028 message ("Modifies clause dereferences non-pointer (type %s): %q",
2038 /*@dependent@*/ sRef clabstract_unrecognizedGlobal (cstring s)
2040 if (cstring_equalLit (s, "nothing"))
2042 return sRef_makeNothing ();
2044 else if (cstring_equalLit (s, "internalState"))
2046 return sRef_makeInternalState ();
2048 else if (cstring_equalLit (s, "fileSystem")
2049 || cstring_equalLit (s, "systemState"))
2051 return sRef_makeSystemState ();
2057 message ("Unrecognized identifier in globals list: %s", s),
2060 return sRef_undefined;
2064 /*@exposed@*/ sRef modListArrowAccess (sRef s, cstring f)
2066 ctype ct = sRef_getType (s);
2067 ctype rt = ctype_realType (ct);
2069 if (ctype_isRealPointer (rt))
2071 ctype b = ctype_baseArrayPtr (rt);
2072 ctype rb = ctype_realType (b);
2074 if (ctype_isStructorUnion (rb))
2076 uentry tf = uentryList_lookupField (ctype_getFields (rb), f);
2078 if (uentry_isUndefined (tf))
2080 voptgenerror (FLG_TYPE,
2081 message ("Modifies list arrow accesses non-existent "
2082 "field %s of %t: %q", f, b,
2087 return sRef_undefined;
2091 if (context_inHeader ())
2093 if (ctype_isAbstract (b))
2098 ("Modifies clause in header file arrow accesses abstract "
2099 "type %s (interface modifies clause should not depend "
2100 "on or expose type representation): %q",
2108 if (ctype_isAbstract (rt))
2113 ("Modifies clause arrow accesses inaccessible abstract "
2114 "type %s (interface modifies clause should not depend "
2115 "on or expose type representation): %q",
2123 cstring_markOwned (f);
2124 return (sRef_makeArrow (s, f));
2130 message ("Modifies clause arrow accesses pointer to "
2131 "non-structure (type %s): %q",
2141 message ("Modifies clause arrow accesses non-pointer (type %s): %q",
2151 sRef checkStateClausesId (uentry ue)
2153 cstring s = uentry_rawName (ue);
2155 if (sRef_isFileOrGlobalScope (uentry_getSref (ue)))
2159 message ("Global variable %s used state clause. (Global variables "
2160 "are not recognized in state clauses. If they are present "
2161 "they are ignored. "
2163 "sufficient interest in support for this, it may be "
2164 "added to a future release. Send mail to "
2165 "info@splint.org.)",
2169 return sRef_undefined;
2173 if (cstring_equalLit (s, "result"))
2177 message ("Special clause list uses %s which is a variable and has special "
2178 "meaning in a modifies list. (Special meaning assumed.)", s),
2181 uentry_showWhereDeclared (ue);
2185 return uentry_getSref (ue);
2191 don;t know what the real date is...
2197 based on checkSpecClausesId
2201 sRef checkbufferConstraintClausesId (uentry ue)
2204 cstring s = uentry_rawName (ue);
2206 if (cstring_equalLit (s, "result"))
2210 message ("Function clause list uses %s which is a variable and has special "
2211 "meaning in a modifies list. (Special meaning assumed.)", s),
2214 uentry_showWhereDeclared (ue);
2218 sr = uentry_getSref (ue);
2220 if (sRef_isInvalid (sr))
2222 llfatalerrorLoc (cstring_makeLiteral ("Macro defined constants can not be used in function "
2223 "constraints unless they are specifed with the constant "
2224 "annotation. To use a macro defined constant include an "
2225 "annotation of the form /*@constant <type> <name>=<value>@*/ "
2226 "somewhere before the function constraint. This restriction "
2227 "may be removed in future releases."));
2230 /* saveCopy to used to mitigate danger of accessing freed memory*/
2231 return sRef_saveCopy (sr);
2234 void checkModifiesId (uentry ue)
2236 cstring s = uentry_rawName (ue);
2238 if (cstring_equalLit (s, "nothing")
2239 || cstring_equalLit (s, "internalState")
2240 || cstring_equalLit (s, "systemState")
2241 || (cstring_equalLit (s, "fileSystem")))
2245 message ("Modifies list uses %s which is a variable and has special "
2246 "meaning in a modifies list. (Special meaning assumed.)", s),
2249 uentry_showWhereDeclared (ue);
2254 /*@exposed@*/ sRef fixModifiesId (cstring s)
2257 cstring pname = makeParam (s);
2258 uentry ue = usymtab_lookupSafe (pname);
2260 cstring_free (pname);
2262 if (cstring_equalLit (s, "nothing"))
2264 ret = sRef_makeNothing ();
2266 else if (cstring_equalLit (s, "internalState"))
2268 ret = sRef_makeInternalState ();
2270 else if (cstring_equalLit (s, "fileSystem")
2271 || cstring_equalLit (s, "systemState"))
2273 ret = sRef_makeSystemState ();
2277 ret = sRef_undefined;
2280 if (sRef_isValid (ret))
2282 if (uentry_isValid (ue))
2286 message ("Modifies list uses %s which is a parameter and has special "
2287 "meaning in a modifies list. (Special meaning assumed.)", s),
2293 if (uentry_isValid (ue))
2295 ret = uentry_getSref (ue);
2299 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2300 ret = sRef_undefined;
2304 message ("Unrecognized identifier in modifies comment: %s", s),
2314 sRef fixStateClausesId (cstring s)
2317 cstring pname = makeParam (s);
2318 uentry ue = usymtab_lookupSafe (pname);
2320 cstring_free (pname);
2322 if (cstring_equalLit (s, "result"))
2324 ret = sRef_makeResult (ctype_unknown);
2328 ret = sRef_undefined;
2331 if (sRef_isValid (ret))
2333 if (uentry_isValid (ue))
2337 message ("Function clause uses %s which is a parameter and has special "
2338 "meaning in a function clause. (Special meaning assumed.)", s),
2344 if (uentry_isValid (ue))
2346 ret = uentry_getSref (ue);
2348 if (sRef_isFileOrGlobalScope (ret))
2352 message ("Global variable %s used in function clause. (Global variables "
2353 "are not recognized in function clauses. If there is "
2354 "sufficient interest in support for this, it may be "
2355 "added to a future release. Send mail to "
2356 "info@splint.org.)",
2360 ret = sRef_undefined;
2366 /* drl This is the code for structure invariants
2368 It is no yet stable enough to be included in a Splint release.
2371 /*check that we're in a structure */
2373 /*@unused@*/ uentryList ueL;
2374 /*@unused@*/ uentry ue2;
2375 /*@unused@*/ ctype ct;
\r
2377 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2378 ret = sRef_undefined;
2381 ct = context_getLastStruct ( ct );
2383 llassert( ctype_isStruct(ct) );
2385 ueL = ctype_getFields (ct);
2387 ue2 = uentryList_lookupField (ueL, s);
2389 if (!uentry_isUndefined(ue2) )
2391 ret = uentry_getSref(ue2);
2394 message("Got field in structure in the annotation constraint: %s (or sref: %s)", s, sRef_unparse(ret) )
2404 message ("Unrecognized identifier in function clause: %s", s),
2414 sRef modListArrayFetch (/*@exposed@*/ sRef s, /*@unused@*/ sRef mexp)
2416 ctype ct = sRef_getType (s);
2417 ctype rt = ctype_realType (ct);
2419 if (ctype_isAP (rt))
2421 if (context_inHeader () && ctype_isAbstract (ct))
2426 ("Modifies clause in header file indexes abstract "
2427 "type %s (interface modifies clause should not depend "
2428 "on or expose type representation): %q",
2434 return (sRef_makeAnyArrayFetch (s));
2441 ("Implementation modifies clause uses array fetch on non-array (type %s): %q",
2442 ctype_unparse (ct), sRef_unparse (s)),
2448 static void clabstract_prepareFunction (uentry e)
2450 uentry_checkParams (e);
2451 DPRINTF (("After prepare: %s", uentry_unparseFull (e)));
2454 sRef clabstract_checkGlobal (exprNode e)
2457 llassert (exprNode_isInitializer (e));
2459 s = exprNode_getSref (e);
2460 DPRINTF (("Initializer: %s -> %s", exprNode_unparse (e), sRef_unparse (s)));
2463 return sRef_copy (s);