modernc.org/cc@v1.0.1/testdata/gcc-6.3.0/gcc/testsuite/gcc.c-torture/execute/multi-ix.c (about)

     1  /* Test for a reload bug:
     2     if you have a memory reference using the indexed addressing
     3     mode, and the base address is a pseudo containing an address in the frame
     4     and this pseudo fails to get a hard register, we end up with a double PLUS,
     5     so the frame address gets reloaded.  Now, when the index got a hard register,
     6     and it dies in this insn, push_reload will consider that hard register as
     7     a reload register, and disregrad overlaps with rld[n_reloads].in .  That is
     8     fine as long as the add can be done with a single insn, but when the
     9     constant is so large that it has to be reloaded into a register first,
    10     that clobbers the index.  */
    11  
    12  #include <stdarg.h>
    13  
    14  #ifdef STACK_SIZE
    15  /* We need to be careful that we don't blow our stack.  Function f, in the
    16     worst case, needs to fit on the stack:
    17  
    18     * 40 int[CHUNK] arrays;
    19     * ~40 ints;
    20     * ~40 pointers for stdarg passing.
    21  
    22     Subtract the last two off STACK_SIZE and figure out what the maximum
    23     chunk size can be.  We make the last bit conservative to account for
    24     register saves and other processor-dependent saving.  Limit the
    25     chunk size to some sane values.  */
    26  
    27  #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
    28  #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
    29  
    30  #define CHUNK								\
    31    MIN (500, (MAX (1, (signed)(STACK_SIZE-40*sizeof(int)-256*sizeof(void *)) \
    32  		      / (signed)(40*sizeof(int)))))
    33  #else
    34  #define CHUNK 500
    35  #endif
    36  
    37  void s(int, ...);
    38  void z(int, ...);
    39  void c(int, ...);
    40  
    41  typedef int l[CHUNK];
    42  
    43  void
    44  f (int n)
    45  {
    46    int i;
    47    l a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
    48    l a10, a11, a12, a13, a14, a15, a16, a17, a18, a19;
    49    l a20, a21, a22, a23, a24, a25, a26, a27, a28, a29;
    50    l a30, a31, a32, a33, a34, a35, a36, a37, a38, a39;
    51    int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
    52    int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;
    53    int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;
    54    int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;
    55  
    56    for (i = 0; i < n; i++)
    57      {
    58        s (40, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
    59  	 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
    60           a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
    61           a30, a31, a32, a33, a34, a35, a36, a37, a38, a39);
    62        i0 = a0[0];
    63        i1 = a1[0];
    64        i2 = a2[0];
    65        i3 = a3[0];
    66        i4 = a4[0];
    67        i5 = a5[0];
    68        i6 = a6[0];
    69        i7 = a7[0];
    70        i8 = a8[0];
    71        i9 = a9[0];
    72        i10 = a10[0];
    73        i11 = a11[0];
    74        i12 = a12[0];
    75        i13 = a13[0];
    76        i14 = a14[0];
    77        i15 = a15[0];
    78        i16 = a16[0];
    79        i17 = a17[0];
    80        i18 = a18[0];
    81        i19 = a19[0];
    82        i20 = a20[0];
    83        i21 = a21[0];
    84        i22 = a22[0];
    85        i23 = a23[0];
    86        i24 = a24[0];
    87        i25 = a25[0];
    88        i26 = a26[0];
    89        i27 = a27[0];
    90        i28 = a28[0];
    91        i29 = a29[0];
    92        i30 = a30[0];
    93        i31 = a31[0];
    94        i32 = a32[0];
    95        i33 = a33[0];
    96        i34 = a34[0];
    97        i35 = a35[0];
    98        i36 = a36[0];
    99        i37 = a37[0];
   100        i38 = a38[0];
   101        i39 = a39[0];
   102        z (40, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
   103  	 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
   104           a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
   105           a30, a31, a32, a33, a34, a35, a36, a37, a38, a39);
   106        a0[i0] = i0;
   107        a1[i1] = i1;
   108        a2[i2] = i2;
   109        a3[i3] = i3;
   110        a4[i4] = i4;
   111        a5[i5] = i5;
   112        a6[i6] = i6;
   113        a7[i7] = i7;
   114        a8[i8] = i8;
   115        a9[i9] = i9;
   116        a10[i10] = i10;
   117        a11[i11] = i11;
   118        a12[i12] = i12;
   119        a13[i13] = i13;
   120        a14[i14] = i14;
   121        a15[i15] = i15;
   122        a16[i16] = i16;
   123        a17[i17] = i17;
   124        a18[i18] = i18;
   125        a19[i19] = i19;
   126        a20[i20] = i20;
   127        a21[i21] = i21;
   128        a22[i22] = i22;
   129        a23[i23] = i23;
   130        a24[i24] = i24;
   131        a25[i25] = i25;
   132        a26[i26] = i26;
   133        a27[i27] = i27;
   134        a28[i28] = i28;
   135        a29[i29] = i29;
   136        a30[i30] = i30;
   137        a31[i31] = i31;
   138        a32[i32] = i32;
   139        a33[i33] = i33;
   140        a34[i34] = i34;
   141        a35[i35] = i35;
   142        a36[i36] = i36;
   143        a37[i37] = i37;
   144        a38[i38] = i38;
   145        a39[i39] = i39;
   146        c (40, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
   147  	 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
   148           a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
   149           a30, a31, a32, a33, a34, a35, a36, a37, a38, a39);
   150      }
   151  }
   152  
   153  int
   154  main ()
   155  {
   156    /* CHUNK needs to be at least 40 to avoid stack corruption,
   157       since index variable i0 in "a[i0] = i0" equals 39.  */
   158    if (CHUNK < 40)
   159      exit (0);
   160  
   161    f (1);
   162    exit (0);
   163  }
   164  
   165  void s(int n, ...)
   166  {
   167    va_list list;
   168  
   169    va_start (list, n);
   170    while (n--)
   171      {
   172        int *a = va_arg (list, int *);
   173        a[0] = n;
   174      }
   175    va_end (list);
   176  }
   177  
   178  void z(int n, ...)
   179  {
   180    va_list list;
   181  
   182    va_start (list, n);
   183    while (n--)
   184      {
   185        int *a = va_arg (list, int *);
   186        __builtin_memset (a, 0, sizeof (l));
   187      }
   188    va_end (list);
   189  }
   190  
   191  void c(int n, ...)
   192  {
   193    va_list list;
   194  
   195    va_start (list, n);
   196    while (n--)
   197      {
   198        int *a = va_arg (list, int *);
   199        if (a[n] != n)
   200  	abort ();
   201      }
   202    va_end (list);
   203  }