1 /* { dg-add-options stack_size } */
2 
3 /* Test for a reload bug:
4    if you have a memory reference using the indexed addressing
5    mode, and the base address is a pseudo containing an address in the frame
6    and this pseudo fails to get a hard register, we end up with a double PLUS,
7    so the frame address gets reloaded.  Now, when the index got a hard register,
8    and it dies in this insn, push_reload will consider that hard register as
9    a reload register, and disregrad overlaps with rld[n_reloads].in .  That is
10    fine as long as the add can be done with a single insn, but when the
11    constant is so large that it has to be reloaded into a register first,
12    that clobbers the index.  */
13 
14 #include <stdarg.h>
15 
16 #ifdef STACK_SIZE
17 /* We need to be careful that we don't blow our stack.  Function f, in the
18    worst case, needs to fit on the stack:
19 
20    * 40 int[CHUNK] arrays;
21    * ~40 ints;
22    * ~40 pointers for stdarg passing.
23 
24    Subtract the last two off STACK_SIZE and figure out what the maximum
25    chunk size can be.  We make the last bit conservative to account for
26    register saves and other processor-dependent saving.  Limit the
27    chunk size to some sane values.  */
28 
29 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
30 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
31 
32 #define CHUNK								\
33   MIN (500, (MAX (1, (signed)(STACK_SIZE-40*sizeof(int)-256*sizeof(void *)) \
34 		      / (signed)(40*sizeof(int)))))
35 #else
36 #define CHUNK 500
37 #endif
38 
39 void s(int, ...);
40 void z(int, ...);
41 void c(int, ...);
42 
43 typedef int l[CHUNK];
44 
45 void
f(int n)46 f (int n)
47 {
48   int i;
49   l a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
50   l a10, a11, a12, a13, a14, a15, a16, a17, a18, a19;
51   l a20, a21, a22, a23, a24, a25, a26, a27, a28, a29;
52   l a30, a31, a32, a33, a34, a35, a36, a37, a38, a39;
53   int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
54   int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;
55   int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;
56   int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;
57 
58   for (i = 0; i < n; i++)
59     {
60       s (40, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
61 	 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
62          a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
63          a30, a31, a32, a33, a34, a35, a36, a37, a38, a39);
64       i0 = a0[0];
65       i1 = a1[0];
66       i2 = a2[0];
67       i3 = a3[0];
68       i4 = a4[0];
69       i5 = a5[0];
70       i6 = a6[0];
71       i7 = a7[0];
72       i8 = a8[0];
73       i9 = a9[0];
74       i10 = a10[0];
75       i11 = a11[0];
76       i12 = a12[0];
77       i13 = a13[0];
78       i14 = a14[0];
79       i15 = a15[0];
80       i16 = a16[0];
81       i17 = a17[0];
82       i18 = a18[0];
83       i19 = a19[0];
84       i20 = a20[0];
85       i21 = a21[0];
86       i22 = a22[0];
87       i23 = a23[0];
88       i24 = a24[0];
89       i25 = a25[0];
90       i26 = a26[0];
91       i27 = a27[0];
92       i28 = a28[0];
93       i29 = a29[0];
94       i30 = a30[0];
95       i31 = a31[0];
96       i32 = a32[0];
97       i33 = a33[0];
98       i34 = a34[0];
99       i35 = a35[0];
100       i36 = a36[0];
101       i37 = a37[0];
102       i38 = a38[0];
103       i39 = a39[0];
104       z (40, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
105 	 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
106          a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
107          a30, a31, a32, a33, a34, a35, a36, a37, a38, a39);
108       a0[i0] = i0;
109       a1[i1] = i1;
110       a2[i2] = i2;
111       a3[i3] = i3;
112       a4[i4] = i4;
113       a5[i5] = i5;
114       a6[i6] = i6;
115       a7[i7] = i7;
116       a8[i8] = i8;
117       a9[i9] = i9;
118       a10[i10] = i10;
119       a11[i11] = i11;
120       a12[i12] = i12;
121       a13[i13] = i13;
122       a14[i14] = i14;
123       a15[i15] = i15;
124       a16[i16] = i16;
125       a17[i17] = i17;
126       a18[i18] = i18;
127       a19[i19] = i19;
128       a20[i20] = i20;
129       a21[i21] = i21;
130       a22[i22] = i22;
131       a23[i23] = i23;
132       a24[i24] = i24;
133       a25[i25] = i25;
134       a26[i26] = i26;
135       a27[i27] = i27;
136       a28[i28] = i28;
137       a29[i29] = i29;
138       a30[i30] = i30;
139       a31[i31] = i31;
140       a32[i32] = i32;
141       a33[i33] = i33;
142       a34[i34] = i34;
143       a35[i35] = i35;
144       a36[i36] = i36;
145       a37[i37] = i37;
146       a38[i38] = i38;
147       a39[i39] = i39;
148       c (40, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
149 	 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
150          a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
151          a30, a31, a32, a33, a34, a35, a36, a37, a38, a39);
152     }
153 }
154 
155 int
main()156 main ()
157 {
158   /* CHUNK needs to be at least 40 to avoid stack corruption,
159      since index variable i0 in "a[i0] = i0" equals 39.  */
160   if (CHUNK < 40)
161     exit (0);
162 
163   f (1);
164   exit (0);
165 }
166 
s(int n,...)167 void s(int n, ...)
168 {
169   va_list list;
170 
171   va_start (list, n);
172   while (n--)
173     {
174       int *a = va_arg (list, int *);
175       a[0] = n;
176     }
177   va_end (list);
178 }
179 
z(int n,...)180 void z(int n, ...)
181 {
182   va_list list;
183 
184   va_start (list, n);
185   while (n--)
186     {
187       int *a = va_arg (list, int *);
188       __builtin_memset (a, 0, sizeof (l));
189     }
190   va_end (list);
191 }
192 
c(int n,...)193 void c(int n, ...)
194 {
195   va_list list;
196 
197   va_start (list, n);
198   while (n--)
199     {
200       int *a = va_arg (list, int *);
201       if (a[n] != n)
202 	abort ();
203     }
204   va_end (list);
205 }
206