From da0cbc1ad4a553c4de111c1181ec7b42c5ddefce Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 5 Feb 2009 22:47:05 +0000 Subject: [PATCH] add support to the diagnostics machinery for mapping warnings and errors to 'fatal' error severity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63894 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Diagnostic.h | 21 ++++++++++++--------- lib/Basic/Diagnostic.cpp | 5 +++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 63dbdd6265..46a8314344 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -56,12 +56,15 @@ namespace clang { /// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs /// to either MAP_IGNORE (nothing), MAP_WARNING (emit a warning), MAP_ERROR - /// (emit as an error), or MAP_DEFAULT (handle the default way). + /// (emit as an error), or MAP_DEFAULT (handle the default way). It allows + /// clients to map errors to MAP_ERROR/MAP_DEFAULT or MAP_FATAL (stop + /// emitting diagnostics after this one). enum Mapping { MAP_DEFAULT = 0, //< Do not map this diagnostic. MAP_IGNORE = 1, //< Map this diagnostic to nothing, ignore it. MAP_WARNING = 2, //< Map this diagnostic to a warning. - MAP_ERROR = 3 //< Map this diagnostic to an error. + MAP_ERROR = 3, //< Map this diagnostic to an error. + MAP_FATAL = 4 //< Map this diagnostic to a fatal error. }; } @@ -73,7 +76,7 @@ class Diagnostic { public: /// Level - The level of the diagnostic, after it has been through mapping. enum Level { - Ignored, Note, Warning, Error + Ignored, Note, Warning, Error, Fatal }; enum ArgumentKind { @@ -96,8 +99,8 @@ private: DiagnosticClient *Client; /// DiagMappings - Mapping information for diagnostics. Mapping info is - /// packed into two bits per diagnostic. - unsigned char DiagMappings[diag::DIAG_UPPER_LIMIT/4]; + /// packed into four bits per diagnostic. + unsigned char DiagMappings[diag::DIAG_UPPER_LIMIT/2]; /// ErrorOccurred - This is set to true when an error is emitted, and is /// sticky. @@ -162,16 +165,16 @@ public: assert(Diag < diag::DIAG_UPPER_LIMIT && "Can only map builtin diagnostics"); assert(isBuiltinNoteWarningOrExtension(Diag) && "Cannot map errors!"); - unsigned char &Slot = DiagMappings[Diag/4]; - unsigned Bits = (Diag & 3)*2; - Slot &= ~(3 << Bits); + unsigned char &Slot = DiagMappings[Diag/2]; + unsigned Bits = (Diag & 1)*4; + Slot &= ~(7 << Bits); Slot |= Map << Bits; } /// getDiagnosticMapping - Return the mapping currently set for the specified /// diagnostic. diag::Mapping getDiagnosticMapping(diag::kind Diag) const { - return (diag::Mapping)((DiagMappings[Diag/4] >> (Diag & 3)*2) & 3); + return (diag::Mapping)((DiagMappings[Diag/2] >> (Diag & 1)*4) & 7); } bool hasErrorOccurred() const { return ErrorOccurred; } diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 2429bddfeb..ae23278f6c 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -33,6 +33,7 @@ enum { EXTENSION = 0x03, EXTWARN = 0x04, ERROR = 0x05, + FATAL = 0x06, class_mask = 0x07 }; @@ -259,7 +260,10 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { case diag::MAP_IGNORE: return Diagnostic::Ignored; case diag::MAP_WARNING: DiagClass = WARNING; break; case diag::MAP_ERROR: DiagClass = ERROR; break; + case diag::MAP_FATAL: DiagClass = FATAL; break; } + } else if (getDiagnosticMapping((diag::kind)DiagID) == diag::MAP_FATAL) { + DiagClass = FATAL; } // Map diagnostic classes based on command line argument settings. @@ -287,6 +291,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { case NOTE: return Diagnostic::Note; case WARNING: return Diagnostic::Warning; case ERROR: return Diagnostic::Error; + case FATAL: return Diagnostic::Fatal; } } -- 2.40.0