r207386 - [SemaCXX] Silence -Wconstant-logical-operand if the operand is a 0/1 from a macro.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Apr 27 17:20:16 PDT 2014
Author: akirtzidis
Date: Sun Apr 27 19:20:16 2014
New Revision: 207386
URL: http://llvm.org/viewvc/llvm-project?rev=207386&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/expressions.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=207386&r1=207385&r2=207386&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Apr 27 19:20:16 2014
@@ -8268,7 +8268,8 @@ inline QualType Sema::CheckLogicalOperan
// 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()
Modified: cfe/trunk/test/SemaCXX/expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/expressions.cpp?rev=207386&r1=207385&r2=207386&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/expressions.cpp Sun Apr 27 19:20:16 2014
@@ -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}}
+}
More information about the cfe-commits
mailing list