aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.
}