summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorJoseph Tremoulet <jotrem@microsoft.com>2019-04-02 15:47:11 +0000
committerJoseph Tremoulet <jotrem@microsoft.com>2019-04-02 15:47:11 +0000
commitb69afa8e9ba51c2e136a9abc3222b8ec40cd128a (patch)
tree90a3f539e43c28822ba0a7fc0c363e6f6472c2be /llvm
parent838bba9c34bf1e5500c2e100327bc764afc8d367 (diff)
downloadbcm5719-llvm-b69afa8e9ba51c2e136a9abc3222b8ec40cd128a.tar.gz
bcm5719-llvm-b69afa8e9ba51c2e136a9abc3222b8ec40cd128a.zip
[PruneEH] Don't split musttail call from ret
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 llvm-svn: 357483
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/IPO/PruneEH.cpp3
-rw-r--r--llvm/test/Transforms/PruneEH/musttail.ll15
2 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/PruneEH.cpp b/llvm/lib/Transforms/IPO/PruneEH.cpp
index 46d42764fd2..ef7b43e8b55 100644
--- a/llvm/lib/Transforms/IPO/PruneEH.cpp
+++ b/llvm/lib/Transforms/IPO/PruneEH.cpp
@@ -203,7 +203,8 @@ static bool SimplifyFunction(Function *F, CallGraph &CG) {
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
diff --git a/llvm/test/Transforms/PruneEH/musttail.ll b/llvm/test/Transforms/PruneEH/musttail.ll
new file mode 100644
index 00000000000..1ad607713c6
--- /dev/null
+++ b/llvm/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 }
OpenPOWER on IntegriCloud