X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/28bf4b0bfd405a2057d865910f8589c54a40f17b..f96fe483eb300ca66a20b6349fb5056f487f3a74:/src/llerror.c diff --git a/src/llerror.c b/src/llerror.c index b4bcd64..16ab431 100644 --- a/src/llerror.c +++ b/src/llerror.c @@ -1,6 +1,6 @@ /* -** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2001 University of Virginia, +** Splint - annotation-assisted static program checker +** Copyright (C) 1994-2002 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -17,9 +17,9 @@ ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ** MA 02111-1307, USA. ** -** For information on lclint: lclint-request@cs.virginia.edu -** To report a bug: lclint-bug@cs.virginia.edu -** For more information: http://lclint.cs.virginia.edu +** For information on splint: info@splint.org +** To report a bug: splint-bug@splint.org +** For more information: http://www.splint.org */ /* ** llerror.c @@ -27,12 +27,13 @@ ** error reporting procedures */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include # include # include "llbasic.h" # include "llmain.h" -# include "version.h" +# include "cpperror.h" +# include "Headers/version.h" /* Visual C++ finds a different version.h on some path! */ /* Don't allow possibly-recursive assertion failures. */ # undef llassert @@ -41,11 +42,8 @@ static void printIndentMessage (FILE *p_stream, /*@only@*/ cstring p_sc, int p_indent) /*@modifies *p_stream@*/ ; -# ifndef NOLCL static int lclerrors = 0; -# endif - -static int lastfileloclen = 10; +static size_t lastfileloclen = 10; static /*@only@*/ cstring lastmsg = cstring_undefined; static int mcount = 0; static /*@only@*/ cstring saveOneMessage = cstring_undefined; @@ -53,10 +51,10 @@ static /*@only@*/ fileloc lastparseerror = fileloc_undefined; static /*@only@*/ fileloc lastbug = fileloc_undefined; static bool llgenerrorreal (char *p_srcFile, int p_srcLine, /*@only@*/ cstring p_s, fileloc p_fl, bool p_iserror, bool p_indent) - /*@modifies g_msgstream@*/ ; + /*@modifies g_warningstream@*/ ; static bool llgenerroraux (char *p_srcFile, int p_srcLine, /*@only@*/ cstring p_s, fileloc p_fl, bool p_iserror, bool p_indent) - /*@modifies g_msgstream@*/ ; + /*@modifies g_warningstream@*/ ; static void printError (FILE *p_stream, /*@only@*/ cstring p_sc) /*@globals lastfileloclen @*/ @@ -64,10 +62,10 @@ static void printError (FILE *p_stream, /*@only@*/ cstring p_sc) static void printMessage (FILE *p_stream, /*@only@*/ cstring p_s) /*@modifies *p_stream@*/ ; -static void llgenhint (/*@only@*/ cstring p_s) /*@modifies g_msgstream@*/ ; +static void llgenhint (/*@only@*/ cstring p_s) /*@modifies g_warningstream@*/ ; static void showSourceLoc (char *srcFile, int srcLine) - /*@modifies g_msgstream@*/ + /*@modifies g_warningstream@*/ { if (context_getFlag (FLG_SHOWSOURCELOC)) { llgenhint (message ("%s:%d: Source code error generation point.", @@ -86,22 +84,25 @@ maxcp (/*@null@*/ /*@returned@*/ char *a, /*@null@*/ /*@returned@*/ char *b) static void printBugReport (void) { - fprintf (stderr, " *** Please report bug to %s ***\n", - LCLINT_MAINTAINER); + fprintf (g_errorstream, " *** Please report bug to %s ***\n", + SPLINT_MAINTAINER); llflush (); /* don't exit (EXIT_FAILURE); */ } static bool s_needsPrepare = TRUE; -void prepareMessage (void) +void prepareMessage () { - if (context_isPreprocessing () + DPRINTF (("Prepare message: %s", bool_unparse (context_loadingLibrary ()))); + showHerald (); + + if ((context_isPreprocessing () || context_loadingLibrary ()) && s_needsPrepare - && context_getDebug (FLG_SHOWSCAN)) + && context_getFlag (FLG_SHOWSCAN)) { llflush (); - fprintf (stderr, " >\n"); + displayScanClose (); s_needsPrepare = FALSE; } @@ -111,11 +112,10 @@ void prepareMessage (void) void closeMessage (void) { if (context_isPreprocessing () - && context_getDebug (FLG_SHOWSCAN)) + && context_getFlag (FLG_SHOWSCAN)) { llflush (); - fprintf (stderr, "< more preprocessing ."); - + displayScanOpen (cstring_makeLiteral ("more preprocessing .")); llassertprotect (!s_needsPrepare); s_needsPrepare = TRUE; } @@ -130,17 +130,31 @@ llmsg (/*@only@*/ cstring s) { context_setNeednl (); prepareMessage (); - printMessage (g_msgstream, s); + printMessage (g_messagestream, s); closeMessage (); } void lldiagmsg (/*@only@*/ cstring s) { + static bool inmsg = FALSE; + + if (inmsg) + { + fprintf (g_errorstream, + "Recursive message call detected: %s\n", + cstring_toCharsSafe (s)); + llexit (LLFAILURE); + } + + inmsg = TRUE; + context_setNeednl (); prepareMessage (); - printMessage (stderr, s); + printMessage (g_messagestream, s); closeMessage (); + + inmsg = FALSE; } void @@ -148,36 +162,31 @@ llmsgplain (/*@only@*/ cstring s) { context_setNeednl (); prepareMessage (); - printMessage (g_msgstream, s); + printMessage (g_messagestream, s); closeMessage (); } -void flagWarning (cstring s) +void llerror_flagWarning (cstring s) { if (context_getFlag (FLG_WARNFLAGS)) { - showHerald (); - - if (fileloc_isBuiltin (g_currentloc)) - { - llmsg (message ("Warning: %s", s)); - } - else - { - llgenmsg (message ("Warning: %s", s), g_currentloc); - } + llgenmsg (s, g_currentloc); + } + else + { + cstring_free (s); } } static void -llgenhint (/*@only@*/ cstring s) /*@modifies g_msgstream@*/ +llgenhint (/*@only@*/ cstring s) /*@modifies g_warningstream@*/ { int indent = context_getIndentSpaces () - 1; if (indent < 0) indent = 0; context_setNeednl (); - printIndentMessage (g_msgstream, s, indent); + printIndentMessage (g_warningstream, s, indent); } void @@ -240,19 +249,36 @@ llsuppresshint2 (char c, flagcode f1, flagcode f2) f2 = FLG_NAMECHECKS; } - if (cstring_isDefined (desc)) + if (f1 == f2) { - llgenhint (message ("%s (Setting either %h%s or %h%s will suppress message)", desc, - c, - flagcode_unparse (f1), - c, - flagcode_unparse (f2))); + if (cstring_isDefined (desc)) + { + llgenhint (message ("%s (Use %h%s to inhibit warning)", desc, + c, + flagcode_unparse (f1))); + } + else + { + llgenhint (message ("(Use %h%s to inhibit warning)", + c, flagcode_unparse (f1))); + } } else { - llgenhint (message ("(Setting either %h%s or %h%s will suppress message)", c, - flagcode_unparse (f1), - c, flagcode_unparse (f2))); + if (cstring_isDefined (desc)) + { + llgenhint (message ("%s (Use either %h%s or %h%s to inhibit warning)", desc, + c, + flagcode_unparse (f1), + c, + flagcode_unparse (f2))); + } + else + { + llgenhint (message ("(Use either %h%s or %h%s to inhibit warning)", c, + flagcode_unparse (f1), + c, flagcode_unparse (f2))); + } } } } @@ -276,12 +302,12 @@ llsuppresshint (char c, flagcode f) if (cstring_isDefined (desc)) { - llgenhint (message ("%s (%h%s will suppress message)", desc, c, + llgenhint (message ("%s (Use %h%s to inhibit warning)", desc, c, flagcode_unparse (f))); } else { - llgenhint (message ("(%h%s will suppress message)", c, + llgenhint (message ("(Use %h%s to inhibit warning)", c, flagcode_unparse (f))); } } @@ -299,7 +325,7 @@ llnosuppresshint (flagcode f) if (cstring_isDefined (desc)) { - printError (g_msgstream, message (" %s", desc)); + printError (g_warningstream, message (" %s", desc)); } } } @@ -344,7 +370,7 @@ mstring_split (/*@returned@*/ char **sp, ** ** if there is a newline in first maxline characters, split there ** if line len is <= maxline, return no split - ** if there is a ':' or ';' followed by ' ' in first maxline characters, + ** if there is a ':' or ';' or ',' followed by ' ' in first maxline characters, ** split there unless the ' ' is followed by a '}', then ** split after '}' ** of the ';' is inside quotation marks @@ -384,8 +410,9 @@ mstring_split (/*@returned@*/ char **sp, { int i = 0; char savechar; - char *lcolon, *lsemi, *splitat; - + char *lcolon, *lsemi, *lcomma; + char *splitat; + splitat = NULL; t = s + maxline - 1; @@ -394,6 +421,8 @@ mstring_split (/*@returned@*/ char **sp, *t = '\0'; lcolon = strrchr (s, ':'); lsemi = strrchr (s, ';'); + lcomma = strrchr (s, ','); + *t = savechar; splitat = maxcp (lcolon, lsemi); @@ -401,7 +430,9 @@ mstring_split (/*@returned@*/ char **sp, if (splitat != NULL && ((int)(splitat - s) > MINLINE) && *(splitat) != '\0' && *(splitat + 1) == ' ' - && (*(splitat + 2) != '}' && (*(splitat + 2) != '\0'))) + && (*(splitat + 2) != '}' + && *(splitat + 2) != ',' + && (*(splitat + 2) != '\0'))) { *(splitat + 1) = '\0'; t = splitat + 2; @@ -410,6 +441,24 @@ mstring_split (/*@returned@*/ char **sp, return; } + if (lcomma != NULL && ((lcomma - s) > maxline - 5)) + { + splitat = lcomma; + + if (splitat != NULL && ((int)(splitat - s) > MINLINE) + && *(splitat) != '\0' + && *(splitat + 1) == ' ' + && (*(splitat + 2) != '}' + && (*(splitat + 2) != '\0'))) + { + *(splitat + 1) = '\0'; + t = splitat + 2; + *tp = t; + llassertprotect (*tp == NULL || (*tp > osp)); + return; + } + } + while (*t != ' ' && *t != '\t' && i < MAXSEARCH) { t--; @@ -501,7 +550,7 @@ void cleanupMessages () if (unprinted == 1 && cstring_isDefined (saveOneMessage)) { prepareMessage (); - printError (g_msgstream, saveOneMessage); + printError (g_warningstream, saveOneMessage); closeMessage (); saveOneMessage = cstring_undefined; } @@ -513,7 +562,7 @@ void cleanupMessages () saveOneMessage = cstring_undefined; } - fprintf (g_msgstream, "%s: (%d more similar errors unprinted)\n", + fprintf (g_warningstream, "%s: (%d more similar errors unprinted)\n", cstring_toCharsSafe (fileloc_filename (g_currentloc)), mcount - context_getLimit ()); } @@ -530,7 +579,7 @@ llgenmsg (/*@only@*/ cstring s, fileloc fl) lastfileloclen = cstring_length (flstring); prepareMessage (); - (void) printError (g_msgstream, message ("%q: %q", flstring, s)); + (void) printError (g_warningstream, message ("%q: %q", flstring, s)); closeMessage (); } @@ -540,7 +589,7 @@ llgenindentmsg (/*@only@*/ cstring s, fileloc fl) cstring flstring = fileloc_unparse (fl); prepareMessage (); - (void) printIndentMessage (g_msgstream, message ("%q: %q", flstring, s), context_getIndentSpaces ()); + (void) printIndentMessage (g_warningstream, message ("%q: %q", flstring, s), context_getIndentSpaces ()); closeMessage (); } @@ -548,7 +597,7 @@ void llgenindentmsgnoloc (/*@only@*/ cstring s) { prepareMessage (); - (void) printIndentMessage (g_msgstream, s, context_getIndentSpaces ()); + (void) printIndentMessage (g_warningstream, s, context_getIndentSpaces ()); closeMessage (); } @@ -563,7 +612,8 @@ llgentypeerroraux (char *srcFile, int srcLine, ctype ut1 = t1; ctype ut2 = t2; - DPRINTF (("Type error: %s / %s : %s / %s", + DPRINTF (("Type error [%s]: %s / %s : %s / %s", + flagcode_unparse (ocode), exprNode_unparse (e1), exprNode_unparse (e2), ctype_unparse (t1), ctype_unparse (t2))); @@ -612,7 +662,20 @@ llgentypeerroraux (char *srcFile, int srcLine, { if (!bool_equal (ctype_isSigned (ut1), ctype_isSigned (ut2))) { - hcode = FLG_IGNORESIGNS; + if (ctype_isArbitraryIntegral (ctype_realType (ut1)) + && !ctype_isArbitraryIntegral (ctype_realType (ut2))) + { + hcode = FLG_MATCHANYINTEGRAL; + } + else if (ctype_isArbitraryIntegral (ctype_realType (ut2)) + && !ctype_isArbitraryIntegral (ctype_realType (ut1))) + { + hcode = FLG_MATCHANYINTEGRAL; + } + else + { + hcode = FLG_IGNORESIGNS; + } } else { @@ -689,56 +752,80 @@ llgentypeerroraux (char *srcFile, int srcLine, ; } } - else if (ctype_isAbstract (ut1) && !ctype_isAbstract (ut2)) + else { - uentry ue1 = usymtab_getTypeEntry (ctype_typeId (ut1)); - ctype ct = uentry_getType (ue1); + ; + } + + if (hcode == INVALID_FLAG) + { + DPRINTF (("[%s] %s - %s / %s", + ctype_unparse (ut1), + bool_unparse (ctype_isEnum (ut1)), + bool_unparse (ctype_isEnum (ctype_realType (ut1))), + bool_unparse (ctype_isInt (ut2)))); - if (ctype_match (ct, ut2)) + if (ctype_isAbstract (ut1) && !ctype_isAbstract (ut2)) { - code = FLG_ABSTRACT; - hint = message ("Underlying types match, but %s is an " - "abstract type that is not accessible here.", - ctype_unparse (t1)); + uentry ue1 = usymtab_getTypeEntry (ctype_typeId (ut1)); + ctype ct = uentry_getType (ue1); + + if (ctype_match (ct, ut2)) + { + code = FLG_ABSTRACT; + hint = message ("Underlying types match, but %s is an " + "abstract type that is not accessible here.", + ctype_unparse (t1)); + } } - } - else if (ctype_isAbstract (ut2) && !ctype_isAbstract (ut1)) - { - uentry ue = usymtab_getTypeEntry (ctype_typeId (ut2)); - ctype ct = uentry_getType (ue); + else if (ctype_isAbstract (ut2) && !ctype_isAbstract (ut1)) + { + uentry ue = usymtab_getTypeEntry (ctype_typeId (ut2)); + ctype ct = uentry_getType (ue); + + if (ctype_match (ct, ut1)) + { + code = FLG_ABSTRACT; + hint = message ("Underlying types match, but %s is an " + "abstract type that is not accessible here.", + ctype_unparse (t2)); + } + } + else + { + ; /* Not an abstract mismatch. */ + } + - if (ctype_match (ct, ut1)) + if (hcode == INVALID_FLAG) { - code = FLG_ABSTRACT; - hint = message ("Underlying types match, but %s is an " - "abstract type that is not accessible here.", - ctype_unparse (t2)); + if ((ctype_isEnum (ut1) && ctype_isInt (ut2)) + || (ctype_isEnum (ut2) && ctype_isInt (ut1))) + { + hcode = FLG_ENUMINT; + } + else if ((ctype_isEnum (ut1) && ctype_isInt (ut2)) + || (ctype_isEnum (ut2) && ctype_isInt (ut1))) + { + hcode = FLG_ENUMINT; + } + else if ((ctype_isSignedChar (ut1) && ctype_isUnsignedChar (ut2)) + || (ctype_isUnsignedChar (ut1) && ctype_isSignedChar (ut2))) + { + hcode = FLG_CHARUNSIGNEDCHAR; + } + else if (ctype_isNumeric (ut1) && ctype_isNumeric (ut2)) + { + hcode = FLG_RELAXTYPES; + DPRINTF (("Setting relax types!")); + } + else + { + DPRINTF (("No special type rule: %s / %s", ctype_unparse (ut1), + ctype_unparse (ut2))); + } } } - else if ((ctype_isEnum (ut1) && ctype_isArbitraryIntegral (ut2)) - || (ctype_isEnum (ut2) && ctype_isArbitraryIntegral (ut1))) - { - code = FLG_ENUMINT; - } - else if ((ctype_isEnum (ut1) && ctype_isArbitraryIntegral (ut2)) - || (ctype_isEnum (ut2) && ctype_isArbitraryIntegral (ut1))) - { - code = FLG_ENUMINT; - } - else if ((ctype_isSignedChar (ut1) && ctype_isUnsignedChar (ut2)) - || (ctype_isUnsignedChar (ut1) && ctype_isSignedChar (ut2))) - { - code = FLG_CHARUNSIGNEDCHAR; - } - else if (ctype_isNumeric (ut1) && ctype_isNumeric (ut2)) - { - code = FLG_RELAXTYPES; - } - else - { - DPRINTF (("No special type rule: %s / %s", ctype_unparse (ut1), - ctype_unparse (ut2))); - } if (cstring_isDefined (hint)) { @@ -760,8 +847,17 @@ llgentypeerroraux (char *srcFile, int srcLine, if (hcode != INVALID_FLAG && hcode != ocode) { code = hcode; - llshowhint (code); + if (context_flagOn (code, fl)) + { + /* The flag is alreay set, something buggy in the flag code */ + llcontbug (message ("No hint available, flag %s is already set.", + flagcode_unparse (code))); + } + else + { + llshowhint (code); + } } else { @@ -789,7 +885,15 @@ xllgenformattypeerror (char *srcFile, int srcLine, ctype t1, exprNode e1, ctype t2, exprNode e2, /*@only@*/ cstring s, fileloc fl) { - return llgentypeerroraux (srcFile, srcLine, FLG_FORMATTYPE, t1, e1, t2, e2, s, fl); + if (!context_suppressFlagMsg (FLG_FORMATTYPE, fl)) + { + return llgentypeerroraux (srcFile, srcLine, FLG_FORMATTYPE, t1, e1, t2, e2, s, fl); + } + else + { + cstring_free (s); + return FALSE; + } } bool @@ -860,11 +964,7 @@ llgenerroraux (char *srcFile, int srcLine, cstring_free (s); return FALSE; } - else - { - ; - } - + if (llgenerrorreal (srcFile, srcLine, s, fl, iserror, indent)) { return TRUE; } else { @@ -902,6 +1002,12 @@ llgenerrorreal (char *srcFile, int srcLine, return FALSE; } + /* + ** If herald has not been displayed, display it before the first message. + */ + + showHerald (); + if (iserror) context_hasError (); if (context_unlimitedMessages ()) @@ -1013,24 +1119,24 @@ llgenerrorreal (char *srcFile, int srcLine, if (context_inIterDef ()) { - fprintf (g_msgstream, "%s: (in iter %s)\n", + fprintf (g_warningstream, "%s: (in iter %s)\n", cstring_toCharsSafe (fname), cstring_toCharsSafe (context_inFunctionName ())); } else if (context_inIterEnd ()) { - fprintf (g_msgstream, "%s: (in iter finalizer %s)\n", + fprintf (g_warningstream, "%s: (in iter finalizer %s)\n", cstring_toCharsSafe (fname), cstring_toCharsSafe (context_inFunctionName ())); } else if (context_inMacro ()) { - fprintf (g_msgstream, "%s: (in macro %s)\n", cstring_toCharsSafe (fname), + fprintf (g_warningstream, "%s: (in macro %s)\n", cstring_toCharsSafe (fname), cstring_toCharsSafe (context_inFunctionName ())); } else { - fprintf (g_msgstream, "%s: (in function %s)\n", + fprintf (g_warningstream, "%s: (in function %s)\n", cstring_toCharsSafe (fname), cstring_toCharsSafe (context_inFunctionName ())); } @@ -1044,11 +1150,11 @@ llgenerrorreal (char *srcFile, int srcLine, if (indent) { - printError (g_msgstream, message (" %q: %q", flstring, s)); + printError (g_warningstream, message (" %q: %q", flstring, s)); } else { - printError (g_msgstream, message ("%q: %q", flstring, s)); + printError (g_warningstream, message ("%q: %q", flstring, s)); } showSourceLoc (srcFile, srcLine); @@ -1103,9 +1209,9 @@ static void printError (FILE *stream, /*@only@*/ cstring sc) { int maxlen = context_getLineLen (); - int nspaces = lastfileloclen + 5; + size_t nspaces = lastfileloclen + 5; int nextlen = maxlen - nspaces; - int len = cstring_length (sc); + size_t len = cstring_length (sc); int indent = 0; char *s = cstring_toCharsSafe (sc); char *os = s; @@ -1113,7 +1219,7 @@ void printError (FILE *stream, /*@only@*/ cstring sc) DPRINTF (("Print error: [%s]", sc)); - if (len < (maxlen + nextlen) && (strchr (s, '\n') == NULL)) + if (size_toInt (len) < (maxlen + nextlen) && (strchr (s, '\n') == NULL)) { mstring_split (&s, &t, maxlen, &indent); @@ -1123,8 +1229,8 @@ void printError (FILE *stream, /*@only@*/ cstring sc) { len = mstring_length (t); - if (len < (maxlen - 3) && (strchr (t, '\n') == NULL) - && len > (nextlen - 1)) + if (size_toInt (len) < (maxlen - 3) && (strchr (t, '\n') == NULL) + && size_toInt (len) > (nextlen - 1)) { fprintf (stream, " %s\n", t); } @@ -1133,7 +1239,7 @@ void printError (FILE *stream, /*@only@*/ cstring sc) char *spaces = (char *) dmalloc ((nspaces + 1) * sizeof (*spaces)); int i; - for (i = 0; i < nspaces; i++) + for (i = 0; i < size_toInt (nspaces); i++) { spaces[i] = ' '; } @@ -1155,7 +1261,7 @@ void printError (FILE *stream, /*@only@*/ cstring sc) { DPRINTF (("Here 1: [%s]", sc)); - if (len < (maxlen + maxlen - 1) && (strchr (s, '\n') != NULL)) + if (size_toInt (len) < (maxlen + maxlen - 1) && (strchr (s, '\n') != NULL)) { nspaces = ((maxlen + maxlen - 1) - len) / 2; @@ -1172,7 +1278,7 @@ void printError (FILE *stream, /*@only@*/ cstring sc) char *spaces = (char *) dmalloc ((nspaces + 1) * sizeof (*spaces)); int i; - for (i = 0; i < nspaces; i++) + for (i = 0; i < size_toInt (nspaces); i++) { spaces[i] = ' '; } @@ -1204,7 +1310,7 @@ void printError (FILE *stream, /*@only@*/ cstring sc) if (t != NULL) { char *spaces = (char *) dmalloc ((nspaces + 1) * sizeof (*spaces)); - int i; + size_t i; for (i = 0; i < nspaces; i++) { @@ -1236,26 +1342,24 @@ void xllfatalbug (char *srcFile, int srcLine, /*@only@*/ cstring s) { prepareMessage (); - printError (stderr, message ("%q: *** Fatal bug: %q", - fileloc_unparse (g_currentloc), s)); + printError (g_errorstream, message ("%q: *** Fatal bug: %q", + fileloc_unparse (g_currentloc), s)); showSourceLoc (srcFile, srcLine); printCodePoint (); printBugReport (); llexit (LLFAILURE); } -# ifndef NOLCL void lclfatalbug (char *msg) { prepareMessage (); - printError (stderr, + printError (g_errorstream, message ("*** Fatal Bug: %s", cstring_fromChars (msg))); printCodePoint (); printBugReport (); llexit (LLFAILURE); } -# endif void checkParseError (void) @@ -1277,7 +1381,8 @@ void llbugaux (cstring file, int line, /*@only@*/ cstring s) { cstring temps = fileloc_unparseRaw (file, line); - fprintf (stderr, "%s: Recursive bug detected: %s\n", + fprintf (g_errorstream, + "%s: Recursive bug detected: %s\n", cstring_toCharsSafe (temps), cstring_toCharsSafe (s)); cstring_free (temps); @@ -1289,107 +1394,88 @@ void llbugaux (cstring file, int line, /*@only@*/ cstring s) prepareMessage (); - /*@i3232@*/ - /* - if (fileloc_isRealLib (g_currentloc)) - { - DPRINTF (("Here we are!")); - llfatalerror (message ("%q: Library file appears to be corrupted. Error: %q: %s", - fileloc_unparse (g_currentloc), - fileloc_unparseRaw (file, line), - s)); - } - */ - if (fileloc_withinLines (lastparseerror, g_currentloc, 7)) { llfatalerror (message ("%q: Cannot recover from parse error.", fileloc_unparse (g_currentloc))); } - (void) fflush (g_msgstream); - printError (stderr, message ("%q: *** Internal Bug at %q: %q [errno: %d]", - fileloc_unparse (g_currentloc), - fileloc_unparseRaw (file, line), - s, errno)); - printCodePoint (); + (void) fflush (g_warningstream); + + printError (g_errorstream, + message ("%q: *** Internal Bug at %q: %q [errno: %d]", + fileloc_unparse (g_currentloc), + fileloc_unparseRaw (file, line), + s, errno)); + + /* printCodePoint (); no longer useful */ - (void) fflush (stderr); - perror ("Possible system error diagnostic: "); - (void) fflush (stderr); + llflush (); + + /* + ** This is confusing, and hardly ever useful. + + if (errno != 0) + { + perror ("Possible system error diagnostic: "); + } + + ** + */ printBugReport (); + llflush (); numbugs++; if (numbugs > context_getBugsLimit () && fileloc_withinLines (lastbug, g_currentloc, 2)) { - llfatalerror (message ("%q: Cannot recover from last bug. (If you really want LCLint to try to continue, use -bugslimit .)", - fileloc_unparse (g_currentloc))); + llfatalerror + (message ("%q: Cannot recover from last bug. " + "(If you really want Splint to try to continue, use -bugslimit .)", + fileloc_unparse (g_currentloc))); } - fprintf (stderr, " (attempting to continue, results may be incorrect)\n"); + fprintf (g_errorstream, " (attempting to continue, results may be incorrect)\n"); fileloc_free (lastbug); lastbug = fileloc_copy (g_currentloc); closeMessage (); - - (void) fflush (stderr); inbug = FALSE; } -# ifndef NOLCL void lclbug (/*@only@*/ cstring s) { prepareMessage (); - printError (stderr, message ("*** Internal Bug: %q", s)); + printError (g_errorstream, message ("*** Internal Bug: %q", s)); printCodePoint (); printBugReport (); - fprintf (stderr, " (attempting to continue, results may be incorrect)\n"); + fprintf (g_errorstream, " (attempting to continue, results may be incorrect)\n"); closeMessage (); } -# endif void -llfatalerror (cstring s) +xllfatalerror (char *srcFile, int srcLine, cstring s) { prepareMessage (); - printError (stderr, s); - printError (stderr, cstring_makeLiteral ("*** Cannot continue.")); + printError (g_errorstream, s); + printError (g_errorstream, cstring_makeLiteral ("*** Cannot continue.")); + showSourceLoc (srcFile, srcLine); llexit (LLFAILURE); } void -llfatalerrorLoc (/*@only@*/ cstring s) +xllfatalerrorLoc (char *srcFile, int srcLine, /*@only@*/ cstring s) { prepareMessage (); - (void) fflush (g_msgstream); - printError (stderr, message ("%q: %q", fileloc_unparse (g_currentloc), s)); - printError (stderr, cstring_makeLiteral ("*** Cannot continue.")); - (void) fflush (g_msgstream); + (void) fflush (g_warningstream); + printError (g_errorstream, message ("%q: %q", fileloc_unparse (g_currentloc), s)); + printError (g_errorstream, cstring_makeLiteral ("*** Cannot continue.")); + showSourceLoc (srcFile, srcLine); + (void) fflush (g_warningstream); llexit (LLFAILURE); } -void -xllgloberror (char *srcFile, int srcLine, /*@only@*/ cstring s) -{ - if (context_inSuppressRegion ()) - { - cstring_free (s); - } - else - { - context_setNeednl (); - prepareMessage (); - context_hasError (); - flagcode_recordError (FLG_SPECIAL); - printError (g_msgstream, s); - showSourceLoc (srcFile, srcLine); - closeMessage (); - } -} - -# ifndef NOLCL bool lclHadError (void) { @@ -1426,15 +1512,14 @@ xlclerror (char *srcFile, int srcLine, ltoken t, /*@only@*/ cstring msg) if (ltoken_getCode (t) != NOTTOKEN) { cstring loc = ltoken_unparseLoc (t); - lastfileloclen = cstring_length (loc); - printError (g_msgstream, message ("%q: %q", loc, msg)); + printError (g_warningstream, message ("%q: %q", loc, msg)); showSourceLoc (srcFile, srcLine); } else { - printError (g_msgstream, msg); + printError (g_warningstream, msg); showSourceLoc (srcFile, srcLine); } } @@ -1443,24 +1528,32 @@ void lclplainerror (/*@only@*/ cstring msg) { lclerrors++; - - printError (g_msgstream, msg); + printError (g_warningstream, msg); } void lclfatalerror (ltoken t, /*@only@*/ cstring msg) { - lclerror (t, msg); - (void) fflush (g_msgstream); - printError (stderr, cstring_makeLiteral ("*** Cannot continue")); + if (ltoken_getCode (t) != NOTTOKEN) + { + cstring loc = ltoken_unparseLoc (t); + lastfileloclen = cstring_length (loc); + printError (g_errorstream, message ("%q: %q", loc, msg)); + } + else + { + printError (g_errorstream, msg); + } + + printError (g_errorstream, cstring_makeLiteral ("*** Cannot continue")); llexit (LLFAILURE); } void lclplainfatalerror (/*@only@*/ cstring msg) { - (void) fflush (g_msgstream); - printError (stderr, message ("*** Cannot continue: %q", msg)); + (void) fflush (g_warningstream); + printError (g_errorstream, message ("*** Cannot continue: %q", msg)); llexit (LLFAILURE); } @@ -1484,7 +1577,6 @@ lclRedeclarationError (ltoken id) lclerror (id, message ("Identifier redeclared: %s", s)); } } -# endif void genppllerror (flagcode code, /*@only@*/ cstring s) { @@ -1496,9 +1588,9 @@ void genppllerror (flagcode code, /*@only@*/ cstring s) { if (context_getFlag (code)) { - if (context_getFlag (FLG_SHOWSCAN) && !context_isInCommandLine ()) + if (!context_isInCommandLine ()) { - fprintf (g_msgstream, " >\n"); + displayScanClose (); } llerror (code, s); @@ -1508,9 +1600,9 @@ void genppllerror (flagcode code, /*@only@*/ cstring s) llsuppresshint ('-', code); } - if (context_getFlag (FLG_SHOWSCAN) && !context_isInCommandLine ()) + if (!context_isInCommandLine ()) { - fprintf (stderr, "< more preprocessing ."); + displayScanOpen (cstring_makeLiteral ("< more preprocessing .")); } } else @@ -1554,11 +1646,11 @@ void ppllerror (/*@only@*/ cstring s) void pplldiagmsg (cstring s) { - if (context_getDebug (FLG_SHOWSCAN) && !context_isInCommandLine ()) + if (!context_isInCommandLine ()) { - fprintf (stderr, " >\n"); + displayScanClose (); lldiagmsg (s); - fprintf (stderr, "< more preprocessing ."); + displayScanOpen (cstring_makeLiteral ("< more preprocessing .")); } else { @@ -1568,16 +1660,9 @@ void pplldiagmsg (cstring s) void loadllmsg (cstring s) { - if (context_getDebug (FLG_SHOWSCAN)) - { - fprintf (stderr, " >\n"); - lldiagmsg (s); - fprintf (stderr, "< ."); - } - else - { - lldiagmsg (s); - } + displayScanClose (); + lldiagmsg (s); + displayScanOpen (cstring_makeLiteral ("< .")); } static void llreportparseerror (/*@only@*/ cstring s) @@ -1595,6 +1680,32 @@ static void llreportparseerror (/*@only@*/ cstring s) } } +bool xcppoptgenerror (char *srcFile, int srcLine, + flagcode o, + /*@only@*/ cstring s, + cppReader *pfile) +{ + bool res = FALSE; + fileloc loc = cppReader_getLoc (pfile); + + if (context_flagOn (o, loc)) + { + if (xlloptgenerror (srcFile, srcLine, o, s, loc)) + { + cppReader_printContainingFiles (pfile); + res = TRUE; + } + } + else + { + cstring_free (s); + } + + fileloc_free (loc); + + return res; +} + bool xlloptgenerror (char *srcFile, int srcLine, flagcode o, /*@only@*/ cstring s, fileloc loc) { @@ -1697,7 +1808,7 @@ bool xllnoptgenerror (char *srcFile, int srcLine, return FALSE; } -void llparseerror (cstring s) +void xllparseerror (char *srcFile, int srcLine, cstring s) { if (context_getFlag (FLG_TRYTORECOVER)) { @@ -1707,14 +1818,16 @@ void llparseerror (cstring s) { if (cstring_isDefined (s)) { - llfatalerror (message ("%q: Parse Error: %q. " - "Too many errors, giving up.", - fileloc_unparse (g_currentloc), s)); + xllfatalerror (srcFile, srcLine, + message ("%q: Parse Error: %q. " + "Too many errors, giving up.", + fileloc_unparse (g_currentloc), s)); } else { - llfatalerror (message ("%q: Parse Error. Too many errors, giving up.", - fileloc_unparse (g_currentloc))); + xllfatalerror (srcFile, srcLine, + message ("%q: Parse Error. Too many errors, giving up.", + fileloc_unparse (g_currentloc))); } } else @@ -1723,10 +1836,12 @@ void llparseerror (cstring s) { llreportparseerror (message ("Parse Error: %q. Attempting to continue.", s)); + showSourceLoc (srcFile, srcLine); } else { llreportparseerror (message ("Parse Error. Attempting to continue.")); + showSourceLoc (srcFile, srcLine); } } } @@ -1743,9 +1858,10 @@ void llparseerror (cstring s) msg = message ("Parse Error."); } - llfatalerror - (message ("%q: %s (For help on parse errors, " - "see lclint -help parseerrors.)", + xllfatalerror + (srcFile, srcLine, + message ("%q: %s (For help on parse errors, " + "see splint -help parseerrors.)", fileloc_unparse (g_currentloc), msg)); } } @@ -1820,10 +1936,10 @@ void llquietbugaux (cstring s, /*@unused@*/ cstring file, /*@unused@*/ int line) # if 0 # ifdef HOMEVERSION llflush (); - printError (stderr, message ("%q: *** Internal Bug at %q: %q [errno: %d]", - fileloc_unparse (g_currentloc), - fileloc_unparseRaw (file, line), - s, errno)); + printError (g_errorstream, message ("%q: *** Internal Bug at %q: %q [errno: %d]", + fileloc_unparse (g_currentloc), + fileloc_unparseRaw (file, line), + s, errno)); printCodePoint (); llflush (); # endif @@ -1834,6 +1950,90 @@ void llquietbugaux (cstring s, /*@unused@*/ cstring file, /*@unused@*/ int line) void llflush (void) { - (void) fflush (g_msgstream); - (void) fflush (stderr); + (void) fflush (g_warningstream); + (void) fflush (g_messagestream); +} + +static bool s_scanOpen = FALSE; + +void displayScan (cstring msg) +{ + if (s_scanOpen) + { + displayScanClose (); + } + + llassert (!s_scanOpen); + + if (context_getFlag (FLG_SHOWSCAN)) + { + showHerald (); + fprintf (g_messagestream, "< %s >\n", cstring_toCharsSafe (msg)); + (void) fflush (g_messagestream); + } + + cstring_free (msg); +} + +void displayScanOpen (cstring msg) +{ + if (s_scanOpen) + { + displayScanClose (); + } + + llassert (!s_scanOpen); + s_scanOpen = TRUE; + + if (context_getFlag (FLG_SHOWSCAN)) + { + fprintf (g_messagestream, "< %s", cstring_toCharsSafe (msg)); + (void) fflush (g_messagestream); + } + + cstring_free (msg); } + +void displayScanContinue (/*@temp@*/ cstring msg) +{ + if (context_getFlag (FLG_SHOWSCAN)) + { + if (s_scanOpen) + { + fprintf (g_messagestream, "%s", cstring_toCharsSafe (msg)); + (void) fflush (g_messagestream); + } + else + { + /* + ** Don't call bug recursively + */ + + fprintf (stderr, "*** Bug: scan continue scan not open\n"); + } + } +} + +void displayScanClose (void) +{ + if (s_scanOpen) + { + if (context_getFlag (FLG_SHOWSCAN)) + { + fprintf (g_messagestream, " >\n"); + (void) fflush (g_messagestream); + } + } + else + { + /* + ** Don't call bug recursively + */ + + fprintf (stderr, "*** Bug: scan close scan not open\n"); + } + + s_scanOpen = FALSE; +} + +