From: David Majnemer Date: Tue, 30 Jun 2015 22:14:01 +0000 (+0000) Subject: [Cloning] Teach CloneModule about personality functions X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5ca5b0d9f4a5c2900e3fe276f349f65a9bc8e38b;p=oota-llvm.git [Cloning] Teach CloneModule about personality functions CloneModule didn't take into account that it needed to remap the value using values in the module. This fixes PR23992. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241122 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index 269332206da..61f1811e7b4 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -99,7 +99,11 @@ Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) { SmallVector Returns; // Ignore returns cloned. CloneFunctionInto(F, I, VMap, /*ModuleLevelChanges=*/true, Returns); + } + + if (I->hasPersonalityFn()) + F->setPersonalityFn(MapValue(I->getPersonalityFn(), VMap)); } // And aliases diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index 18d3ca62675..e2671499e81 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -415,4 +415,39 @@ TEST_F(CloneFunc, DebugIntrinsics) { } } +class CloneModule : public ::testing::Test { +protected: + void SetUp() override { + SetupModule(); + CreateOldModule(); + CreateNewModule(); + } + + void SetupModule() { OldM = new Module("", C); } + + void CreateOldModule() { + IRBuilder<> IBuilder(C); + + auto *FuncType = FunctionType::get(Type::getVoidTy(C), false); + auto *PersFn = Function::Create(FuncType, GlobalValue::ExternalLinkage, + "persfn", OldM); + auto *F = + Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM); + F->setPersonalityFn(PersFn); + auto *Entry = BasicBlock::Create(C, "", F); + IBuilder.SetInsertPoint(Entry); + IBuilder.CreateRetVoid(); + } + + void CreateNewModule() { NewM = llvm::CloneModule(OldM); } + + LLVMContext C; + Module *OldM; + Module *NewM; +}; + +TEST_F(CloneModule, Verify) { + EXPECT_FALSE(verifyModule(*NewM)); +} + }