[PATCH] D39339: [CallGraph] Refine call graph for indirect calls with !callees metadata

Justin Bogner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 14:23:11 PDT 2019


bogner accepted this revision.
bogner added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/lib/Analysis/CallGraph.cpp:182-189
+  CGN = llvm::make_unique<CallGraphNode>(nullptr);
+  for (const MDOperand &Op : Callees->operands())
+    if (auto *MDConstant = mdconst::extract_or_null<Constant>(Op)) {
+      auto *F = cast<Function>(MDConstant);
+
+      assert(!F->isIntrinsic());
+      CGN->addCalledFunction(nullptr, getOrInsertFunction(F));
----------------
rudkx wrote:
> bogner wrote:
> > rudkx wrote:
> > > bogner wrote:
> > > > Maybe I'm misreading this, but isn't `CGN == nullptr` here, given the assignment just above?
> > > `GCN` should be a non-null `CallGraphNode` holding a `Function *` that has a `nullptr` value.
> > Ah right. In that case, doesn't the node get destroyed when the `unique_ptr` goes out of scope here? You may have meant to use `.release()`, but in that case who owns this object?
> `GCN` is a reference to the `unique_ptr<T>` in the map, and `unique_ptr` has a move assignment operator, so it transfers ownership to the map node right after it is allocated.
Ah, I see. The use of `auto &` is subtle and I didn't notice that we were actually assigning a reference here. Nevermind.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D39339/new/

https://reviews.llvm.org/D39339





More information about the llvm-commits mailing list