mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-23 20:15:35 +00:00
Use TrackingVH instead of WeakVH for NamedMDNode's operands, since nodes
referenced by NamedMDNodes shouldn't be deleted. llvm-svn: 109021
This commit is contained in:
parent
328a6ebeae
commit
b0db34a612
@ -185,7 +185,7 @@ class NamedMDNode : public Value, public ilist_node<NamedMDNode> {
|
||||
|
||||
std::string Name;
|
||||
Module *Parent;
|
||||
void *Operands; // SmallVector<WeakVH<MDNode>, 4>
|
||||
void *Operands; // SmallVector<TrackingVH<MDNode>, 4>
|
||||
|
||||
void setParent(Module *M) { Parent = M; }
|
||||
protected:
|
||||
|
@ -346,8 +346,8 @@ void ilist_traits<NamedMDNode>::removeNodeFromList(NamedMDNode *N) {
|
||||
ST.remove(N->getName());
|
||||
}
|
||||
|
||||
static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) {
|
||||
return *(SmallVector<WeakVH, 4>*)Operands;
|
||||
static SmallVector<TrackingVH<MDNode>, 4> &getNMDOps(void *Operands) {
|
||||
return *(SmallVector<TrackingVH<MDNode>, 4>*)Operands;
|
||||
}
|
||||
|
||||
NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
|
||||
@ -355,11 +355,11 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
|
||||
unsigned NumMDs, Module *ParentModule)
|
||||
: Value(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
|
||||
setName(N);
|
||||
Operands = new SmallVector<WeakVH, 4>();
|
||||
Operands = new SmallVector<TrackingVH<MDNode>, 4>();
|
||||
|
||||
SmallVector<WeakVH, 4> &Node = getNMDOps(Operands);
|
||||
SmallVector<TrackingVH<MDNode>, 4> &Node = getNMDOps(Operands);
|
||||
for (unsigned i = 0; i != NumMDs; ++i)
|
||||
Node.push_back(WeakVH(MDs[i]));
|
||||
Node.push_back(TrackingVH<MDNode>(MDs[i]));
|
||||
|
||||
if (ParentModule)
|
||||
ParentModule->getNamedMDList().push_back(this);
|
||||
@ -389,12 +389,12 @@ unsigned NamedMDNode::getNumOperands() const {
|
||||
/// getOperand - Return specified operand.
|
||||
MDNode *NamedMDNode::getOperand(unsigned i) const {
|
||||
assert(i < getNumOperands() && "Invalid Operand number!");
|
||||
return dyn_cast_or_null<MDNode>(getNMDOps(Operands)[i]);
|
||||
return dyn_cast_or_null<MDNode>(&*getNMDOps(Operands)[i]);
|
||||
}
|
||||
|
||||
/// addOperand - Add metadata Operand.
|
||||
void NamedMDNode::addOperand(MDNode *M) {
|
||||
getNMDOps(Operands).push_back(WeakVH(M));
|
||||
getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
|
||||
}
|
||||
|
||||
/// eraseFromParent - Drop all references and remove the node from parent
|
||||
|
Loading…
Reference in New Issue
Block a user