Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / test / unwind_06.pass.cpp
blob98d297e2fca1772bc6504c13b31df95cdd979371
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
11 #include <exception>
12 #include <stdlib.h>
13 #include <assert.h>
14 #include <stdio.h>
16 // Suppress diagnostics about deprecated volatile operations
17 #if defined(__GNUC__) && !defined(__clang__)
18 # pragma GCC diagnostic ignored "-Wvolatile"
19 #endif
21 // Compile with -Os to get compiler uses float registers to hold float variables
23 double get_(int x) { return (double)x; }
25 double (* volatile get)(int) = get_;
27 volatile int counter;
29 double try1(bool v) {
30 double a = get(0);
31 double b = get(1);
32 for (counter = 100; counter; counter = counter - 1)
33 a += get(1) + b;
34 if (v) throw 10;
35 return get(0)+a+b;
38 double try2(bool v) {
39 double a = get(0);
40 double b = get(1);
41 double c = get(2);
42 for (counter = 100; counter; counter = counter - 1)
43 a += get(1) + b + c;
44 if (v) throw 10;
45 return get(0)+a+b+c;
48 double try3(bool v) {
49 double a = get(0);
50 double b = get(1);
51 double c = get(2);
52 double d = get(3);
53 for (counter = 100; counter; counter = counter - 1)
54 a += get(1) + b + c + d;
55 if (v) throw 10;
56 return get(0)+a+b+c+d;
59 double try4(bool v) {
60 double a = get(0);
61 double b = get(0);
62 double c = get(0);
63 double d = get(0);
64 double e = get(0);
65 for (counter = 100; counter; counter = counter - 1)
66 a += get(1) + b+c+d+e;
67 if (v) throw 10;
68 return get(0)+a+b+c+d+e;
71 double try5(bool v) {
72 double a = get(0);
73 double b = get(0);
74 double c = get(0);
75 double d = get(0);
76 double e = get(0);
77 double f = get(0);
78 for (counter = 100; counter; counter = counter - 1)
79 a += get(1) + b+c+d+e+f;
80 if (v) throw 10;
81 return get(0)+a+b+c+d+e+f;
84 double try6(bool v) {
85 double a = get(0);
86 double b = get(0);
87 double c = get(0);
88 double d = get(0);
89 double e = get(0);
90 double f = get(0);
91 double g = get(0);
92 for (counter = 100; counter; counter = counter - 1)
93 a += get(1) + b+c+d+e+f+g;
94 if (v) throw 10;
95 return get(0)+a+b+c+d+e+f+g;
98 double try7(bool v) {
99 double a = get(0);
100 double b = get(0);
101 double c = get(0);
102 double d = get(0);
103 double e = get(0);
104 double f = get(0);
105 double g = get(0);
106 double h = get(0);
107 for (counter = 100; counter; counter = counter - 1)
108 a += get(1) + b+c+d+e+f+g+h;
109 if (v) throw 10;
110 return get(0)+a+b+c+d+e+f+g+h;
113 double try8(bool v) {
114 double a = get(0);
115 double b = get(0);
116 double c = get(0);
117 double d = get(0);
118 double e = get(0);
119 double f = get(0);
120 double g = get(0);
121 double h = get(0);
122 double i = get(0);
123 for (counter = 100; counter; counter = counter - 1)
124 a += get(1) + b+c+d+e+f+g+h+i;
125 if (v) throw 10;
126 return get(0)+a+b+c+d+e+f+g+h+i;
133 double foo()
135 double a = get(1);
136 double b = get(2);
137 double c = get(3);
138 double d = get(4);
139 double e = get(5);
140 double f = get(6);
141 double g = get(7);
142 double h = get(8);
143 try {
144 try1(true);
146 catch (int) {
148 assert(a == get(1));
149 assert(b == get(2));
150 assert(c == get(3));
151 assert(d == get(4));
152 assert(e == get(5));
153 assert(f == get(6));
154 assert(g == get(7));
155 assert(h == get(8));
157 try {
158 try2(true);
160 catch (int) {
162 assert(a == get(1));
163 assert(b == get(2));
164 assert(c == get(3));
165 assert(d == get(4));
166 assert(e == get(5));
167 assert(f == get(6));
168 assert(g == get(7));
169 assert(h == get(8));
171 try {
172 try3(true);
174 catch (int) {
176 assert(a == get(1));
177 assert(b == get(2));
178 assert(c == get(3));
179 assert(d == get(4));
180 assert(e == get(5));
181 assert(f == get(6));
182 assert(g == get(7));
183 assert(h == get(8));
185 try {
186 try4(true);
188 catch (int) {
190 assert(a == get(1));
191 assert(b == get(2));
192 assert(c == get(3));
193 assert(d == get(4));
194 assert(e == get(5));
195 assert(f == get(6));
196 assert(g == get(7));
197 assert(h == get(8));
199 try {
200 try5(true);
202 catch (int) {
204 assert(a == get(1));
205 assert(b == get(2));
206 assert(c == get(3));
207 assert(d == get(4));
208 assert(e == get(5));
209 assert(f == get(6));
210 assert(g == get(7));
211 assert(h == get(8));
213 try {
214 try6(true);
216 catch (int) {
218 assert(a == get(1));
219 assert(b == get(2));
220 assert(c == get(3));
221 assert(d == get(4));
222 assert(e == get(5));
223 assert(f == get(6));
224 assert(g == get(7));
225 assert(h == get(8));
227 try {
228 try7(true);
230 catch (int) {
232 assert(a == get(1));
233 assert(b == get(2));
234 assert(c == get(3));
235 assert(d == get(4));
236 assert(e == get(5));
237 assert(f == get(6));
238 assert(g == get(7));
239 assert(h == get(8));
241 try {
242 try8(true);
244 catch (int) {
246 assert(a == get(1));
247 assert(b == get(2));
248 assert(c == get(3));
249 assert(d == get(4));
250 assert(e == get(5));
251 assert(f == get(6));
252 assert(g == get(7));
253 assert(h == get(8));
255 return a+b+c+d+e+f+g+h;
260 int main(int, char**) {
261 foo();
262 return 0;