1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

Cloning: Also clone global variable attached metadata.

llvm-svn: 285161
This commit is contained in:
Peter Collingbourne 2016-10-26 02:57:33 +00:00
parent 870852fa93
commit f4cf97ceb0
2 changed files with 15 additions and 0 deletions

View File

@ -119,6 +119,11 @@ std::unique_ptr<Module> llvm::CloneModule(
}
if (I->hasInitializer())
GV->setInitializer(MapValue(I->getInitializer(), VMap));
SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
I->getAllMetadata(MDs);
for (auto MD : MDs)
GV->addMetadata(MD.first, *MapMetadata(MD.second, VMap));
}
// Similarly, copy over function bodies now...

View File

@ -403,6 +403,11 @@ protected:
void SetupModule() { OldM = new Module("", C); }
void CreateOldModule() {
auto GV = new GlobalVariable(
*OldM, Type::getInt32Ty(C), false, GlobalValue::ExternalLinkage,
ConstantInt::get(Type::getInt32Ty(C), 1), "gv");
GV->addMetadata(LLVMContext::MD_type, *MDNode::get(C, {}));
DIBuilder DBuilder(*OldM);
IRBuilder<> IBuilder(C);
@ -459,4 +464,9 @@ TEST_F(CloneModule, Subprogram) {
EXPECT_EQ(SP->getFile()->getFilename(), "filename.c");
EXPECT_EQ(SP->getLine(), (unsigned)4);
}
TEST_F(CloneModule, GlobalMetadata) {
GlobalVariable *NewGV = NewM->getGlobalVariable("gv");
EXPECT_NE(nullptr, NewGV->getMetadata(LLVMContext::MD_type));
}
}