2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-integral-1.c
blob522646dd5cbec815cda558e7263cdba9644c83da
1 /* Copyright (C) 2004 Free Software Foundation.
3 Verify that integral FP expressions are optimized.
5 Written by Kaveh Ghazi, 2004-03-16. */
7 /* { dg-do link } */
8 /* We need -ffinite-math-only so that we can fold "foo != foo", where
9 foo is a floating point expression. We need -fno-math-errno so
10 that various math functions are marked const/pure and can be
11 folded. */
12 /* { dg-options "-ffinite-math-only -fno-math-errno" } */
14 extern int link_failure (int);
16 /* Test that the various FP truncation builtins detect integral
17 arguments. */
18 #define CHECK_FN(MATHFN) \
19 if (__builtin_##MATHFN(i1) != i1) link_failure (__LINE__); \
20 if (__builtin_##MATHFN##f(i1) != i1) link_failure (__LINE__); \
21 if (__builtin_##MATHFN##l(i1) != i1) link_failure (__LINE__);
23 #define CHECK_FN_RET(MATHFN, RET) \
24 if (__builtin_##MATHFN(i1) != (RET)(double)i1) link_failure (__LINE__); \
25 if (__builtin_##MATHFN##f(i1) != (RET)(float)i1) link_failure (__LINE__); \
26 if (__builtin_##MATHFN##l(i1) != (RET)(long double)i1) link_failure (__LINE__);
28 /* Check that various other integral expressions are detected. */
29 #define CHECK_EXPR(EXPR,NAME) \
30 if (__builtin_ceill(EXPR) != (EXPR)) link_failure (__LINE__); \
31 if (__builtin_lroundl(EXPR) != (long)(long double)(EXPR)) link_failure (__LINE__);
33 void __attribute__ ((__noinline__)) test (int i1, int i2)
35 CHECK_FN(ceil);
36 CHECK_FN(floor);
37 CHECK_FN(nearbyint);
38 CHECK_FN(rint);
39 CHECK_FN(round);
40 CHECK_FN(trunc);
41 CHECK_FN_RET(lround, long);
42 CHECK_FN_RET(llround, long long);
43 CHECK_FN_RET(lrint, long);
44 CHECK_FN_RET(llrint, long long);
45 CHECK_FN_RET(lceil, long);
46 CHECK_FN_RET(llceil, long long);
47 CHECK_FN_RET(lfloor, long);
48 CHECK_FN_RET(llfloor, long long);
50 CHECK_EXPR (5.0, REAL_CST);
51 CHECK_EXPR (5.0F, REAL_CSTf);
52 CHECK_EXPR (5.0L, REAL_CSTl);
53 CHECK_EXPR ((double)i1, FLOAT_EXPR);
54 CHECK_EXPR ((float)i1, FLOAT_EXPRf);
55 CHECK_EXPR ((long double)i1, FLOAT_EXPRl);
56 CHECK_EXPR (__builtin_fabs(i1), ABS_EXPR);
57 CHECK_EXPR (__builtin_fabsf(i1), ABS_EXPRf);
58 CHECK_EXPR (__builtin_fabsl(i1), ABS_EXPRl);
59 CHECK_EXPR (((void)i1,(double)i2), COMPOUND_EXPR);
60 CHECK_EXPR ((double)i1+i2, PLUS_EXPR);
61 CHECK_EXPR ((double)i1-i2, MINUS_EXPR);
62 CHECK_EXPR ((double)i1*i2, MULT_EXPR);
65 int main (void)
67 test (1, 2);
68 return 0;