summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cdce3.C
blob: e6ca58c46ec2a0ca236d57a5ef194a798a8deebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* { dg-do run } */
/* { dg-require-effective-target c99_runtime } */
/* { dg-skip-if "exp2* missing despite C99 runtime" { alpha*-dec-osf5* } } */
/* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details  -DGNU_EXTENSION -DLARGE_LONG_DOUBLE -lm" { target { pow10 && large_long_double } } } */
/* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details -DLARGE_LONG_DOUBLE -lm" { target { {! pow10 } && large_long_double } } } */
/* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details -DGNU_EXTENSION -lm" { target { pow10 && {! large_long_double } } } } */
/* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details -lm" { target { {! pow10 } && {! large_long_double } } } } */
/* { dg-add-options ieee } */
/* { dg-final { scan-tree-dump  "cdce3.C:93: note: function call is shrink-wrapped into error conditions\." "cdce" { target { pow10 } } } } */
/* { dg-final { scan-tree-dump  "cdce3.C:94: note: function call is shrink-wrapped into error conditions\." "cdce" { target { pow10 } } } } */
/* { dg-final { scan-tree-dump  "cdce3.C:96: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:97: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:98: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:99: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:100: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:101: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:102: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:103: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:104: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:105: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:106: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:107: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:108: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { scan-tree-dump  "cdce3.C:109: note: function call is shrink-wrapped into error conditions\." "cdce" } } */
/* { dg-final { cleanup-tree-dump "cdce" } } */
#include <stdlib.h>
#include <math.h>
#ifdef DEBUG
#include <stdio.h>
#endif
#include <errno.h>
typedef void (*FP) (int xp);
#define NI __attribute__((noinline))

#if defined(LARGE_LONG_DOUBLE)
typedef long double ldouble; 
ldouble result;

#define DEF_MATH_FUNC(prefix, name) NI void prefix##name##f (int x) \
{ \
  float yy = name##f ((float) x); \
  STORE_RESULT; \
} \
NI void prefix##name (int x) \
{ \
  double yy = name ((double)x); \
  STORE_RESULT; \
} \
NI void prefix##name##l (int x) \
{ \
  ldouble yy = name##l ((ldouble)x); \
  STORE_RESULT; \
}
#else
double result;

#define DEF_MATH_FUNC(prefix, name) NI void prefix##name##f (int x) \
{ \
  float yy = name##f ((float) x); \
  STORE_RESULT; \
} \
NI void prefix##name (int x) \
{ \
  double yy = name ((double)x); \
  STORE_RESULT; \
}
#endif

#undef STORE_RESULT
#define STORE_RESULT result = yy
#if defined(GNU_EXTENSION)
DEF_MATH_FUNC (m,pow10)
DEF_MATH_FUNC (m,exp10)
#endif
DEF_MATH_FUNC (m,exp2)
DEF_MATH_FUNC (m,exp)
DEF_MATH_FUNC (m,expm1)
DEF_MATH_FUNC (m,cosh)
DEF_MATH_FUNC (m,sinh)
DEF_MATH_FUNC (m,acos)
DEF_MATH_FUNC (m,asin)
DEF_MATH_FUNC (m,acosh)
DEF_MATH_FUNC (m,atanh)
DEF_MATH_FUNC (m,log)
DEF_MATH_FUNC (m,log2)
DEF_MATH_FUNC (m,log10)
DEF_MATH_FUNC (m,log1p)
DEF_MATH_FUNC (m,sqrt)

#undef STORE_RESULT
#define STORE_RESULT
#if defined(GNU_EXTENSION)
DEF_MATH_FUNC (o,pow10)
DEF_MATH_FUNC (o,exp10)
#endif
DEF_MATH_FUNC (o,exp2)
DEF_MATH_FUNC (o,exp)
DEF_MATH_FUNC (o,expm1)
DEF_MATH_FUNC (o,cosh)
DEF_MATH_FUNC (o,sinh)
DEF_MATH_FUNC (o,acos)
DEF_MATH_FUNC (o,asin)
DEF_MATH_FUNC (o,acosh)
DEF_MATH_FUNC (o,atanh)
DEF_MATH_FUNC (o,log)
DEF_MATH_FUNC (o,log2)
DEF_MATH_FUNC (o,log10)
DEF_MATH_FUNC (o,log1p)
DEF_MATH_FUNC (o,sqrt)

