aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-07-15 00:26:43 +0000
committerChris Lattner <sabre@nondot.org>2010-07-15 00:26:43 +0000
commit23ef3e4f044d701d0f84980fd9816fedf17fc0cb (patch)
tree19b26b61ea0da8e3fe53e535062feafa70a1691f
parent30c514c225342844700ed4640ec6d90ddf0e12b2 (diff)
restrict the && -> & warning to cover a case daniel noted.
Don't warn about "logically bool" expressions on the RHS, even if they fold to a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108388 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExpr.cpp4
-rw-r--r--test/Sema/exprs.c2
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index c06943f671..5f46a977b1 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -5742,6 +5742,10 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14]
// is a constant.
if (lex->getType()->isIntegerType() && !lex->getType()->isBooleanType() &&
rex->getType()->isIntegerType() && rex->isEvaluatable(Context) &&
+ // Don't warn if the RHS is a (constant folded) boolean expression like
+ // "sizeof(int) == 4".
+ !rex->isKnownToHaveBooleanValue() &&
+ // Don't warn in macros.
!Loc.isMacroID())
Diag(Loc, diag::warn_logical_instead_of_bitwise)
<< rex->getSourceRange()
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index 54e44693e0..9d3da90854 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -144,4 +144,6 @@ void test19() {
int test20(int x) {
return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+
+ return x && sizeof(int) == 4; // no warning.
}