Allow -Wformat to be enabled without -Wformat-security. GCC gates
authorChandler Carruth <chandlerc@gmail.com>
Mon, 21 Feb 2011 00:07:51 +0000 (00:07 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 21 Feb 2011 00:07:51 +0000 (00:07 +0000)
-Wformat-security on -Wformat, not vice-versa.

Fixes PR8486. Patch by Oleg Slezberg.

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

include/clang/Basic/DiagnosticGroups.td
test/Sema/format-strings.c

index d4377c9a0b07baa230cdccbe52467a8fd2828fb5..412fb587108e14f3c9642fbf80396fcc17a4581c 100644 (file)
@@ -198,9 +198,11 @@ def Unused : DiagGroup<"unused",
                         DiagCategory<"Unused Entity Issue">;
 
 // Format settings.
-def Format : DiagGroup<"format", [FormatExtraArgs, FormatZeroLength, NonNull]>,
+def FormatSecurity : DiagGroup<"format-security">;
+def Format : DiagGroup<"format",
+                       [FormatExtraArgs, FormatZeroLength, NonNull,
+                        FormatSecurity]>,
              DiagCategory<"Format String Issue">;
-def FormatSecurity : DiagGroup<"format-security", [Format]>;
 def FormatNonLiteral : DiagGroup<"format-nonliteral", [FormatSecurity]>;
 def FormatY2K : DiagGroup<"format-y2k", [Format]>;
 def Format2 : DiagGroup<"format=2",
index be506d7c6b191e0a0f206580ed0f524bdeac0a5d..fe4f4567cbdb9a2b50e5c06f85f7448154fdf8c4 100644 (file)
@@ -340,3 +340,13 @@ void posix_extensions() {
   printf("%'f\n", (float) 1.0); // no-warning
   printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}}
 }
+
+// PR8486
+//
+// Test what happens when -Wformat is on, but -Wformat-security is off.
+#pragma GCC diagnostic warning "-Wformat"
+#pragma GCC diagnostic ignored "-Wformat-security"
+
+void pr8486() {
+  printf("%s", 1); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}}
+}