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

     1  /* Problem originally visible on ia64.
     2  
     3     There is a partial redundancy of "in + 1" that makes GCSE want to
     4     transform the final while loop to 
     5  
     6       p = in + 1;
     7       tmp = p;
     8       ...
     9       goto start;
    10     top:
    11       tmp = tmp + 1;
    12     start:
    13       in = tmp;
    14       if (in < p) goto top;
    15  
    16     We miscalculate the number of loop iterations as (p - tmp) = 0
    17     instead of (p - in) = 1, which results in overflow in the doloop
    18     optimization.  */
    19  
    20  static const char *
    21  test (const char *in, char *out)
    22  {
    23    while (1)
    24      {
    25        if (*in == 'a')
    26  	{
    27  	  const char *p = in + 1;
    28  	  while (*p == 'x')
    29  	    ++p;
    30  	  if (*p == 'b')
    31  	    return p;
    32  	  while (in < p)
    33  	    *out++ = *in++;
    34  	}
    35      }
    36  }
    37  
    38  int main ()
    39  {
    40    char out[4];
    41    test ("aab", out);
    42    return 0;
    43  }