Warn about -Wno-foo where foo is an unknown warning option. This is helpful
authorChad Rosier <mcrosier@apple.com>
Wed, 16 May 2012 19:28:02 +0000 (19:28 +0000)
committerChad Rosier <mcrosier@apple.com>
Wed, 16 May 2012 19:28:02 +0000 (19:28 +0000)
for subtle misspellings such as -Wno-unused-command-line-arguments instead of
-Wno-unused-command-line-argument.

Also fix the diagnostic messages to properly handle -Wno- options.  Previously,
the positive version was always emitted (i.e., -Wfoo was emitted for -Wno-foo).
rdar://11461500

llvm-svn: 156937

clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/Frontend/Warnings.cpp
clang/test/Driver/warning-options.cpp

index 5d6b887..5e44ddf 100644 (file)
@@ -94,13 +94,13 @@ def warn_unknown_warning_option : Warning<
     InGroup<DiagGroup<"unknown-warning-option"> >;
 def warn_unknown_negative_warning_option : Warning<
     "unknown warning option '%0'?">,
-    InGroup<DiagGroup<"unknown-warning-option"> >, DefaultIgnore;
+    InGroup<DiagGroup<"unknown-warning-option"> >;
 def warn_unknown_warning_option_suggest : Warning<
     "unknown warning option '%0'; did you mean '%1'?">,
     InGroup<DiagGroup<"unknown-warning-option"> >;
 def warn_unknown_negative_warning_option_suggest : Warning<
     "unknown warning option '%0'; did you mean '%1'?">,
-    InGroup<DiagGroup<"unknown-warning-option"> >, DefaultIgnore;
+    InGroup<DiagGroup<"unknown-warning-option"> >;
 def warn_unknown_warning_specifier : Warning<
     "unknown %0 warning specifier: '%1'">,
     InGroup<DiagGroup<"unknown-warning-option"> >;
index ec5fde0..80c0ebf 100644 (file)
@@ -83,6 +83,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
     bool SetDiagnostic = (Report == 0);
     for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
       StringRef Opt = Opts.Warnings[i];
+      StringRef OrigOpt = Opts.Warnings[i];
 
       // Treat -Wformat=0 as an alias for -Wno-format.
       if (Opt == "format=0")
@@ -130,7 +131,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
           if ((Opt[5] != '=' && Opt[5] != '-') || Opt.size() == 6) {
             if (Report)
               Diags.Report(diag::warn_unknown_warning_specifier)
-                << "-Werror" << ("-W" + Opt.str());
+                << "-Werror" << ("-W" + OrigOpt.str());
             continue;
           }
           Specifier = Opt.substr(6);
@@ -158,7 +159,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
           if ((Opt[12] != '=' && Opt[12] != '-') || Opt.size() == 13) {
             if (Report)
               Diags.Report(diag::warn_unknown_warning_specifier)
-                << "-Wfatal-errors" << ("-W" + Opt.str());
+                << "-Wfatal-errors" << ("-W" + OrigOpt.str());
             continue;
           }
           Specifier = Opt.substr(13);
@@ -182,7 +183,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
       
       if (Report) {
         if (DiagIDs->getDiagnosticsInGroup(Opt, _Diags))
-          EmitUnknownDiagWarning(Diags, "-W", Opt, isPositive);
+          EmitUnknownDiagWarning(Diags, "-W", OrigOpt, isPositive);
       } else {
         Diags.setDiagnosticGroupMapping(Opt, Mapping);
       }
index a36210d..1a2d51d 100644 (file)
@@ -2,3 +2,9 @@
 // LARGE_VALUE_COPY_DEFAULT: -Wlarge-by-value-copy=64
 // RUN: %clang -### -Wlarge-by-value-copy=128 %s 2>&1 | FileCheck -check-prefix=LARGE_VALUE_COPY_JOINED %s
 // LARGE_VALUE_COPY_JOINED: -Wlarge-by-value-copy=128
+
+// RUN: %clang -c -Wmonkey -Wno-monkey -Wno-unused-command-line-arguments \
+// RUN:        -Wno-unused-command-line-argument %s 2>&1 | FileCheck %s
+// CHECK: unknown warning option '-Wmonkey'
+// CHECK: unknown warning option '-Wno-monkey'
+// CHECK: unknown warning option '-Wno-unused-command-line-arguments'