summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/overflow-add-5.c
blob: 905a60a73b392c7d26cc5c8560989dc29a271eb0 (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
/* { dg-do run } */
/* { dg-options "-fsanitize=signed-integer-overflow" } */

int __attribute__ ((noinline))
foo (int i, int j)
{
  return (i + j) - (i | j);
}

/* { dg-output "signed integer overflow: 2147483647 \\+ 1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 2147483647 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */

int __attribute__ ((noinline))
bar (int i, int j)
{
  return (i + j) - (i & j);
}

/* { dg-output "\[^\n\r]*signed integer overflow: 2147483647 \\+ 1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'" } */

int
main ()
{
  int r = foo (__INT_MAX__, 1);
  asm volatile ("" : "+g" (r));
  r = bar (__INT_MAX__, 1);
  asm volatile ("" : "+g" (r));
  return 0;
}