#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Dwarf.h"
+#include "llvm/Support/ValueHandle.h"
namespace llvm {
class BasicBlock;
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
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.
/// 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.