diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-04 08:45:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-04 11:21:36 +0200 |
commit | cda88ec7a43162df37098c4525c33451266a1575 (patch) | |
tree | 4f80310ab0ef1210b7dcd4d769b70c59fbc09f1e /compilerplugins/clang | |
parent | f45ff1a7147e6a9479c669f082dd74349c6bcb4b (diff) |
loplugin:simplifybool a little more aggressive
with expressions like !(a && b)
Change-Id: Id2acec2a8d0eaaa8e5e37dbd2cae7281be36572e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100040
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/buriedassign.cxx | 8 | ||||
-rw-r--r-- | compilerplugins/clang/compat.hxx | 9 | ||||
-rw-r--r-- | compilerplugins/clang/simplifybool.cxx | 2 |
3 files changed, 11 insertions, 8 deletions
diff --git a/compilerplugins/clang/buriedassign.cxx b/compilerplugins/clang/buriedassign.cxx index 1758a4fcbca8..658ad4789d87 100644 --- a/compilerplugins/clang/buriedassign.cxx +++ b/compilerplugins/clang/buriedassign.cxx @@ -255,12 +255,6 @@ static bool isAssignmentOp(clang::OverloadedOperatorKind Opc) || Opc == OO_AmpEqual || Opc == OO_CaretEqual || Opc == OO_PipeEqual; } -static bool isComparisonOp(clang::OverloadedOperatorKind op) -{ - return op == OO_Less || op == OO_Greater || op == OO_LessEqual || op == OO_GreaterEqual - || op == OO_EqualEqual || op == OO_ExclaimEqual; -} - static const Expr* IgnoreImplicitAndConversionOperator(const Expr* expr) { expr = compat::IgnoreImplicit(expr); @@ -570,7 +564,7 @@ void BuriedAssign::MarkConditionForControlLoops(Expr const* expr) else if (auto cxxOper = dyn_cast<CXXOperatorCallExpr>(expr)) { // handle: ((xxx = foo()) != error) - if (isComparisonOp(cxxOper->getOperator())) + if (compat::isComparisonOp(cxxOper)) { MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(0))->IgnoreParens()); MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(1))->IgnoreParens()); diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index ed9d3ec942dc..fb8791f978b4 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -300,6 +300,15 @@ inline clang::QualType getDeclaredReturnType(clang::FunctionDecl const * decl) { #endif } +// The isComparisonOp method on CXXOperatorCallExpr is not available yet for the clang we require +inline bool isComparisonOp(clang::CXXOperatorCallExpr const * callExpr) +{ + using namespace clang; + auto op = callExpr->getOperator(); + return op == OO_Less || op == OO_Greater || op == OO_LessEqual || op == OO_GreaterEqual + || op == OO_EqualEqual || op == OO_ExclaimEqual; +} + } #endif diff --git a/compilerplugins/clang/simplifybool.cxx b/compilerplugins/clang/simplifybool.cxx index ff50cb47f0c7..89c262f54c98 100644 --- a/compilerplugins/clang/simplifybool.cxx +++ b/compilerplugins/clang/simplifybool.cxx @@ -302,7 +302,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) { if (binaryOp->isComparisonOp()) return expr; if (auto cxxOpCall = dyn_cast<CXXOperatorCallExpr>(expr)) - if (cxxOpCall->getOperator() == OO_ExclaimEqual) + if (compat::isComparisonOp(cxxOpCall)) return expr; return (Expr const*)nullptr; }; |