]> granicus.if.org Git - clang/commitdiff
Don't hide #warnings in a system header, same as gcc. Fixes rdar://8495837.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 21 Apr 2011 23:08:23 +0000 (23:08 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 21 Apr 2011 23:08:23 +0000 (23:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129951 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.td
include/clang/Basic/DiagnosticIDs.h
include/clang/Basic/DiagnosticLexKinds.td
lib/Basic/DiagnosticIDs.cpp
test/Misc/warn-in-system-header.c [new file with mode: 0644]
test/Misc/warn-in-system-header.h [new file with mode: 0644]

index 688f8fa39e6f76f43b53a3cf1b1d42ae191b8b85..50a22c4a91208545778575ed66d6b329f161bb18 100644 (file)
@@ -18,7 +18,8 @@ def MAP_IGNORE  : DiagMapping;
 def MAP_WARNING : DiagMapping;
 def MAP_ERROR   : DiagMapping;
 def MAP_FATAL   : DiagMapping;
-def MAP_WARNING_NO_WERROR : DiagMapping;
+def MAP_WARNING_NO_WERROR             : DiagMapping;
+def MAP_WARNING_SHOW_IN_SYSTEM_HEADER : DiagMapping;
 
 // Define the diagnostic classes.
 class DiagClass;
@@ -76,7 +77,10 @@ class DefaultIgnore { DiagMapping DefaultMapping = MAP_IGNORE; }
 class DefaultWarn   { DiagMapping DefaultMapping = MAP_WARNING; }
 class DefaultError  { DiagMapping DefaultMapping = MAP_ERROR; }
 class DefaultFatal  { DiagMapping DefaultMapping = MAP_FATAL; }
-class DefaultWarnNoWerror  { DiagMapping DefaultMapping = MAP_WARNING_NO_WERROR; }
+class DefaultWarnNoWerror { DiagMapping DefaultMapping= MAP_WARNING_NO_WERROR; }
+class DefaultWarnShowInSystemHeader {
+  DiagMapping DefaultMapping = MAP_WARNING_SHOW_IN_SYSTEM_HEADER;
+}
 
 class NoSFINAE { bit SFINAE = 0; }
 class AccessControl { bit AccessControl = 1; }
index f4dec257ef2f2807d8f478c3b6b0411868e73ea5..0296b96d00f6f1306e690bbe97650a0bc1099404 100644 (file)
@@ -64,9 +64,12 @@ namespace clang {
       /// Map this diagnostic to "warning", but make it immune to -Werror.  This
       /// happens when you specify -Wno-error=foo.
       MAP_WARNING_NO_WERROR = 5,
+      /// Map this diagnostic to "warning", but make it immune to
+      /// -Wno-system-headers.
+      MAP_WARNING_SHOW_IN_SYSTEM_HEADER = 6,
       /// Map this diagnostic to "error", but make it immune to -Wfatal-errors.
       /// This happens for -Wno-fatal-errors=foo.
-      MAP_ERROR_NO_WFATAL = 6
+      MAP_ERROR_NO_WFATAL = 7
     };
   }
 
index b30606c3e38f38db9252b0f0ef263c003f8148c8..3514ccace22a9dfd53b5377eef94f840eebead3f 100644 (file)
@@ -114,7 +114,8 @@ def err_invalid_pth_file : Error<
 //===----------------------------------------------------------------------===//
 // Preprocessor Diagnostics
 //===----------------------------------------------------------------------===//
-def pp_hash_warning : Warning<"#warning%0">, InGroup<PoundWarning>;
+def pp_hash_warning : Warning<"#warning%0">,
+  InGroup<PoundWarning>, DefaultWarnShowInSystemHeader;
 def pp_include_next_in_primary : Warning<
   "#include_next in primary source file">;
 def pp_include_macros_out_of_predefines : Error<
index f92a34edd2653505e995635cb640b4e9e952773b..b4dd575a9684fa79204fc692ea8379c1179e2754 100644 (file)
@@ -404,6 +404,8 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
   if (mapping)
     *mapping = (diag::Mapping) (MappingInfo & 7);
 
+  bool ShouldEmitInSystemHeader = false;
+
   switch (MappingInfo & 7) {
   default: assert(0 && "Unknown mapping!");
   case diag::MAP_IGNORE:
@@ -426,6 +428,9 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
   case diag::MAP_FATAL:
     Result = DiagnosticIDs::Fatal;
     break;
+  case diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER:
+    ShouldEmitInSystemHeader = true;
+    // continue as MAP_WARNING.
   case diag::MAP_WARNING:
     // If warnings are globally mapped to ignore or error, do it.
     if (Diag.IgnoreAllWarnings)
@@ -477,6 +482,7 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
       DiagClass != CLASS_ERROR &&
       // Custom diagnostics always are emitted in system headers.
       DiagID < diag::DIAG_UPPER_LIMIT &&
+      !ShouldEmitInSystemHeader &&
       Diag.SuppressSystemWarnings &&
       Loc.isValid() &&
       Diag.getSourceManager().isInSystemHeader(
diff --git a/test/Misc/warn-in-system-header.c b/test/Misc/warn-in-system-header.c
new file mode 100644 (file)
index 0000000..7e4615e
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -isystem %S %s -fsyntax-only -verify 
+
+#include <warn-in-system-header.h>
+// expected-warning {{#warning}}
diff --git a/test/Misc/warn-in-system-header.h b/test/Misc/warn-in-system-header.h
new file mode 100644 (file)
index 0000000..5e127b9
--- /dev/null
@@ -0,0 +1,4 @@
+
+
+
+#warning the cake is a lie