(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
ubsan/
overflow-div-2.c
       1  /* { dg-do run { target *-*-linux* *-*-gnu* } } */
       2  /* { dg-shouldfail "ubsan" } */
       3  /* { dg-options "-fsanitize=undefined -fno-sanitize-recover=integer-divide-by-zero" } */
       4  
       5  #include <limits.h>
       6  #include <signal.h>
       7  #include <stdlib.h>
       8  
       9  int cnt;
      10  
      11  __attribute__((noipa)) int
      12  foo (int x, int y)
      13  {
      14    return x / y;
      15  }
      16  
      17  void
      18  handler (int i)
      19  {
      20    if (cnt++ != 0)
      21      exit (0);
      22    volatile int b = foo (5, 0);
      23    exit (0);
      24  }
      25  
      26  int
      27  main (void)
      28  {
      29    struct sigaction s;
      30    sigemptyset (&s.sa_mask);
      31    s.sa_handler = handler;
      32    s.sa_flags = 0;
      33    sigaction (SIGFPE, &s, NULL);
      34    volatile int a = foo (INT_MIN, -1);
      35    cnt++;
      36    volatile int b = foo (5, 0);
      37    return 0;
      38  }
      39  
      40  /* { dg-output "division of -2147483648 by -1 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
      41  /* { dg-output "\[^\n\r]*division by zero\[^\n\r]*" } */