aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/pr108789.c
blob: 32ee19be1c40554b443c470ff60f8a9a6295ef37 (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
/* PR middle-end/108789 */

int
add (unsigned *r, const unsigned *a, const unsigned *b)
{
  return __builtin_add_overflow (*a, *b, r);
}

int
mul (unsigned *r, const unsigned *a, const unsigned *b)
{
  return __builtin_mul_overflow (*a, *b, r);
}

int
main ()
{
  unsigned x;

  /* 1073741824U + 1073741824U should not overflow.  */
  x = (__INT_MAX__ + 1U) / 2;
  if (add (&x, &x, &x))
    __builtin_abort ();

  /* 256U * 256U should not overflow */
  x = 1U << (sizeof (int) * __CHAR_BIT__ / 4);
  if (mul (&x, &x, &x))
    __builtin_abort ();

  /* 2147483648U + 2147483648U should overflow */
  x = __INT_MAX__ + 1U;
  if (!add (&x, &x, &x))
    __builtin_abort ();

  /* 65536U * 65536U should overflow */
  x = 1U << (sizeof (int) * __CHAR_BIT__ / 2);
  if (!mul (&x, &x, &x))
    __builtin_abort ();
}