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 
30 
test(int a,int b)31 void test(int a, int b)
32 {
33   if (test2(a) != b)
34     abort();
35   if (test3(a) != b)
36     abort();
37   if (test5(a) != b)
38     abort();
39   if (test6(a) != b)
40     abort();
41 }
42 
43 
main()44 int main()
45 {
46 #if INT_MAX == 2147483647
47   test(0x00000000,0x80000000);
48   test(0x80000000,0x00000000);
49   test(0x12345678,0x92345678);
50   test(0x92345678,0x12345678);
51   test(0x7fffffff,0xffffffff);
52   test(0xffffffff,0x7fffffff);
53 #endif
54 
55 #if INT_MAX == 32767
56   test(0x0000,0x8000);
57   test(0x8000,0x0000);
58   test(0x1234,0x9234);
59   test(0x9234,0x1234);
60   test(0x7fff,0xffff);
61   test(0xffff,0x7fff);
62 #endif
63 
64   return 0;
65 }
66