r373817 - [Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of bool in languages without a bool type
David Bolvansky via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 5 01:02:11 PDT 2019
Author: xbolva00
Date: Sat Oct 5 01:02:11 2019
New Revision: 373817
URL: http://llvm.org/viewvc/llvm-project?rev=373817&view=rev
Log:
[Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of bool in languages without a bool type
Thanks for this advice, Richard Trieu!
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373817&r1=373816&r2=373817&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Oct 5 01:02:11 2019
@@ -13479,7 +13479,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
// C99 does not support '~' for complex conjugation.
Diag(OpLoc, diag::ext_integer_complement_complex)
<< resultType << Input.get()->getSourceRange();
- else if (Input.get()->IgnoreParenImpCasts()->getType()->isBooleanType())
+ else if (Input.get()->isKnownToHaveBooleanValue())
Diag(OpLoc, diag::warn_bitwise_negation_bool)
<< FixItHint::CreateReplacement(OpLoc, "!");
else if (resultType->hasIntegerRepresentation())
Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373817&r1=373816&r2=373817&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original)
+++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Sat Oct 5 01:02:11 2019
@@ -19,4 +19,6 @@ void test(boolean b, int i) {
b = ~i;
i = ~b; // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
+ b = ~(i > 4); // expected-warning {{bitwise negation of a boolean expression; did you mean logical negation?}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
}
More information about the cfe-commits
mailing list