modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/20040409-2w.c (about)

     1  /* { dg-additional-options "-fwrapv" } */
     2  
     3  #include <limits.h>
     4  
     5  extern void abort ();
     6  
     7  int test3(int x)
     8  {
     9    return (x + INT_MIN) ^ 0x1234;
    10  }
    11  
    12  int test4(int x)
    13  {
    14    return (x ^ 0x1234) + INT_MIN;
    15  }
    16  
    17  int test5(int x)
    18  {
    19    return (x - INT_MIN) ^ 0x1234;
    20  }
    21  
    22  int test6(int x)
    23  {
    24    return (x ^ 0x1234) - INT_MIN;
    25  }
    26  
    27  int test9(int x)
    28  {
    29    int y = INT_MIN;
    30    int z = 0x1234;
    31    return (x + y) ^ z;
    32  }
    33  
    34  int test10(int x)
    35  {
    36    int y = 0x1234;
    37    int z = INT_MIN;
    38    return (x ^ y) + z;
    39  }
    40  
    41  int test11(int x)
    42  {
    43    int y = INT_MIN;
    44    int z = 0x1234;
    45    return (x - y) ^ z;
    46  }
    47  
    48  int test12(int x)
    49  {
    50    int y = 0x1234;
    51    int z = INT_MIN;
    52    return (x ^ y) - z;
    53  }
    54  
    55  
    56  void test(int a, int b)
    57  {
    58    if (test3(a) != b)
    59      abort();
    60    if (test4(a) != b)
    61      abort();
    62    if (test5(a) != b)
    63      abort();
    64    if (test6(a) != b)
    65      abort();
    66    if (test9(a) != b)
    67      abort();
    68    if (test10(a) != b)
    69      abort();
    70    if (test11(a) != b)
    71      abort();
    72    if (test12(a) != b)
    73      abort();
    74  }
    75  
    76  
    77  int main()
    78  {
    79  #if INT_MAX == 2147483647
    80    test(0x00000000,0x80001234);
    81    test(0x00001234,0x80000000);
    82    test(0x80000000,0x00001234);
    83    test(0x80001234,0x00000000);
    84    test(0x7fffffff,0xffffedcb);
    85    test(0xffffffff,0x7fffedcb);
    86  #endif
    87  
    88  #if INT_MAX == 32767
    89    test(0x0000,0x9234);
    90    test(0x1234,0x8000);
    91    test(0x8000,0x1234);
    92    test(0x9234,0x0000);
    93    test(0x7fff,0xedcb);
    94    test(0xffff,0x6dcb);
    95  #endif
    96  
    97    return 0;
    98  }
    99