]> granicus.if.org Git - clang/commitdiff
[clang] Emit `diagnose_if` warnings from system headers
authorEric Fiselier <eric@efcs.ca>
Fri, 13 Jan 2017 22:11:40 +0000 (22:11 +0000)
committerEric Fiselier <eric@efcs.ca>
Fri, 13 Jan 2017 22:11:40 +0000 (22:11 +0000)
Summary: In order for libc++ to meaningfully use `diagnose_if` warnings they need to be emitted from system headers by default. This patch changes the `diagnose_if` warning diagnostic to be shown in system headers.

Reviewers: george.burgess.iv, rsmith, aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D28703

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

include/clang/Basic/DiagnosticSemaKinds.td
test/Sema/Inputs/diagnose-if-warn-system-header.h [new file with mode: 0644]
test/Sema/diagnose_if.c

index 1c3937fb5facf4bf98859929e94548f3e7e35f11..0d0f68713d7d64adadbebaa7844ea4a8df91f336 100644 (file)
@@ -3380,7 +3380,8 @@ def note_ovl_candidate_has_pass_object_size_params: Note<
     "candidate address cannot be taken because parameter %0 has "
     "pass_object_size attribute">;
 def err_diagnose_if_succeeded : Error<"%0">;
-def warn_diagnose_if_succeeded : Warning<"%0">, InGroup<UserDefinedWarnings>;
+def warn_diagnose_if_succeeded : Warning<"%0">, InGroup<UserDefinedWarnings>,
+    ShowInSystemHeader;
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
     "candidate disabled: %0">;
 def note_ovl_candidate_disabled_by_extension : Note<
diff --git a/test/Sema/Inputs/diagnose-if-warn-system-header.h b/test/Sema/Inputs/diagnose-if-warn-system-header.h
new file mode 100644 (file)
index 0000000..753c69d
--- /dev/null
@@ -0,0 +1,11 @@
+#pragma GCC system_header
+
+inline int system_header_func(int x)
+  __attribute__((diagnose_if(x == x, "system header warning", "warning"))) // expected-note {{from 'diagnose_if' attribute}}
+{
+  return 0;
+}
+
+void test_system_header() {
+  system_header_func(0); // expected-warning {{system header warning}}
+}
index 219e393bc0cc4bbd5d967781c6f58924f4a64d1d..6dd8bafe8be6ede3d09589f673a4f358ad1977e6 100644 (file)
@@ -150,3 +150,6 @@ void alwaysWarnWithArg(int a) _diagnose_if(1 || a, "alwaysWarn", "warning"); //
 void runAlwaysWarnWithArg(int a) {
   alwaysWarnWithArg(a); // expected-warning{{alwaysWarn}}
 }
+
+// Test that diagnose_if warnings generated in system headers are not ignored.
+#include "Inputs/diagnose-if-warn-system-header.h"