[llvm-commits] [llvm] r82507 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp
Daniel Dunbar
daniel at zuster.org
Mon Sep 21 19:03:19 PDT 2009
Author: ddunbar
Date: Mon Sep 21 21:03:18 2009
New Revision: 82507
URL: http://llvm.org/viewvc/llvm-project?rev=82507&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Analysis/DebugInfo.h
llvm/trunk/lib/Analysis/DebugInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=82507&r1=82506&r2=82507&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Mon Sep 21 21:03:18 2009
@@ -24,6 +24,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Dwarf.h"
+#include "llvm/Support/ValueHandle.h"
namespace llvm {
class BasicBlock;
@@ -45,7 +46,7 @@
class DIDescriptor {
protected:
- MDNode *DbgNode;
+ TrackingVH<MDNode> DbgNode;
/// DIDescriptor constructor. If the specified node is non-null, check
/// to make sure that the tag in the descriptor matches 'RequiredTag'. If
Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=82507&r1=82506&r2=82507&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Mon Sep 21 21:03:18 2009
@@ -267,8 +267,17 @@
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 @@
/// 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.
More information about the llvm-commits
mailing list