Summary:
When inserting an `unreachable` after a noreturn call, we must ensure
that it's not a musttail call to avoid breaking the IR invariants for
musttail calls.
Reviewers: fedor.sergeev, majnemer
Reviewed By: majnemer
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60079
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357483
91177308-0d34-0410-b5e6-
96231b3b80d8
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
if (CallInst *CI = dyn_cast<CallInst>(I++))
- if (CI->doesNotReturn() && !isa<UnreachableInst>(I)) {
+ if (CI->doesNotReturn() && !CI->isMustTailCall() &&
+ !isa<UnreachableInst>(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
--- /dev/null
+; 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 }