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