| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable -fno-sanitize-recover=signed-integer-overflow" } */ |
| 3 |
/* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable -fno-sanitize-recover=signed-integer-overflow -Wno-volatile" { target c++ } } */ |
| 4 |
|
| 5 |
#define SCHAR_MAX __SCHAR_MAX__ |
| 6 |
#define SCHAR_MIN (-__SCHAR_MAX__ - 1) |
| 7 |
#define SHRT_MAX __SHRT_MAX__ |
| 8 |
#define SHRT_MIN (-__SHRT_MAX__ - 1) |
| 9 |
#define INT_MAX __INT_MAX__ |
| 10 |
#define INT_MIN (-__INT_MAX__ - 1) |
| 11 |
|
| 12 |
void __attribute__((noinline,noclone)) |
| 13 |
check (int i, int j) |
| 14 |
{ |
| 15 |
if (i != j) |
| 16 |
__builtin_abort (); |
| 17 |
} |
| 18 |
|
| 19 |
int |
| 20 |
main (void) |
| 21 |
{ |
| 22 |
#if __INT_MAX__ == 2147483647 |
| 23 |
/* Here, nothing should fail. */ |
| 24 |
volatile int i = -1; |
| 25 |
volatile int j = INT_MIN; |
| 26 |
volatile int k = j - i; |
| 27 |
check (k, -2147483647); |
| 28 |
k = i - j; |
| 29 |
check (k, 2147483647); |
| 30 |
j++; |
| 31 |
check (j, -2147483647); |
| 32 |
|
| 33 |
i = 1; |
| 34 |
j = INT_MAX; |
| 35 |
k = i - j; |
| 36 |
check (k, -2147483646); |
| 37 |
k = j - i; |
| 38 |
check (k, 2147483646); |
| 39 |
j--; |
| 40 |
check (k, 2147483646); |
| 41 |
#endif |
| 42 |
|
| 43 |
/* Test integer promotion. */ |
| 44 |
#if __SCHAR_MAX__ == 127 |
| 45 |
volatile signed char a = SCHAR_MIN; |
| 46 |
volatile signed char b = 1; |
| 47 |
volatile signed char c = a - b; |
| 48 |
check (c, 127); |
| 49 |
a--; |
| 50 |
check (a, 127); |
| 51 |
#endif |
| 52 |
|
| 53 |
#if __SHRT_MAX__ == 32767 |
| 54 |
volatile short d = SHRT_MIN; |
| 55 |
volatile short e = 1; |
| 56 |
volatile short f = d - e; |
| 57 |
check (f, 32767); |
| 58 |
d--; |
| 59 |
check (d, 32767); |
| 60 |
#endif |
| 61 |
return 0; |
| 62 |
} |