comparison gcc/testsuite/gcc.dg/pr85388-1.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
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 { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } } */
4 /* { dg-require-effective-target cet } */
5 /* { dg-require-effective-target split_stack } */
6 /* { dg-options "-fsplit-stack -fcf-protection" } */
7
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include <sys/resource.h>
11
12 /* Use a noinline function to ensure that the buffer is not removed
13 from the stack. */
14 static void use_buffer (char *buf) __attribute__ ((noinline));
15 static void
16 use_buffer (char *buf)
17 {
18 buf[0] = '\0';
19 }
20
21 /* Each recursive call uses 10,000 bytes. We call it 1000 times,
22 using a total of 10,000,000 bytes. If -fsplit-stack is not
23 working, that will overflow our stack limit. */
24
25 static void
26 down (int i)
27 {
28 char buf[10000];
29
30 if (i > 0)
31 {
32 use_buffer (buf);
33 down (i - 1);
34 }
35 }
36
37 int
38 main (void)
39 {
40 struct rlimit r;
41
42 /* We set a stack limit because we are usually invoked via make, and
43 make sets the stack limit to be as large as possible. */
44 r.rlim_cur = 8192 * 1024;
45 r.rlim_max = 8192 * 1024;
46 if (setrlimit (RLIMIT_STACK, &r) != 0)
47 abort ();
48 down (1000);
49 return 0;
50 }