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

Noel Grandin noel.grandin at collabora.co.uk
Thu Oct 20 08:50:44 UTC 2016


 compilerplugins/clang/expandablemethods.cxx |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

New commits:
commit e9ada6294d08983c30e043dc79e441cafa92257c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Oct 20 08:27:55 2016 +0200

    fix bug in expandablemethods plugin
    
    where using a std::map instead of a std::set meant that it
    sometimes miscounted the number of callsites
    
    Change-Id: I1e2ebcf44fe006827e66620ae4c9bbc813835414

diff --git a/compilerplugins/clang/expandablemethods.cxx b/compilerplugins/clang/expandablemethods.cxx
index 73946f5..308c8f1 100644
--- a/compilerplugins/clang/expandablemethods.cxx
+++ b/compilerplugins/clang/expandablemethods.cxx
@@ -48,7 +48,7 @@ bool operator < (const MyFuncInfo &lhs, const MyFuncInfo &rhs)
 
 // try to limit the voluminous output a little
 
-static std::unordered_map<std::string, MyFuncInfo> calledFromMap;
+static std::set<std::pair<std::string, MyFuncInfo>> calledFromSet;
 static std::set<MyFuncInfo> definitionSet;
 static std::set<MyFuncInfo> calledFromOutsideSet;
 static std::set<MyFuncInfo> largeFunctionSet;
@@ -73,7 +73,7 @@ public:
             output += "definition:\t" + s.access + "\t" + s.returnType + "\t" + s.nameAndParams + "\t" + s.sourceLocation + "\n";
         for (const MyFuncInfo & s : calledFromOutsideSet)
             output += "outside:\t" + s.returnType + "\t" + s.nameAndParams + "\n";
-        for (const std::pair<std::string,MyFuncInfo> & s : calledFromMap)
+        for (const std::pair<std::string,MyFuncInfo> & s : calledFromSet)
             output += "calledFrom:\t" + s.first
                        + "\t" + s.second.returnType + "\t" + s.second.nameAndParams + "\n";
         for (const MyFuncInfo & s : largeFunctionSet)
@@ -265,15 +265,12 @@ bool ExpandableMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
 
 void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunctionDecl, const Expr* expr )
 {
-    if (maTraversingFunctions.empty()) {
-        return;
-    }
     const FunctionDecl* canonicalFunctionDecl = calleeFunctionDecl->getCanonicalDecl();
     if (!isCalleeFunctionInteresting(canonicalFunctionDecl)) {
         return;
     }
 
-    calledFromMap.emplace(toString(expr->getLocStart()), niceName(canonicalFunctionDecl));
+    calledFromSet.emplace(toString(expr->getLocStart()), niceName(canonicalFunctionDecl));
 
     if (const UnaryOperator* unaryOp = dyn_cast_or_null<UnaryOperator>(parentStmt(expr))) {
         if (unaryOp->getOpcode() == UO_AddrOf) {
@@ -282,12 +279,19 @@ void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct
     }
 
     const CXXMethodDecl* calleeMethodDecl = dyn_cast<CXXMethodDecl>(calleeFunctionDecl);
-    const CXXMethodDecl* callsiteParentMethodDecl = dyn_cast<CXXMethodDecl>(maTraversingFunctions.back());
-    if (!callsiteParentMethodDecl
-        || calleeMethodDecl->getParent() != callsiteParentMethodDecl->getParent())
+    if (maTraversingFunctions.empty())
     {
         calledFromOutsideSet.insert(niceName(canonicalFunctionDecl));
     }
+    else
+    {
+        const CXXMethodDecl* callsiteParentMethodDecl = dyn_cast<CXXMethodDecl>(maTraversingFunctions.back());
+        if (!callsiteParentMethodDecl
+            || calleeMethodDecl->getParent() != callsiteParentMethodDecl->getParent())
+        {
+            calledFromOutsideSet.insert(niceName(canonicalFunctionDecl));
+        }
+    }
 }
 
 bool ExpandableMethods::isCalleeFunctionInteresting(const FunctionDecl* functionDecl)


More information about the Libreoffice-commits mailing list