modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/20040409-3w.c (about) 1 /* { dg-additional-options "-fwrapv" } */ 2 3 #include <limits.h> 4 5 extern void abort (); 6 7 int test2(int x) 8 { 9 return ~(x + INT_MIN); 10 } 11 12 int test3(int x) 13 { 14 return ~(x - INT_MIN); 15 } 16 17 int test5(int x) 18 { 19 int y = INT_MIN; 20 return ~(x + y); 21 } 22 23 int test6(int x) 24 { 25 int y = INT_MIN; 26 return ~(x - y); 27 } 28 29 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 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