Skip to content

Commit 701e1d4

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd7732fe7ae41' from apple/stable/20210107 into swift/release/5.5
2 parents 4b324b4 + d7732fe commit 701e1d4

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

llvm/lib/CodeGen/SjLjEHPrepare.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,12 @@ bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
472472

473473
// Finally, for any returns from this function, if this function contains an
474474
// invoke, add a call to unregister the function context.
475-
for (ReturnInst *Return : Returns)
476-
CallInst::Create(UnregisterFn, FuncCtx, "", Return);
475+
for (ReturnInst *Return : Returns) {
476+
Instruction *InsertPoint = Return;
477+
if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
478+
InsertPoint = CI;
479+
CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint);
480+
}
477481

478482
return true;
479483
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39439.
2+
; RUN: llc -mtriple i386-windows-gnu -exception-model sjlj -filetype asm -o - %s -verify-machineinstrs=0 | FileCheck %s
3+
4+
declare void @_Z20function_that_throwsv()
5+
declare i32 @__gxx_personality_sj0(...)
6+
declare i8* @__cxa_begin_catch(i8*)
7+
declare void @__cxa_end_catch()
8+
declare void @_callee();
9+
10+
define void @_Z8functionv() personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*) {
11+
entry:
12+
invoke void @_Z20function_that_throwsv()
13+
to label %try.cont unwind label %lpad
14+
15+
lpad:
16+
%0 = landingpad { i8*, i32 }
17+
catch i8* null
18+
%1 = extractvalue { i8*, i32 } %0, 0
19+
%2 = tail call i8* @__cxa_begin_catch(i8* %1)
20+
tail call void @__cxa_end_catch()
21+
br label %try.cont
22+
23+
try.cont:
24+
musttail call void @_callee();
25+
ret void
26+
}
27+
28+
; CHECK-LABEL: __Z8functionv:
29+
; CHECK: calll __Unwind_SjLj_Unregister
30+
; CHECK-NOT: {{.*}}:
31+
; CHECK: jmp __callee

0 commit comments

Comments
 (0)