fix PR9015, a crash linking recursive metadata.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124099 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2011-01-24 03:18:24 +00:00
parent 96c0771c01
commit 51e62f0f73
3 changed files with 22 additions and 6 deletions

View File

@ -38,15 +38,16 @@ Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM,
if (!MD->isFunctionLocal() && (Flags & RF_NoModuleLevelChanges))
return VM[V] = const_cast<Value*>(V);
// Create a dummy node in case we have a metadata cycle.
MDNode *Dummy = MDNode::getTemporary(V->getContext(), 0, 0);
VM[V] = Dummy;
// Check all operands to see if any need to be remapped.
for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i) {
Value *OP = MD->getOperand(i);
if (OP == 0 || MapValue(OP, VM, Flags) == OP) continue;
// Ok, at least one operand needs remapping. Create a dummy node in case
// we have a metadata cycle.
MDNode *Dummy = MDNode::getTemporary(V->getContext(), 0, 0);
VM[V] = Dummy;
// Ok, at least one operand needs remapping.
SmallVector<Value*, 4> Elts;
Elts.reserve(MD->getNumOperands());
for (i = 0; i != e; ++i) {
@ -55,12 +56,16 @@ Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM,
}
MDNode *NewMD = MDNode::get(V->getContext(), Elts.data(), Elts.size());
Dummy->replaceAllUsesWith(NewMD);
VM[V] = NewMD;
MDNode::deleteTemporary(Dummy);
return VM[V] = NewMD;
return NewMD;
}
VM[V] = const_cast<Value*>(V);
MDNode::deleteTemporary(Dummy);
// No operands needed remapping. Use an identity mapping.
return VM[V] = const_cast<Value*>(V);
return const_cast<Value*>(V);
}
// Okay, this either must be a constant (which may or may not be mappable) or

View File

@ -10,3 +10,4 @@ define void @foo() {
%x = call i8 @llvm.something(metadata !21)
ret void
}

View File

@ -10,3 +10,13 @@ define void @foo1() {
%x = call i8 @llvm.something(metadata !22)
ret void
}
; PR9015
define void @test() {
ret void, !abc !0
}
!0 = metadata !{metadata !0, i32 42 }