llvm.org GIT mirror llvm / 51e62f0
fix PR9015, a crash linking recursive metadata. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124099 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
3 changed file(s) with 22 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
3737 if (!MD->isFunctionLocal() && (Flags & RF_NoModuleLevelChanges))
3838 return VM[V] = const_cast(V);
3939
40 // Create a dummy node in case we have a metadata cycle.
41 MDNode *Dummy = MDNode::getTemporary(V->getContext(), 0, 0);
42 VM[V] = Dummy;
43
4044 // Check all operands to see if any need to be remapped.
4145 for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i) {
4246 Value *OP = MD->getOperand(i);
4347 if (OP == 0 || MapValue(OP, VM, Flags) == OP) continue;
4448
45 // Ok, at least one operand needs remapping. Create a dummy node in case
46 // we have a metadata cycle.
47 MDNode *Dummy = MDNode::getTemporary(V->getContext(), 0, 0);
48 VM[V] = Dummy;
49 // Ok, at least one operand needs remapping.
4950 SmallVector Elts;
5051 Elts.reserve(MD->getNumOperands());
5152 for (i = 0; i != e; ++i) {
5455 }
5556 MDNode *NewMD = MDNode::get(V->getContext(), Elts.data(), Elts.size());
5657 Dummy->replaceAllUsesWith(NewMD);
58 VM[V] = NewMD;
5759 MDNode::deleteTemporary(Dummy);
58 return VM[V] = NewMD;
60 return NewMD;
5961 }
6062
63 VM[V] = const_cast(V);
64 MDNode::deleteTemporary(Dummy);
65
6166 // No operands needed remapping. Use an identity mapping.
62 return VM[V] = const_cast(V);
67 return const_cast(V);
6368 }
6469
6570 // Okay, this either must be a constant (which may or may not be mappable) or
99 %x = call i8 @llvm.something(metadata !21)
1010 ret void
1111 }
12
99 %x = call i8 @llvm.something(metadata !22)
1010 ret void
1111 }
12
13
14
15 ; PR9015
16 define void @test() {
17 ret void, !abc !0
18 }
19
20 !0 = metadata !{metadata !0, i32 42 }
21