1 //===------------------------- unwind_06.cpp ------------------------------===// 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 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: no-exceptions 10 11 #include <exception> 12 #include <stdlib.h> 13 #include <assert.h> 14 #include <stdio.h> 15 16 // Suppress diagnostics about deprecated volatile operations 17 #if defined(__GNUC__) && (__GNUC__ >= 10) && !defined(__clang__) 18 # pragma GCC diagnostic ignored "-Wvolatile" 19 #endif 20 21 // Compile with -Os to get compiler uses float registers to hold float variables 22 get_(int x)23double get_(int x) { return (double)x; } 24 25 double (* volatile get)(int) = get_; 26 27 volatile int counter; 28 try1(bool v)29double 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; 36 } 37 try2(bool v)38double 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; 46 } 47 try3(bool v)48double 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; 57 } 58 try4(bool v)59double 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; 69 } 70 try5(bool v)71double 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; 82 } 83 try6(bool v)84double 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; 96 } 97 try7(bool v)98double 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; 111 } 112 try8(bool v)113double 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; 127 } 128 129 130 131 132 foo()133double foo() 134 { 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); 145 } 146 catch (int) { 147 } 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)); 156 157 try { 158 try2(true); 159 } 160 catch (int) { 161 } 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)); 170 171 try { 172 try3(true); 173 } 174 catch (int) { 175 } 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)); 184 185 try { 186 try4(true); 187 } 188 catch (int) { 189 } 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)); 198 199 try { 200 try5(true); 201 } 202 catch (int) { 203 } 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)); 212 213 try { 214 try6(true); 215 } 216 catch (int) { 217 } 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)); 226 227 try { 228 try7(true); 229 } 230 catch (int) { 231 } 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)); 240 241 try { 242 try8(true); 243 } 244 catch (int) { 245 } 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)); 254 255 return a+b+c+d+e+f+g+h; 256 } 257 258 259 main(int,char **)260int main(int, char**) { 261 foo(); 262 return 0; 263 } 264