]> granicus.if.org Git - clang/commitdiff
Due to a bug, -Wno-everything works like -Weverything. Fix the bug by having
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 27 Jan 2012 06:15:43 +0000 (06:15 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 27 Jan 2012 06:15:43 +0000 (06:15 +0000)
-Wno-everything remap all warnings to ignored.

We can now use "-Wno-everything -W<warning>" to ignore all warnings except
specific ones.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149121 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
include/clang/Basic/DiagnosticIDs.h
lib/Basic/Diagnostic.cpp
lib/Basic/DiagnosticIDs.cpp
lib/Frontend/Warnings.cpp

index 4f5fe6501ef2825f3b70e9844a6ffce5059bfa78..c587a1d6e200fe0c291554cf49dfabb52852ee1e 100644 (file)
@@ -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; }
   
index 30fda595383ba5a997a3b886bd736cf219238a8c..40fc3a98be3779363cc7a6318954b682be7c5acc 100644 (file)
@@ -263,6 +263,9 @@ public:
   bool getDiagnosticsInGroup(StringRef Group,
                              llvm::SmallVectorImpl<diag::kind> &Diags) const;
 
+  /// \brief Get the set of all diagnostic IDs.
+  void getAllDiagnostics(llvm::SmallVectorImpl<diag::kind> &Diags) const;
+
   /// \brief Get the warning option with the closest edit distance to the given
   /// group name.
   static StringRef getNearestWarningOption(StringRef Group);
index 67ea056417f6828bfb8b2c5d52faa8bd38ea4c02..eab79d6442d7b8ad6697960fa93f0558d072c3eb 100644 (file)
@@ -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<diag::kind, 64> 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!");
 
index b3c4d033c289e85b5b4c33fbbacaefc4e7554327..9f09f72e868f2c4205b16323aff6e7159deeaaec 100644 (file)
@@ -682,6 +682,12 @@ bool DiagnosticIDs::getDiagnosticsInGroup(
   return false;
 }
 
+void DiagnosticIDs::getAllDiagnostics(
+                               llvm::SmallVectorImpl<diag::kind> &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.
index 576dd3d445992944e71b7f67d17ccf5efb687a5d..f68e03b0d513e2a9c228a18e0a50e4523893f24a 100644 (file)
@@ -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;
       }