summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/ValueMapper.cpp
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-05-28 17:26:03 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-05-28 17:26:03 +0000
commitbcc47419d9a88e6b58a9e2a7c0ee4c7bf43e91b4 (patch)
tree9882cd837b184dd2c913b6080591860958f7dd5d /llvm/lib/Transforms/Utils/ValueMapper.cpp
parent9c3eb5960ad8c225cf577c38423f435f6a7184e3 (diff)
downloadbcm5719-llvm-bcc47419d9a88e6b58a9e2a7c0ee4c7bf43e91b4.tar.gz
bcm5719-llvm-bcc47419d9a88e6b58a9e2a7c0ee4c7bf43e91b4.zip
ValueMapper: fix assertion when null-mapping a constant for linking metadata
Summary: When RF_NullMapMissingGlobalValues is set, mapValue can return null for GlobalValue. When mapping the operands of a constant that is referenced from metadata, we need to handle this case and actually return null instead of mapping this constant. Reviewers: dexonsmith, rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D20713 llvm-svn: 271129
Diffstat (limited to 'llvm/lib/Transforms/Utils/ValueMapper.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 5a48a204973..d82f513419f 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -429,13 +429,23 @@ Value *Mapper::mapValue(const Value *V) {
if (BlockAddress *BA = dyn_cast<BlockAddress>(C))
return mapBlockAddress(*BA);
+ auto mapValueOrNull = [this](Value *V) {
+ auto Mapped = mapValue(V);
+ assert((Mapped || (Flags & RF_NullMapMissingGlobalValues)) &&
+ "Unexpected null mapping for constant operand without "
+ "NullMapMissingGlobalValues flag");
+ return Mapped;
+ };
+
// Otherwise, we have some other constant to remap. Start by checking to see
// if all operands have an identity remapping.
unsigned OpNo = 0, NumOperands = C->getNumOperands();
Value *Mapped = nullptr;
for (; OpNo != NumOperands; ++OpNo) {
Value *Op = C->getOperand(OpNo);
- Mapped = mapValue(Op);
+ Mapped = mapValueOrNull(Op);
+ if (!Mapped)
+ return nullptr;
if (Mapped != Op)
break;
}
@@ -462,8 +472,12 @@ Value *Mapper::mapValue(const Value *V) {
Ops.push_back(cast<Constant>(Mapped));
// Map the rest of the operands that aren't processed yet.
- for (++OpNo; OpNo != NumOperands; ++OpNo)
- Ops.push_back(cast<Constant>(mapValue(C->getOperand(OpNo))));
+ for (++OpNo; OpNo != NumOperands; ++OpNo) {
+ Mapped = mapValueOrNull(C->getOperand(OpNo));
+ if (!Mapped)
+ return nullptr;
+ Ops.push_back(cast<Constant>(Mapped));
+ }
}
Type *NewSrcTy = nullptr;
if (TypeMapper)
OpenPOWER on IntegriCloud