]> granicus.if.org Git - clang/commitdiff
Implement '-Weverything', which enables all warnings except those explicitly mapped...
authorTed Kremenek <kremenek@apple.com>
Thu, 18 Aug 2011 01:12:56 +0000 (01:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 18 Aug 2011 01:12:56 +0000 (01:12 +0000)
Currently this includes -pedantic warnings as well; we'll need to consider whether these should
be included.

This works as expected with -Werror.

Test cases were added to Sema/warn-unused-parameters.c, but they should probably be broken off into
their own test file.

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

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Basic/DiagnosticIDs.cpp
lib/Frontend/Warnings.cpp
test/Sema/warn-unused-parameters.c

index 8cc1771f4f024065339b03c11d39207ffe512f47..c02654b2c7101602f75c2ba595fbd8587f141268 100644 (file)
@@ -149,7 +149,8 @@ public:
 private:
   unsigned char AllExtensionsSilenced; // Used by __extension__
   bool IgnoreAllWarnings;        // Ignore all warnings: -w
-  bool WarningsAsErrors;         // Treat warnings like errors:
+  bool WarningsAsErrors;         // Treat warnings like errors.
+  bool EnableAllWarnings;        // Enable all warnings.
   bool ErrorsAsFatal;            // Treat errors like fatal errors.
   bool SuppressSystemWarnings;   // Suppress warnings in system headers.
   bool SuppressAllDiagnostics;   // Suppress all diagnostics.
@@ -370,6 +371,12 @@ public:
   void setIgnoreAllWarnings(bool Val) { IgnoreAllWarnings = Val; }
   bool getIgnoreAllWarnings() const { return IgnoreAllWarnings; }
 
+  /// setEnableAllWarnings - When set to true, any unmapped ignored warnings
+  /// are no longer ignored.  If this and IgnoreAllWarnings are both set,
+  /// then that one wins.
+  void setEnableAllWarnings(bool Val) { EnableAllWarnings = Val; }
+  bool getEnableAllWarnngs() const { return EnableAllWarnings; }
+  
   /// setWarningsAsErrors - When set to true, any warnings reported are issued
   /// as errors.
   void setWarningsAsErrors(bool Val) { WarningsAsErrors = Val; }
index b82b062a729ead4c8acbaa1112a6df40664e1706..0e4159db8db8c7a45518233df343ecaa92f75324 100644 (file)
@@ -43,6 +43,7 @@ Diagnostic::Diagnostic(const llvm::IntrusiveRefCntPtr<DiagnosticIDs> &diags,
   AllExtensionsSilenced = 0;
   IgnoreAllWarnings = false;
   WarningsAsErrors = false;
+  EnableAllWarnings = false;
   ErrorsAsFatal = false;
   SuppressSystemWarnings = false;
   SuppressAllDiagnostics = false;
index fa397c9ac93ad2092d004795a174b80ca5338d08..ace92aceb4673c55723ce2d5ad180dd4944b18a8 100644 (file)
@@ -496,14 +496,27 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
   switch (MappingInfo & 7) {
   default: assert(0 && "Unknown mapping!");
   case diag::MAP_IGNORE:
-    // Ignore this, unless this is an extension diagnostic and we're mapping
-    // them onto warnings or errors.
-    if (!isBuiltinExtensionDiag(DiagID) ||  // Not an extension
-        Diag.ExtBehavior == Diagnostic::Ext_Ignore || // Ext ignored
-        (MappingInfo & 8) != 0)             // User explicitly mapped it.
+    if (Diag.EnableAllWarnings) {
+      // Leave the warning disabled if it was explicitly ignored.
+      if ((MappingInfo & 8) != 0)
+        return DiagnosticIDs::Ignored;
+     
+      Result = Diag.WarningsAsErrors ? DiagnosticIDs::Error 
+                                     : DiagnosticIDs::Warning;
+    }
+    // Otherwise, ignore this diagnostic unless this is an extension diagnostic
+    // and we're mapping them onto warnings or errors.
+    else if (!isBuiltinExtensionDiag(DiagID) ||  // Not an extension
+             Diag.ExtBehavior == Diagnostic::Ext_Ignore || // Ext ignored
+             (MappingInfo & 8) != 0) {           // User explicitly mapped it.
       return DiagnosticIDs::Ignored;
-    Result = DiagnosticIDs::Warning;
-    if (Diag.ExtBehavior == Diagnostic::Ext_Error) Result = DiagnosticIDs::Error;
+    }
+    else {
+      Result = DiagnosticIDs::Warning;
+    }
+
+    if (Diag.ExtBehavior == Diagnostic::Ext_Error)
+      Result = DiagnosticIDs::Error;
     if (Result == DiagnosticIDs::Error && Diag.ErrorsAsFatal)
       Result = DiagnosticIDs::Fatal;
     break;
index 215f8f8b22b744550d98d693bd194a5466b93922..d24779e1a98d07236ce95305a5a72981a4f6a345 100644 (file)
@@ -98,6 +98,13 @@ void clang::ProcessWarningOptions(Diagnostic &Diags,
       Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
       Opt = Specifier;
     }
+    
+    // -Weverything is a special case as well.  It implicitly enables all
+    // warnings, including ones not explicitly in a warning group.
+    if (Opt == "everything") {
+      Diags.setEnableAllWarnings(true);
+      continue;
+    }
 
     // -Wfatal-errors is yet another special case.
     if (Opt.startswith("fatal-errors")) {
index e47ddd5e00d515554583ffc3f2d7648ab05ad125..af048e77e886aea447858822a20398783daa8ee9 100644 (file)
@@ -19,4 +19,12 @@ static void achor() {};
 
 // CHECK: 5:12: warning: unused parameter 'y'
 // CHECK: 12:15: warning: unused parameter 'y'
-// CHECK-unused: 1 warning generated
\ No newline at end of file
+// CHECK-unused: 1 warning generated
+
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything %s 2>&1 | FileCheck -check-prefix=CHECK-everything %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-everything-error %s
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Wno-unused %s 2>&1 | FileCheck -check-prefix=CHECK-everything-no-unused %s
+// CHECK-everything: 6 warnings generated
+// CHECK-everything-error: 5 errors generated
+// CHECK-everything-no-unused: 5 warnings generated
+