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