aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/pr85095.c
blob: abcb1785a16e4500671da8bdc17b049929f94c8a (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
40
41
42
43
44
45
46
47
48
49
50
51
52
/* PR target/85095 */

__attribute__((noinline, noclone)) unsigned long
f1 (unsigned long a, unsigned long b)
{
  unsigned long i = __builtin_add_overflow (a, b, &a);
  return a + i;
}

__attribute__((noinline, noclone)) unsigned long
f2 (unsigned long a, unsigned long b)
{
  unsigned long i = __builtin_add_overflow (a, b, &a);
  return a - i;
}

__attribute__((noinline, noclone)) unsigned long
f3 (unsigned int a, unsigned int b)
{
  unsigned int i = __builtin_add_overflow (a, b, &a);
  return a + i;
}

__attribute__((noinline, noclone)) unsigned long
f4 (unsigned int a, unsigned int b)
{
  unsigned int i = __builtin_add_overflow (a, b, &a);
  return a - i;
}

int
main ()
{
  if (f1 (16UL, -18UL) != -2UL
      || f1 (16UL, -17UL) != -1UL
      || f1 (16UL, -16UL) != 1UL
      || f1 (16UL, -15UL) != 2UL
      || f2 (24UL, -26UL) != -2UL
      || f2 (24UL, -25UL) != -1UL
      || f2 (24UL, -24UL) != -1UL
      || f2 (24UL, -23UL) != 0UL
      || f3 (32U, -34U) != -2U
      || f3 (32U, -33U) != -1U
      || f3 (32U, -32U) != 1U
      || f3 (32U, -31U) != 2U
      || f4 (35U, -37U) != -2U
      || f4 (35U, -36U) != -1U
      || f4 (35U, -35U) != -1U
      || f4 (35U, -34U) != 0U)
    __builtin_abort ();
  return 0;
}