Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/pr108789.c

raw
1 /* PR middle-end/108789 */
2
3 int
4 add (unsigned *r, const unsigned *a, const unsigned *b)
5 {
6 return __builtin_add_overflow (*a, *b, r);
7 }
8
9 int
10 mul (unsigned *r, const unsigned *a, const unsigned *b)
11 {
12 return __builtin_mul_overflow (*a, *b, r);
13 }
14
15 int
16 main ()
17 {
18 unsigned x;
19
20 /* 1073741824U + 1073741824U should not overflow. */
21 x = (__INT_MAX__ + 1U) / 2;
22 if (add (&x, &x, &x))
23 __builtin_abort ();
24
25 /* 256U * 256U should not overflow */
26 x = 1U << (sizeof (int) * __CHAR_BIT__ / 4);
27 if (mul (&x, &x, &x))
28 __builtin_abort ();
29
30 /* 2147483648U + 2147483648U should overflow */
31 x = __INT_MAX__ + 1U;
32 if (!add (&x, &x, &x))
33 __builtin_abort ();
34
35 /* 65536U * 65536U should overflow */
36 x = 1U << (sizeof (int) * __CHAR_BIT__ / 2);
37 if (!mul (&x, &x, &x))
38 __builtin_abort ();
39 }