diff options
author | Alp Toker <alp@nuanti.com> | 2014-06-12 10:15:20 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-06-12 10:15:20 +0000 |
commit | 46df1c0db8a3265009f5b315247b657708883fe8 (patch) | |
tree | b8c65f5bf61b4484ce3184f34265c0ec8815ea63 /clang/lib | |
parent | 789ba735703c70c928b8753b80280eecb374050a (diff) | |
download | bcm5719-llvm-46df1c0db8a3265009f5b315247b657708883fe8.tar.gz bcm5719-llvm-46df1c0db8a3265009f5b315247b657708883fe8.zip |
Complete the switch from mappings to declarative diagnostic severities
This begins to address cognitive dissonance caused by treating the Note
diagnostic level as a severity in the diagnostic engine.
No change in functionality.
llvm-svn: 210758
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/ARCMigrate/ARCMT.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 22 | ||||
-rw-r--r-- | clang/lib/Basic/DiagnosticIDs.cpp | 94 | ||||
-rw-r--r-- | clang/lib/Basic/Warnings.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/PrintPreprocessedOutput.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Lex/Pragma.cpp | 28 | ||||
-rw-r--r-- | clang/lib/Parse/ParsePragma.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 2 |
8 files changed, 84 insertions, 80 deletions
diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp index 617bb6875e6..6032b001d33 100644 --- a/clang/lib/ARCMigrate/ARCMT.cpp +++ b/clang/lib/ARCMigrate/ARCMT.cpp @@ -313,7 +313,7 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, pass.setNoFinalizeRemoval(NoFinalizeRemoval); if (!NoNSAllocReallocError) Diags->setDiagnosticMapping(diag::warn_arcmt_nsalloc_realloc, - diag::MAP_ERROR, SourceLocation()); + diag::Severity::Error, SourceLocation()); for (unsigned i=0, e = transforms.size(); i != e; ++i) transforms[i](pass); diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 97299611f0d..98826882894 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -166,7 +166,7 @@ void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag, assert(Diag < diag::DIAG_UPPER_LIMIT && "Can only map builtin diagnostics"); assert((Diags->isBuiltinWarningOrExtension(Diag) || - (Map == diag::MAP_FATAL || Map == diag::MAP_ERROR)) && + (Map == diag::Severity::Fatal || Map == diag::Severity::Error)) && "Cannot map errors into warnings!"); assert(!DiagStatePoints.empty()); assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location"); @@ -174,10 +174,10 @@ void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag, FullSourceLoc Loc = SourceMgr? FullSourceLoc(L, *SourceMgr) : FullSourceLoc(); FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc; // Don't allow a mapping to a warning override an error/fatal mapping. - if (Map == diag::MAP_WARNING) { + if (Map == diag::Severity::Warning) { DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); - if (Info.getSeverity() == diag::MAP_ERROR || - Info.getSeverity() == diag::MAP_FATAL) + if (Info.getSeverity() == diag::Severity::Error || + Info.getSeverity() == diag::Severity::Fatal) Map = Info.getSeverity(); } DiagnosticMapping Mapping = makeUserMapping(Map, L); @@ -249,7 +249,7 @@ bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group, // If we are enabling this feature, just set the diagnostic mappings to map to // errors. if (Enabled) - return setDiagnosticGroupMapping(Group, diag::MAP_ERROR); + return setDiagnosticGroupMapping(Group, diag::Severity::Error); // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and // potentially downgrade anything already mapped to be a warning. @@ -263,9 +263,9 @@ bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group, for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) { DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(GroupDiags[i]); - if (Info.getSeverity() == diag::MAP_ERROR || - Info.getSeverity() == diag::MAP_FATAL) - Info.setSeverity(diag::MAP_WARNING); + if (Info.getSeverity() == diag::Severity::Error || + Info.getSeverity() == diag::Severity::Fatal) + Info.setSeverity(diag::Severity::Warning); Info.setNoWarningAsError(true); } @@ -278,7 +278,7 @@ bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group, // If we are enabling this feature, just set the diagnostic mappings to map to // fatal errors. if (Enabled) - return setDiagnosticGroupMapping(Group, diag::MAP_FATAL); + return setDiagnosticGroupMapping(Group, diag::Severity::Fatal); // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and // potentially downgrade anything already mapped to be an error. @@ -292,8 +292,8 @@ bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group, for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) { DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(GroupDiags[i]); - if (Info.getSeverity() == diag::MAP_FATAL) - Info.setSeverity(diag::MAP_ERROR); + if (Info.getSeverity() == diag::Severity::Fatal) + Info.setSeverity(diag::Severity::Error); Info.setNoErrorAsFatal(true); } diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index a99ae2661b8..0bf4355770d 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -155,13 +155,13 @@ CATEGORY(ANALYSIS, SEMA) static DiagnosticMapping GetDefaultDiagMapping(unsigned DiagID) { DiagnosticMapping Info = DiagnosticMapping::Make( - diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false); + diag::Severity::Fatal, /*IsUser=*/false, /*IsPragma=*/false); if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) { Info.setSeverity((diag::Severity)StaticInfo->DefaultSeverity); if (StaticInfo->WarnNoWerror) { - assert(Info.getSeverity() == diag::MAP_WARNING && + assert(Info.getSeverity() == diag::Severity::Warning && "Unexpected mapping with no-Werror bit!"); Info.setNoWarningAsError(true); } @@ -342,7 +342,7 @@ bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID, return false; EnabledByDefault = - GetDefaultDiagMapping(DiagID).getSeverity() != diag::MAP_IGNORE; + GetDefaultDiagMapping(DiagID).getSeverity() != diag::Severity::Ignored; return true; } @@ -350,7 +350,7 @@ bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) { if (DiagID >= diag::DIAG_UPPER_LIMIT) return false; - return GetDefaultDiagMapping(DiagID).getSeverity() == diag::MAP_ERROR; + return GetDefaultDiagMapping(DiagID).getSeverity() == diag::Severity::Error; } bool DiagnosticIDs::isRemark(unsigned DiagID) { @@ -366,6 +366,21 @@ StringRef DiagnosticIDs::getDescription(unsigned DiagID) const { return CustomDiagInfo->getDescription(DiagID); } +static DiagnosticIDs::Level toLevel(diag::Severity SV) { + switch (SV) { + case diag::Severity::Ignored: + return DiagnosticIDs::Ignored; + case diag::Severity::Remark: + return DiagnosticIDs::Remark; + case diag::Severity::Warning: + return DiagnosticIDs::Warning; + case diag::Severity::Error: + return DiagnosticIDs::Error; + case diag::Severity::Fatal: + return DiagnosticIDs::Fatal; + } +} + /// getDiagnosticLevel - Based on the way the client configured the /// DiagnosticsEngine object, classify the specified diagnostic ID into a Level, /// by consumable the DiagnosticClient. @@ -378,7 +393,7 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, unsigned DiagClass = getBuiltinDiagClass(DiagID); if (DiagClass == CLASS_NOTE) return DiagnosticIDs::Note; - return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag); + return toLevel(getDiagnosticSeverity(DiagID, DiagClass, Loc, Diag)); } /// \brief Based on the way the client configured the Diagnostic @@ -387,13 +402,15 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, /// /// \param Loc The source location we are interested in finding out the /// diagnostic state. Can be null in order to query the latest state. -DiagnosticIDs::Level -DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, - SourceLocation Loc, - const DiagnosticsEngine &Diag) const { +diag::Severity +DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, unsigned DiagClass, + SourceLocation Loc, + const DiagnosticsEngine &Diag) const { + assert(DiagClass != CLASS_NOTE); + // Specific non-error diagnostics may be mapped to various levels from ignored // to error. Errors can only be mapped to fatal. - DiagnosticIDs::Level Result = DiagnosticIDs::Fatal; + diag::Severity Result = diag::Severity::Fatal; DiagnosticsEngine::DiagStatePointsTy::iterator Pos = Diag.GetDiagStatePointForLoc(Loc); @@ -402,33 +419,19 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, // Get the mapping information, or compute it lazily. DiagnosticMapping &Mapping = State->getOrAddMapping((diag::kind)DiagID); - switch (Mapping.getSeverity()) { - case diag::MAP_IGNORE: - Result = DiagnosticIDs::Ignored; - break; - case diag::MAP_REMARK: - Result = DiagnosticIDs::Remark; - break; - case diag::MAP_WARNING: - Result = DiagnosticIDs::Warning; - break; - case diag::MAP_ERROR: - Result = DiagnosticIDs::Error; - break; - case diag::MAP_FATAL: - Result = DiagnosticIDs::Fatal; - break; - } + // TODO: Can a null severity really get here? + if (Mapping.getSeverity() != diag::Severity()) + Result = Mapping.getSeverity(); // Upgrade ignored diagnostics if -Weverything is enabled. - if (Diag.EnableAllWarnings && Result == DiagnosticIDs::Ignored && + if (Diag.EnableAllWarnings && Result == diag::Severity::Ignored && !Mapping.isUser()) - Result = DiagnosticIDs::Warning; + Result = diag::Severity::Warning; // Diagnostics of class REMARK are either printed as remarks or in case they // have been added to -Werror they are printed as errors. - if (DiagClass == CLASS_REMARK && Result == DiagnosticIDs::Warning) - Result = DiagnosticIDs::Remark; + if (DiagClass == CLASS_REMARK && Result == diag::Severity::Warning) + Result = diag::Severity::Remark; // Ignore -pedantic diagnostics inside __extension__ blocks. // (The diagnostics controlled by -pedantic are the extension diagnostics @@ -436,7 +439,7 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, bool EnabledByDefault = false; bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault); if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault) - return DiagnosticIDs::Ignored; + return diag::Severity::Ignored; // For extension diagnostics that haven't been explicitly mapped, check if we // should upgrade the diagnostic. @@ -446,37 +449,38 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, break; case DiagnosticsEngine::Ext_Warn: // Upgrade ignored diagnostics to warnings. - if (Result == DiagnosticIDs::Ignored) - Result = DiagnosticIDs::Warning; + if (Result == diag::Severity::Ignored) + Result = diag::Severity::Warning; break; case DiagnosticsEngine::Ext_Error: // Upgrade ignored or warning diagnostics to errors. - if (Result == DiagnosticIDs::Ignored || Result == DiagnosticIDs::Warning) - Result = DiagnosticIDs::Error; + if (Result == diag::Severity::Ignored || + Result == diag::Severity::Warning) + Result = diag::Severity::Error; break; } } // At this point, ignored errors can no longer be upgraded. - if (Result == DiagnosticIDs::Ignored) + if (Result == diag::Severity::Ignored) return Result; // Honor -w, which is lower in priority than pedantic-errors, but higher than // -Werror. - if (Result == DiagnosticIDs::Warning && Diag.IgnoreAllWarnings) - return DiagnosticIDs::Ignored; + if (Result == diag::Severity::Warning && Diag.IgnoreAllWarnings) + return diag::Severity::Ignored; // If -Werror is enabled, map warnings to errors unless explicitly disabled. - if (Result == DiagnosticIDs::Warning) { + if (Result == diag::Severity::Warning) { if (Diag.WarningsAsErrors && !Mapping.hasNoWarningAsError()) - Result = DiagnosticIDs::Error; + Result = diag::Severity::Error; } // If -Wfatal-errors is enabled, map errors to fatal unless explicity // disabled. - if (Result == DiagnosticIDs::Error) { + if (Result == diag::Severity::Error) { if (Diag.ErrorsAsFatal && !Mapping.hasNoErrorAsFatal()) - Result = DiagnosticIDs::Fatal; + Result = diag::Severity::Fatal; } // Custom diagnostics always are emitted in system headers. @@ -486,11 +490,11 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, // If we are in a system header, we ignore it. We look at the diagnostic class // because we also want to ignore extensions and warnings in -Werror and // -pedantic-errors modes, which *map* warnings/extensions to errors. - if (Result >= DiagnosticIDs::Warning && DiagClass != CLASS_ERROR && + if (Result >= diag::Severity::Warning && DiagClass != CLASS_ERROR && !ShowInSystemHeader && Diag.SuppressSystemWarnings && Loc.isValid() && Diag.getSourceManager().isInSystemHeader( Diag.getSourceManager().getExpansionLoc(Loc))) - return DiagnosticIDs::Ignored; + return diag::Severity::Ignored; return Result; } diff --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp index df72ef7186c..a0a2164423c 100644 --- a/clang/lib/Basic/Warnings.cpp +++ b/clang/lib/Basic/Warnings.cpp @@ -107,7 +107,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags, // Figure out how this option affects the warning. If -Wfoo, map the // diagnostic to a warning, if -Wno-foo, map it to ignore. diag::Severity Mapping = - isPositive ? diag::MAP_WARNING : diag::MAP_IGNORE; + isPositive ? diag::Severity::Warning : diag::Severity::Ignored; // -Wsystem-headers is a special case, not driven by the option table. It // cannot be controlled with -Werror. @@ -125,7 +125,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags, Diags.setEnableAllWarnings(true); } else { Diags.setEnableAllWarnings(false); - Diags.setMappingForAllDiagnostics(diag::MAP_IGNORE); + Diags.setMappingForAllDiagnostics(diag::Severity::Ignored); } } continue; diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index bde1fa16314..4a6f8dbef92 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -447,19 +447,19 @@ void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc, MoveToLine(Loc); OS << "#pragma " << Namespace << " diagnostic "; switch (Map) { - case diag::MAP_REMARK: + case diag::Severity::Remark: OS << "remark"; break; - case diag::MAP_WARNING: + case diag::Severity::Warning: OS << "warning"; break; - case diag::MAP_ERROR: + case diag::Severity::Error: OS << "error"; break; - case diag::MAP_IGNORE: + case diag::Severity::Ignored: OS << "ignored"; break; - case diag::MAP_FATAL: + case diag::Severity::Fatal: OS << "fatal"; break; } diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index ea3a10d5369..f1b96f8b558 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -954,16 +954,7 @@ public: IdentifierInfo *II = Tok.getIdentifierInfo(); PPCallbacks *Callbacks = PP.getPPCallbacks(); - diag::Severity Map; - if (II->isStr("warning")) - Map = diag::MAP_WARNING; - else if (II->isStr("error")) - Map = diag::MAP_ERROR; - else if (II->isStr("ignored")) - Map = diag::MAP_IGNORE; - else if (II->isStr("fatal")) - Map = diag::MAP_FATAL; - else if (II->isStr("pop")) { + if (II->isStr("pop")) { if (!PP.getDiagnostics().popMappings(DiagLoc)) PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop); else if (Callbacks) @@ -974,7 +965,16 @@ public: if (Callbacks) Callbacks->PragmaDiagnosticPush(DiagLoc, Namespace); return; - } else { + } + + diag::Severity SV = llvm::StringSwitch<diag::Severity>(II->getName()) + .Case("ignored", diag::Severity::Ignored) + .Case("warning", diag::Severity::Warning) + .Case("error", diag::Severity::Error) + .Case("fatal", diag::Severity::Fatal) + .Default(diag::Severity()); + + if (SV == diag::Severity()) { PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid); return; } @@ -998,12 +998,12 @@ public: return; } - if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.substr(2), - Map, DiagLoc)) + if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.substr(2), SV, + DiagLoc)) PP.Diag(StringLoc, diag::warn_pragma_diagnostic_unknown_warning) << WarningName; else if (Callbacks) - Callbacks->PragmaDiagnostic(DiagLoc, Namespace, Map, WarningName); + Callbacks->PragmaDiagnostic(DiagLoc, Namespace, SV, WarningName); } }; diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index 751a8361774..723d4140151 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -1216,7 +1216,7 @@ PragmaNoOpenMPHandler::HandlePragma(Preprocessor &PP, DiagnosticsEngine::Ignored) { PP.Diag(FirstTok, diag::warn_pragma_omp_ignored); PP.getDiagnostics().setDiagnosticMapping(diag::warn_pragma_omp_ignored, - diag::MAP_IGNORE, + diag::Severity::Ignored, SourceLocation()); } PP.DiscardUntilEndOfDirective(); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index cbb6401e2e9..855991d9143 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2542,7 +2542,7 @@ void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, I = point.State->begin(), E = point.State->end(); I != E; ++I) { if (I->second.isPragma()) { Record.push_back(I->first); - Record.push_back(I->second.getSeverity()); + Record.push_back((unsigned)I->second.getSeverity()); } } Record.push_back(-1); // mark the end of the diag/map pairs for this |