diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-09-22 02:03:18 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-09-22 02:03:18 +0000 |
| commit | 0356483539b10c8add2b45921372248f4d186fb1 (patch) | |
| tree | e1ae33a9966837edceece2e4e546c478587ea624 /llvm/lib | |
| parent | 70d4fb0d97287117fe7a09fbb5e352ffe1f6eebc (diff) | |
| download | bcm5719-llvm-0356483539b10c8add2b45921372248f4d186fb1.tar.gz bcm5719-llvm-0356483539b10c8add2b45921372248f4d186fb1.zip | |
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.
llvm-svn: 82507
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/DebugInfo.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/DebugInfo.cpp b/llvm/lib/Analysis/DebugInfo.cpp index a0721618964..531f609fd18 100644 --- a/llvm/lib/Analysis/DebugInfo.cpp +++ b/llvm/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. |

