diff --git a/include/clang/Analysis/CallGraph.h b/include/clang/Analysis/CallGraph.h index 6ff1e7f939a3ae99cac231d4a35d98e7be66e919..ea1c4a01e185c1863f7f0df0f6eb259b42512bd1 100644 --- a/include/clang/Analysis/CallGraph.h +++ b/include/clang/Analysis/CallGraph.h @@ -34,7 +34,8 @@ class CallGraphNode; class CallGraph : public RecursiveASTVisitor<CallGraph> { friend class CallGraphNode; - typedef llvm::DenseMap<const Decl *, CallGraphNode *> FunctionMapTy; + typedef llvm::DenseMap<const Decl *, std::unique_ptr<CallGraphNode>> + FunctionMapTy; /// FunctionMap owns all CallGraphNodes. FunctionMapTy FunctionMap; @@ -198,9 +199,11 @@ template <> struct GraphTraits<clang::CallGraph*> static NodeType *getEntryNode(clang::CallGraph *CGN) { return CGN->getRoot(); // Start at the external node! } - typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy; - static clang::CallGraphNode *CGGetValue(PairTy P) { return P.second; } + static clang::CallGraphNode * + CGGetValue(clang::CallGraph::const_iterator::value_type &P) { + return P.second.get(); + } // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator<clang::CallGraph::iterator, decltype(&CGGetValue)> @@ -223,9 +226,11 @@ template <> struct GraphTraits<const clang::CallGraph*> : static NodeType *getEntryNode(const clang::CallGraph *CGN) { return CGN->getRoot(); } - typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy; - static clang::CallGraphNode *CGGetValue(PairTy P) { return P.second; } + static clang::CallGraphNode * + CGGetValue(clang::CallGraph::const_iterator::value_type &P) { + return P.second.get(); + } // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator<clang::CallGraph::const_iterator, diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index 9d522fe7c6c5134ce9eee65c2d13d5efc035f560..0cb5a3fe14ebc150e65561ba9975731299d73c6d 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -104,9 +104,7 @@ CallGraph::CallGraph() { Root = getOrInsertNode(nullptr); } -CallGraph::~CallGraph() { - llvm::DeleteContainerSeconds(FunctionMap); -} +CallGraph::~CallGraph() {} bool CallGraph::includeInGraph(const Decl *D) { assert(D); @@ -142,22 +140,22 @@ void CallGraph::addNodeForDecl(Decl* D, bool IsGlobal) { CallGraphNode *CallGraph::getNode(const Decl *F) const { FunctionMapTy::const_iterator I = FunctionMap.find(F); if (I == FunctionMap.end()) return nullptr; - return I->second; + return I->second.get(); } CallGraphNode *CallGraph::getOrInsertNode(Decl *F) { if (F && !isa<ObjCMethodDecl>(F)) F = F->getCanonicalDecl(); - CallGraphNode *&Node = FunctionMap[F]; + std::unique_ptr<CallGraphNode> &Node = FunctionMap[F]; if (Node) - return Node; + return Node.get(); - Node = new CallGraphNode(F); + Node = llvm::make_unique<CallGraphNode>(F); // Make Root node a parent of all functions to make sure all are reachable. if (F) - Root->addCallee(Node, this); - return Node; + Root->addCallee(Node.get(), this); + return Node.get(); } void CallGraph::print(raw_ostream &OS) const {