#if defined(LARGE_LONG_DOUBLE)
#define INIT_MATH_FUNC(prefix, name, lb, ub) { prefix##name##f, #name "f", 0, 0, lb, ub }, \
{ prefix##name, #name, 0, 0, lb, ub }, \
{ prefix##name##l, #name "l" , 0, 0, lb, ub }, 
#else
#define INIT_MATH_FUNC(prefix, name, lb, ub) { prefix##name##f, #name "f", 0, 0, lb, ub }, \
{ prefix##name, #name, 0, 0, lb, ub },
#endif

struct MathFuncInfo
{
  FP math_func;
  const char*  name;
  int lb;
  int ub;
  bool has_lb;
  bool has_ub;
} math_func_arr[] = { 
#if defined(GNU_EXTENSION)
  INIT_MATH_FUNC (m,pow10, false, true)
  INIT_MATH_FUNC (m,exp10, false, true)
#endif
  INIT_MATH_FUNC (m,exp2, false, true)
  INIT_MATH_FUNC (m,expm1, false, true)
  INIT_MATH_FUNC (m,exp, false, true)
  INIT_MATH_FUNC (m,cosh, true, true)
  INIT_MATH_FUNC (m,sinh, true, true)
  INIT_MATH_FUNC (m,acos, true, true)
  INIT_MATH_FUNC (m,asin, true, true)
  INIT_MATH_FUNC (m,acosh, true, false)
  INIT_MATH_FUNC (m,atanh, true, true)
  INIT_MATH_FUNC (m,log10, true, false)
  INIT_MATH_FUNC (m,log, true, false)
  INIT_MATH_FUNC (m,log2, true, false)
  INIT_MATH_FUNC (m,log1p, true, false)
  INIT_MATH_FUNC (m,sqrt, true, false)
  { 0, 0,  0, 0, 0, 0} };

MathFuncInfo opt_math_func_arr[] = 
{
#if defined(GNU_EXTENSION)
  INIT_MATH_FUNC (o,pow10, false, true)
  INIT_MATH_FUNC (o,exp10, false, true)
#endif
  INIT_MATH_FUNC (o,exp2, false, true)
  INIT_MATH_FUNC (o,expm1, false, true)
  INIT_MATH_FUNC (o,exp, false, true)
  INIT_MATH_FUNC (o,cosh, true, true)
  INIT_MATH_FUNC (o,sinh, true, true)
  INIT_MATH_FUNC (o,acos, true, true)
  INIT_MATH_FUNC (o,asin, true, true)
  INIT_MATH_FUNC (o,acosh, true, false)
  INIT_MATH_FUNC (o,atanh, true, true)
  INIT_MATH_FUNC (o,log10, true, false)
  INIT_MATH_FUNC (o,log, true, false)
  INIT_MATH_FUNC (o,log2, true, false)
  INIT_MATH_FUNC (o,log1p, true, false)
  INIT_MATH_FUNC (o,sqrt, true, false)
  { 0, 0,  0, 0, 0, 0} };

int test (MathFuncInfo* math_func_infos)
{
  int i = 0;
  int te = 0;

  for (i = 0; math_func_infos[i].math_func; i++)
    {
      MathFuncInfo& info = math_func_infos[i];
      int j;
      if (info.has_lb)
        {
          for (j = 0; j > -500000; j--)
            {
        
              errno = 0;
              info.math_func (j);
              if (errno != 0)
                {
		  te++;
                  info.lb = j ;
                  break;
                }
            }
        }
      if (info.has_ub)
        {
          for (j = 0; j < 500000; j++)
            {
              errno = 0;
              info.math_func (j);
              if (errno != 0)
              {
	        te++;
                info.ub = j ;
                break;
              }
            }
        }
    }
  return te;
}

int main()
{
   int te1, te2;

   te1 = test (&math_func_arr[0]);
   te2 = test (&opt_math_func_arr[0]);

   // Now examine the result 
   int i = 0;
   int errcnt = 0;
   for (i = 0; math_func_arr[i].math_func; i++)
   {
      MathFuncInfo& info = math_func_arr[i];
      MathFuncInfo& opt_info = opt_math_func_arr[i];
#ifdef DEBUG
      fprintf (stderr," %s: lb = %d, ub = %d: lb_opt = %d, ub_opt = %d\n",
	info.name, info.lb, info.ub, opt_info.lb, opt_info.ub);
#endif
      if (info.lb != opt_info.lb) errcnt ++;
      if (info.ub != opt_info.ub) errcnt ++;
   }
   if (errcnt) abort();
   return 0;
}