summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2019-10-07 21:57:03 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2019-10-07 21:57:03 +0000
commitaaea76ba02301efd8aa0c8d5da4af400d03b2fb6 (patch)
tree9f18baeba9bbbc72a186f573d5b47fb7fff794a5 /clang/lib/Sema
parentee33c61e341c23cbffe5c583107353d54fc67be8 (diff)
downloadbcm5719-llvm-aaea76ba02301efd8aa0c8d5da4af400d03b2fb6.tar.gz
bcm5719-llvm-aaea76ba02301efd8aa0c8d5da4af400d03b2fb6.zip
[Diagnostics] Emit better -Wbool-operation's warning message if we known that the result is always true
llvm-svn: 373973
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp7
-rw-r--r--clang/lib/Sema/SemaExpr.cpp4
2 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index eeddff6c714..de8e1ef87a9 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11896,6 +11896,13 @@ static void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC,
if (E->isTypeDependent() || E->isValueDependent())
return;
+ if (const auto *UO = dyn_cast<UnaryOperator>(E))
+ if (UO->getOpcode() == UO_Not &&
+ UO->getSubExpr()->isKnownToHaveBooleanValue())
+ S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool)
+ << OrigE->getSourceRange() << T->isBooleanType()
+ << FixItHint::CreateReplacement(UO->getBeginLoc(), "!");
+
// For conditional operators, we analyze the arguments as if they
// were being fed directly into the output.
if (isa<ConditionalOperator>(E)) {
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3cb999dacc4..f08b6168094 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13479,10 +13479,6 @@ 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()->isKnownToHaveBooleanValue())
- Diag(OpLoc, diag::warn_bitwise_negation_bool)
- << Input.get()->getSourceRange()
- << FixItHint::CreateReplacement(OpLoc, "!");
else if (resultType->hasIntegerRepresentation())
break;
else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) {
OpenPOWER on IntegriCloud