diff options
Diffstat (limited to 'clang/lib/Analysis/CallGraph.cpp')
-rw-r--r-- | clang/lib/Analysis/CallGraph.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/Analysis/CallGraph.cpp b/clang/lib/Analysis/CallGraph.cpp index 76be292dad8d..59cc939b6fd1 100644 --- a/clang/lib/Analysis/CallGraph.cpp +++ b/clang/lib/Analysis/CallGraph.cpp @@ -66,16 +66,16 @@ public: return nullptr; } - void addCalledDecl(Decl *D) { - if (G->includeInGraph(D)) { + void addCalledDecl(Decl *D, Expr *CallExpr) { + if (G->includeCalleeInGraph(D)) { CallGraphNode *CalleeNode = G->getOrInsertNode(D); - CallerNode->addCallee(CalleeNode); + CallerNode->addCallee({CalleeNode, CallExpr}); } } void VisitCallExpr(CallExpr *CE) { if (Decl *D = getDeclFromCall(CE)) - addCalledDecl(D); + addCalledDecl(D, CE); VisitChildren(CE); } @@ -89,14 +89,14 @@ public: void VisitCXXNewExpr(CXXNewExpr *E) { if (FunctionDecl *FD = E->getOperatorNew()) - addCalledDecl(FD); + addCalledDecl(FD, E); VisitChildren(E); } void VisitCXXConstructExpr(CXXConstructExpr *E) { CXXConstructorDecl *Ctor = E->getConstructor(); if (FunctionDecl *Def = Ctor->getDefinition()) - addCalledDecl(Def); + addCalledDecl(Def, E); VisitChildren(E); } @@ -122,7 +122,7 @@ public: else D = IDecl->lookupPrivateClassMethod(Sel); if (D) { - addCalledDecl(D); + addCalledDecl(D, ME); NumObjCCallEdges++; } } @@ -157,6 +157,10 @@ bool CallGraph::includeInGraph(const Decl *D) { if (!D->hasBody()) return false; + return includeCalleeInGraph(D); +} + +bool CallGraph::includeCalleeInGraph(const Decl *D) { if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { // We skip function template definitions, as their semantics is // only determined when they are instantiated. @@ -207,7 +211,7 @@ CallGraphNode *CallGraph::getOrInsertNode(Decl *F) { Node = std::make_unique<CallGraphNode>(F); // Make Root node a parent of all functions to make sure all are reachable. if (F) - Root->addCallee(Node.get()); + Root->addCallee({Node.get(), /*Call=*/nullptr}); return Node.get(); } @@ -230,8 +234,8 @@ void CallGraph::print(raw_ostream &OS) const { OS << " calls: "; for (CallGraphNode::const_iterator CI = N->begin(), CE = N->end(); CI != CE; ++CI) { - assert(*CI != Root && "No one can call the root node."); - (*CI)->print(OS); + assert(CI->Callee != Root && "No one can call the root node."); + CI->Callee->print(OS); OS << " "; } OS << '\n'; |