1 ; RUN: llc < %s -disable-fp-elim -mtriple=x86_64-pc-linux-gnu -mcpu=corei7 -o - | FileCheck %s
2 ; This test is fairly fragile. The goal is to ensure that "large" stack
3 ; objects are allocated closest to the stack protector (i.e., farthest away
4 ; from the Stack Pointer.) In standard SSP mode this means that large (>=
5 ; ssp-buffer-size) arrays and structures containing such arrays are
6 ; closet to the protector. With sspstrong and sspreq this means large
7 ; arrays/structures-with-arrays are closest, followed by small (< ssp-buffer-size)
8 ; arrays/structures-with-arrays, and then addr-taken variables.
10 ; Ideally, we only want verify that the objects appear in the correct groups
11 ; and that the groups have the correct relative stack offset. The ordering
12 ; within a group is not relevant to this test. Unfortunately, there is not
13 ; an elegant way to do this, so just match the offset for each object.
14 ; RUN: llc < %s -disable-fp-elim -mtriple=x86_64-unknown-unknown -O0 -mcpu=corei7 -o - \
15 ; RUN: | FileCheck --check-prefix=FAST-NON-LIN %s
16 ; FastISel was not setting the StackProtectorIndex when lowering
17 ; Intrinsic::stackprotector and as a result the stack re-arrangement code was
18 ; never applied. This problem only shows up on non-Linux platforms because on
19 ; Linux the stack protector cookie is loaded from a special address space which
20 ; always triggers standard ISel. Run a basic test to ensure that at -O0
21 ; on a non-linux target the data layout rules are triggered.
23 %struct.struct_large_char = type { [8 x i8] }
24 %struct.struct_large_char2 = type { [2 x i8], [8 x i8] }
25 %struct.struct_small_char = type { [2 x i8] }
26 %struct.struct_large_nonchar = type { [8 x i32] }
27 %struct.struct_small_nonchar = type { [2 x i16] }
29 define void @layout_ssp() ssp {
31 ; Expected stack layout for ssp is
32 ; -16 large_char . Group 1, nested arrays, arrays >= ssp-buffer-size
33 ; -24 struct_large_char .
34 ; -28 scalar1 | Everything else
41 ; -88 struct_small_char
42 ; -120 struct_large_nonchar
43 ; -128 struct_small_nonchar
46 ; CHECK: call{{l|q}} get_scalar1
47 ; CHECK: movl %eax, -28(
48 ; CHECK: call{{l|q}} end_scalar1
50 ; CHECK: call{{l|q}} get_scalar2
51 ; CHECK: movl %eax, -32(
52 ; CHECK: call{{l|q}} end_scalar2
54 ; CHECK: call{{l|q}} get_scalar3
55 ; CHECK: movl %eax, -36(
56 ; CHECK: call{{l|q}} end_scalar3
58 ; CHECK: call{{l|q}} get_addrof
59 ; CHECK: movl %eax, -40(
60 ; CHECK: call{{l|q}} end_addrof
62 ; CHECK: get_small_nonchar
63 ; CHECK: movw %ax, -44(
64 ; CHECK: call{{l|q}} end_small_nonchar
66 ; CHECK: call{{l|q}} get_large_nonchar
67 ; CHECK: movl %eax, -80(
68 ; CHECK: call{{l|q}} end_large_nonchar
70 ; CHECK: call{{l|q}} get_small_char
71 ; CHECK: movb %al, -82(
72 ; CHECK: call{{l|q}} end_small_char
74 ; CHECK: call{{l|q}} get_large_char
75 ; CHECK: movb %al, -16(
76 ; CHECK: call{{l|q}} end_large_char
78 ; CHECK: call{{l|q}} get_struct_large_char
79 ; CHECK: movb %al, -24(
80 ; CHECK: call{{l|q}} end_struct_large_char
82 ; CHECK: call{{l|q}} get_struct_small_char
83 ; CHECK: movb %al, -88(
84 ; CHECK: call{{l|q}} end_struct_small_char
86 ; CHECK: call{{l|q}} get_struct_large_nonchar
87 ; CHECK: movl %eax, -120(
88 ; CHECK: call{{l|q}} end_struct_large_nonchar
90 ; CHECK: call{{l|q}} get_struct_small_nonchar
91 ; CHECK: movw %ax, -128(
92 ; CHECK: call{{l|q}} end_struct_small_nonchar
93 %x = alloca i32, align 4
94 %y = alloca i32, align 4
95 %z = alloca i32, align 4
96 %ptr = alloca i32, align 4
97 %small2 = alloca [2 x i16], align 2
98 %large2 = alloca [8 x i32], align 16
99 %small = alloca [2 x i8], align 1
100 %large = alloca [8 x i8], align 1
101 %a = alloca %struct.struct_large_char, align 1
102 %b = alloca %struct.struct_small_char, align 1
103 %c = alloca %struct.struct_large_nonchar, align 8
104 %d = alloca %struct.struct_small_nonchar, align 2
105 %call = call i32 @get_scalar1()
106 store i32 %call, i32* %x, align 4
107 call void @end_scalar1()
108 %call1 = call i32 @get_scalar2()
109 store i32 %call1, i32* %y, align 4
110 call void @end_scalar2()
111 %call2 = call i32 @get_scalar3()
112 store i32 %call2, i32* %z, align 4
113 call void @end_scalar3()
114 %call3 = call i32 @get_addrof()
115 store i32 %call3, i32* %ptr, align 4
116 call void @end_addrof()
117 %call4 = call signext i16 @get_small_nonchar()
118 %arrayidx = getelementptr inbounds [2 x i16]* %small2, i32 0, i64 0
119 store i16 %call4, i16* %arrayidx, align 2
120 call void @end_small_nonchar()
121 %call5 = call i32 @get_large_nonchar()
122 %arrayidx6 = getelementptr inbounds [8 x i32]* %large2, i32 0, i64 0
123 store i32 %call5, i32* %arrayidx6, align 4
124 call void @end_large_nonchar()
125 %call7 = call signext i8 @get_small_char()
126 %arrayidx8 = getelementptr inbounds [2 x i8]* %small, i32 0, i64 0
127 store i8 %call7, i8* %arrayidx8, align 1
128 call void @end_small_char()
129 %call9 = call signext i8 @get_large_char()
130 %arrayidx10 = getelementptr inbounds [8 x i8]* %large, i32 0, i64 0
131 store i8 %call9, i8* %arrayidx10, align 1
132 call void @end_large_char()
133 %call11 = call signext i8 @get_struct_large_char()
134 %foo = getelementptr inbounds %struct.struct_large_char* %a, i32 0, i32 0
135 %arrayidx12 = getelementptr inbounds [8 x i8]* %foo, i32 0, i64 0
136 store i8 %call11, i8* %arrayidx12, align 1
137 call void @end_struct_large_char()
138 %call13 = call signext i8 @get_struct_small_char()
139 %foo14 = getelementptr inbounds %struct.struct_small_char* %b, i32 0, i32 0
140 %arrayidx15 = getelementptr inbounds [2 x i8]* %foo14, i32 0, i64 0
141 store i8 %call13, i8* %arrayidx15, align 1
142 call void @end_struct_small_char()
143 %call16 = call i32 @get_struct_large_nonchar()
144 %foo17 = getelementptr inbounds %struct.struct_large_nonchar* %c, i32 0, i32 0
145 %arrayidx18 = getelementptr inbounds [8 x i32]* %foo17, i32 0, i64 0
146 store i32 %call16, i32* %arrayidx18, align 4
147 call void @end_struct_large_nonchar()
148 %call19 = call signext i16 @get_struct_small_nonchar()
149 %foo20 = getelementptr inbounds %struct.struct_small_nonchar* %d, i32 0, i32 0
150 %arrayidx21 = getelementptr inbounds [2 x i16]* %foo20, i32 0, i64 0
151 store i16 %call19, i16* %arrayidx21, align 2
152 call void @end_struct_small_nonchar()
153 %arraydecay = getelementptr inbounds [8 x i8]* %large, i32 0, i32 0
154 %arraydecay22 = getelementptr inbounds [2 x i8]* %small, i32 0, i32 0
155 %arraydecay23 = getelementptr inbounds [8 x i32]* %large2, i32 0, i32 0
156 %arraydecay24 = getelementptr inbounds [2 x i16]* %small2, i32 0, i32 0
157 %0 = load i32* %x, align 4
158 %1 = load i32* %y, align 4
159 %2 = load i32* %z, align 4
160 %coerce.dive = getelementptr %struct.struct_large_char* %a, i32 0, i32 0
161 %3 = bitcast [8 x i8]* %coerce.dive to i64*
162 %4 = load i64* %3, align 1
163 %coerce.dive25 = getelementptr %struct.struct_small_char* %b, i32 0, i32 0
164 %5 = bitcast [2 x i8]* %coerce.dive25 to i16*
165 %6 = load i16* %5, align 1
166 %coerce.dive26 = getelementptr %struct.struct_small_nonchar* %d, i32 0, i32 0
167 %7 = bitcast [2 x i16]* %coerce.dive26 to i32*
168 %8 = load i32* %7, align 1
169 call void @takes_all(i64 %4, i16 %6, %struct.struct_large_nonchar* byval align 8 %c, i32 %8, i8* %arraydecay, i8* %arraydecay22, i32* %arraydecay23, i16* %arraydecay24, i32* %ptr, i32 %0, i32 %1, i32 %2)
173 define void @fast_non_linux() ssp {
175 ; FAST-NON-LIN: fast_non_linux:
176 ; FAST-NON-LIN: call{{l|q}} get_scalar1
177 ; FAST-NON-LIN: movl %eax, -20(
178 ; FAST-NON-LIN: call{{l|q}} end_scalar1
180 ; FAST-NON-LIN: call{{l|q}} get_large_char
181 ; FAST-NON-LIN: movb %al, -16(
182 ; FAST-NON-LIN: call{{l|q}} end_large_char
183 %x = alloca i32, align 4
184 %large = alloca [8 x i8], align 1
185 %call = call i32 @get_scalar1()
186 store i32 %call, i32* %x, align 4
187 call void @end_scalar1()
188 %call1 = call signext i8 @get_large_char()
189 %arrayidx = getelementptr inbounds [8 x i8]* %large, i32 0, i64 0
190 store i8 %call1, i8* %arrayidx, align 1
191 call void @end_large_char()
192 %0 = load i32* %x, align 4
193 %arraydecay = getelementptr inbounds [8 x i8]* %large, i32 0, i32 0
194 call void @takes_two(i32 %0, i8* %arraydecay)
198 declare i32 @get_scalar1()
199 declare void @end_scalar1()
201 declare i32 @get_scalar2()
202 declare void @end_scalar2()
204 declare i32 @get_scalar3()
205 declare void @end_scalar3()
207 declare i32 @get_addrof()
208 declare void @end_addrof()
210 declare signext i16 @get_small_nonchar()
211 declare void @end_small_nonchar()
213 declare i32 @get_large_nonchar()
214 declare void @end_large_nonchar()
216 declare signext i8 @get_small_char()
217 declare void @end_small_char()
219 declare signext i8 @get_large_char()
220 declare void @end_large_char()
222 declare signext i8 @get_struct_large_char()
223 declare void @end_struct_large_char()
225 declare signext i8 @get_struct_large_char2()
226 declare void @end_struct_large_char2()
228 declare signext i8 @get_struct_small_char()
229 declare void @end_struct_small_char()
231 declare i32 @get_struct_large_nonchar()
232 declare void @end_struct_large_nonchar()
234 declare signext i16 @get_struct_small_nonchar()
235 declare void @end_struct_small_nonchar()
237 declare void @takes_all(i64, i16, %struct.struct_large_nonchar* byval align 8, i32, i8*, i8*, i32*, i16*, i32*, i32, i32, i32)
238 declare void @takes_two(i32, i8*)