Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/multi-ix.c

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