From: Argyrios Kyrtzidis Date: Fri, 27 Jan 2012 06:15:43 +0000 (+0000) Subject: Due to a bug, -Wno-everything works like -Weverything. Fix the bug by having X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11583c757bac6ce5c342f2eb572055dd2619a657;p=clang Due to a bug, -Wno-everything works like -Weverything. Fix the bug by having -Wno-everything remap all warnings to ignored. We can now use "-Wno-everything -W" to ignore all warnings except specific ones. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149121 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 4f5fe6501e..c587a1d6e2 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -476,6 +476,12 @@ public: /// \returns True if the given group is unknown, false otherwise. bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled); + /// \brief Add the specified mapping to all diagnostics. Mainly to be used + /// by -Wno-everything to disable all warnings but allow subsequent -W options + /// to enable specific warnings. + bool setMappingToAllDiagnostics(diag::Mapping Map, + SourceLocation Loc = SourceLocation()); + bool hasErrorOccurred() const { return ErrorOccurred; } bool hasFatalErrorOccurred() const { return FatalErrorOccurred; } diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h index 30fda59538..40fc3a98be 100644 --- a/include/clang/Basic/DiagnosticIDs.h +++ b/include/clang/Basic/DiagnosticIDs.h @@ -263,6 +263,9 @@ public: bool getDiagnosticsInGroup(StringRef Group, llvm::SmallVectorImpl &Diags) const; + /// \brief Get the set of all diagnostic IDs. + void getAllDiagnostics(llvm::SmallVectorImpl &Diags) const; + /// \brief Get the warning option with the closest edit distance to the given /// group name. static StringRef getNearestWarningOption(StringRef Group); diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 67ea056417..eab79d6442 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -295,6 +295,20 @@ bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group, return false; } +bool DiagnosticsEngine::setMappingToAllDiagnostics(diag::Mapping Map, + SourceLocation Loc) { + // Get all the diagnostics. + llvm::SmallVector AllDiags; + Diags->getAllDiagnostics(AllDiags); + + // Set the mapping. + for (unsigned i = 0, e = AllDiags.size(); i != e; ++i) + if (Diags->isBuiltinWarningOrExtension(AllDiags[i])) + setDiagnosticMapping(AllDiags[i], Map, Loc); + + return false; +} + void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) { assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!"); diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index b3c4d033c2..9f09f72e86 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -682,6 +682,12 @@ bool DiagnosticIDs::getDiagnosticsInGroup( return false; } +void DiagnosticIDs::getAllDiagnostics( + llvm::SmallVectorImpl &Diags) const { + for (unsigned i = 0; i != StaticDiagInfoSize; ++i) + Diags.push_back(StaticDiagInfo[i].DiagID); +} + StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) { StringRef Best; unsigned BestDistance = Group.size() + 1; // Sanity threshold. diff --git a/lib/Frontend/Warnings.cpp b/lib/Frontend/Warnings.cpp index 576dd3d445..f68e03b0d5 100644 --- a/lib/Frontend/Warnings.cpp +++ b/lib/Frontend/Warnings.cpp @@ -110,8 +110,14 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags, // -Weverything is a special case as well. It implicitly enables all // warnings, including ones not explicitly in a warning group. if (Opt == "everything") { - if (SetDiagnostic) - Diags.setEnableAllWarnings(true); + if (SetDiagnostic) { + if (isPositive) { + Diags.setEnableAllWarnings(true); + } else { + Diags.setEnableAllWarnings(false); + Diags.setMappingToAllDiagnostics(diag::MAP_IGNORE); + } + } continue; }