[PATCH] D25427: [Analysis] Use unique_ptr for CallGraph::FunctionMap.
Justin Lebar via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 9 23:25:38 PDT 2016
jlebar created this revision.
jlebar added a reviewer: timshen.
jlebar added a subscriber: cfe-commits.
The decltype(declval) dance in the iterator traits is necessary because
DenseMap iterators aren't over std::pairs, but rather are over a
pair-like type defined in DenseMap. It used to work because we were
making a copy of the pair, but now that we're binding a reference to the
pair, we need to get the type exactly right.
https://reviews.llvm.org/D25427
Files:
clang/include/clang/Analysis/CallGraph.h
clang/lib/Analysis/CallGraph.cpp
Index: clang/lib/Analysis/CallGraph.cpp
===================================================================
--- clang/lib/Analysis/CallGraph.cpp
+++ clang/lib/Analysis/CallGraph.cpp
@@ -104,9 +104,7 @@
Root = getOrInsertNode(nullptr);
}
-CallGraph::~CallGraph() {
- llvm::DeleteContainerSeconds(FunctionMap);
-}
+CallGraph::~CallGraph() {}
bool CallGraph::includeInGraph(const Decl *D) {
assert(D);
@@ -142,22 +140,22 @@
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 {
Index: clang/include/clang/Analysis/CallGraph.h
===================================================================
--- clang/include/clang/Analysis/CallGraph.h
+++ clang/include/clang/Analysis/CallGraph.h
@@ -34,7 +34,8 @@
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 @@
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(decltype(*std::declval<clang::CallGraph::const_iterator>()) &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 @@
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(decltype(*std::declval<clang::CallGraph::const_iterator>()) &P) {
+ return P.second.get();
+ }
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef mapped_iterator<clang::CallGraph::const_iterator,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25427.74107.patch
Type: text/x-patch
Size: 2970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161010/2e8794b2/attachment-0001.bin>
More information about the cfe-commits
mailing list