2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / gcc.dg / split-1.c
blob91fcb4aa55ec5f2778e872be4bc2ecae3cf5f89d
1 /* This test needs to use setrlimit to set the stack size, so it can
2 only run on Unix. */
3 /* { dg-do run { target *-*-linux* *-*-gnu* *-*-solaris* *-*-darwin* } } */
4 /* { dg-require-effective-target split_stack } */
5 /* { dg-options "-fsplit-stack" } */
7 #include <stdlib.h>
8 #include <sys/types.h>
9 #include <sys/resource.h>
11 /* Use a noinline function to ensure that the buffer is not removed
12 from the stack. */
13 static void use_buffer (char *buf) __attribute__ ((noinline));
14 static void
15 use_buffer (char *buf)
17 buf[0] = '\0';
20 /* Each recursive call uses 10,000 bytes. We call it 1000 times,
21 using a total of 10,000,000 bytes. If -fsplit-stack is not
22 working, that will overflow our stack limit. */
24 static void
25 down (int i)
27 char buf[10000];
29 if (i > 0)
31 use_buffer (buf);
32 down (i - 1);
36 int
37 main (void)
39 struct rlimit r;
41 /* We set a stack limit because we are usually invoked via make, and
42 make sets the stack limit to be as large as possible. */
43 r.rlim_cur = 8192 * 1024;
44 r.rlim_max = 8192 * 1024;
45 if (setrlimit (RLIMIT_STACK, &r) != 0)
46 abort ();
47 down (1000);
48 return 0;