summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/overflow-mul-2.c
blob: 54b382a418066fd9831eb6235298185670de0a23 (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
/* { dg-do run } */
/* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */

#define INT_MAX __INT_MAX__
#define LONG_MAX __LONG_MAX__

int
main (void)
{
  volatile int j = INT_MAX;
  volatile int i = 2;
  volatile int k = j * i;
  k = i * j;

  volatile long int m = LONG_MAX;
  volatile long int n = 2;
  volatile long int o = m * n;
  o = n * m;

  return 0;
}

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