xref: /aosp_15_r20/external/libcxxabi/test/unwind_06.pass.cpp (revision c05d8e5dc3e10f6ce4317e8bc22cc4a25f55fa94)
1*c05d8e5dSAndroid Build Coastguard Worker //===------------------------- unwind_06.cpp ------------------------------===//
2*c05d8e5dSAndroid Build Coastguard Worker //
3*c05d8e5dSAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*c05d8e5dSAndroid Build Coastguard Worker //
5*c05d8e5dSAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*c05d8e5dSAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*c05d8e5dSAndroid Build Coastguard Worker //
8*c05d8e5dSAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*c05d8e5dSAndroid Build Coastguard Worker 
10*c05d8e5dSAndroid Build Coastguard Worker // UNSUPPORTED: libcxxabi-no-exceptions
11*c05d8e5dSAndroid Build Coastguard Worker 
12*c05d8e5dSAndroid Build Coastguard Worker #include <exception>
13*c05d8e5dSAndroid Build Coastguard Worker #include <stdlib.h>
14*c05d8e5dSAndroid Build Coastguard Worker #include <assert.h>
15*c05d8e5dSAndroid Build Coastguard Worker #include <stdio.h>
16*c05d8e5dSAndroid Build Coastguard Worker 
17*c05d8e5dSAndroid Build Coastguard Worker // Compile with -Os to get compiler uses float registers to hold float variables
18*c05d8e5dSAndroid Build Coastguard Worker 
get_(int x)19*c05d8e5dSAndroid Build Coastguard Worker double get_(int x) { return (double)x; }
20*c05d8e5dSAndroid Build Coastguard Worker 
21*c05d8e5dSAndroid Build Coastguard Worker double (* volatile get)(int) = get_;
22*c05d8e5dSAndroid Build Coastguard Worker 
23*c05d8e5dSAndroid Build Coastguard Worker volatile int counter;
24*c05d8e5dSAndroid Build Coastguard Worker 
try1(bool v)25*c05d8e5dSAndroid Build Coastguard Worker double try1(bool v) {
26*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
27*c05d8e5dSAndroid Build Coastguard Worker   double b = get(1);
28*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
29*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b;
30*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
31*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b;
32*c05d8e5dSAndroid Build Coastguard Worker }
33*c05d8e5dSAndroid Build Coastguard Worker 
try2(bool v)34*c05d8e5dSAndroid Build Coastguard Worker double try2(bool v) {
35*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
36*c05d8e5dSAndroid Build Coastguard Worker   double b = get(1);
37*c05d8e5dSAndroid Build Coastguard Worker   double c = get(2);
38*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
39*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b + c;
40*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
41*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c;
42*c05d8e5dSAndroid Build Coastguard Worker }
43*c05d8e5dSAndroid Build Coastguard Worker 
try3(bool v)44*c05d8e5dSAndroid Build Coastguard Worker double try3(bool v) {
45*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
46*c05d8e5dSAndroid Build Coastguard Worker   double b = get(1);
47*c05d8e5dSAndroid Build Coastguard Worker   double c = get(2);
48*c05d8e5dSAndroid Build Coastguard Worker   double d = get(3);
49*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
50*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b + c + d;
51*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
52*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c+d;
53*c05d8e5dSAndroid Build Coastguard Worker }
54*c05d8e5dSAndroid Build Coastguard Worker 
try4(bool v)55*c05d8e5dSAndroid Build Coastguard Worker double try4(bool v) {
56*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
57*c05d8e5dSAndroid Build Coastguard Worker   double b = get(0);
58*c05d8e5dSAndroid Build Coastguard Worker   double c = get(0);
59*c05d8e5dSAndroid Build Coastguard Worker   double d = get(0);
60*c05d8e5dSAndroid Build Coastguard Worker   double e = get(0);
61*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
62*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b+c+d+e;
63*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
64*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c+d+e;
65*c05d8e5dSAndroid Build Coastguard Worker }
66*c05d8e5dSAndroid Build Coastguard Worker 
try5(bool v)67*c05d8e5dSAndroid Build Coastguard Worker double try5(bool v) {
68*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
69*c05d8e5dSAndroid Build Coastguard Worker   double b = get(0);
70*c05d8e5dSAndroid Build Coastguard Worker   double c = get(0);
71*c05d8e5dSAndroid Build Coastguard Worker   double d = get(0);
72*c05d8e5dSAndroid Build Coastguard Worker   double e = get(0);
73*c05d8e5dSAndroid Build Coastguard Worker   double f = get(0);
74*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
75*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b+c+d+e+f;
76*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
77*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c+d+e+f;
78*c05d8e5dSAndroid Build Coastguard Worker }
79*c05d8e5dSAndroid Build Coastguard Worker 
try6(bool v)80*c05d8e5dSAndroid Build Coastguard Worker double try6(bool v) {
81*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
82*c05d8e5dSAndroid Build Coastguard Worker   double b = get(0);
83*c05d8e5dSAndroid Build Coastguard Worker   double c = get(0);
84*c05d8e5dSAndroid Build Coastguard Worker   double d = get(0);
85*c05d8e5dSAndroid Build Coastguard Worker   double e = get(0);
86*c05d8e5dSAndroid Build Coastguard Worker   double f = get(0);
87*c05d8e5dSAndroid Build Coastguard Worker   double g = get(0);
88*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
89*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b+c+d+e+f+g;
90*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
91*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c+d+e+f+g;
92*c05d8e5dSAndroid Build Coastguard Worker }
93*c05d8e5dSAndroid Build Coastguard Worker 
try7(bool v)94*c05d8e5dSAndroid Build Coastguard Worker double try7(bool v) {
95*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
96*c05d8e5dSAndroid Build Coastguard Worker   double b = get(0);
97*c05d8e5dSAndroid Build Coastguard Worker   double c = get(0);
98*c05d8e5dSAndroid Build Coastguard Worker   double d = get(0);
99*c05d8e5dSAndroid Build Coastguard Worker   double e = get(0);
100*c05d8e5dSAndroid Build Coastguard Worker   double f = get(0);
101*c05d8e5dSAndroid Build Coastguard Worker   double g = get(0);
102*c05d8e5dSAndroid Build Coastguard Worker   double h = get(0);
103*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
104*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b+c+d+e+f+g+h;
105*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
106*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c+d+e+f+g+h;
107*c05d8e5dSAndroid Build Coastguard Worker }
108*c05d8e5dSAndroid Build Coastguard Worker 
try8(bool v)109*c05d8e5dSAndroid Build Coastguard Worker double try8(bool v) {
110*c05d8e5dSAndroid Build Coastguard Worker   double a = get(0);
111*c05d8e5dSAndroid Build Coastguard Worker   double b = get(0);
112*c05d8e5dSAndroid Build Coastguard Worker   double c = get(0);
113*c05d8e5dSAndroid Build Coastguard Worker   double d = get(0);
114*c05d8e5dSAndroid Build Coastguard Worker   double e = get(0);
115*c05d8e5dSAndroid Build Coastguard Worker   double f = get(0);
116*c05d8e5dSAndroid Build Coastguard Worker   double g = get(0);
117*c05d8e5dSAndroid Build Coastguard Worker   double h = get(0);
118*c05d8e5dSAndroid Build Coastguard Worker   double i = get(0);
119*c05d8e5dSAndroid Build Coastguard Worker   for (counter = 100; counter; --counter)
120*c05d8e5dSAndroid Build Coastguard Worker     a += get(1) + b+c+d+e+f+g+h+i;
121*c05d8e5dSAndroid Build Coastguard Worker   if (v) throw 10;
122*c05d8e5dSAndroid Build Coastguard Worker   return get(0)+a+b+c+d+e+f+g+h+i;
123*c05d8e5dSAndroid Build Coastguard Worker }
124*c05d8e5dSAndroid Build Coastguard Worker 
125*c05d8e5dSAndroid Build Coastguard Worker 
126*c05d8e5dSAndroid Build Coastguard Worker 
127*c05d8e5dSAndroid Build Coastguard Worker 
128*c05d8e5dSAndroid Build Coastguard Worker 
foo()129*c05d8e5dSAndroid Build Coastguard Worker double foo()
130*c05d8e5dSAndroid Build Coastguard Worker {
131*c05d8e5dSAndroid Build Coastguard Worker   double a = get(1);
132*c05d8e5dSAndroid Build Coastguard Worker   double b = get(2);
133*c05d8e5dSAndroid Build Coastguard Worker   double c = get(3);
134*c05d8e5dSAndroid Build Coastguard Worker   double d = get(4);
135*c05d8e5dSAndroid Build Coastguard Worker   double e = get(5);
136*c05d8e5dSAndroid Build Coastguard Worker   double f = get(6);
137*c05d8e5dSAndroid Build Coastguard Worker   double g = get(7);
138*c05d8e5dSAndroid Build Coastguard Worker   double h = get(8);
139*c05d8e5dSAndroid Build Coastguard Worker   try {
140*c05d8e5dSAndroid Build Coastguard Worker     try1(true);
141*c05d8e5dSAndroid Build Coastguard Worker   }
142*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
143*c05d8e5dSAndroid Build Coastguard Worker   }
144*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
145*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
146*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
147*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
148*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
149*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
150*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
151*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
152*c05d8e5dSAndroid Build Coastguard Worker 
153*c05d8e5dSAndroid Build Coastguard Worker   try {
154*c05d8e5dSAndroid Build Coastguard Worker     try2(true);
155*c05d8e5dSAndroid Build Coastguard Worker   }
156*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
157*c05d8e5dSAndroid Build Coastguard Worker   }
158*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
159*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
160*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
161*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
162*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
163*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
164*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
165*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
166*c05d8e5dSAndroid Build Coastguard Worker 
167*c05d8e5dSAndroid Build Coastguard Worker   try {
168*c05d8e5dSAndroid Build Coastguard Worker     try3(true);
169*c05d8e5dSAndroid Build Coastguard Worker   }
170*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
171*c05d8e5dSAndroid Build Coastguard Worker   }
172*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
173*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
174*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
175*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
176*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
177*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
178*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
179*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
180*c05d8e5dSAndroid Build Coastguard Worker 
181*c05d8e5dSAndroid Build Coastguard Worker   try {
182*c05d8e5dSAndroid Build Coastguard Worker     try4(true);
183*c05d8e5dSAndroid Build Coastguard Worker   }
184*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
185*c05d8e5dSAndroid Build Coastguard Worker   }
186*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
187*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
188*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
189*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
190*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
191*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
192*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
193*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
194*c05d8e5dSAndroid Build Coastguard Worker 
195*c05d8e5dSAndroid Build Coastguard Worker   try {
196*c05d8e5dSAndroid Build Coastguard Worker     try5(true);
197*c05d8e5dSAndroid Build Coastguard Worker   }
198*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
199*c05d8e5dSAndroid Build Coastguard Worker   }
200*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
201*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
202*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
203*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
204*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
205*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
206*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
207*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
208*c05d8e5dSAndroid Build Coastguard Worker 
209*c05d8e5dSAndroid Build Coastguard Worker   try {
210*c05d8e5dSAndroid Build Coastguard Worker     try6(true);
211*c05d8e5dSAndroid Build Coastguard Worker   }
212*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
213*c05d8e5dSAndroid Build Coastguard Worker   }
214*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
215*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
216*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
217*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
218*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
219*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
220*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
221*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
222*c05d8e5dSAndroid Build Coastguard Worker 
223*c05d8e5dSAndroid Build Coastguard Worker   try {
224*c05d8e5dSAndroid Build Coastguard Worker     try7(true);
225*c05d8e5dSAndroid Build Coastguard Worker   }
226*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
227*c05d8e5dSAndroid Build Coastguard Worker   }
228*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
229*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
230*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
231*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
232*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
233*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
234*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
235*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
236*c05d8e5dSAndroid Build Coastguard Worker 
237*c05d8e5dSAndroid Build Coastguard Worker   try {
238*c05d8e5dSAndroid Build Coastguard Worker     try8(true);
239*c05d8e5dSAndroid Build Coastguard Worker   }
240*c05d8e5dSAndroid Build Coastguard Worker   catch (int e) {
241*c05d8e5dSAndroid Build Coastguard Worker   }
242*c05d8e5dSAndroid Build Coastguard Worker   assert(a == get(1));
243*c05d8e5dSAndroid Build Coastguard Worker   assert(b == get(2));
244*c05d8e5dSAndroid Build Coastguard Worker   assert(c == get(3));
245*c05d8e5dSAndroid Build Coastguard Worker   assert(d == get(4));
246*c05d8e5dSAndroid Build Coastguard Worker   assert(e == get(5));
247*c05d8e5dSAndroid Build Coastguard Worker   assert(f == get(6));
248*c05d8e5dSAndroid Build Coastguard Worker   assert(g == get(7));
249*c05d8e5dSAndroid Build Coastguard Worker   assert(h == get(8));
250*c05d8e5dSAndroid Build Coastguard Worker 
251*c05d8e5dSAndroid Build Coastguard Worker   return a+b+c+d+e+f+g+h;
252*c05d8e5dSAndroid Build Coastguard Worker }
253*c05d8e5dSAndroid Build Coastguard Worker 
254*c05d8e5dSAndroid Build Coastguard Worker 
255*c05d8e5dSAndroid Build Coastguard Worker 
main()256*c05d8e5dSAndroid Build Coastguard Worker int main()
257*c05d8e5dSAndroid Build Coastguard Worker {
258*c05d8e5dSAndroid Build Coastguard Worker   foo();
259*c05d8e5dSAndroid Build Coastguard Worker }
260