Skip to content

Commit 09415a8

Browse files
committed
[CodeExtractor] Do not marked outlined calls which may resume EH as noreturn
Treat terminators which resume exception propagation as returning instructions (at least, for the purposes of marking outlined functions `noreturn`). This is to avoid inserting traps after calls to outlined functions which unwind. rdar://46129950 llvm-svn: 348404
1 parent c10590f commit 09415a8

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

llvm/lib/Transforms/Utils/CodeExtractor.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1369,9 +1369,12 @@ Function *CodeExtractor::extractCodeRegion() {
13691369
DVI->eraseFromParent();
13701370
}
13711371

1372-
// Mark the new function `noreturn` if applicable.
1372+
// Mark the new function `noreturn` if applicable. Terminators which resume
1373+
// exception propagation are treated as returning instructions. This is to
1374+
// avoid inserting traps after calls to outlined functions which unwind.
13731375
bool doesNotReturn = none_of(*newFunction, [](const BasicBlock &BB) {
1374-
return isa<ReturnInst>(BB.getTerminator());
1376+
const Instruction *Term = BB.getTerminator();
1377+
return isa<ReturnInst>(Term) || isa<ResumeInst>(Term);
13751378
});
13761379
if (doesNotReturn)
13771380
newFunction->setDoesNotReturn();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: opt -hotcoldsplit -S < %s | FileCheck %s
2+
3+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-apple-macosx10.14.0"
5+
6+
; Do not mark outlined functions which resume exception unwinding as noreturn.
7+
8+
; CHECK-LABEL: define {{.*}}@foo.cold.1(
9+
; CHECK: resume
10+
; CHECK-NOT: noreturn
11+
define i32 @foo(i32 %cond) personality i8 0 {
12+
entry:
13+
invoke void @llvm.donothing() to label %normal unwind label %exception
14+
15+
exception:
16+
%cleanup = landingpad i32 cleanup
17+
br i1 undef, label %normal, label %continue_exception
18+
19+
continue_exception:
20+
call void @sideeffect(i32 0)
21+
call void @sideeffect(i32 1)
22+
call void @sink()
23+
resume i32 undef
24+
25+
normal:
26+
br i1 undef, label %continue_exception, label %exit
27+
28+
exit:
29+
call void @sideeffect(i32 2)
30+
ret i32 0
31+
}
32+
33+
declare void @sideeffect(i32)
34+
35+
declare void @sink() cold
36+
37+
declare void @llvm.donothing() nounwind readnone

0 commit comments

Comments
 (0)