Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 783f7f9

Browse files
committed
Don't sibcall between SysV and Win64 convention functions
The shadow stack space expectations won't match. Fixes PR22709. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230667 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5300f55 commit 783f7f9

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,6 +3381,12 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
33813381
bool IsCalleeWin64 = Subtarget->isCallingConvWin64(CalleeCC);
33823382
bool IsCallerWin64 = Subtarget->isCallingConvWin64(CallerCC);
33833383

3384+
// Win64 functions have extra shadow space for argument homing. Don't do the
3385+
// sibcall if the caller and callee have mismatched expectations for this
3386+
// space.
3387+
if (IsCalleeWin64 != IsCallerWin64)
3388+
return false;
3389+
33843390
if (DAG.getTarget().Options.GuaranteedTailCallOpt) {
33853391
if (IsTailCallConvention(CalleeCC) && CCMatch)
33863392
return true;

test/CodeGen/X86/sibcall-win64.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s
2+
3+
declare x86_64_win64cc void @win64_callee(i32)
4+
declare void @sysv_callee(i32)
5+
6+
define void @sysv_caller(i32 %p1) {
7+
entry:
8+
tail call x86_64_win64cc void @win64_callee(i32 %p1)
9+
ret void
10+
}
11+
12+
; CHECK-LABEL: sysv_caller:
13+
; CHECK: subq $40, %rsp
14+
; CHECK: callq win64_callee
15+
; CHECK: addq $40, %rsp
16+
; CHECK: retq
17+
18+
define x86_64_win64cc void @win64_caller(i32 %p1) {
19+
entry:
20+
tail call void @sysv_callee(i32 %p1)
21+
ret void
22+
}
23+
24+
; CHECK-LABEL: win64_caller:
25+
; CHECK: callq sysv_callee
26+
; CHECK: retq
27+
28+
define void @sysv_matched(i32 %p1) {
29+
tail call void @sysv_callee(i32 %p1)
30+
ret void
31+
}
32+
33+
; CHECK-LABEL: sysv_matched:
34+
; CHECK: jmp sysv_callee # TAILCALL
35+
36+
define x86_64_win64cc void @win64_matched(i32 %p1) {
37+
tail call x86_64_win64cc void @win64_callee(i32 %p1)
38+
ret void
39+
}
40+
41+
; CHECK-LABEL: win64_matched:
42+
; CHECK: jmp win64_callee # TAILCALL

0 commit comments

Comments
 (0)