diff options
| author | David Blaikie <dblaikie@gmail.com> | 2012-02-10 21:07:25 +0000 |
|---|---|---|
| committer | David Blaikie <dblaikie@gmail.com> | 2012-02-10 21:07:25 +0000 |
| commit | 59fe3f89cb4e79364ff6e9ac8d25d3e7855b153f (patch) | |
| tree | 8601dee637f9e6649e906f64b772bee43f2aeec5 /clang | |
| parent | 6b83daefd3ebd81caf8773617fb2685505584466 (diff) | |
| download | bcm5719-llvm-59fe3f89cb4e79364ff6e9ac8d25d3e7855b153f.tar.gz bcm5719-llvm-59fe3f89cb4e79364ff6e9ac8d25d3e7855b153f.zip | |
Support all null pointer literals in format strings.
llvm-svn: 150276
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 15 | ||||
| -rw-r--r-- | clang/test/SemaCXX/format-strings-0x.cpp | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/format-strings.cpp | 2 |
3 files changed, 11 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index be326880d58..cf0469592f8 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1369,6 +1369,13 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args, 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 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args, 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; diff --git a/clang/test/SemaCXX/format-strings-0x.cpp b/clang/test/SemaCXX/format-strings-0x.cpp index 9359c7b1f99..e7c5904c66e 100644 --- a/clang/test/SemaCXX/format-strings-0x.cpp +++ b/clang/test/SemaCXX/format-strings-0x.cpp @@ -10,4 +10,6 @@ void f(char **sp, float *fp) { printf("%a", 1.0); scanf("%afoobar", fp); + printf(nullptr); + printf(*sp); // expected-warning {{not a string literal}} } diff --git a/clang/test/SemaCXX/format-strings.cpp b/clang/test/SemaCXX/format-strings.cpp index 456167dfc96..0d5b62598d1 100644 --- a/clang/test/SemaCXX/format-strings.cpp +++ b/clang/test/SemaCXX/format-strings.cpp @@ -47,6 +47,8 @@ extern "C" { 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}} } |

