1 /* { dg-do run } */
2 /* { dg-skip-if "doubles are floats" { "avr-*-*" } } */
3 /* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details -fdump-tree-optimized -lm" } */
4 /* { dg-final { scan-tree-dump "cdce2.c:16: \[^\n\r]* function call is shrink-wrapped into error conditions\." "cdce" } } */
5 /* { dg-final { scan-tree-dump "log \\(\[^\n\r]*\\); \\\[tail call\\\]" "optimized" } } */
6
7 #include <stdlib.h>
8 #include <math.h>
9 #include <errno.h>
10 int total_err_count = 0;
11 double foo_opt (double y) __attribute__((noinline));
12 double foo_opt (double y)
13 {
14 double yy = 0;
15 errno = 0;
16 yy = log (y);
17 return 0;
18 }
19
20 double foo (double y) __attribute__((noinline));
21 double foo (double y)
22 {
23 double yy = 0;
24 errno = 0;
25 yy = log (y);
26 return yy;
27 }
28
29 int test (double (*fp) (double y))
30 {
31 int i,x;
32 for (i = -100; i < 100; i++)
33 {
34 fp (i);
35 if (errno)
36 total_err_count ++;
37 }
38
39 return total_err_count;
40 }
41
42 int main ()
43 {
44 int en1, en2;
45 double yy;
46 total_err_count = 0;
47 en1 = test (foo_opt);
48 total_err_count = 0;
49 en2 = test (foo);
50
51 if (en1 != en2)
52 abort();
53
54 return 0;
55 }