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