(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
ubsan/
overflow-negate-1.c
       1  /* { dg-do run } */
       2  /* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */
       3  
       4  #define INT_MIN (-__INT_MAX__ - 1)
       5  #define LONG_MIN (-__LONG_MAX__ - 1L)
       6  #define LLONG_MIN (-__LONG_LONG_MAX__ - 1LL)
       7  
       8  int
       9  main (void)
      10  {
      11    int e = 1, f = -1;
      12    volatile int i = INT_MIN;
      13    volatile int i2 = i & (((((((-i) + 1) - 1) + 1) - 1) + 1) - 1);
      14    i2 = -(i + e + f);
      15    i = -i;
      16  
      17    volatile long int li = LONG_MIN;
      18    volatile long int li2 = li & (((((((-li) + 1) - 1) + 1) - 1) + 1) - 1);
      19    li2 = -(li + e + f);
      20    li = -li;
      21  
      22    volatile long long int lli = LLONG_MIN;
      23    volatile long long int lli2 = lli & (((((((-lli) + 1) - 1) + 1) - 1) + 1) - 1);
      24    lli2 = -(lli + e + f);
      25    lli = -lli;
      26  
      27    return 0;
      28  }
      29  
      30  /* { dg-output "negation of -2147483648 cannot be represented in type 'int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      31  /* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      32  /* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      33  /* { dg-output "\[^\n\r]*negation of -\[^\n\r]* cannot be represented in type 'long int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      34  /* { dg-output "\[^\n\r]*negation of -\[^\n\r]* cannot be represented in type 'long int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      35  /* { dg-output "\[^\n\r]*negation of -\[^\n\r]* cannot be represented in type 'long int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      36  /* { dg-output "\[^\n\r]*negation of -9223372036854775808 cannot be represented in type 'long long int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      37  /* { dg-output "\[^\n\r]*negation of -9223372036854775808 cannot be represented in type 'long long int'\[^\n\r]*; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
      38  /* { dg-output "\[^\n\r]*negation of -9223372036854775808 cannot be represented in type 'long long int'\[^\n\r]*; cast to an unsigned type to negate this value to itself" } */