Index: lib/Transforms/Utils/CloneModule.cpp =================================================================== --- lib/Transforms/Utils/CloneModule.cpp +++ lib/Transforms/Utils/CloneModule.cpp @@ -124,8 +124,11 @@ for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { Function *F = cast(VMap[&*I]); if (!ShouldCloneDefinition(&*I)) { - // Skip after setting the correct linkage for an external reference. + // Skip after setting the correct linkage for an external reference, F->setLinkage(GlobalValue::ExternalLinkage); + // ... and mapping the personality function. + if (I->hasPersonalityFn()) + F->setPersonalityFn(MapValue(I->getPersonalityFn(), VMap)); continue; } if (!I->isDeclaration()) { Index: test/tools/llvm-split/personality.ll =================================================================== --- /dev/null +++ test/tools/llvm-split/personality.ll @@ -0,0 +1,17 @@ +; Test that "personality" attributes are correctly updated when cloning modules. +; RUN: llvm-split -o %t %s +; RUN: llvm-dis -o - %t0 | FileCheck --check-prefix=CHECK0 %s +; RUN: llvm-dis -o - %t1 | FileCheck --check-prefix=CHECK1 %s + +; CHECK0: define void @foo() +; CHECK1: declare void @foo() +define void @foo() { + ret void +} + +; CHECK0: declare void @bar() personality i8* bitcast (void ()* @foo to i8*) +; CHECK1: define void @bar() personality i8* bitcast (void ()* @foo to i8*) +define void @bar() personality i8* bitcast (void ()* @foo to i8*) +{ + ret void +}