1 /* The goal here is to ensure that dynamic allocations via vlas or
2 alloca calls receive probing.
3
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?. */
8
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 } */
12
13 __attribute__((noinline, noclone)) void
14 foo (char *p)
15 {
16 asm volatile ("" : : "r" (p) : "memory");
17 }
18
19 /* Simple VLA, no other locals. */
20 __attribute__((noinline, noclone)) void
21 f0 (int x)
22 {
23 char vla[x];
24 foo (vla);
25 }
26
27 /* Simple VLA, small local frame. */
28 __attribute__((noinline, noclone)) void
29 f1 (int x)
30 {
31 char locals[128];
32 char vla[x];
33 foo (vla);
34 }
35
36 /* Small constant alloca, no other locals. */
37 __attribute__((noinline, noclone)) void
38 f2 (int x)
39 {
40 char *vla = __builtin_alloca (128);
41 foo (vla);
42 }
43
44 /* Big constant alloca, small local frame. */
45 __attribute__((noinline, noclone)) void
46 f3 (int x)
47 {
48 char locals[128];
49 char *vla = __builtin_alloca (16384);
50 foo (vla);
51 }
52
53 /* Big constant alloca, small local frame. */
54 __attribute__((noinline, noclone)) void
55 f3a (int x)
56 {
57 char locals[128];
58 char *vla = __builtin_alloca (32768);
59 foo (vla);
60 }
61
62 /* Nonconstant alloca, no other locals. */
63 __attribute__((noinline, noclone)) void
64 f4 (int x)
65 {
66 char *vla = __builtin_alloca (x);
67 foo (vla);
68 }
69
70 /* Nonconstant alloca, small local frame. */
71 __attribute__((noinline, noclone)) void
72 f5 (int x)
73 {
74 char locals[128];
75 char *vla = __builtin_alloca (x);
76 foo (vla);
77 }
78
79 /* { dg-final { scan-rtl-dump-times "allocation and probing residuals" 7 "expand" } } */
80
81
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 } } } } */