1 /* { dg-do run } */
2 /* { dg-require-effective-target split_stack } */
3 /* { dg-options "-fsplit-stack -O2" } */
4 /* { dg-options "-fsplit-stack -O2 -mno-accumulate-outgoing-args" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
5 
6 /* A case that used to fail on 32-bit x86 when optimizing and not
7    using -maccumulate-args.  The stack adjustment of the alloca got
8    mixed up with the arguments pushed on the stack to the function
9    before the call of alloca.  */
10 
11 #include <stdlib.h>
12 
13 typedef struct { const char* s; int l; } s;
14 
15 typedef unsigned long long align16 __attribute__ ((aligned(16)));
16 
17 s gobats (const void *, int) __attribute__ ((noinline));
18 
19 s
gobats(const void * p,int l)20 gobats (const void* p __attribute__ ((unused)),
21 	int l __attribute__ ((unused)))
22 {
23   s v;
24   v.s = 0;
25   v.l = 0;
26   return v;
27 }
28 
29 void check_aligned (void *p) __attribute__ ((noinline));
30 
31 void
check_aligned(void * p)32 check_aligned (void *p)
33 {
34   if (((__SIZE_TYPE__) p & 0xf) != 0)
35     abort ();
36 }
37 
38 void gap (void *) __attribute__ ((noinline));
39 
gap(void * p)40 void gap (void *p)
41 {
42   align16 a;
43   check_aligned (&a);
44 }
45 
46 int
main(int argc,char ** argv)47 main (int argc, char **argv)
48 {
49   s *space;
50   gobats(0, 16);
51   space = (s *) alloca(sizeof(s) + 1);
52   *space = (s){0, 16};
53   gap(space);
54   return 0;
55 }
56