Index: llvm/trunk/lib/Transforms/IPO/PruneEH.cpp =================================================================== --- llvm/trunk/lib/Transforms/IPO/PruneEH.cpp +++ llvm/trunk/lib/Transforms/IPO/PruneEH.cpp @@ -203,7 +203,8 @@ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) if (CallInst *CI = dyn_cast(I++)) - if (CI->doesNotReturn() && !isa(I)) { + if (CI->doesNotReturn() && !CI->isMustTailCall() && + !isa(I)) { // This call calls a function that cannot return. Insert an // unreachable instruction after it and simplify the code. Do this // by splitting the BB, adding the unreachable, then deleting the Index: llvm/trunk/test/Transforms/PruneEH/musttail.ll =================================================================== --- llvm/trunk/test/Transforms/PruneEH/musttail.ll +++ llvm/trunk/test/Transforms/PruneEH/musttail.ll @@ -0,0 +1,15 @@ +; RUN: opt -prune-eh -S < %s | FileCheck %s + +declare void @noreturn() + +define void @testfn() { + ; A musttail call must be followed by (optional bitcast then) ret, + ; so make sure we don't insert an unreachable + ; CHECK: musttail call void @noreturn + ; CHECK-NOT: unreachable + ; CHECK-NEXT: ret void + musttail call void @noreturn() #0 + ret void +} + +attributes #0 = { noreturn }