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

Stephan Bergmann sbergman at redhat.com
Wed Aug 30 10:26:42 UTC 2017


 compilerplugins/clang/constparams.cxx |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

New commits:
commit 99fb14ef729f9b92edcdd4bd7940d48fff6a7307
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Aug 30 12:22:19 2017 +0200

    ...in which Johnny returns from the fair
    
    and finds loplugin:constparams adapted to ObjCMessageExpr
    
    Change-Id: I6e1ddd0fb1a8a61d5a78c156bccfc29f7233909e

diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx
index bac52a422618..8c42e5a27c6b 100644
--- a/compilerplugins/clang/constparams.cxx
+++ b/compilerplugins/clang/constparams.cxx
@@ -186,6 +186,8 @@ bool ConstParams::VisitFunctionDecl(const FunctionDecl * functionDecl)
             || name == "egiGraphicExport"
             || name == "etiGraphicExport"
             || name == "epsGraphicExport"
+            || name == "QueueCallbackFunction"
+                // apple_remote/source/HIDRemoteControlDevice.m
             )
                 return true;
     }
@@ -392,6 +394,24 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar
             }
         }
         return false; // TODO ????
+    } else if (auto callExpr = dyn_cast<ObjCMessageExpr>(parent)) {
+        if (callExpr->getInstanceReceiver() == stmt) {
+            return true;
+        }
+        if (auto const method = callExpr->getMethodDecl()) {
+            // TODO could do better
+            if (method->isVariadic()) {
+                return false;
+            }
+            assert(method->param_size() == callExpr->getNumArgs());
+            for (unsigned i = 0; i < callExpr->getNumArgs(); ++i) {
+                if (callExpr->getArg(i) == stmt) {
+                    return isPointerOrReferenceToConst(
+                        method->param_begin()[i]->getType());
+                }
+            }
+        }
+        return false; // TODO ????
     } else if (isa<CXXReinterpretCastExpr>(parent)) {
         return false;
     } else if (isa<CXXConstCastExpr>(parent)) {


More information about the Libreoffice-commits mailing list