compilerplugins/clang/casttovoid.cxx | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
New commits: commit 4ec6a5e3ac89e9cbfaf19cdc0848566bcd4a0571 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Jul 7 17:15:21 2017 +0200 Only consider calls on const member functions as consumptions Change-Id: I968614ba25affe58ea05c97c97dd10912359df2c Reviewed-on: https://gerrit.libreoffice.org/39755 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/casttovoid.cxx b/compilerplugins/clang/casttovoid.cxx index 01d1e65e3363..f38d366314c5 100644 --- a/compilerplugins/clang/casttovoid.cxx +++ b/compilerplugins/clang/casttovoid.cxx @@ -195,13 +195,38 @@ public: } unsigned firstArg = 0; if (auto const cmce = dyn_cast<CXXMemberCallExpr>(expr)) { - recordConsumption(cmce->getImplicitObjectArgument()); + if (auto const e1 = cmce->getMethodDecl()) { + if (e1->isConst() || e1->isStatic()) { + recordConsumption(cmce->getImplicitObjectArgument()); + } + } else if (auto const e2 = dyn_cast<BinaryOperator>( + cmce->getCallee()->IgnoreParenImpCasts())) + { + switch (e2->getOpcode()) { + case BO_PtrMemD: + case BO_PtrMemI: + if (e2->getRHS()->getType()->getAs<MemberPointerType>() + ->getPointeeType()->getAs<FunctionProtoType>() + ->isConst()) + { + recordConsumption(e2->getLHS()); + } + break; + default: + break; + } + } } else if (isa<CXXOperatorCallExpr>(expr)) { - auto const dc = expr->getDirectCallee(); - if (dc != nullptr && isa<CXXMethodDecl>(dc)) { - assert(expr->getNumArgs() != 0); - recordConsumption(expr->getArg(0)); - firstArg = 1; + if (auto const cmd = dyn_cast_or_null<CXXMethodDecl>( + expr->getDirectCallee())) + { + if (!cmd->isStatic()) { + assert(expr->getNumArgs() != 0); + if (cmd->isConst()) { + recordConsumption(expr->getArg(0)); + } + firstArg = 1; + } } } auto fun = expr->getDirectCallee(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits