From e9ada6294d08983c30e043dc79e441cafa92257c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 20 Oct 2016 08:27:55 +0200 Subject: 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 --- compilerplugins/clang/expandablemethods.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/expandablemethods.cxx b/compilerplugins/clang/expandablemethods.cxx index 73946f5e3c1c..308c8f17c36a 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 calledFromMap; +static std::set> calledFromSet; static std::set definitionSet; static std::set calledFromOutsideSet; static std::set 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 & s : calledFromMap) + for (const std::pair & 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(parentStmt(expr))) { if (unaryOp->getOpcode() == UO_AddrOf) { @@ -282,12 +279,19 @@ void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct } const CXXMethodDecl* calleeMethodDecl = dyn_cast(calleeFunctionDecl); - const CXXMethodDecl* callsiteParentMethodDecl = dyn_cast(maTraversingFunctions.back()); - if (!callsiteParentMethodDecl - || calleeMethodDecl->getParent() != callsiteParentMethodDecl->getParent()) + if (maTraversingFunctions.empty()) { calledFromOutsideSet.insert(niceName(canonicalFunctionDecl)); } + else + { + const CXXMethodDecl* callsiteParentMethodDecl = dyn_cast(maTraversingFunctions.back()); + if (!callsiteParentMethodDecl + || calleeMethodDecl->getParent() != callsiteParentMethodDecl->getParent()) + { + calledFromOutsideSet.insert(niceName(canonicalFunctionDecl)); + } + } } bool ExpandableMethods::isCalleeFunctionInteresting(const FunctionDecl* functionDecl) -- cgit