[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 9 17:24:08 UTC 2021


 compilerplugins/clang/stringadd.cxx |   89 +++++++++++++++++-------------------
 1 file changed, 44 insertions(+), 45 deletions(-)

New commits:
commit 6a1ed1e5cdb9f56fc8c7278b7361c7b2aa200bb8
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Jul 9 15:08:24 2021 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Jul 9 19:23:34 2021 +0200

    Remove redundant duplicate check
    
    Change-Id: I311496e25ac617c6b174b828978a1298231bd433
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118686
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

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())
             {


More information about the Libreoffice-commits mailing list