[cfe-commits] r150260 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/format-strings.cpp
Ted Kremenek
kremenek at apple.com
Fri Feb 10 11:13:52 PST 2012
Author: kremenek
Date: Fri Feb 10 13:13:51 2012
New Revision: 150260
URL: http://llvm.org/viewvc/llvm-project?rev=150260&view=rev
Log:
Enhance checking for null format string literal to take into account __null. Fixes <rdar://problem/8269537>.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/format-strings.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=150260&r1=150259&r2=150260&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Feb 10 13:13:51 2012
@@ -1381,6 +1381,7 @@
inFunctionCall);
}
+ case Stmt::GNUNullExprClass:
case Stmt::IntegerLiteralClass:
// Technically -Wformat-nonliteral does not warn about this case.
// The behavior of printf and friends in this case is implementation
Modified: cfe/trunk/test/SemaCXX/format-strings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings.cpp?rev=150260&r1=150259&r2=150260&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/format-strings.cpp (original)
+++ cfe/trunk/test/SemaCXX/format-strings.cpp Fri Feb 10 13:13:51 2012
@@ -39,3 +39,14 @@
printf(foo.gettext("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
printf(Foo::gettext_static("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
}
+
+// Test handling __null for format string literal checking.
+extern "C" {
+ int test_null_format(const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+}
+
+void rdar8269537(const char *f)
+{
+ test_null_format(__null); // no-warning
+ test_null_format(f); // expected-warning {{not a string literal}}
+}
More information about the cfe-commits
mailing list