diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-07-09 15:08:24 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-07-09 19:23:34 +0200 |
commit | 6a1ed1e5cdb9f56fc8c7278b7361c7b2aa200bb8 (patch) | |
tree | e2ace6713986c723c32dac19698f71a6526b62de /compilerplugins | |
parent | 90d33528ceb9d3a6b0edda708ca102c16c320b0d (diff) |
Remove redundant duplicate check
Change-Id: I311496e25ac617c6b174b828978a1298231bd433
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118686
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringadd.cxx | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx index 394139dbb354..f10072497767 100644 --- a/compilerplugins/clang/stringadd.cxx +++ b/compilerplugins/clang/stringadd.cxx @@ -346,69 +346,68 @@ bool StringAdd::isSideEffectFree(Expr const* expr) { // check for calls through OUString::number/OUString::unacquired if (auto calleeMethodDecl = dyn_cast_or_null<CXXMethodDecl>(callExpr->getCalleeDecl())) - if (calleeMethodDecl) + { + if (calleeMethodDecl->getIdentifier()) { - if (calleeMethodDecl->getIdentifier()) + auto name = calleeMethodDecl->getName(); + if (callExpr->getNumArgs() > 0 + && (name == "number" || name == "unacquired" || name == "boolean" + || name == "copy")) { - auto name = calleeMethodDecl->getName(); - if (callExpr->getNumArgs() > 0 - && (name == "number" || name == "unacquired" || name == "boolean" - || name == "copy")) + auto tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); + if (tc.Class("OUString") || tc.Class("OString")) { - auto tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); - if (tc.Class("OUString") || tc.Class("OString")) - { - if (isSideEffectFree(callExpr->getArg(0))) - return true; - } + if (isSideEffectFree(callExpr->getArg(0))) + return true; } } - else if (auto const d = dyn_cast<CXXConversionDecl>(calleeMethodDecl)) + } + else if (auto const d = dyn_cast<CXXConversionDecl>(calleeMethodDecl)) + { + if (loplugin::TypeCheck(d->getConversionType()) + .ClassOrStruct("basic_string_view") + .StdNamespace()) { - if (loplugin::TypeCheck(d->getConversionType()) - .ClassOrStruct("basic_string_view") - .StdNamespace()) + auto const tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); + if (tc.Class("OUString").Namespace("rtl").GlobalNamespace() + || tc.Class("OString").Namespace("rtl").GlobalNamespace()) { - auto const tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); - if (tc.Class("OUString").Namespace("rtl").GlobalNamespace() - || tc.Class("OString").Namespace("rtl").GlobalNamespace()) - { - if (isSideEffectFree(callExpr->getCallee())) - return true; - } + if (isSideEffectFree(callExpr->getCallee())) + return true; } } - // Aggressively assume that calls to const member functions are side effect free (if - // all of the call's sub-expressions are): - if (calleeMethodDecl->isConst()) + } + // Aggressively assume that calls to const member functions are side effect free (if + // all of the call's sub-expressions are): + if (calleeMethodDecl->isConst()) + { + auto sef = true; + // Other options besides CXXMemberCallExpr are e.g. CXXOperatorCallExpr which + // does not have such a target expression: + if (auto const mce = dyn_cast<CXXMemberCallExpr>(callExpr)) { - auto sef = true; - // Other options besides CXXMemberCallExpr are e.g. CXXOperatorCallExpr which - // does not have such a target expression: - if (auto const mce = dyn_cast<CXXMemberCallExpr>(callExpr)) + if (!isSideEffectFree(mce->getImplicitObjectArgument())) { - if (!isSideEffectFree(mce->getImplicitObjectArgument())) - { - sef = false; - } + sef = false; } - if (sef) + } + if (sef) + { + for (unsigned i = 0; i != callExpr->getNumArgs(); ++i) { - for (unsigned i = 0; i != callExpr->getNumArgs(); ++i) + if (!isSideEffectFree(callExpr->getArg(i))) { - if (!isSideEffectFree(callExpr->getArg(i))) - { - sef = false; - break; - } + sef = false; + break; } } - if (sef) - { - return true; - } + } + if (sef) + { + return true; } } + } if (auto calleeFunctionDecl = dyn_cast_or_null<FunctionDecl>(callExpr->getCalleeDecl())) if (calleeFunctionDecl && calleeFunctionDecl->getIdentifier()) { |