[PATCH] D113812: [Cloning] Clone metadata on function declarations
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 1 15:40:51 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG512534bc16d2: [Cloning] Clone metadata on function declarations (authored by aeubanks).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113812/new/
https://reviews.llvm.org/D113812
Files:
llvm/lib/Transforms/Utils/CloneModule.cpp
llvm/unittests/Transforms/Utils/CloningTest.cpp
Index: llvm/unittests/Transforms/Utils/CloningTest.cpp
===================================================================
--- llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -921,6 +921,10 @@
IBuilder.SetInsertPoint(Entry);
IBuilder.CreateRetVoid();
+ auto *G =
+ Function::Create(FuncType, GlobalValue::ExternalLinkage, "g", OldM);
+ G->addMetadata(LLVMContext::MD_type, *MDNode::get(C, {}));
+
// Finalize the debug info
DBuilder.finalize();
}
@@ -934,10 +938,10 @@
TEST_F(CloneModule, Verify) {
// Confirm the old module is (still) valid.
- EXPECT_FALSE(verifyModule(*OldM));
+ EXPECT_FALSE(verifyModule(*OldM, &errs()));
// Check the new module.
- EXPECT_FALSE(verifyModule(*NewM));
+ EXPECT_FALSE(verifyModule(*NewM, &errs()));
}
TEST_F(CloneModule, OldModuleUnchanged) {
@@ -955,6 +959,11 @@
EXPECT_EQ(SP->getLine(), (unsigned)4);
}
+TEST_F(CloneModule, FunctionDeclarationMetadata) {
+ Function *NewF = NewM->getFunction("g");
+ EXPECT_NE(nullptr, NewF->getMetadata(LLVMContext::MD_type));
+}
+
TEST_F(CloneModule, GlobalMetadata) {
GlobalVariable *NewGV = NewM->getGlobalVariable("gv");
EXPECT_NE(nullptr, NewGV->getMetadata(LLVMContext::MD_type));
Index: llvm/lib/Transforms/Utils/CloneModule.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CloneModule.cpp
+++ llvm/lib/Transforms/Utils/CloneModule.cpp
@@ -135,10 +135,18 @@
// Similarly, copy over function bodies now...
//
for (const Function &I : M) {
- if (I.isDeclaration())
+ Function *F = cast<Function>(VMap[&I]);
+
+ if (I.isDeclaration()) {
+ // Copy over metadata for declarations since we're not doing it below in
+ // CloneFunctionInto().
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
+ I.getAllMetadata(MDs);
+ for (auto MD : MDs)
+ F->addMetadata(MD.first, *MapMetadata(MD.second, VMap));
continue;
+ }
- Function *F = cast<Function>(VMap[&I]);
if (!ShouldCloneDefinition(&I)) {
// Skip after setting the correct linkage for an external reference.
F->setLinkage(GlobalValue::ExternalLinkage);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113812.391153.patch
Type: text/x-patch
Size: 2240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211201/18dbf1f3/attachment.bin>
More information about the llvm-commits
mailing list