1*fe36f081STimo Kreuzer // Copyright (c) Microsoft. All rights reserved.
2*fe36f081STimo Kreuzer // Licensed under the MIT license. See LICENSE file in the project root for
3*fe36f081STimo Kreuzer // full license information.
4*fe36f081STimo Kreuzer
5*fe36f081STimo Kreuzer /*
6*fe36f081STimo Kreuzer * Exercise lots of different kinds of C++ EH frames. Compile this with
7*fe36f081STimo Kreuzer * every combination of opts you can to stress the C++ EH frame code in the
8*fe36f081STimo Kreuzer * backend.
9*fe36f081STimo Kreuzer */
10*fe36f081STimo Kreuzer
11*fe36f081STimo Kreuzer #include <stdio.h>
12*fe36f081STimo Kreuzer #include <malloc.h>
13*fe36f081STimo Kreuzer
14*fe36f081STimo Kreuzer #ifndef ALIGN
15*fe36f081STimo Kreuzer #define ALIGN 64
16*fe36f081STimo Kreuzer #endif
17*fe36f081STimo Kreuzer
18*fe36f081STimo Kreuzer extern int TestFunc(int, ...);
19*fe36f081STimo Kreuzer
20*fe36f081STimo Kreuzer int failures;
21*fe36f081STimo Kreuzer
22*fe36f081STimo Kreuzer int global;
23*fe36f081STimo Kreuzer bool TestFuncThrows;
24*fe36f081STimo Kreuzer
25*fe36f081STimo Kreuzer struct SmallObj
26*fe36f081STimo Kreuzer {
~SmallObjSmallObj27*fe36f081STimo Kreuzer virtual ~SmallObj()
28*fe36f081STimo Kreuzer {
29*fe36f081STimo Kreuzer TestFunc(1, this);
30*fe36f081STimo Kreuzer };
31*fe36f081STimo Kreuzer
32*fe36f081STimo Kreuzer int x;
33*fe36f081STimo Kreuzer };
34*fe36f081STimo Kreuzer
35*fe36f081STimo Kreuzer struct BigObj
36*fe36f081STimo Kreuzer {
~BigObjBigObj37*fe36f081STimo Kreuzer virtual ~BigObj()
38*fe36f081STimo Kreuzer {
39*fe36f081STimo Kreuzer TestFunc(1, this);
40*fe36f081STimo Kreuzer };
41*fe36f081STimo Kreuzer
42*fe36f081STimo Kreuzer char x[4096];
43*fe36f081STimo Kreuzer };
44*fe36f081STimo Kreuzer
Simple(int arg)45*fe36f081STimo Kreuzer int Simple(int arg)
46*fe36f081STimo Kreuzer {
47*fe36f081STimo Kreuzer puts(__FUNCTION__);
48*fe36f081STimo Kreuzer int res = 0;
49*fe36f081STimo Kreuzer SmallObj f;
50*fe36f081STimo Kreuzer return TestFunc(1, &f, &res, &arg);
51*fe36f081STimo Kreuzer }
52*fe36f081STimo Kreuzer
Try(int arg)53*fe36f081STimo Kreuzer int Try(int arg)
54*fe36f081STimo Kreuzer {
55*fe36f081STimo Kreuzer puts(__FUNCTION__);
56*fe36f081STimo Kreuzer int res = 0;
57*fe36f081STimo Kreuzer SmallObj f;
58*fe36f081STimo Kreuzer try {
59*fe36f081STimo Kreuzer res = TestFunc(1, &f, &res, &arg);
60*fe36f081STimo Kreuzer } catch (double) {
61*fe36f081STimo Kreuzer res = TestFunc(2, &f, &res, &arg);
62*fe36f081STimo Kreuzer }
63*fe36f081STimo Kreuzer return res;
64*fe36f081STimo Kreuzer }
65*fe36f081STimo Kreuzer
GSCookie(int arg)66*fe36f081STimo Kreuzer int GSCookie(int arg)
67*fe36f081STimo Kreuzer {
68*fe36f081STimo Kreuzer puts(__FUNCTION__);
69*fe36f081STimo Kreuzer int res = 0;
70*fe36f081STimo Kreuzer char buf[16];
71*fe36f081STimo Kreuzer SmallObj f;
72*fe36f081STimo Kreuzer return TestFunc(1, buf, &f, &res, &arg);
73*fe36f081STimo Kreuzer }
74*fe36f081STimo Kreuzer
TryAndGSCookie(int arg)75*fe36f081STimo Kreuzer int TryAndGSCookie(int arg)
76*fe36f081STimo Kreuzer {
77*fe36f081STimo Kreuzer puts(__FUNCTION__);
78*fe36f081STimo Kreuzer int res = 0;
79*fe36f081STimo Kreuzer char buf[16];
80*fe36f081STimo Kreuzer SmallObj f;
81*fe36f081STimo Kreuzer try {
82*fe36f081STimo Kreuzer res = TestFunc(1, &buf, &f, &res, &arg);
83*fe36f081STimo Kreuzer } catch (double) {
84*fe36f081STimo Kreuzer res = TestFunc(2, &buf, &f, &res, &arg);
85*fe36f081STimo Kreuzer }
86*fe36f081STimo Kreuzer return res;
87*fe36f081STimo Kreuzer }
88*fe36f081STimo Kreuzer
Align(int arg)89*fe36f081STimo Kreuzer int Align(int arg)
90*fe36f081STimo Kreuzer {
91*fe36f081STimo Kreuzer puts(__FUNCTION__);
92*fe36f081STimo Kreuzer int res = 0;
93*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
94*fe36f081STimo Kreuzer SmallObj f;
95*fe36f081STimo Kreuzer return TestFunc(1, d, &f, &res, &arg);
96*fe36f081STimo Kreuzer }
97*fe36f081STimo Kreuzer
TryAndAlign(int arg)98*fe36f081STimo Kreuzer int TryAndAlign(int arg)
99*fe36f081STimo Kreuzer {
100*fe36f081STimo Kreuzer puts(__FUNCTION__);
101*fe36f081STimo Kreuzer int res = 0;
102*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
103*fe36f081STimo Kreuzer SmallObj f;
104*fe36f081STimo Kreuzer try {
105*fe36f081STimo Kreuzer res = TestFunc(1, d, &f, &res, &arg);
106*fe36f081STimo Kreuzer } catch (double) {
107*fe36f081STimo Kreuzer res = TestFunc(2, d, &f, &res, &arg);
108*fe36f081STimo Kreuzer }
109*fe36f081STimo Kreuzer return res;
110*fe36f081STimo Kreuzer }
111*fe36f081STimo Kreuzer
GSCookieAndAlign(int arg)112*fe36f081STimo Kreuzer int GSCookieAndAlign(int arg)
113*fe36f081STimo Kreuzer {
114*fe36f081STimo Kreuzer puts(__FUNCTION__);
115*fe36f081STimo Kreuzer int res = 0;
116*fe36f081STimo Kreuzer char buf[16];
117*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
118*fe36f081STimo Kreuzer SmallObj f;
119*fe36f081STimo Kreuzer return TestFunc(1, buf, d, &f, &res, &arg);
120*fe36f081STimo Kreuzer }
121*fe36f081STimo Kreuzer
TryAndGSCookieAndAlign(int arg)122*fe36f081STimo Kreuzer int TryAndGSCookieAndAlign(int arg)
123*fe36f081STimo Kreuzer {
124*fe36f081STimo Kreuzer puts(__FUNCTION__);
125*fe36f081STimo Kreuzer int res = 0;
126*fe36f081STimo Kreuzer char buf[16];
127*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
128*fe36f081STimo Kreuzer SmallObj f;
129*fe36f081STimo Kreuzer try {
130*fe36f081STimo Kreuzer res = TestFunc(1, buf, d, &f, &res, &arg);
131*fe36f081STimo Kreuzer } catch (double) {
132*fe36f081STimo Kreuzer res = TestFunc(2, buf, d, &f, &res, &arg);
133*fe36f081STimo Kreuzer }
134*fe36f081STimo Kreuzer return res;
135*fe36f081STimo Kreuzer }
136*fe36f081STimo Kreuzer
Alloca(int arg)137*fe36f081STimo Kreuzer int Alloca(int arg)
138*fe36f081STimo Kreuzer {
139*fe36f081STimo Kreuzer puts(__FUNCTION__);
140*fe36f081STimo Kreuzer int res = 0;
141*fe36f081STimo Kreuzer SmallObj f;
142*fe36f081STimo Kreuzer return TestFunc(1, _alloca(global), &f, &res, &arg);
143*fe36f081STimo Kreuzer }
144*fe36f081STimo Kreuzer
TryAndAlloca(int arg)145*fe36f081STimo Kreuzer int TryAndAlloca(int arg)
146*fe36f081STimo Kreuzer {
147*fe36f081STimo Kreuzer puts(__FUNCTION__);
148*fe36f081STimo Kreuzer int res = 0;
149*fe36f081STimo Kreuzer SmallObj f;
150*fe36f081STimo Kreuzer try {
151*fe36f081STimo Kreuzer res = TestFunc(1, _alloca(global), &f, &res, &arg);
152*fe36f081STimo Kreuzer } catch (double) {
153*fe36f081STimo Kreuzer res = TestFunc(2, &f, &res, &arg);
154*fe36f081STimo Kreuzer }
155*fe36f081STimo Kreuzer return res;
156*fe36f081STimo Kreuzer }
157*fe36f081STimo Kreuzer
GSCookieAndAlloca(int arg)158*fe36f081STimo Kreuzer int GSCookieAndAlloca(int arg)
159*fe36f081STimo Kreuzer {
160*fe36f081STimo Kreuzer puts(__FUNCTION__);
161*fe36f081STimo Kreuzer int res = 0;
162*fe36f081STimo Kreuzer char buf[16];
163*fe36f081STimo Kreuzer SmallObj f;
164*fe36f081STimo Kreuzer return TestFunc(1, buf, _alloca(global), &f, &res, &arg);
165*fe36f081STimo Kreuzer }
166*fe36f081STimo Kreuzer
TryAndGSCookieAndAlloca(int arg)167*fe36f081STimo Kreuzer int TryAndGSCookieAndAlloca(int arg)
168*fe36f081STimo Kreuzer {
169*fe36f081STimo Kreuzer puts(__FUNCTION__);
170*fe36f081STimo Kreuzer int res = 0;
171*fe36f081STimo Kreuzer char buf[16];
172*fe36f081STimo Kreuzer SmallObj f;
173*fe36f081STimo Kreuzer try {
174*fe36f081STimo Kreuzer res = TestFunc(1, &buf, _alloca(global), &f, &res, &arg);
175*fe36f081STimo Kreuzer } catch (double) {
176*fe36f081STimo Kreuzer res = TestFunc(2, &buf, &f, &res, &arg);
177*fe36f081STimo Kreuzer }
178*fe36f081STimo Kreuzer return res;
179*fe36f081STimo Kreuzer }
180*fe36f081STimo Kreuzer
AlignAndAlloca(int arg)181*fe36f081STimo Kreuzer int AlignAndAlloca(int arg)
182*fe36f081STimo Kreuzer {
183*fe36f081STimo Kreuzer puts(__FUNCTION__);
184*fe36f081STimo Kreuzer int res = 0;
185*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
186*fe36f081STimo Kreuzer SmallObj f;
187*fe36f081STimo Kreuzer return TestFunc(1, d, _alloca(global), &f, &res, &arg);
188*fe36f081STimo Kreuzer }
189*fe36f081STimo Kreuzer
TryAndAlignAndAlloca(int arg)190*fe36f081STimo Kreuzer int TryAndAlignAndAlloca(int arg)
191*fe36f081STimo Kreuzer {
192*fe36f081STimo Kreuzer puts(__FUNCTION__);
193*fe36f081STimo Kreuzer int res = 0;
194*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
195*fe36f081STimo Kreuzer SmallObj f;
196*fe36f081STimo Kreuzer try {
197*fe36f081STimo Kreuzer res = TestFunc(1, d, _alloca(global), &f, &res, &arg);
198*fe36f081STimo Kreuzer } catch (double) {
199*fe36f081STimo Kreuzer res = TestFunc(2, d, &f, &res, &arg);
200*fe36f081STimo Kreuzer }
201*fe36f081STimo Kreuzer return res;
202*fe36f081STimo Kreuzer }
203*fe36f081STimo Kreuzer
GSCookieAndAlignAndAlloca(int arg)204*fe36f081STimo Kreuzer int GSCookieAndAlignAndAlloca(int arg)
205*fe36f081STimo Kreuzer {
206*fe36f081STimo Kreuzer puts(__FUNCTION__);
207*fe36f081STimo Kreuzer int res = 0;
208*fe36f081STimo Kreuzer char buf[16];
209*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
210*fe36f081STimo Kreuzer SmallObj f;
211*fe36f081STimo Kreuzer return TestFunc(1, buf, d, _alloca(global), &f, &res, &arg);
212*fe36f081STimo Kreuzer }
213*fe36f081STimo Kreuzer
TryAndGSCookieAndAlignAndAlloca(int arg)214*fe36f081STimo Kreuzer int TryAndGSCookieAndAlignAndAlloca(int arg)
215*fe36f081STimo Kreuzer {
216*fe36f081STimo Kreuzer puts(__FUNCTION__);
217*fe36f081STimo Kreuzer int res = 0;
218*fe36f081STimo Kreuzer char buf[16];
219*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
220*fe36f081STimo Kreuzer SmallObj f;
221*fe36f081STimo Kreuzer try {
222*fe36f081STimo Kreuzer res = TestFunc(1, buf, d, _alloca(global), &f, &res, &arg);
223*fe36f081STimo Kreuzer } catch (double) {
224*fe36f081STimo Kreuzer res = TestFunc(2, buf, d, &f, &res, &arg);
225*fe36f081STimo Kreuzer }
226*fe36f081STimo Kreuzer return res;
227*fe36f081STimo Kreuzer }
228*fe36f081STimo Kreuzer
229*fe36f081STimo Kreuzer /* The *AndBigLocals set of functions try to trigger EBP adjustment */
230*fe36f081STimo Kreuzer
BigLocals(int arg)231*fe36f081STimo Kreuzer int BigLocals(int arg)
232*fe36f081STimo Kreuzer {
233*fe36f081STimo Kreuzer puts(__FUNCTION__);
234*fe36f081STimo Kreuzer int res = 0;
235*fe36f081STimo Kreuzer BigObj f1;
236*fe36f081STimo Kreuzer return TestFunc(1, &f1, &res, &res, &res, &res, &res, &arg);
237*fe36f081STimo Kreuzer }
238*fe36f081STimo Kreuzer
TryAndBigLocals(int arg)239*fe36f081STimo Kreuzer int TryAndBigLocals(int arg)
240*fe36f081STimo Kreuzer {
241*fe36f081STimo Kreuzer puts(__FUNCTION__);
242*fe36f081STimo Kreuzer int res = 0;
243*fe36f081STimo Kreuzer BigObj f1;
244*fe36f081STimo Kreuzer try {
245*fe36f081STimo Kreuzer res = TestFunc(1, &f1, &res, &res, &res, &res, &res, &arg);
246*fe36f081STimo Kreuzer } catch (double) {
247*fe36f081STimo Kreuzer res = TestFunc(2, &f1, &res, &res, &res, &res, &res, &arg);
248*fe36f081STimo Kreuzer }
249*fe36f081STimo Kreuzer return res;
250*fe36f081STimo Kreuzer }
251*fe36f081STimo Kreuzer
GSCookieAndBigLocals(int arg)252*fe36f081STimo Kreuzer int GSCookieAndBigLocals(int arg)
253*fe36f081STimo Kreuzer {
254*fe36f081STimo Kreuzer puts(__FUNCTION__);
255*fe36f081STimo Kreuzer int res = 0;
256*fe36f081STimo Kreuzer char buf[16];
257*fe36f081STimo Kreuzer BigObj f1;
258*fe36f081STimo Kreuzer return TestFunc(1, buf, &f1, &res, &res, &res, &res, &res, &arg);
259*fe36f081STimo Kreuzer }
260*fe36f081STimo Kreuzer
TryAndGSCookieAndBigLocals(int arg)261*fe36f081STimo Kreuzer int TryAndGSCookieAndBigLocals(int arg)
262*fe36f081STimo Kreuzer {
263*fe36f081STimo Kreuzer puts(__FUNCTION__);
264*fe36f081STimo Kreuzer int res = 0;
265*fe36f081STimo Kreuzer char buf[16];
266*fe36f081STimo Kreuzer BigObj f1;
267*fe36f081STimo Kreuzer try {
268*fe36f081STimo Kreuzer res = TestFunc(1, &buf, &f1, &res, &res, &res, &res, &res, &arg);
269*fe36f081STimo Kreuzer } catch (double) {
270*fe36f081STimo Kreuzer res = TestFunc(2, &buf, &f1, &res, &res, &res, &res, &res, &arg);
271*fe36f081STimo Kreuzer }
272*fe36f081STimo Kreuzer return res;
273*fe36f081STimo Kreuzer }
274*fe36f081STimo Kreuzer
AlignAndBigLocals(int arg)275*fe36f081STimo Kreuzer int AlignAndBigLocals(int arg)
276*fe36f081STimo Kreuzer {
277*fe36f081STimo Kreuzer puts(__FUNCTION__);
278*fe36f081STimo Kreuzer int res = 0;
279*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
280*fe36f081STimo Kreuzer BigObj f1;
281*fe36f081STimo Kreuzer return TestFunc(1, d, &f1, &res, &res, &res, &res, &res, &arg);
282*fe36f081STimo Kreuzer }
283*fe36f081STimo Kreuzer
TryAndAlignAndBigLocals(int arg)284*fe36f081STimo Kreuzer int TryAndAlignAndBigLocals(int arg)
285*fe36f081STimo Kreuzer {
286*fe36f081STimo Kreuzer puts(__FUNCTION__);
287*fe36f081STimo Kreuzer int res = 0;
288*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
289*fe36f081STimo Kreuzer BigObj f1;
290*fe36f081STimo Kreuzer try {
291*fe36f081STimo Kreuzer res = TestFunc(1, d, &f1, &res, &res, &res, &res, &res, &arg);
292*fe36f081STimo Kreuzer } catch (double) {
293*fe36f081STimo Kreuzer res = TestFunc(2, d, &f1, &res, &res, &res, &res, &res, &arg);
294*fe36f081STimo Kreuzer }
295*fe36f081STimo Kreuzer return res;
296*fe36f081STimo Kreuzer }
297*fe36f081STimo Kreuzer
GSCookieAndAlignAndBigLocals(int arg)298*fe36f081STimo Kreuzer int GSCookieAndAlignAndBigLocals(int arg)
299*fe36f081STimo Kreuzer {
300*fe36f081STimo Kreuzer puts(__FUNCTION__);
301*fe36f081STimo Kreuzer int res = 0;
302*fe36f081STimo Kreuzer char buf[16];
303*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
304*fe36f081STimo Kreuzer BigObj f1;
305*fe36f081STimo Kreuzer return TestFunc(1, buf, d, &f1, &res, &res, &res, &res, &res, &arg);
306*fe36f081STimo Kreuzer }
307*fe36f081STimo Kreuzer
TryAndGSCookieAndAlignAndBigLocals(int arg)308*fe36f081STimo Kreuzer int TryAndGSCookieAndAlignAndBigLocals(int arg)
309*fe36f081STimo Kreuzer {
310*fe36f081STimo Kreuzer puts(__FUNCTION__);
311*fe36f081STimo Kreuzer int res = 0;
312*fe36f081STimo Kreuzer char buf[16];
313*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
314*fe36f081STimo Kreuzer BigObj f1;
315*fe36f081STimo Kreuzer try {
316*fe36f081STimo Kreuzer res = TestFunc(1, buf, d, &f1, &res, &res, &res, &res, &res, &arg);
317*fe36f081STimo Kreuzer } catch (double) {
318*fe36f081STimo Kreuzer res = TestFunc(2, buf, d, &f1, &res, &res, &res, &res, &res, &arg);
319*fe36f081STimo Kreuzer }
320*fe36f081STimo Kreuzer return res;
321*fe36f081STimo Kreuzer }
322*fe36f081STimo Kreuzer
AllocaAndBigLocals(int arg)323*fe36f081STimo Kreuzer int AllocaAndBigLocals(int arg)
324*fe36f081STimo Kreuzer {
325*fe36f081STimo Kreuzer puts(__FUNCTION__);
326*fe36f081STimo Kreuzer int res = 0;
327*fe36f081STimo Kreuzer BigObj f1;
328*fe36f081STimo Kreuzer return TestFunc(1, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
329*fe36f081STimo Kreuzer }
330*fe36f081STimo Kreuzer
TryAndAllocaAndBigLocals(int arg)331*fe36f081STimo Kreuzer int TryAndAllocaAndBigLocals(int arg)
332*fe36f081STimo Kreuzer {
333*fe36f081STimo Kreuzer puts(__FUNCTION__);
334*fe36f081STimo Kreuzer int res = 0;
335*fe36f081STimo Kreuzer BigObj f1;
336*fe36f081STimo Kreuzer try {
337*fe36f081STimo Kreuzer res = TestFunc(1, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
338*fe36f081STimo Kreuzer } catch (double) {
339*fe36f081STimo Kreuzer res = TestFunc(2, &f1, &res, &res, &res, &res, &res, &arg);
340*fe36f081STimo Kreuzer }
341*fe36f081STimo Kreuzer return res;
342*fe36f081STimo Kreuzer }
343*fe36f081STimo Kreuzer
GSCookieAndAllocaAndBigLocals(int arg)344*fe36f081STimo Kreuzer int GSCookieAndAllocaAndBigLocals(int arg)
345*fe36f081STimo Kreuzer {
346*fe36f081STimo Kreuzer puts(__FUNCTION__);
347*fe36f081STimo Kreuzer int res = 0;
348*fe36f081STimo Kreuzer char buf[16];
349*fe36f081STimo Kreuzer BigObj f1;
350*fe36f081STimo Kreuzer return TestFunc(1, buf, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
351*fe36f081STimo Kreuzer }
352*fe36f081STimo Kreuzer
TryAndGSCookieAndAllocaAndBigLocals(int arg)353*fe36f081STimo Kreuzer int TryAndGSCookieAndAllocaAndBigLocals(int arg)
354*fe36f081STimo Kreuzer {
355*fe36f081STimo Kreuzer puts(__FUNCTION__);
356*fe36f081STimo Kreuzer int res = 0;
357*fe36f081STimo Kreuzer char buf[16];
358*fe36f081STimo Kreuzer BigObj f1;
359*fe36f081STimo Kreuzer try {
360*fe36f081STimo Kreuzer res = TestFunc(1, &buf, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
361*fe36f081STimo Kreuzer } catch (double) {
362*fe36f081STimo Kreuzer res = TestFunc(2, &buf, &f1, &res, &res, &res, &res, &res, &arg);
363*fe36f081STimo Kreuzer }
364*fe36f081STimo Kreuzer return res;
365*fe36f081STimo Kreuzer }
366*fe36f081STimo Kreuzer
AlignAndAllocaAndBigLocals(int arg)367*fe36f081STimo Kreuzer int AlignAndAllocaAndBigLocals(int arg)
368*fe36f081STimo Kreuzer {
369*fe36f081STimo Kreuzer puts(__FUNCTION__);
370*fe36f081STimo Kreuzer int res = 0;
371*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
372*fe36f081STimo Kreuzer BigObj f1;
373*fe36f081STimo Kreuzer return TestFunc(1, d, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
374*fe36f081STimo Kreuzer }
375*fe36f081STimo Kreuzer
TryAndAlignAndAllocaAndBigLocals(int arg)376*fe36f081STimo Kreuzer int TryAndAlignAndAllocaAndBigLocals(int arg)
377*fe36f081STimo Kreuzer {
378*fe36f081STimo Kreuzer puts(__FUNCTION__);
379*fe36f081STimo Kreuzer int res = 0;
380*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
381*fe36f081STimo Kreuzer BigObj f1;
382*fe36f081STimo Kreuzer try {
383*fe36f081STimo Kreuzer res = TestFunc(1, d, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
384*fe36f081STimo Kreuzer } catch (double) {
385*fe36f081STimo Kreuzer res = TestFunc(2, d, &f1, &res, &res, &res, &res, &res, &arg);
386*fe36f081STimo Kreuzer }
387*fe36f081STimo Kreuzer return res;
388*fe36f081STimo Kreuzer }
389*fe36f081STimo Kreuzer
GSCookieAndAlignAndAllocaAndBigLocals(int arg)390*fe36f081STimo Kreuzer int GSCookieAndAlignAndAllocaAndBigLocals(int arg)
391*fe36f081STimo Kreuzer {
392*fe36f081STimo Kreuzer puts(__FUNCTION__);
393*fe36f081STimo Kreuzer int res = 0;
394*fe36f081STimo Kreuzer char buf[16];
395*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
396*fe36f081STimo Kreuzer BigObj f1;
397*fe36f081STimo Kreuzer return TestFunc(1, buf, d, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
398*fe36f081STimo Kreuzer }
399*fe36f081STimo Kreuzer
TryAndGSCookieAndAlignAndAllocaAndBigLocals(int arg)400*fe36f081STimo Kreuzer int TryAndGSCookieAndAlignAndAllocaAndBigLocals(int arg)
401*fe36f081STimo Kreuzer {
402*fe36f081STimo Kreuzer puts(__FUNCTION__);
403*fe36f081STimo Kreuzer int res = 0;
404*fe36f081STimo Kreuzer char buf[16];
405*fe36f081STimo Kreuzer __declspec(align(ALIGN)) double d[4];
406*fe36f081STimo Kreuzer BigObj f1;
407*fe36f081STimo Kreuzer try {
408*fe36f081STimo Kreuzer res = TestFunc(1, buf, d, _alloca(global), &f1, &res, &res, &res, &res, &res, &arg);
409*fe36f081STimo Kreuzer } catch (double) {
410*fe36f081STimo Kreuzer res = TestFunc(2, buf, d, &f1, &res, &res, &res, &res, &res, &arg);
411*fe36f081STimo Kreuzer }
412*fe36f081STimo Kreuzer return res;
413*fe36f081STimo Kreuzer }
414*fe36f081STimo Kreuzer
415*fe36f081STimo Kreuzer __declspec(noinline)
TestFunc(int,...)416*fe36f081STimo Kreuzer int TestFunc(int, ...)
417*fe36f081STimo Kreuzer {
418*fe36f081STimo Kreuzer if (TestFuncThrows)
419*fe36f081STimo Kreuzer {
420*fe36f081STimo Kreuzer TestFuncThrows = false;
421*fe36f081STimo Kreuzer throw 123;
422*fe36f081STimo Kreuzer }
423*fe36f081STimo Kreuzer
424*fe36f081STimo Kreuzer return global;
425*fe36f081STimo Kreuzer }
426*fe36f081STimo Kreuzer
RunTests()427*fe36f081STimo Kreuzer void RunTests()
428*fe36f081STimo Kreuzer {
429*fe36f081STimo Kreuzer puts("Test pass 1 - no throws");
430*fe36f081STimo Kreuzer
431*fe36f081STimo Kreuzer try
432*fe36f081STimo Kreuzer {
433*fe36f081STimo Kreuzer Simple(1);
434*fe36f081STimo Kreuzer Try(1);
435*fe36f081STimo Kreuzer GSCookie(1);
436*fe36f081STimo Kreuzer TryAndGSCookie(1);
437*fe36f081STimo Kreuzer Align(1);
438*fe36f081STimo Kreuzer TryAndAlign(1);
439*fe36f081STimo Kreuzer GSCookieAndAlign(1);
440*fe36f081STimo Kreuzer TryAndGSCookieAndAlign(1);
441*fe36f081STimo Kreuzer Alloca(1);
442*fe36f081STimo Kreuzer TryAndAlloca(1);
443*fe36f081STimo Kreuzer GSCookieAndAlloca(1);
444*fe36f081STimo Kreuzer TryAndGSCookieAndAlloca(1);
445*fe36f081STimo Kreuzer AlignAndAlloca(1);
446*fe36f081STimo Kreuzer TryAndAlignAndAlloca(1);
447*fe36f081STimo Kreuzer GSCookieAndAlignAndAlloca(1);
448*fe36f081STimo Kreuzer TryAndGSCookieAndAlignAndAlloca(1);
449*fe36f081STimo Kreuzer BigLocals(1);
450*fe36f081STimo Kreuzer TryAndBigLocals(1);
451*fe36f081STimo Kreuzer GSCookieAndBigLocals(1);
452*fe36f081STimo Kreuzer TryAndGSCookieAndBigLocals(1);
453*fe36f081STimo Kreuzer AlignAndBigLocals(1);
454*fe36f081STimo Kreuzer TryAndAlignAndBigLocals(1);
455*fe36f081STimo Kreuzer GSCookieAndAlignAndBigLocals(1);
456*fe36f081STimo Kreuzer TryAndGSCookieAndAlignAndBigLocals(1);
457*fe36f081STimo Kreuzer AllocaAndBigLocals(1);
458*fe36f081STimo Kreuzer TryAndAllocaAndBigLocals(1);
459*fe36f081STimo Kreuzer GSCookieAndAllocaAndBigLocals(1);
460*fe36f081STimo Kreuzer TryAndGSCookieAndAllocaAndBigLocals(1);
461*fe36f081STimo Kreuzer AlignAndAllocaAndBigLocals(1);
462*fe36f081STimo Kreuzer TryAndAlignAndAllocaAndBigLocals(1);
463*fe36f081STimo Kreuzer GSCookieAndAlignAndAllocaAndBigLocals(1);
464*fe36f081STimo Kreuzer TryAndGSCookieAndAlignAndAllocaAndBigLocals(1);
465*fe36f081STimo Kreuzer }
466*fe36f081STimo Kreuzer catch (...)
467*fe36f081STimo Kreuzer {
468*fe36f081STimo Kreuzer puts("ERROR - throw not expected");
469*fe36f081STimo Kreuzer ++failures;
470*fe36f081STimo Kreuzer }
471*fe36f081STimo Kreuzer
472*fe36f081STimo Kreuzer puts("Test pass 2 - throws");
473*fe36f081STimo Kreuzer
474*fe36f081STimo Kreuzer for (int i = 0; i < 32; ++i)
475*fe36f081STimo Kreuzer {
476*fe36f081STimo Kreuzer TestFuncThrows = true;
477*fe36f081STimo Kreuzer bool caught = false;
478*fe36f081STimo Kreuzer try
479*fe36f081STimo Kreuzer {
480*fe36f081STimo Kreuzer switch (i)
481*fe36f081STimo Kreuzer {
482*fe36f081STimo Kreuzer case 0: Simple(1); break;
483*fe36f081STimo Kreuzer case 1: Try(1); break;
484*fe36f081STimo Kreuzer case 2: GSCookie(1); break;
485*fe36f081STimo Kreuzer case 3: TryAndGSCookie(1); break;
486*fe36f081STimo Kreuzer case 4: Align(1); break;
487*fe36f081STimo Kreuzer case 5: TryAndAlign(1); break;
488*fe36f081STimo Kreuzer case 6: GSCookieAndAlign(1); break;
489*fe36f081STimo Kreuzer case 7: TryAndGSCookieAndAlign(1); break;
490*fe36f081STimo Kreuzer case 8: Alloca(1); break;
491*fe36f081STimo Kreuzer case 9: TryAndAlloca(1); break;
492*fe36f081STimo Kreuzer case 10: GSCookieAndAlloca(1); break;
493*fe36f081STimo Kreuzer case 11: TryAndGSCookieAndAlloca(1); break;
494*fe36f081STimo Kreuzer case 12: AlignAndAlloca(1); break;
495*fe36f081STimo Kreuzer case 13: TryAndAlignAndAlloca(1); break;
496*fe36f081STimo Kreuzer case 14: GSCookieAndAlignAndAlloca(1); break;
497*fe36f081STimo Kreuzer case 15: TryAndGSCookieAndAlignAndAlloca(1); break;
498*fe36f081STimo Kreuzer case 16: BigLocals(1); break;
499*fe36f081STimo Kreuzer case 17: TryAndBigLocals(1); break;
500*fe36f081STimo Kreuzer case 18: GSCookieAndBigLocals(1); break;
501*fe36f081STimo Kreuzer case 19: TryAndGSCookieAndBigLocals(1); break;
502*fe36f081STimo Kreuzer case 20: AlignAndBigLocals(1); break;
503*fe36f081STimo Kreuzer case 21: TryAndAlignAndBigLocals(1); break;
504*fe36f081STimo Kreuzer case 22: GSCookieAndAlignAndBigLocals(1); break;
505*fe36f081STimo Kreuzer case 23: TryAndGSCookieAndAlignAndBigLocals(1); break;
506*fe36f081STimo Kreuzer case 24: AllocaAndBigLocals(1); break;
507*fe36f081STimo Kreuzer case 25: TryAndAllocaAndBigLocals(1); break;
508*fe36f081STimo Kreuzer case 26: GSCookieAndAllocaAndBigLocals(1); break;
509*fe36f081STimo Kreuzer case 27: TryAndGSCookieAndAllocaAndBigLocals(1); break;
510*fe36f081STimo Kreuzer case 28: AlignAndAllocaAndBigLocals(1); break;
511*fe36f081STimo Kreuzer case 29: TryAndAlignAndAllocaAndBigLocals(1); break;
512*fe36f081STimo Kreuzer case 30: GSCookieAndAlignAndAllocaAndBigLocals(1); break;
513*fe36f081STimo Kreuzer case 31: TryAndGSCookieAndAlignAndAllocaAndBigLocals(1); break;
514*fe36f081STimo Kreuzer }
515*fe36f081STimo Kreuzer }
516*fe36f081STimo Kreuzer catch (int)
517*fe36f081STimo Kreuzer {
518*fe36f081STimo Kreuzer caught = true;
519*fe36f081STimo Kreuzer }
520*fe36f081STimo Kreuzer
521*fe36f081STimo Kreuzer if (!caught)
522*fe36f081STimo Kreuzer {
523*fe36f081STimo Kreuzer puts("ERROR - did not catch expected thrown object");
524*fe36f081STimo Kreuzer ++failures;
525*fe36f081STimo Kreuzer }
526*fe36f081STimo Kreuzer }
527*fe36f081STimo Kreuzer }
528*fe36f081STimo Kreuzer
main()529*fe36f081STimo Kreuzer int main()
530*fe36f081STimo Kreuzer {
531*fe36f081STimo Kreuzer __try
532*fe36f081STimo Kreuzer {
533*fe36f081STimo Kreuzer RunTests();
534*fe36f081STimo Kreuzer }
535*fe36f081STimo Kreuzer __except (1)
536*fe36f081STimo Kreuzer {
537*fe36f081STimo Kreuzer puts("ERROR - Unexpectedly caught an exception");
538*fe36f081STimo Kreuzer ++failures;
539*fe36f081STimo Kreuzer }
540*fe36f081STimo Kreuzer
541*fe36f081STimo Kreuzer if (failures)
542*fe36f081STimo Kreuzer {
543*fe36f081STimo Kreuzer printf("Test failed with %d failure%s\n",
544*fe36f081STimo Kreuzer failures, failures == 1 ? "" : "s");
545*fe36f081STimo Kreuzer }
546*fe36f081STimo Kreuzer else
547*fe36f081STimo Kreuzer {
548*fe36f081STimo Kreuzer puts("Test passed");
549*fe36f081STimo Kreuzer }
550*fe36f081STimo Kreuzer
551*fe36f081STimo Kreuzer return failures;
552*fe36f081STimo Kreuzer }
553