PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / stack-check-3.c
blobf0bf7c71a5b26e43012e0069b7f63f828b6c315f
1 /* The goal here is to ensure that dynamic allocations via vlas or
2 alloca calls receive probing.
4 Scanning the RTL or assembly code seems like insanity here as does
5 checking for particular allocation sizes and probe offsets. For
6 now we just verify that there's an allocation + probe loop and
7 residual allocation + probe for f?. */
9 /* { dg-do compile } */
10 /* { dg-options "-O2 -fstack-clash-protection -fdump-rtl-expand -fno-optimize-sibling-calls --param stack-clash-protection-probe-interval=12 --param stack-clash-protection-guard-size=12" } */
11 /* { dg-require-effective-target supports_stack_clash_protection } */
13 __attribute__((noinline, noclone)) void
14 foo (char *p)
16 asm volatile ("" : : "r" (p) : "memory");
19 /* Simple VLA, no other locals. */
20 __attribute__((noinline, noclone)) void
21 f0 (int x)
23 char vla[x];
24 foo (vla);
27 /* Simple VLA, small local frame. */
28 __attribute__((noinline, noclone)) void
29 f1 (int x)
31 char locals[128];
32 char vla[x];
33 foo (vla);
36 /* Small constant alloca, no other locals. */
37 __attribute__((noinline, noclone)) void
38 f2 (int x)
40 char *vla = __builtin_alloca (128);
41 foo (vla);
44 /* Big constant alloca, small local frame. */
45 __attribute__((noinline, noclone)) void
46 f3 (int x)
48 char locals[128];
49 char *vla = __builtin_alloca (16384);
50 foo (vla);
53 /* Big constant alloca, small local frame. */
54 __attribute__((noinline, noclone)) void
55 f3a (int x)
57 char locals[128];
58 char *vla = __builtin_alloca (32768);
59 foo (vla);
62 /* Nonconstant alloca, no other locals. */
63 __attribute__((noinline, noclone)) void
64 f4 (int x)
66 char *vla = __builtin_alloca (x);
67 foo (vla);
70 /* Nonconstant alloca, small local frame. */
71 __attribute__((noinline, noclone)) void
72 f5 (int x)
74 char locals[128];
75 char *vla = __builtin_alloca (x);
76 foo (vla);
79 /* { dg-final { scan-rtl-dump-times "allocation and probing residuals" 7 "expand" } } */
82 /* { dg-final { scan-rtl-dump-times "allocation and probing in loop" 7 "expand" { target callee_realigns_stack } } } */
83 /* { dg-final { scan-rtl-dump-times "allocation and probing in loop" 4 "expand" { target { ! callee_realigns_stack } } } } */
84 /* { dg-final { scan-rtl-dump-times "allocation and probing in rotated loop" 1 "expand" { target { ! callee_realigns_stack } } } } */
85 /* { dg-final { scan-rtl-dump-times "allocation and probing inline" 1 "expand" { target { ! callee_realigns_stack } } } } */
86 /* { dg-final { scan-rtl-dump-times "skipped dynamic allocation and probing loop" 1 "expand" { target { ! callee_realigns_stack } } } } */