From e67657d5211f6e95ddf8bd621108608573b00d5d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 6 Aug 2020 13:32:43 +0200 Subject: loplugin:simplifybool more look for expressions like !(a && !b) which can be expanded out Change-Id: I72515a9638762b050f9a258c08da39ebfa2ef8e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100579 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/simplifybool.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/simplifybool.cxx b/compilerplugins/clang/simplifybool.cxx index 89c262f54c98..d2e53d63aae9 100644 --- a/compilerplugins/clang/simplifybool.cxx +++ b/compilerplugins/clang/simplifybool.cxx @@ -293,11 +293,17 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { } else if (binaryOp->isLogicalOp()) { - auto containsNegationOrComparison = [](Expr const * expr) { + // if we find a negation condition inside, it is definitely better + // to expand it out + bool foundLNot = false; + auto containsNegationOrComparison = [&](Expr const * expr) { expr = ignoreParenImpCastAndComma(expr); if (auto unaryOp = dyn_cast(expr)) if (unaryOp->getOpcode() == UO_LNot) + { + foundLNot = true; return expr; + } if (auto binaryOp = dyn_cast(expr)) if (binaryOp->isComparisonOp()) return expr; @@ -308,9 +314,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { }; auto lhs = containsNegationOrComparison(binaryOp->getLHS()); auto rhs = containsNegationOrComparison(binaryOp->getRHS()); - if (!lhs || !rhs) - return true; - if (lhs || rhs) + if (foundLNot || (lhs && rhs)) report( DiagnosticsEngine::Warning, ("logical negation of logical op containing negation, can be simplified"), -- cgit