aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/pr56917.c
blob: cfbae97c0c69c45a6ff43b7fcf562eed5c4b3039 (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
/* PR middle-end/56917 */
/* { dg-do run } */
/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=undefined" } */

#define INT_MIN (-__INT_MAX__ - 1)
#define LONG_MIN (-__LONG_MAX__ - 1L)
#define LLONG_MIN (-__LONG_LONG_MAX__ - 1LL)

int __attribute__ ((noinline,noclone))
fn1 (unsigned int u)
{
  return (-(int) (u - 1U)) - 1;
}

long __attribute__ ((noinline,noclone))
fn2 (unsigned long int ul)
{
  return (-(long) (ul - 1UL)) - 1L;
}

long long __attribute__ ((noinline,noclone))
fn3 (unsigned long long int ull)
{
  return (-(long long) (ull - 1ULL)) - 1LL;
}

int
main (void)
{
  if (fn1 (__INT_MAX__ + 1U) != INT_MIN
      || fn2 (__LONG_MAX__ + 1UL) != LONG_MIN
      || fn3 (__LONG_LONG_MAX__ + 1ULL) != LLONG_MIN)
    __builtin_abort ();
}