diff options
| author | Richard Trieu <rtrieu@google.com> | 2014-11-19 06:08:18 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2014-11-19 06:08:18 +0000 |
| commit | 791b86ec55a71659cbddc3bbaaf495c699872ddf (patch) | |
| tree | dc711812cf4e6fbb29ef1939516da3dfcaa6a0d4 | |
| parent | f552996fb397558dfccdcd9b2b8c62d608663265 (diff) | |
| download | bcm5719-llvm-791b86ec55a71659cbddc3bbaaf495c699872ddf.tar.gz bcm5719-llvm-791b86ec55a71659cbddc3bbaaf495c699872ddf.zip | |
Add the exception for strings in logical and expressions to -Wstring-conversion
for C code.
llvm-svn: 222327
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 11 | ||||
| -rw-r--r-- | clang/test/Sema/warn-string-conversion.c | 17 |
2 files changed, 26 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index aa6bf1760d3..91ba91e4f53 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -6613,10 +6613,17 @@ void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) { continue; AnalyzeImplicitConversions(S, ChildExpr, CC); } + if (BO && BO->isLogicalOp()) { - ::CheckBoolLikeConversion(S, BO->getLHS(), BO->getLHS()->getExprLoc()); - ::CheckBoolLikeConversion(S, BO->getRHS(), BO->getRHS()->getExprLoc()); + Expr *SubExpr = BO->getLHS()->IgnoreParenImpCasts(); + if (!IsLogicalAndOperator || !isa<StringLiteral>(SubExpr)) + ::CheckBoolLikeConversion(S, SubExpr, SubExpr->getExprLoc()); + + SubExpr = BO->getRHS()->IgnoreParenImpCasts(); + if (!IsLogicalAndOperator || !isa<StringLiteral>(SubExpr)) + ::CheckBoolLikeConversion(S, SubExpr, SubExpr->getExprLoc()); } + if (const UnaryOperator *U = dyn_cast<UnaryOperator>(E)) if (U->getOpcode() == UO_LNot) ::CheckBoolLikeConversion(S, U->getSubExpr(), CC); diff --git a/clang/test/Sema/warn-string-conversion.c b/clang/test/Sema/warn-string-conversion.c new file mode 100644 index 00000000000..708dd543e40 --- /dev/null +++ b/clang/test/Sema/warn-string-conversion.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -Wstring-conversion %s + +#define assert(EXPR) (void)(EXPR); + +// Expection for common assert form. +void test1() { + assert(0 && "foo"); + assert("foo" && 0); + assert(0 || "foo"); // expected-warning {{string literal}} +} + +void test2() { + if ("hi") {} // expected-warning {{string literal}} + while ("hello") {} // expected-warning {{string literal}} + for (;"howdy";) {} // expected-warning {{string literal}} + do { } while ("hey"); // expected-warning {{string literal}} +} |

