r352535 - Fix the behavior of clang's -w flag.

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 29 11:33:48 PST 2019


Author: jyknight
Date: Tue Jan 29 11:33:48 2019
New Revision: 352535

URL: http://llvm.org/viewvc/llvm-project?rev=352535&view=rev
Log:
Fix the behavior of clang's -w flag.

It is intended to disable _all_ warnings, even those upgraded to
errors via `-Werror=warningname` or `#pragma clang diagnostic error'

Fixes: https://llvm.org/PR38231
Differential Revision: https://reviews.llvm.org/D53199

Added:
    cfe/trunk/test/Frontend/warning-mapping-6.c
Modified:
    cfe/trunk/lib/Basic/DiagnosticIDs.cpp
    cfe/trunk/test/Frontend/optimization-remark.c
    cfe/trunk/test/Frontend/warning-mapping-2.c
    cfe/trunk/test/Frontend/warning-mapping-4.c
    cfe/trunk/test/Frontend/warning-mapping-5.c
    cfe/trunk/test/Modules/implementation-of-module.m

Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=352535&r1=352534&r2=352535&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Tue Jan 29 11:33:48 2019
@@ -456,12 +456,17 @@ DiagnosticIDs::getDiagnosticSeverity(uns
   if (Result == diag::Severity::Ignored)
     return Result;
 
-  // Honor -w, which is lower in priority than pedantic-errors, but higher than
-  // -Werror.
-  // FIXME: Under GCC, this also suppresses warnings that have been mapped to
-  // errors by -W flags and #pragma diagnostic.
-  if (Result == diag::Severity::Warning && State->IgnoreAllWarnings)
-    return diag::Severity::Ignored;
+  // Honor -w: this disables all messages which which are not Error/Fatal by
+  // default (disregarding attempts to upgrade severity from Warning to Error),
+  // as well as disabling all messages which are currently mapped to Warning
+  // (whether by default or downgraded from Error via e.g. -Wno-error or #pragma
+  // diagnostic.)
+  if (State->IgnoreAllWarnings) {
+    if (Result == diag::Severity::Warning ||
+        (Result >= diag::Severity::Error &&
+         !isDefaultMappingAsError((diag::kind)DiagID)))
+      return diag::Severity::Ignored;
+  }
 
   // If -Werror is enabled, map warnings to errors unless explicitly disabled.
   if (Result == diag::Severity::Warning) {

Modified: cfe/trunk/test/Frontend/optimization-remark.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/optimization-remark.c?rev=352535&r1=352534&r2=352535&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/optimization-remark.c (original)
+++ cfe/trunk/test/Frontend/optimization-remark.c Tue Jan 29 11:33:48 2019
@@ -13,6 +13,9 @@
 // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
 // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -Reverything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
 //
+// Check that -w doesn't disable remarks.
+// RUN: %clang_cc1 %s -Rpass=inline -w -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
+//
 // FIXME: -Reverything should imply -Rpass=.*.
 // RUN: %clang_cc1 %s -Reverything -emit-llvm -o - 2>/dev/null | FileCheck %s --check-prefix=CHECK-NO-REMARKS
 //

Modified: cfe/trunk/test/Frontend/warning-mapping-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-2.c?rev=352535&r1=352534&r2=352535&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/warning-mapping-2.c (original)
+++ cfe/trunk/test/Frontend/warning-mapping-2.c Tue Jan 29 11:33:48 2019
@@ -1,5 +1,7 @@
-// Check that -w has lower priority than -pedantic-errors.
+// Check that -w takes precedence over -pedantic-errors.
 // RUN: %clang_cc1 -verify -pedantic-errors -w %s
 
-void f0() { f1(); } // expected-error {{implicit declaration of function}}
+// Expect *not* to see a diagnostic for "implicit declaration of function"
+// expected-no-diagnostics
 
+void f0() { f1(); }

Modified: cfe/trunk/test/Frontend/warning-mapping-4.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-4.c?rev=352535&r1=352534&r2=352535&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/warning-mapping-4.c (original)
+++ cfe/trunk/test/Frontend/warning-mapping-4.c Tue Jan 29 11:33:48 2019
@@ -1,5 +1,9 @@
+// Verify that various combinations of flags properly keep the sign-compare
+// warning disabled.
+
 // RUN: %clang_cc1 -verify -Wno-error=sign-compare %s
 // RUN: %clang_cc1 -verify -Wsign-compare -w -Wno-error=sign-compare %s
+// RUN: %clang_cc1 -verify -w -Werror=sign-compare %s
 // expected-no-diagnostics
 
 int f0(int x, unsigned y) {

Modified: cfe/trunk/test/Frontend/warning-mapping-5.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-5.c?rev=352535&r1=352534&r2=352535&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/warning-mapping-5.c (original)
+++ cfe/trunk/test/Frontend/warning-mapping-5.c Tue Jan 29 11:33:48 2019
@@ -1,6 +1,5 @@
-// Check that #pragma diagnostic warning overrides -Werror. This matches GCC's
-// original documentation, but not its earlier implementations.
-// 
+// Check that #pragma diagnostic warning overrides -Werror.
+//
 // RUN: %clang_cc1 -verify -Werror %s
 
 #pragma clang diagnostic warning "-Wsign-compare"

Added: cfe/trunk/test/Frontend/warning-mapping-6.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/warning-mapping-6.c?rev=352535&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/warning-mapping-6.c (added)
+++ cfe/trunk/test/Frontend/warning-mapping-6.c Tue Jan 29 11:33:48 2019
@@ -0,0 +1,9 @@
+// Check that "#pragma diagnostic error" is suppressed by -w.
+//
+// RUN: %clang_cc1 -verify -Werror -w %s
+
+// expected-no-diagnostics
+#pragma gcc diagnostic error "-Wsign-compare"
+int f0(int x, unsigned y) {
+  return x < y;
+}

Modified: cfe/trunk/test/Modules/implementation-of-module.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/implementation-of-module.m?rev=352535&r1=352534&r2=352535&view=diff
==============================================================================
--- cfe/trunk/test/Modules/implementation-of-module.m (original)
+++ cfe/trunk/test/Modules/implementation-of-module.m Tue Jan 29 11:33:48 2019
@@ -1,17 +1,17 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Werror=auto-import %s -I %S/Inputs \
 // RUN:     -fmodule-implementation-of category_right -fsyntax-only
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Werror=auto-import %s -I %S/Inputs \
 // RUN:     -fmodule-implementation-of category_right -dM -E -o - 2>&1 | FileCheck %s
 // CHECK-NOT: __building_module
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Werror=auto-import %s -I %S/Inputs \
 // RUN:     -fmodule-implementation-of category_left -verify
 
-// RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
+// RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Werror=auto-import %s -I %S/Inputs \
 // RUN:     -fmodule-implementation-of category_right -emit-pch -o %t.pch
-// RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
+// RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Werror=auto-import %s -I %S/Inputs \
 // RUN:     -DWITH_PREFIX -fmodules-ignore-macro=WITH_PREFIX -include-pch %t.pch -fmodule-implementation-of category_right
 
 #ifndef WITH_PREFIX




More information about the cfe-commits mailing list