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

     1  /* PR c/3711
     2     This testcase ICEd on IA-32 at -O0 and was miscompiled otherwise,
     3     because std_expand_builtin_va_arg didn't handle variable size types.  */
     4  /* { dg-require-effective-target alloca } */
     5  
     6  #include <stdarg.h>
     7  
     8  extern void abort (void);
     9  extern void exit (int);
    10  
    11  void bar (int c)
    12  {
    13    static int d = '0';
    14  
    15    if (c != d++)
    16      abort ();
    17    if (c < '0' || c > '9')
    18      abort ();
    19  }
    20  
    21  void foo (int size, ...)
    22  {
    23    struct
    24    {
    25      char x[size];
    26    } d;
    27    va_list ap;
    28    int i;
    29  
    30    va_start (ap, size);
    31    d = va_arg (ap, typeof (d));
    32    for (i = 0; i < size; i++)
    33      bar (d.x[i]);
    34    d = va_arg (ap, typeof (d));
    35    for (i = 0; i < size; i++)
    36      bar (d.x[i]);
    37    va_end (ap);
    38  }
    39  
    40  int main (void)
    41  {
    42    int z = 5;
    43    struct { char a[z]; } x, y;
    44            
    45    x.a[0] = '0';
    46    x.a[1] = '1';
    47    x.a[2] = '2';
    48    x.a[3] = '3';
    49    x.a[4] = '4';
    50    y.a[0] = '5';
    51    y.a[1] = '6';
    52    y.a[2] = '7';
    53    y.a[3] = '8';
    54    y.a[4] = '9';
    55    foo (z, x, y);
    56    exit (0);
    57  }