From: Daniel Dunbar Date: Thu, 29 Sep 2011 01:52:06 +0000 (+0000) Subject: Basic/Diagnostics: Add three explicit bits to DiagnosticMappingInfo to track "no... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5e41333b06fdf036d58495490eb14d6a0a3fcf7;p=clang Basic/Diagnostics: Add three explicit bits to DiagnosticMappingInfo to track "no-warning-as-error", "no-error-as-fatal", and "show-in-system-header", and update DiagnosticsEngine::setDiagnosticGroup{WarningAsError,ErrorAsFatal} and GetDefaultDiagMappingInfo to set them appropriately. - No actual functionality change for now, we still also use the diag::Mapping::{MAP_WARNING_NO_ERROR,MAP_ERROR_NO_FATAL,MAP_WARNING_SHOW_IN_SYSTEM_HEADER} for a little while longer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140768 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h index 6a6a87e0fd..e119f310a2 100644 --- a/include/clang/Basic/DiagnosticIDs.h +++ b/include/clang/Basic/DiagnosticIDs.h @@ -83,11 +83,14 @@ class DiagnosticMappingInfo { unsigned Mapping : 3; unsigned IsUser : 1; unsigned IsPragma : 1; + unsigned HasShowInSystemHeader : 1; + unsigned HasNoWarningAsError : 1; + unsigned HasNoErrorAsFatal : 1; public: static DiagnosticMappingInfo MakeUnset() { DiagnosticMappingInfo Result; - Result.Mapping = Result.IsUser = Result.IsPragma = 0; + Result.Mapping = 0; return Result; } @@ -97,14 +100,28 @@ public: Result.Mapping = Mapping; Result.IsUser = IsUser; Result.IsPragma = IsPragma; + Result.HasShowInSystemHeader = 0; + Result.HasNoWarningAsError = 0; + Result.HasNoErrorAsFatal = 0; return Result; } + bool isUnset() const { return Mapping == 0; } + diag::Mapping getMapping() const { return diag::Mapping(Mapping); } + void setMapping(diag::Mapping Value) { Mapping = Value; } + bool isUser() const { return IsUser; } bool isPragma() const { return IsPragma; } - bool isUnset() const { return Mapping == 0; } + bool hasShowInSystemHeader() const { return HasShowInSystemHeader; } + void setShowInSystemHeader(bool Value) { HasShowInSystemHeader = Value; } + + bool hasNoWarningAsError() const { return HasNoWarningAsError; } + void setNoWarningAsError(bool Value) { HasNoWarningAsError = Value; } + + bool hasNoErrorAsFatal() const { return HasNoErrorAsFatal; } + void setNoErrorAsFatal(bool Value) { HasNoErrorAsFatal = Value; } }; /// \brief Used for handling and querying diagnostic IDs. Can be used and shared diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 0402aaa1af..e9abfb733e 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -239,14 +239,56 @@ bool DiagnosticsEngine::setDiagnosticGroupMapping( bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled) { - diag::Mapping Map = Enabled ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR; - return setDiagnosticGroupMapping(Group, Map); + // If we are enabling this feature, just set the diagnostic mappings to map to + // errors. + if (Enabled) + return setDiagnosticGroupMapping(Group, diag::MAP_ERROR); + + // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and + // potentially downgrade anything already mapped to be a warning. + + // Get the diagnostics in this group. + llvm::SmallVector GroupDiags; + if (Diags->getDiagnosticsInGroup(Group, GroupDiags)) + return true; + + // Perform the mapping change. + for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) { + DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo( + GroupDiags[i]); + + Info.setMapping(diag::MAP_WARNING_NO_WERROR); + Info.setNoWarningAsError(true); + } + + return false; } bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled) { - diag::Mapping Map = Enabled ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL; - return setDiagnosticGroupMapping(Group, Map); + // If we are enabling this feature, just set the diagnostic mappings to map to + // fatal errors. + if (Enabled) + return setDiagnosticGroupMapping(Group, diag::MAP_FATAL); + + // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and + // potentially downgrade anything already mapped to be an error. + + // Get the diagnostics in this group. + llvm::SmallVector GroupDiags; + if (Diags->getDiagnosticsInGroup(Group, GroupDiags)) + return true; + + // Perform the mapping change. + for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) { + DiagnosticMappingInfo &Info = GetCurDiagState()->getOrAddMappingInfo( + GroupDiags[i]); + + Info.setMapping(diag::MAP_ERROR_NO_WFATAL); + Info.setNoErrorAsFatal(true); + } + + return false; } void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) { diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index 3129f731f1..65e5c635d5 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -184,26 +184,29 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { return Found; } -static diag::Mapping GetDefaultDiagMapping(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) { - // Compute the effective mapping based on the extra bits. - diag::Mapping Mapping = (diag::Mapping) Info->Mapping; +static DiagnosticMappingInfo GetDefaultDiagMappingInfo(unsigned DiagID) { + DiagnosticMappingInfo Info = DiagnosticMappingInfo::MakeInfo( + diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false); + + if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) { + Info.setMapping((diag::Mapping) StaticInfo->Mapping); - if (Info->WarnNoWerror) { - assert(Mapping == diag::MAP_WARNING && + if (StaticInfo->WarnNoWerror) { + assert(Info.getMapping() == diag::MAP_WARNING && "Unexpected mapping with no-Werror bit!"); - Mapping = diag::MAP_WARNING_NO_WERROR; + Info.setMapping(diag::MAP_WARNING_NO_WERROR); + Info.setNoWarningAsError(true); } - if (Info->WarnShowInSystemHeader) { - assert(Mapping == diag::MAP_WARNING && + if (StaticInfo->WarnShowInSystemHeader) { + assert(Info.getMapping() == diag::MAP_WARNING && "Unexpected mapping with show-in-system-header bit!"); - Mapping = diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER; + Info.setMapping(diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER); + Info.setShowInSystemHeader(true); } - - return Mapping; } - return diag::MAP_FATAL; + + return Info; } /// getWarningOptionForDiag - Return the lowest-level warning option that @@ -247,8 +250,7 @@ DiagnosticMappingInfo &DiagnosticsEngine::DiagState::getOrAddMappingInfo( // Initialize the entry if we added it. if (Result.second) { assert(Result.first->second.isUnset() && "unexpected unset entry"); - Result.first->second = DiagnosticMappingInfo::MakeInfo( - GetDefaultDiagMapping(Diag), /*IsUser=*/false, /*IsPragma=*/false); + Result.first->second = GetDefaultDiagMappingInfo(Diag); } return Result.first->second; @@ -474,7 +476,8 @@ bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID, getBuiltinDiagClass(DiagID) != CLASS_EXTENSION) return false; - EnabledByDefault = GetDefaultDiagMapping(DiagID) != diag::MAP_IGNORE; + EnabledByDefault = + GetDefaultDiagMappingInfo(DiagID).getMapping() != diag::MAP_IGNORE; return true; } @@ -482,7 +485,7 @@ bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) { if (DiagID >= diag::DIAG_UPPER_LIMIT) return false; - return GetDefaultDiagMapping(DiagID) == diag::MAP_ERROR; + return GetDefaultDiagMappingInfo(DiagID).getMapping() == diag::MAP_ERROR; } /// getDescription - Given a diagnostic ID, return a description of the