aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/overflow-div-3.c
blob: 479dffb03044a68eefefe6a55a126d522337ec81 (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
/* { dg-do run { target *-*-linux* *-*-gnu* } } */
/* { dg-shouldfail "ubsan" } */
/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=signed-integer-overflow" } */

#include <limits.h>
#include <signal.h>
#include <stdlib.h>

int cnt;

__attribute__((noipa)) int
foo (int x, int y)
{
  return x / y;
}

void
handler (int i)
{
  if (cnt++ != 0)
    exit (0);
  volatile int b = foo (INT_MIN, -1);
  exit (0);
}

int
main (void)
{
  struct sigaction s;
  sigemptyset (&s.sa_mask);
  s.sa_handler = handler;
  s.sa_flags = 0;
  sigaction (SIGFPE, &s, NULL);
  volatile int a = foo (42, 0);
  cnt++;
  volatile int b = foo (INT_MIN, -1);
  return 0;
}

/* { dg-output "division by zero\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*division of -2147483648 by -1 cannot be represented in type 'int'" } */