Merge pull request #2709 from GorillaSapiens/gps4bugs

added reporting of fatal/error/warning/note location generation with …
This commit is contained in:
Bob Andrews
2025-06-17 19:51:02 +02:00
committed by GitHub
2 changed files with 87 additions and 22 deletions

View File

@@ -39,6 +39,7 @@
/* common */ /* common */
#include "coll.h" #include "coll.h"
#include "debugflag.h"
#include "print.h" #include "print.h"
#include "strbuf.h" #include "strbuf.h"
@@ -183,11 +184,15 @@ static unsigned GetDiagnosticLineNum (void)
void Fatal (const char* Format, ...) void Fatal_ (const char *file, int line, const char* Format, ...)
/* Print a message about a fatal error and die */ /* Print a message about a fatal error and die */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
fprintf (stderr, "%s:%u: Fatal: ", GetDiagnosticFileName (), GetDiagnosticLineNum ()); fprintf (stderr, "%s:%u: Fatal: ", GetDiagnosticFileName (), GetDiagnosticLineNum ());
va_start (ap, Format); va_start (ap, Format);
@@ -203,11 +208,15 @@ void Fatal (const char* Format, ...)
void Internal (const char* Format, ...) void Internal_ (const char *file, int line, const char* Format, ...)
/* Print a message about an internal compiler error and die */ /* Print a message about an internal compiler error and die */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
fprintf (stderr, "%s:%u: Internal compiler error:\n", fprintf (stderr, "%s:%u: Internal compiler error:\n",
GetDiagnosticFileName (), GetDiagnosticLineNum ()); GetDiagnosticFileName (), GetDiagnosticLineNum ());
@@ -270,10 +279,15 @@ static void IntError (errcat_t EC, LineInfo* LI, const char* Msg, va_list ap)
void LIError (errcat_t EC, LineInfo* LI, const char* Format, ...) void LIError_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...)
/* Print an error message with the line info given explicitly */ /* Print an error message with the line info given explicitly */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntError (EC, LI, Format, ap); IntError (EC, LI, Format, ap);
va_end (ap); va_end (ap);
@@ -281,10 +295,15 @@ void LIError (errcat_t EC, LineInfo* LI, const char* Format, ...)
void Error (const char* Format, ...) void Error_ (const char *file, int line, const char* Format, ...)
/* Print an error message */ /* Print an error message */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntError (EC_PARSER, GetDiagnosticLI (), Format, ap); IntError (EC_PARSER, GetDiagnosticLI (), Format, ap);
va_end (ap); va_end (ap);
@@ -292,10 +311,15 @@ void Error (const char* Format, ...)
void PPError (const char* Format, ...) void PPError_ (const char *file, int line, const char* Format, ...)
/* Print an error message. For use within the preprocessor */ /* Print an error message. For use within the preprocessor */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntError (EC_PP, GetCurLineInfo (), Format, ap); IntError (EC_PP, GetCurLineInfo (), Format, ap);
va_end (ap); va_end (ap);
@@ -346,10 +370,15 @@ static void IntWarning (errcat_t EC, LineInfo* LI, const char* Msg, va_list ap)
void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...) void LIWarning_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...)
/* Print a warning message with the line info given explicitly */ /* Print a warning message with the line info given explicitly */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntWarning (EC, LI, Format, ap); IntWarning (EC, LI, Format, ap);
va_end (ap); va_end (ap);
@@ -357,10 +386,15 @@ void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...)
void Warning (const char* Format, ...) void Warning_ (const char *file, int line, const char* Format, ...)
/* Print a warning message */ /* Print a warning message */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntWarning (EC_PARSER, GetDiagnosticLI (), Format, ap); IntWarning (EC_PARSER, GetDiagnosticLI (), Format, ap);
va_end (ap); va_end (ap);
@@ -368,10 +402,15 @@ void Warning (const char* Format, ...)
void PPWarning (const char* Format, ...) void PPWarning_ (const char *file, int line, const char* Format, ...)
/* Print a warning message. For use within the preprocessor */ /* Print a warning message. For use within the preprocessor */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntWarning (EC_PP, GetCurLineInfo (), Format, ap); IntWarning (EC_PP, GetCurLineInfo (), Format, ap);
va_end (ap); va_end (ap);
@@ -436,10 +475,15 @@ static void IntNote (const LineInfo* LI, const char* Msg, va_list ap)
void LINote (const LineInfo* LI, const char* Format, ...) void LINote_ (const char *file, int line, const LineInfo* LI, const char* Format, ...)
/* Print a note message with the line info given explicitly */ /* Print a note message with the line info given explicitly */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntNote (LI, Format, ap); IntNote (LI, Format, ap);
va_end (ap); va_end (ap);
@@ -447,10 +491,15 @@ void LINote (const LineInfo* LI, const char* Format, ...)
void Note (const char* Format, ...) void Note_ (const char *file, int line, const char* Format, ...)
/* Print a note message */ /* Print a note message */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntNote (GetDiagnosticLI (), Format, ap); IntNote (GetDiagnosticLI (), Format, ap);
va_end (ap); va_end (ap);
@@ -458,10 +507,15 @@ void Note (const char* Format, ...)
void PPNote (const char* Format, ...) void PPNote_ (const char *file, int line, const char* Format, ...)
/* Print a note message. For use within the preprocessor */ /* Print a note message. For use within the preprocessor */
{ {
va_list ap; va_list ap;
if (Debug) {
fprintf(stderr, "[%s:%d] ", file, line);
}
va_start (ap, Format); va_start (ap, Format);
IntNote (GetDiagnosticLI (), Format, ap); IntNote (GetDiagnosticLI (), Format, ap);
va_end (ap); va_end (ap);

View File

@@ -103,28 +103,36 @@ struct StrBuf;
void PrintFileInclusionInfo (const LineInfo* LI); void PrintFileInclusionInfo (const LineInfo* LI);
/* Print hierarchy of file inclusion */ /* Print hierarchy of file inclusion */
void Fatal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2))); void Fatal_ (const char *file, int line, const char* Format, ...) attribute ((noreturn, format (printf, 3, 4)));
#define Fatal(...) Fatal_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a message about a fatal error and die */ /* Print a message about a fatal error and die */
void Internal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2))); void Internal_ (const char *file, int line, const char* Format, ...) attribute ((noreturn, format (printf, 3, 4)));
#define Internal(...) Internal_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a message about an internal compiler error and die */ /* Print a message about an internal compiler error and die */
void Error (const char* Format, ...) attribute ((format (printf, 1, 2))); void Error_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
#define Error(...) Error_(__FILE__, __LINE__, __VA_ARGS__)
/* Print an error message */ /* Print an error message */
void LIError (errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 3, 4))); void LIError_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 5, 6)));
#define LIError(...) LIError_(__FILE__, __LINE__, __VA_ARGS__)
/* Print an error message with the line info given explicitly */ /* Print an error message with the line info given explicitly */
void PPError (const char* Format, ...) attribute ((format (printf, 1, 2))); void PPError_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
#define PPError(...) PPError_(__FILE__, __LINE__, __VA_ARGS__)
/* Print an error message. For use within the preprocessor */ /* Print an error message. For use within the preprocessor */
void Warning (const char* Format, ...) attribute ((format (printf, 1, 2))); void Warning_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
#define Warning(...) Warning_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a warning message */ /* Print a warning message */
void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 3, 4))); void LIWarning_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 5, 6)));
#define LIWarning(...) LIWarning_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a warning message with the line info given explicitly */ /* Print a warning message with the line info given explicitly */
void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2))); void PPWarning_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
#define PPWarning(...) PPWarning_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a warning message. For use within the preprocessor */ /* Print a warning message. For use within the preprocessor */
void UnreachableCodeWarning (void); void UnreachableCodeWarning (void);
@@ -140,13 +148,16 @@ IntStack* FindWarning (const char* Name);
void ListWarnings (FILE* F); void ListWarnings (FILE* F);
/* Print a list of warning types/names to the given file */ /* Print a list of warning types/names to the given file */
void Note (const char* Format, ...) attribute ((format (printf, 1, 2))); void Note_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
#define Note(...) Note_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a note message */ /* Print a note message */
void LINote (const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 2, 3))); void LINote_ (const char *file, int line, const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 4, 5)));
#define LINote(...) LINote_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a note message with the line info given explicitly */ /* Print a note message with the line info given explicitly */
void PPNote (const char* Format, ...) attribute ((format (printf, 1, 2))); void PPNote_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
#define PPNote(...) PPNote_(__FILE__, __LINE__, __VA_ARGS__)
/* Print a note message. For use within the preprocessor */ /* Print a note message. For use within the preprocessor */
unsigned GetTotalErrors (void); unsigned GetTotalErrors (void);