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