]> granicus.if.org Git - clang/commitdiff
[Diagnostics] Use Expr::isKnownToHaveBooleanValue() to check bitwise negation of...
authorDavid Bolvansky <david.bolvansky@gmail.com>
Sat, 5 Oct 2019 08:02:11 +0000 (08:02 +0000)
committerDavid Bolvansky <david.bolvansky@gmail.com>
Sat, 5 Oct 2019 08:02:11 +0000 (08:02 +0000)
Thanks for this advice, Richard Trieu!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373817 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/warn-bitwise-negation-bool.c

index 667441cbaa5f298f4f1553a8ba076bc0978cc285..c18f54cefde695877bede178e998800dbc2b4e33 100644 (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())
index dfec00055cd53b7451e494718628e45bbb51440e..435d783439c690f4d6dc3338942fdf82aefb02d7 100644 (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}:"!"
 }