(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
tree-ssa/
pr84969.c
       1  /* { dg-do run } */
       2  /* { dg-options "-O2 -ftree-loop-distribute-patterns" } */
       3  
       4  static void
       5  __attribute__((noipa, noinline))
       6  foo (char **values, int ndim, char *needquotes, int *dims)
       7  {
       8    int i;
       9    int j = 0;
      10    int k = 0;
      11    char *retval = (char *)__builtin_malloc(1000); 
      12    char *p = retval;
      13    char *tmp;
      14  
      15    int indx[111];
      16  
      17  #define APPENDSTR(str)	(__builtin_strcpy(p, (str)), p += __builtin_strlen(p))
      18  #define APPENDCHAR(ch)	(*p++ = (ch), *p = '\0')
      19  
      20  	APPENDCHAR('{');
      21  	for (i = 0; i < ndim; i++)
      22  		indx[i] = 0;
      23  	do
      24  	{
      25  		for (i = j; i < ndim - 1; i++)
      26  			APPENDCHAR('{');
      27  
      28  			APPENDSTR(values[k]);
      29  		k++;
      30  
      31  		for (i = ndim - 1; i >= 0; i--)
      32  		{
      33  			indx[i] = (indx[i] + 1) % dims[i];
      34  			if (indx[i])
      35  			{
      36  				APPENDCHAR(',');
      37  				break;
      38  			}
      39  			else
      40  				APPENDCHAR('}');
      41  		}
      42  		j = i;
      43  	} while (j != -1);
      44  
      45  	if (__builtin_strcmp (retval, "{{{0,1},{2,3}}}") != 0)
      46  	  __builtin_abort ();
      47  }
      48  
      49  int main()
      50  {
      51    char* array[4] = {"0", "1", "2", "3"};
      52    char f[] = {0, 0, 0, 0, 0, 0, 0, 0};
      53    int dims[] = {1, 2, 2};
      54    foo (array, 3, f, dims);
      55  
      56    return 0;
      57  }