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