[llvm-commits] [llvm] r124099 - in /llvm/trunk: lib/Transforms/Utils/ValueMapper.cpp test/Linker/linkmdnode.ll test/Linker/linkmdnode2.ll
Chris Lattner
sabre at nondot.org
Sun Jan 23 19:18:24 PST 2011
Author: lattner
Date: Sun Jan 23 21:18:24 2011
New Revision: 124099
URL: http://llvm.org/viewvc/llvm-project?rev=124099&view=rev
Log:
fix PR9015, a crash linking recursive metadata.
Modified:
llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
llvm/trunk/test/Linker/linkmdnode.ll
llvm/trunk/test/Linker/linkmdnode2.ll
Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=124099&r1=124098&r2=124099&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Sun Jan 23 21:18:24 2011
@@ -38,15 +38,16 @@
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 @@
}
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
Modified: llvm/trunk/test/Linker/linkmdnode.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/linkmdnode.ll?rev=124099&r1=124098&r2=124099&view=diff
==============================================================================
--- llvm/trunk/test/Linker/linkmdnode.ll (original)
+++ llvm/trunk/test/Linker/linkmdnode.ll Sun Jan 23 21:18:24 2011
@@ -10,3 +10,4 @@
%x = call i8 @llvm.something(metadata !21)
ret void
}
+
Modified: llvm/trunk/test/Linker/linkmdnode2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/linkmdnode2.ll?rev=124099&r1=124098&r2=124099&view=diff
==============================================================================
--- llvm/trunk/test/Linker/linkmdnode2.ll (original)
+++ llvm/trunk/test/Linker/linkmdnode2.ll Sun Jan 23 21:18:24 2011
@@ -10,3 +10,13 @@
%x = call i8 @llvm.something(metadata !22)
ret void
}
+
+
+
+; PR9015
+define void @test() {
+ ret void, !abc !0
+}
+
+!0 = metadata !{metadata !0, i32 42 }
+
More information about the llvm-commits
mailing list