diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-28 20:16:12 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-28 20:16:12 +0000 |
commit | 450e29cb4ccbfa022bb9fd4c5f57571f8b1200f5 (patch) | |
tree | 5922bf5ef849012d3db8e83240e73b873e20a89d | |
parent | d4d1a51895929a22ae13a27616e71b91c5ce9662 (diff) | |
download | bcm5719-llvm-450e29cb4ccbfa022bb9fd4c5f57571f8b1200f5.tar.gz bcm5719-llvm-450e29cb4ccbfa022bb9fd4c5f57571f8b1200f5.zip |
fix PR6112 - When globalopt (or any other pass) does RAUW(@G, %G),
metadata references in non-function-local MDNodes should drop to
null.
llvm-svn: 102519
-rw-r--r-- | llvm/lib/VMCore/Metadata.cpp | 17 | ||||
-rw-r--r-- | llvm/test/Transforms/GlobalOpt/metadata.ll | 19 |
2 files changed, 34 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp index 72de0321c3a..092fe00a536 100644 --- a/llvm/lib/VMCore/Metadata.cpp +++ b/llvm/lib/VMCore/Metadata.cpp @@ -178,6 +178,13 @@ void MDNode::destroy() { free(this); } +/// isFunctionLocalValue - Return true if this is a value that would require a +/// function-local MDNode. +static bool isFunctionLocalValue(Value *V) { + return isa<Instruction>(V) || isa<Argument>(V) || isa<BasicBlock>(V) || + (isa<MDNode>(V) && cast<MDNode>(V)->isFunctionLocal()); +} + MDNode *MDNode::getMDNode(LLVMContext &Context, Value *const *Vals, unsigned NumVals, FunctionLocalness FL, bool Insert) { @@ -188,8 +195,7 @@ MDNode *MDNode::getMDNode(LLVMContext &Context, Value *const *Vals, for (unsigned i = 0; i != NumVals; ++i) { Value *V = Vals[i]; if (!V) continue; - if (isa<Instruction>(V) || isa<Argument>(V) || isa<BasicBlock>(V) || - (isa<MDNode>(V) && cast<MDNode>(V)->isFunctionLocal())) { + if (isFunctionLocalValue(V)) { isFunctionLocal = true; break; } @@ -262,6 +268,13 @@ void MDNode::setIsNotUniqued() { void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) { Value *From = *Op; + // If is possible that someone did GV->RAUW(inst), replacing a global variable + // with an instruction or some other function-local object. If this is a + // non-function-local MDNode, it can't point to a function-local object. + // Handle this case by implicitly dropping the MDNode reference to null. + if (!isFunctionLocal() && To && isFunctionLocalValue(To)) + To = 0; + if (From == To) return; diff --git a/llvm/test/Transforms/GlobalOpt/metadata.ll b/llvm/test/Transforms/GlobalOpt/metadata.ll new file mode 100644 index 00000000000..55b2ff90ee8 --- /dev/null +++ b/llvm/test/Transforms/GlobalOpt/metadata.ll @@ -0,0 +1,19 @@ +; RUN: opt -S -globalopt metadata.ll | FileCheck %s + +; PR6112 - When globalopt does RAUW(@G, %G), the metadata reference should drop +; to null. +@G = internal global i8** null + +define i32 @main(i32 %argc, i8** %argv) { +; CHECK: @main +; CHECK: %G = alloca + store i8** %argv, i8*** @G + ret i32 0 +} + +!named = !{!0} + +; CHECK: !0 = metadata !{null} +!0 = metadata !{i8*** @G} + + |