1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

Remap metadata attached to global variables.

Fix for PR32577.
Global variables may have !associated metadata, which includes a reference to another global. It needs remapping.

llvm-svn: 302203
This commit is contained in:
Evgeniy Stepanov 2017-05-04 23:29:39 +00:00
parent 41ba4538e4
commit c40d5a1d2a
2 changed files with 23 additions and 5 deletions

View File

@ -121,6 +121,8 @@ public:
void addFlags(RemapFlags Flags);
void remapGlobalObjectMetadata(GlobalObject &GO);
Value *mapValue(const Value *V);
void remapInstruction(Instruction *I);
void remapFunction(Function &F);
@ -802,6 +804,7 @@ void Mapper::flush() {
switch (E.Kind) {
case WorklistEntry::MapGlobalInit:
E.Data.GVInit.GV->setInitializer(mapConstant(E.Data.GVInit.Init));
remapGlobalObjectMetadata(*E.Data.GVInit.GV);
break;
case WorklistEntry::MapAppendingVar: {
unsigned PrefixSize = AppendingInits.size() - E.AppendingGVNumNewMembers;
@ -892,6 +895,14 @@ void Mapper::remapInstruction(Instruction *I) {
I->mutateType(TypeMapper->remapType(I->getType()));
}
void Mapper::remapGlobalObjectMetadata(GlobalObject &GO) {
SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
GO.getAllMetadata(MDs);
GO.clearMetadata();
for (const auto &I : MDs)
GO.addMetadata(I.first, *cast<MDNode>(mapMetadata(I.second)));
}
void Mapper::remapFunction(Function &F) {
// Remap the operands.
for (Use &Op : F.operands())
@ -899,11 +910,7 @@ void Mapper::remapFunction(Function &F) {
Op = mapValue(Op);
// Remap the metadata attachments.
SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
F.getAllMetadata(MDs);
F.clearMetadata();
for (const auto &I : MDs)
F.addMetadata(I.first, *cast<MDNode>(mapMetadata(I.second)));
remapGlobalObjectMetadata(F);
// Remap the argument types.
if (TypeMapper)

View File

@ -0,0 +1,11 @@
; RUN: llvm-link %s -S | FileCheck %s
; CHECK-DAG: @a = global i32 0
; CHECK-DAG: @b = global i32 0, !associated !0
; CHECK-DAG: !0 = !{i32* @b}
@a = global i32 0
@b = global i32 0, !associated !0
!0 = !{i32* @b}