(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
pr78468.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target alloca } */
       3  /* { dg-options "-O2 -fno-inline" } */
       4  
       5  /* Test that targets correctly round the size of the outgoing arguments
       6     to a multiple of STACK_BOUNDARY.  There is a serious alignment bug if
       7     aligned alloca does not get aligned!  */
       8  
       9  __extension__ typedef __UINTPTR_TYPE__ uintptr_t;
      10  extern void abort (void);
      11  
      12  volatile int xx;
      13  volatile int x = 16;
      14  
      15  void
      16  t1 (int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7,
      17      void *p, int align)
      18  {
      19    xx = x0 + x1 + x2 + x3 + x4 + x4 + x6 + x7;
      20    if ((int)(uintptr_t)p & (align-1))
      21      abort ();
      22  }
      23  
      24  void
      25  t2 (int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7,
      26      void *p, int align, int dummy)
      27  {
      28    xx = x0 + x1 + x2 + x3 + x4 + x4 + x6 + x7;
      29    if ((int)(uintptr_t)p & (align-1))
      30      abort ();
      31  }
      32  
      33  void
      34  t1_a4 (int size)
      35  {
      36    void *p = __builtin_alloca_with_align (size, 32);
      37    t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 4);
      38  }
      39  
      40  void
      41  t2_a4 (int size)
      42  {
      43    void *p = __builtin_alloca_with_align (size, 32);
      44    t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 4, 0);
      45  }
      46  
      47  void
      48  t1_a8 (int size)
      49  {
      50    void *p = __builtin_alloca_with_align (size, 64);
      51    t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 8);
      52  }
      53  
      54  void
      55  t2_a8 (int size)
      56  {
      57    void *p = __builtin_alloca_with_align (size, 64);
      58    t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 8, 0);
      59  }
      60  
      61  void
      62  t1_a16 (int size)
      63  {
      64    void *p = __builtin_alloca_with_align (size, 128);
      65    t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 16);
      66  }
      67  
      68  void
      69  t2_a16 (int size)
      70  {
      71    void *p = __builtin_alloca_with_align (size, 128);
      72    t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 16, 0);
      73  }
      74  
      75  void
      76  t1_a32 (int size)
      77  {
      78    void *p = __builtin_alloca_with_align (size, 256);
      79    t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 32);
      80  }
      81  
      82  void
      83  t2_a32 (int size)
      84  {
      85    void *p = __builtin_alloca_with_align (size, 256);
      86    t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 32, 0);
      87  }
      88  
      89  
      90  int
      91  main ()
      92  {
      93    t1_a4 (x);
      94    t2_a4 (x);
      95    t1_a8 (x);
      96    t2_a8 (x);
      97    t1_a16 (x);
      98    t2_a16 (x);
      99    t1_a32 (x);
     100    t2_a32 (x);
     101    return 0;
     102  }