1; RUN: llc -mtriple=i686-pc-windows -no-x86-call-frame-opt < %s | FileCheck %s
2
3target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
4
5declare x86_thiscallcc void @thiscall_thunk(i8* %this, ...)
6define i32 @call_varargs_thiscall_thunk(i8* %a, i32 %b, i32 %c, i32 %d) {
7  call x86_thiscallcc void (i8*, ...) @thiscall_thunk(i8* %a, i32 1, i32 2)
8  call x86_thiscallcc void (i8*, ...) @thiscall_thunk(i8* %a, i32 1, i32 2)
9  %t1 = add i32 %b, %c
10  %r = add i32 %t1, %d
11  ret i32 %r
12}
13
14; CHECK: _call_varargs_thiscall_thunk:
15; CHECK: calll _thiscall_thunk
16; CHECK-NEXT: subl $8, %esp
17
18; We don't mangle the argument size into variadic callee cleanup functions.
19
20declare x86_stdcallcc void @stdcall_thunk(i8* %this, ...)
21define i32 @call_varargs_stdcall_thunk(i8* %a, i32 %b, i32 %c, i32 %d) {
22  call x86_stdcallcc void (i8*, ...) @stdcall_thunk(i8* %a, i32 1, i32 2)
23  call x86_stdcallcc void (i8*, ...) @stdcall_thunk(i8* %a, i32 1, i32 2)
24  %t1 = add i32 %b, %c
25  %r = add i32 %t1, %d
26  ret i32 %r
27}
28
29; CHECK: _call_varargs_stdcall_thunk:
30; CHECK: calll _stdcall_thunk{{$}}
31; CHECK-NEXT: subl $12, %esp
32
33declare x86_fastcallcc void @fastcall_thunk(i8* %this, ...)
34define i32 @call_varargs_fastcall_thunk(i8* %a, i32 %b, i32 %c, i32 %d) {
35  call x86_fastcallcc void (i8*, ...) @fastcall_thunk(i8* inreg %a, i32 inreg 1, i32 2)
36  call x86_fastcallcc void (i8*, ...) @fastcall_thunk(i8* inreg %a, i32 inreg 1, i32 2)
37  %t1 = add i32 %b, %c
38  %r = add i32 %t1, %d
39  ret i32 %r
40}
41
42; CHECK: _call_varargs_fastcall_thunk:
43; CHECK: calll @fastcall_thunk{{$}}
44; CHECK-NEXT: subl $4, %esp
45
46; If you actually return from such a thunk, it will only pop the non-variadic
47; portion of the arguments, which is different from what the callee passes.
48
49define x86_stdcallcc void @varargs_stdcall_return(i32, i32, ...) {
50  ret void
51}
52
53; CHECK: _varargs_stdcall_return:
54; CHECK: retl $8
55