summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Metadata.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-05-04 12:43:36 +0000
committerDuncan Sands <baldrick@free.fr>2010-05-04 12:43:36 +0000
commitc2928c6ef525210efa5ace625544043fcfd2e940 (patch)
tree7df7df4d132f22aa9f1af6cece2133484adc84ce /llvm/lib/VMCore/Metadata.cpp
parent80fecfff455db51f52b95a00e329ae19e1f2242a (diff)
downloadbcm5719-llvm-c2928c6ef525210efa5ace625544043fcfd2e940.tar.gz
bcm5719-llvm-c2928c6ef525210efa5ace625544043fcfd2e940.zip
Fix a variant of PR6112 found by thinking about it: when doing
RAUW of a global variable with a local variable in function F, if function local metadata M in function G was using the global then M would become function-local to both F and G, which is not allowed. See the testcase for an example. Fixed by detecting this situation and zapping the metadata operand when it occurs. llvm-svn: 103007
Diffstat (limited to 'llvm/lib/VMCore/Metadata.cpp')
-rw-r--r--llvm/lib/VMCore/Metadata.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp
index 092fe00a536..73376f5a6b7 100644
--- a/llvm/lib/VMCore/Metadata.cpp
+++ b/llvm/lib/VMCore/Metadata.cpp
@@ -115,14 +115,17 @@ MDNode::~MDNode() {
}
static const Function *getFunctionForValue(Value *V) {
- assert(!isa<MDNode>(V) && "does not iterate over metadata operands");
if (!V) return NULL;
- if (Instruction *I = dyn_cast<Instruction>(V))
- return I->getParent()->getParent();
- if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
- return BB->getParent();
+ if (Instruction *I = dyn_cast<Instruction>(V)) {
+ BasicBlock *BB = I->getParent();
+ return BB ? BB->getParent() : 0;
+ }
if (Argument *A = dyn_cast<Argument>(V))
return A->getParent();
+ if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
+ return BB->getParent();
+ if (MDNode *MD = dyn_cast<MDNode>(V))
+ return MD->getFunction();
return NULL;
}
@@ -272,8 +275,19 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
// 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;
+ // Likewise if the MDNode is function-local but for a different function.
+ if (To && isFunctionLocalValue(To)) {
+ if (!isFunctionLocal())
+ To = 0;
+ else {
+ const Function *F = getFunction();
+ const Function *FV = getFunctionForValue(To);
+ // Metadata can be function-local without having an associated function.
+ // So only consider functions to have changed if non-null.
+ if (F && FV && F != FV)
+ To = 0;
+ }
+ }
if (From == To)
return;
OpenPOWER on IntegriCloud