summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-04-28 00:20:16 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-04-28 00:20:16 +0000
commitd6eb2b9f4d4fc236376e3a5a7b8faa31e8dd427d (patch)
treeacfd3fea20ef0eea4652c569d2f36ad595f10aa4
parent20c5693e9e9d0cc801bc2411870b1a9d6362f425 (diff)
downloadbcm5719-llvm-d6eb2b9f4d4fc236376e3a5a7b8faa31e8dd427d.tar.gz
bcm5719-llvm-d6eb2b9f4d4fc236376e3a5a7b8faa31e8dd427d.zip
[SemaCXX] Silence -Wconstant-logical-operand if the operand is a 0/1 from a macro.
Libraries specify enabled/disabled features using macro defs of 0/1, in such cases the -Wconstant-logical-operand is noise. rdar://15410291 llvm-svn: 207386
-rw-r--r--clang/lib/Sema/SemaExpr.cpp3
-rw-r--r--clang/test/SemaCXX/expressions.cpp10
2 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6d624adc4eb..595770dc36b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8268,7 +8268,8 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14]
// Parens on the RHS are ignored.
llvm::APSInt Result;
if (RHS.get()->EvaluateAsInt(Result, Context))
- if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType()) ||
+ if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+ !RHS.get()->getExprLoc().isMacroID()) ||
(Result != 0 && Result != 1)) {
Diag(Loc, diag::warn_logical_instead_of_bitwise)
<< RHS.get()->getSourceRange()
diff --git a/clang/test/SemaCXX/expressions.cpp b/clang/test/SemaCXX/expressions.cpp
index 25a9c841725..1a50c99c590 100644
--- a/clang/test/SemaCXX/expressions.cpp
+++ b/clang/test/SemaCXX/expressions.cpp
@@ -125,3 +125,13 @@ namespace pr16992 {
return (sizeof T());
}
}
+
+void test4() {
+ #define X 0
+ #define Y 1
+ bool r1 = X || Y;
+
+ #define Y2 2
+ bool r2 = X || Y2; // expected-warning {{use of logical '||' with constant operand}} \
+ // expected-note {{use '|' for a bitwise operation}}
+}
OpenPOWER on IntegriCloud