From 48a097bfb6b2ab1ed67d2341a5b51c5d2b61af5b Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 22 Sep 2009 02:03:18 +0000 Subject: Switch DIDescriptor to use a TrackingVH. - This makes it much safer to work with debug info, since it was extraordinarily easy to have dangling pointers thanks to MDNode uniquing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82507 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/DebugInfo.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/Analysis/DebugInfo.cpp') diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index a072161896..531f609fd1 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -267,8 +267,17 @@ void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) { return; assert (!D.isNull() && "Can not replace with null"); - DbgNode->replaceAllUsesWith(D.getNode()); - delete DbgNode; + + // Since we use a TrackingVH for the node, its easy for clients to manufacture + // legitimate situations where they want to replaceAllUsesWith() on something + // which, due to uniquing, has merged with the source. We shield clients from + // this detail by allowing a value to be replaced with replaceAllUsesWith() + // itself. + if (getNode() != D.getNode()) { + MDNode *Node = DbgNode; + Node->replaceAllUsesWith(D.getNode()); + delete Node; + } } /// Verify - Verify that a compile unit is well formed. @@ -395,7 +404,7 @@ bool DISubprogram::describes(const Function *F) { /// dump - Print descriptor. void DIDescriptor::dump() const { errs() << "[" << dwarf::TagString(getTag()) << "] "; - errs().write_hex((intptr_t)DbgNode) << ']'; + errs().write_hex((intptr_t) &*DbgNode) << ']'; } /// dump - Print compile unit. -- cgit v1.2.3-18-g5258