OSDN Git Service

2008-06-04 Xinliang David Li <davidxl@google.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cdce3.C
1 /* { dg-do  run { target { ! "*-*-darwin" } } } */
2 /* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details  -lm" } */
3 /* { dg-final { scan-tree-dump  "cdce3.C:68: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
4 /* { dg-final { scan-tree-dump  "cdce3.C:69: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
5 /* { dg-final { scan-tree-dump  "cdce3.C:70: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
6 /* { dg-final { scan-tree-dump  "cdce3.C:71: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
7 /* { dg-final { scan-tree-dump  "cdce3.C:72: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
8 /* { dg-final { scan-tree-dump  "cdce3.C:73: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
9 /* { dg-final { scan-tree-dump  "cdce3.C:74: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
10 /* { dg-final { scan-tree-dump  "cdce3.C:75: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
11 /* { dg-final { scan-tree-dump  "cdce3.C:76: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
12 /* { dg-final { scan-tree-dump  "cdce3.C:77: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
13 /* { dg-final { scan-tree-dump  "cdce3.C:78: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
14 /* { dg-final { scan-tree-dump  "cdce3.C:79: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
15 /* { dg-final { scan-tree-dump  "cdce3.C:80: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
16 /* { dg-final { scan-tree-dump  "cdce3.C:81: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
17 /* { dg-final { scan-tree-dump  "cdce3.C:82: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
18 /* { dg-final { scan-tree-dump  "cdce3.C:83: note: function call is shrink-wrapped into error conditions\." "cdce" } }*/
19 /* { dg-final { cleanup-tree-dump "cdce" } } */
20 #include <stdlib.h>
21 #include <math.h>
22 #ifdef DEBUG
23 #include <stdio.h>
24 #endif
25 #include <errno.h>
26 typedef long double ldouble; 
27 typedef void (*FP) (int xp);
28 #define NI __attribute__((noinline))
29 ldouble result;
30
31 #define DEF_MATH_FUNC(prefix, name) NI void prefix##name##f (int x) \
32 { \
33   float yy = name##f ((float) x); \
34   STORE_RESULT; \
35 } \
36 NI void prefix##name (int x) \
37 { \
38   double yy = name ((double)x); \
39   STORE_RESULT; \
40 } \
41 NI void prefix##name##l (int x) \
42 { \
43   ldouble yy = name##l ((ldouble)x); \
44   STORE_RESULT; \
45
46
47 #undef STORE_RESULT
48 #define STORE_RESULT result = yy
49 DEF_MATH_FUNC (m,pow10)
50 DEF_MATH_FUNC (m,exp10)
51 DEF_MATH_FUNC (m,exp2)
52 DEF_MATH_FUNC (m,exp)
53 DEF_MATH_FUNC (m,expm1)
54 DEF_MATH_FUNC (m,cosh)
55 DEF_MATH_FUNC (m,sinh)
56 DEF_MATH_FUNC (m,acos)
57 DEF_MATH_FUNC (m,asin)
58 DEF_MATH_FUNC (m,acosh)
59 DEF_MATH_FUNC (m,atanh)
60 DEF_MATH_FUNC (m,log)
61 DEF_MATH_FUNC (m,log2)
62 DEF_MATH_FUNC (m,log10)
63 DEF_MATH_FUNC (m,log1p)
64 DEF_MATH_FUNC (m,sqrt)
65
66 #undef STORE_RESULT
67 #define STORE_RESULT
68 DEF_MATH_FUNC (o,pow10)
69 DEF_MATH_FUNC (o,exp10)
70 DEF_MATH_FUNC (o,exp2)
71 DEF_MATH_FUNC (o,exp)
72 DEF_MATH_FUNC (o,expm1)
73 DEF_MATH_FUNC (o,cosh)
74 DEF_MATH_FUNC (o,sinh)
75 DEF_MATH_FUNC (o,acos)
76 DEF_MATH_FUNC (o,asin)
77 DEF_MATH_FUNC (o,acosh)
78 DEF_MATH_FUNC (o,atanh)
79 DEF_MATH_FUNC (o,log)
80 DEF_MATH_FUNC (o,log2)
81 DEF_MATH_FUNC (o,log10)
82 DEF_MATH_FUNC (o,log1p)
83 DEF_MATH_FUNC (o,sqrt)
84
85 #define INIT_MATH_FUNC(prefix, name, lb, ub) { prefix##name##f, #name "f", 0, 0, lb, ub }, \
86 { prefix##name, #name, 0, 0, lb, ub }, \
87 { prefix##name##l, #name "l" , 0, 0, lb, ub }, 
88
89 struct MathFuncInfo
90 {
91   FP math_func;
92   const char*  name;
93   int lb;
94   int ub;
95   bool has_lb;
96   bool has_ub;
97 } math_func_arr[] = { 
98   INIT_MATH_FUNC (m,pow10, false, true)
99   INIT_MATH_FUNC (m,exp10, false, true)
100   INIT_MATH_FUNC (m,exp2, false, true)
101   INIT_MATH_FUNC (m,expm1, false, true)
102   INIT_MATH_FUNC (m,exp, false, true)
103   INIT_MATH_FUNC (m,cosh, true, true)
104   INIT_MATH_FUNC (m,sinh, true, true)
105   INIT_MATH_FUNC (m,acos, true, true)
106   INIT_MATH_FUNC (m,asin, true, true)
107   INIT_MATH_FUNC (m,acosh, true, false)
108   INIT_MATH_FUNC (m,atanh, true, true)
109   INIT_MATH_FUNC (m,log10, true, false)
110   INIT_MATH_FUNC (m,log, true, false)
111   INIT_MATH_FUNC (m,log2, true, false)
112   INIT_MATH_FUNC (m,log1p, true, false)
113   INIT_MATH_FUNC (m,sqrt, true, false)
114   { 0, 0,  0, 0, 0, 0} };
115
116 MathFuncInfo opt_math_func_arr[] = 
117 { INIT_MATH_FUNC (o,pow10, false, true)
118   INIT_MATH_FUNC (o,exp10, false, true)
119   INIT_MATH_FUNC (o,exp2, false, true)
120   INIT_MATH_FUNC (o,expm1, false, true)
121   INIT_MATH_FUNC (o,exp, false, true)
122   INIT_MATH_FUNC (o,cosh, true, true)
123   INIT_MATH_FUNC (o,sinh, true, true)
124   INIT_MATH_FUNC (o,acos, true, true)
125   INIT_MATH_FUNC (o,asin, true, true)
126   INIT_MATH_FUNC (o,acosh, true, false)
127   INIT_MATH_FUNC (o,atanh, true, true)
128   INIT_MATH_FUNC (o,log10, true, false)
129   INIT_MATH_FUNC (o,log, true, false)
130   INIT_MATH_FUNC (o,log2, true, false)
131   INIT_MATH_FUNC (o,log1p, true, false)
132   INIT_MATH_FUNC (o,sqrt, true, false)
133   { 0, 0,  0, 0, 0, 0} };
134
135 int test (MathFuncInfo* math_func_infos)
136 {
137   int i = 0;
138   int te = 0;
139
140   for (i = 0; math_func_infos[i].math_func; i++)
141     {
142       MathFuncInfo& info = math_func_infos[i];
143       int j;
144       if (info.has_lb)
145         {
146           for (j = 0; j > -500000; j--)
147             {
148         
149               errno = 0;
150               info.math_func (j);
151               if (errno != 0)
152                 {
153                   te++;
154                   info.lb = j ;
155                   break;
156                 }
157             }
158         }
159       if (info.has_ub)
160         {
161           for (j = 0; j < 500000; j++)
162             {
163               errno = 0;
164               info.math_func (j);
165               if (errno != 0)
166               {
167                 te++;
168                 info.ub = j ;
169                 break;
170               }
171             }
172         }
173     }
174   return te;
175 }
176
177 int main()
178 {
179    int te1, te2;
180
181    te1 = test (&math_func_arr[0]);
182    te2 = test (&opt_math_func_arr[0]);
183
184    // Now examine the result 
185    int i = 0;
186    int errcnt = 0;
187    for (i = 0; math_func_arr[i].math_func; i++)
188    {
189       MathFuncInfo& info = math_func_arr[i];
190       MathFuncInfo& opt_info = opt_math_func_arr[i];
191 #ifdef DEBUG
192       fprintf (stderr," %s: lb = %d, ub = %d: lb_opt = %d, ub_opt = %d\n",
193         info.name, info.lb, info.ub, opt_info.lb, opt_info.ub);
194 #endif
195       if (info.lb != opt_info.lb) errcnt ++;
196       if (info.ub != opt_info.ub) errcnt ++;
197    }
198    if (errcnt) abort();
199    return 0;
200 }