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