llvm.org GIT mirror llvm / d10baa1
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271129 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 3 years ago
2 changed file(s) with 28 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
428428 if (BlockAddress *BA = dyn_cast(C))
429429 return mapBlockAddress(*BA);
430430
431 auto mapValueOrNull = [this](Value *V) {
432 auto Mapped = mapValue(V);
433 assert((Mapped || (Flags & RF_NullMapMissingGlobalValues)) &&
434 "Unexpected null mapping for constant operand without "
435 "NullMapMissingGlobalValues flag");
436 return Mapped;
437 };
438
431439 // Otherwise, we have some other constant to remap. Start by checking to see
432440 // if all operands have an identity remapping.
433441 unsigned OpNo = 0, NumOperands = C->getNumOperands();
434442 Value *Mapped = nullptr;
435443 for (; OpNo != NumOperands; ++OpNo) {
436444 Value *Op = C->getOperand(OpNo);
437 Mapped = mapValue(Op);
445 Mapped = mapValueOrNull(Op);
446 if (!Mapped)
447 return nullptr;
438448 if (Mapped != Op)
439449 break;
440450 }
461471 Ops.push_back(cast(Mapped));
462472
463473 // Map the rest of the operands that aren't processed yet.
464 for (++OpNo; OpNo != NumOperands; ++OpNo)
465 Ops.push_back(cast(mapValue(C->getOperand(OpNo))));
474 for (++OpNo; OpNo != NumOperands; ++OpNo) {
475 Mapped = mapValueOrNull(C->getOperand(OpNo));
476 if (!Mapped)
477 return nullptr;
478 Ops.push_back(cast(Mapped));
479 }
466480 }
467481 Type *NewSrcTy = nullptr;
468482 if (TypeMapper)
0 ; RUN: llvm-link %s -S -o - | FileCheck %s
1 ; Check that the constant is not linked and the metadata is correctly referencing a nullptr
2 ; CHECK: !0 = !{!"foo", null, i64 16}
3
4
5
6 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-apple-macosx10.12.0"
8 @foo = external unnamed_addr constant { [4 x i8*], [32 x i8] }, align 32
9 !llvm.bitsets = !{!0}
10 !0 = !{!"foo", [4 x i8*]* getelementptr inbounds ({ [4 x i8*], [32 x i8] }, { [4 x i8*], [32 x i8] }* @foo, i32 0, i32 0), i64 16}