Skip to content

Commit 1d07098

Browse files
authored
[WinEH] Take musttail calls into account when unlinking eh records (#119702)
Exception handling records are unlinked on function return. However, if there is a musttail call before the return, that's the de-facto point of termination and the unlinking instructions must be inserted *before* that. Fixes #119255
1 parent d26df32 commit 1d07098

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

llvm/lib/Target/X86/X86WinEHState.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
363363
Instruction *T = BB.getTerminator();
364364
if (!isa<ReturnInst>(T))
365365
continue;
366+
367+
// If there is a musttail call, that's the de-facto terminator.
368+
if (CallInst *CI = BB.getTerminatingMustTailCall())
369+
T = CI;
370+
366371
Builder.SetInsertPoint(T);
367372
unlinkExceptionRegistration(Builder);
368373
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
target triple = "i386-pc-windows-msvc"
4+
5+
; Check that codegen doesn't fail due to wineh inserting instructions between
6+
; the musttail call and return instruction.
7+
8+
9+
define void @test() personality ptr @__CxxFrameHandler3 {
10+
; CHECK-LABEL: test:
11+
12+
entry:
13+
invoke void @foo() to label %try.cont unwind label %catch.dispatch
14+
15+
catch.dispatch:
16+
%0 = catchswitch within none [label %catch] unwind to caller
17+
18+
catch:
19+
%1 = catchpad within %0 [ptr null, i32 64, ptr null]
20+
catchret from %1 to label %try.cont
21+
22+
try.cont:
23+
; CHECK: movl %{{[a-z0-9]+}}, %fs:0
24+
; CHECK: jmp _bar
25+
26+
musttail call void @bar()
27+
ret void
28+
}
29+
30+
declare i32 @__CxxFrameHandler3(...)
31+
declare void @foo()
32+
declare void @bar()

0 commit comments

Comments
 (0)