[Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of bool in languages without a bool type

Thanks for this advice, Richard Trieu!

llvm-svn: 373817
This commit is contained in:
David Bolvansky 2019-10-05 08:02:11 +00:00
parent 482f4d9aa9
commit 559265c8da
2 changed files with 3 additions and 1 deletions

View File

@ -13479,7 +13479,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
// 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())

View File

@ -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}:"!"
}