llvm.org GIT mirror llvm / 5ca5b0d
[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 David Majnemer 5 years ago
2 changed file(s) with 40 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
9898
9999 SmallVector Returns; // Ignore returns cloned.
100100 CloneFunctionInto(F, I, VMap, /*ModuleLevelChanges=*/true, Returns);
101
101102 }
103
104 if (I->hasPersonalityFn())
105 F->setPersonalityFn(MapValue(I->getPersonalityFn(), VMap));
102106 }
103107
104108 // And aliases
414414 }
415415 }
416416
417 }
417 class CloneModule : public ::testing::Test {
418 protected:
419 void SetUp() override {
420 SetupModule();
421 CreateOldModule();
422 CreateNewModule();
423 }
424
425 void SetupModule() { OldM = new Module("", C); }
426
427 void CreateOldModule() {
428 IRBuilder<> IBuilder(C);
429
430 auto *FuncType = FunctionType::get(Type::getVoidTy(C), false);
431 auto *PersFn = Function::Create(FuncType, GlobalValue::ExternalLinkage,
432 "persfn", OldM);
433 auto *F =
434 Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM);
435 F->setPersonalityFn(PersFn);
436 auto *Entry = BasicBlock::Create(C, "", F);
437 IBuilder.SetInsertPoint(Entry);
438 IBuilder.CreateRetVoid();
439 }
440
441 void CreateNewModule() { NewM = llvm::CloneModule(OldM); }
442
443 LLVMContext C;
444 Module *OldM;
445 Module *NewM;
446 };
447
448 TEST_F(CloneModule, Verify) {
449 EXPECT_FALSE(verifyModule(*NewM));
450 }
451
452 }