2 /* { dg-options "-O2 -fdump-tree-optimized -g" } */
4 /* SUB_OVERFLOW should be folded into unsigned subtraction,
5 because ovf is never used. */
6 __attribute__((noinline
, noclone
)) int
7 fn1 (int x
, unsigned int y
)
10 int ovf
= __builtin_sub_overflow (x
, y
, &res
);
17 /* MUL_OVERFLOW should be folded into unsigned multiplication,
18 because ovf is never used. */
19 __attribute__((noinline
, noclone
)) int
20 fn2 (signed char x
, long int y
)
23 int ovf
= __builtin_mul_overflow (x
, y
, &res
);
30 #if __SIZEOF_INT__ > __SIZEOF_SHORT__ && __SIZEOF_INT__ > 1
31 /* ADD_OVERFLOW should be folded into unsigned addition,
32 because it never overflows. */
33 __attribute__((noinline
, noclone
)) int
34 fn3 (signed char x
, unsigned short y
, int *ovf
)
37 *ovf
= __builtin_add_overflow (x
, y
, &res
);
42 /* MUL_OVERFLOW should be folded into unsigned multiplication,
43 because it never overflows. */
44 __attribute__((noinline
, noclone
)) long int
45 fn4 (long int x
, long int y
, int *ovf
)
49 y
= (y
& 65535) - 32768;
50 *ovf
= __builtin_mul_overflow (x
, y
, &res
);
54 #if __SIZEOF_INT__ > 1
55 /* MUL_OVERFLOW should be folded into unsigned multiplication,
56 because it always overflows. */
57 __attribute__((noinline
, noclone
)) signed char
58 fn5 (long int x
, long int y
, int *ovf
)
61 x
= (x
& 63) + (__SCHAR_MAX__
/ 4);
63 *ovf
= __builtin_mul_overflow (x
, y
, &res
);
68 /* ADD_OVERFLOW should be folded into unsigned additrion,
69 because it never overflows. */
70 __attribute__((noinline
, noclone
)) unsigned char
71 fn6 (unsigned char x
, unsigned char y
, int *ovf
)
74 x
= (x
& 63) + ((unsigned char) ~0 - 66);
76 *ovf
= __builtin_add_overflow (x
, y
, &res
);
80 /* ADD_OVERFLOW should be folded into unsigned additrion,
81 because it always overflows. */
82 __attribute__((noinline
, noclone
)) unsigned char
83 fn7 (unsigned char x
, unsigned char y
, int *ovf
)
86 x
= (x
& 15) + ((unsigned char) ~0 - 15);
88 *ovf
= __builtin_add_overflow (x
, y
, &res
);
96 if (fn1 (-10, __INT_MAX__
) != (int) (-10U - __INT_MAX__
)
98 || fn2 (32, 16383) != (short int) 524256ULL)
100 #if __SIZEOF_INT__ > __SIZEOF_SHORT__ && __SIZEOF_INT__ > 1
101 if (fn3 (__SCHAR_MAX__
, (unsigned short) ~0, &ovf
) != (int) (__SCHAR_MAX__
+ (unsigned short) ~0)
103 || fn3 (-__SCHAR_MAX__
- 1, 0, &ovf
) != (int) (-__SCHAR_MAX__
- 1)
107 if (fn4 (65535, 0, &ovf
) != 65535L * -32768 || ovf
)
109 #if __SIZEOF_INT__ > 1
110 if (fn5 (0, 0, &ovf
) != (signed char) (__SCHAR_MAX__
/ 4 * 5)
112 || fn5 (63, 3, &ovf
) != (signed char) ((__SCHAR_MAX__
/ 4 + 63) * 8)
116 if (fn6 (0, 0, &ovf
) != (unsigned char) ~0 - 66
118 || fn6 (63, 3, &ovf
) != (unsigned char) ~0
121 if (fn7 (0, 0, &ovf
) != 0
123 || fn7 (63, 3, &ovf
) != 18
129 /* { dg-final { scan-tree-dump-not "ADD_OVERFLOW" "optimized" } } */
130 /* { dg-final { scan-tree-dump-not "SUB_OVERFLOW" "optimized" } } */
131 /* { dg-final { scan-tree-dump-not "MUL_OVERFLOW" "optimized" } } */