Stackmap shadows should consider call returns a branch target.
[oota-llvm.git] / test / CodeGen / X86 / musttail-indirect.ll
1 ; RUN: llc < %s -mtriple=i686-win32 | FileCheck %s
2 ; RUN: llc < %s -mtriple=i686-win32 -O0 | FileCheck %s
3
4 ; IR simplified from the following C++ snippet compiled for i686-windows-msvc:
5
6 ; struct A { A(); ~A(); int a; };
7 ;
8 ; struct B {
9 ;   virtual int  f(int);
10 ;   virtual int  g(A, int, A);
11 ;   virtual void h(A, int, A);
12 ;   virtual A    i(A, int, A);
13 ;   virtual A    j(int);
14 ; };
15 ;
16 ; int  (B::*mp_f)(int)       = &B::f;
17 ; int  (B::*mp_g)(A, int, A) = &B::g;
18 ; void (B::*mp_h)(A, int, A) = &B::h;
19 ; A    (B::*mp_i)(A, int, A) = &B::i;
20 ; A    (B::*mp_j)(int)       = &B::j;
21
22 ; Each member pointer creates a thunk.  The ones with inalloca are required to
23 ; tail calls by the ABI, even at O0.
24
25 %struct.B = type { i32 (...)** }
26 %struct.A = type { i32 }
27
28 ; CHECK-LABEL: f_thunk:
29 ; CHECK: jmpl
30 ; CHECK-NOT: ret
31 define x86_thiscallcc i32 @f_thunk(%struct.B* %this, i32) {
32 entry:
33   %1 = bitcast %struct.B* %this to i32 (%struct.B*, i32)***
34   %vtable = load i32 (%struct.B*, i32)*** %1
35   %2 = load i32 (%struct.B*, i32)** %vtable
36   %3 = musttail call x86_thiscallcc i32 %2(%struct.B* %this, i32 %0)
37   ret i32 %3
38 }
39
40 ; Inalloca thunks shouldn't require any stores to the stack.
41 ; CHECK-LABEL: g_thunk:
42 ; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}}
43 ; CHECK: jmpl
44 ; CHECK-NOT: ret
45 define x86_thiscallcc i32 @g_thunk(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca) {
46 entry:
47   %1 = bitcast %struct.B* %this to i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)***
48   %vtable = load i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** %1
49   %vfn = getelementptr inbounds i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vtable, i32 1
50   %2 = load i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vfn
51   %3 = musttail call x86_thiscallcc i32 %2(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca %0)
52   ret i32 %3
53 }
54
55 ; CHECK-LABEL: h_thunk:
56 ; CHECK: jmpl
57 ; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}}
58 ; CHECK-NOT: ret
59 define x86_thiscallcc void @h_thunk(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca) {
60 entry:
61   %1 = bitcast %struct.B* %this to void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)***
62   %vtable = load void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** %1
63   %vfn = getelementptr inbounds void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vtable, i32 2
64   %2 = load void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vfn
65   musttail call x86_thiscallcc void %2(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca %0)
66   ret void
67 }
68
69 ; CHECK-LABEL: i_thunk:
70 ; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}}
71 ; CHECK: jmpl
72 ; CHECK-NOT: ret
73 define x86_thiscallcc %struct.A* @i_thunk(%struct.B* %this, <{ %struct.A*, %struct.A, i32, %struct.A }>* inalloca) {
74 entry:
75   %1 = bitcast %struct.B* %this to %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)***
76   %vtable = load %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*** %1
77   %vfn = getelementptr inbounds %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)** %vtable, i32 3
78   %2 = load %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)** %vfn
79   %3 = musttail call x86_thiscallcc %struct.A* %2(%struct.B* %this, <{ %struct.A*, %struct.A, i32, %struct.A }>* inalloca %0)
80   ret %struct.A* %3
81 }
82
83 ; CHECK-LABEL: j_thunk:
84 ; CHECK: jmpl
85 ; CHECK-NOT: ret
86 define x86_thiscallcc void @j_thunk(%struct.A* noalias sret %agg.result, %struct.B* %this, i32) {
87 entry:
88   %1 = bitcast %struct.B* %this to void (%struct.A*, %struct.B*, i32)***
89   %vtable = load void (%struct.A*, %struct.B*, i32)*** %1
90   %vfn = getelementptr inbounds void (%struct.A*, %struct.B*, i32)** %vtable, i32 4
91   %2 = load void (%struct.A*, %struct.B*, i32)** %vfn
92   musttail call x86_thiscallcc void %2(%struct.A* sret %agg.result, %struct.B* %this, i32 %0)
93   ret void
94 }
95
96 ; CHECK-LABEL: _stdcall_thunk@8:
97 ; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}}
98 ; CHECK: jmpl
99 ; CHECK-NOT: ret
100 define x86_stdcallcc i32 @stdcall_thunk(<{ %struct.B*, %struct.A }>* inalloca) {
101 entry:
102   %this_ptr = getelementptr inbounds <{ %struct.B*, %struct.A }>* %0, i32 0, i32 0
103   %this = load %struct.B** %this_ptr
104   %1 = bitcast %struct.B* %this to i32 (<{ %struct.B*, %struct.A }>*)***
105   %vtable = load i32 (<{ %struct.B*, %struct.A }>*)*** %1
106   %vfn = getelementptr inbounds i32 (<{ %struct.B*, %struct.A }>*)** %vtable, i32 1
107   %2 = load i32 (<{ %struct.B*, %struct.A }>*)** %vfn
108   %3 = musttail call x86_stdcallcc i32 %2(<{ %struct.B*, %struct.A }>* inalloca %0)
109   ret i32 %3
110 }
111
112 ; CHECK-LABEL: @fastcall_thunk@8:
113 ; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}}
114 ; CHECK: jmpl
115 ; CHECK-NOT: ret
116 define x86_fastcallcc i32 @fastcall_thunk(%struct.B* inreg %this, <{ %struct.A }>* inalloca) {
117 entry:
118   %1 = bitcast %struct.B* %this to i32 (%struct.B*, <{ %struct.A }>*)***
119   %vtable = load i32 (%struct.B*, <{ %struct.A }>*)*** %1
120   %vfn = getelementptr inbounds i32 (%struct.B*, <{ %struct.A }>*)** %vtable, i32 1
121   %2 = load i32 (%struct.B*, <{ %struct.A }>*)** %vfn
122   %3 = musttail call x86_fastcallcc i32 %2(%struct.B* inreg %this, <{ %struct.A }>* inalloca %0)
123   ret i32 %3
124 }