[cfe-commits] r150276 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/format-strings-0x.cpp test/SemaCXX/format-strings.cpp
David Blaikie
dblaikie at gmail.com
Fri Feb 10 13:07:25 PST 2012
Author: dblaikie
Date: Fri Feb 10 15:07:25 2012
New Revision: 150276
URL: http://llvm.org/viewvc/llvm-project?rev=150276&view=rev
Log:
Support all null pointer literals in format strings.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/format-strings-0x.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=150276&r1=150275&r2=150276&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Feb 10 15:07:25 2012
@@ -1369,6 +1369,13 @@
E = E->IgnoreParenCasts();
+ if (E->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
+ // Technically -Wformat-nonliteral does not warn about this case.
+ // The behavior of printf and friends in this case is implementation
+ // dependent. Ideally if the format string cannot be null then
+ // it should have a 'nonnull' attribute in the function prototype.
+ return true;
+
switch (E->getStmtClass()) {
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass: {
@@ -1381,14 +1388,6 @@
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
- // dependent. Ideally if the format string cannot be null then
- // it should have a 'nonnull' attribute in the function prototype.
- return true;
-
case Stmt::ImplicitCastExprClass: {
E = cast<ImplicitCastExpr>(E)->getSubExpr();
goto tryAgain;
Modified: cfe/trunk/test/SemaCXX/format-strings-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings-0x.cpp?rev=150276&r1=150275&r2=150276&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/format-strings-0x.cpp (original)
+++ cfe/trunk/test/SemaCXX/format-strings-0x.cpp Fri Feb 10 15:07:25 2012
@@ -10,4 +10,6 @@
printf("%a", 1.0);
scanf("%afoobar", fp);
+ printf(nullptr);
+ printf(*sp); // expected-warning {{not a string literal}}
}
Modified: cfe/trunk/test/SemaCXX/format-strings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings.cpp?rev=150276&r1=150275&r2=150276&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/format-strings.cpp (original)
+++ cfe/trunk/test/SemaCXX/format-strings.cpp Fri Feb 10 15:07:25 2012
@@ -47,6 +47,8 @@
void rdar8269537(const char *f)
{
+ test_null_format(false); // expected-warning {{null from a constant boolean}}
+ test_null_format(0); // no-warning
test_null_format(__null); // no-warning
test_null_format(f); // expected-warning {{not a string literal}}
}
More information about the cfe-commits
mailing list