1 /* { dg-additional-options "-fwrapv" } */
2 
3 #include <limits.h>
4 
5 extern void abort ();
6 
test2(int x)7 int test2(int x)
8 {
9   return ~(x + INT_MIN);
10 }
11 
test3(int x)12 int test3(int x)
13 {
14   return ~(x - INT_MIN);
15 }
16 
test5(int x)17 int test5(int x)
18 {
19   int y = INT_MIN;
20   return ~(x + y);
21 }
22 
test6(int x)23 int test6(int x)
24 {
25   int y = INT_MIN;
26   return ~(x - y);
27 }
28 
29 
test(int a,int b)30 void test(int a, int b)
31 {
32   if (test2(a) != b)
33     abort();
34   if (test3(a) != b)
35     abort();
36   if (test5(a) != b)
37     abort();
38   if (test6(a) != b)
39     abort();
40 }
41 
42 
main()43 int main()
44 {
45 #if INT_MAX == 2147483647
46   test(0x00000000,0x7fffffff);
47   test(0x80000000,0xffffffff);
48   test(0x12345678,0x6dcba987);
49   test(0x92345678,0xedcba987);
50   test(0x7fffffff,0x00000000);
51   test(0xffffffff,0x80000000);
52 #endif
53 
54 #if INT_MAX == 32767
55   test(0x0000,0x7fff);
56   test(0x8000,0xffff);
57   test(0x1234,0x6dcb);
58   test(0x9234,0xedcb);
59   test(0x7fff,0x0000);
60   test(0xffff,0x8000);
61 #endif
62 
63   return 0;
64 }
65 
66