xref: /llvm-project/clang/test/CodeGen/stack-clash-protection.c (revision c5de4dd1eab00df76c1a68c5f397304ceacb71f2)
1 // Check the correct function attributes are generated
2 // RUN: %clang_cc1 -triple x86_64-linux -O0 -emit-llvm -o- %s -fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
3 // RUN: %clang_cc1 -triple s390x-linux-gnu -O0 -emit-llvm -o- %s -fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
4 // RUN: %clang_cc1 -triple powerpc64le-linux-gnu -O0 -emit-llvm -o- %s -fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
5 // RUN: %clang_cc1 -triple powerpc64-linux-gnu -O0 -emit-llvm -o- %s -fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
6 // RUN: %clang_cc1 -triple aarch64-linux-gnu -O0 -emit-llvm -o- %s -fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
7 
8 // CHECK: define{{.*}} void @large_stack() #[[A:.*]] {
large_stack(void)9 void large_stack(void) {
10   volatile int stack[20000], i;
11   for (i = 0; i < sizeof(stack) / sizeof(int); ++i)
12     stack[i] = i;
13 }
14 
15 // CHECK: define{{.*}} void @vla({{.*}}) #[[A]] {
vla(int n)16 void vla(int n) {
17   volatile int vla[n];
18   __builtin_memset(&vla[0], 0, 1);
19 }
20 
21 // CHECK: define{{.*}} void @builtin_alloca({{.*}}) #[[A]] {
builtin_alloca(int n)22 void builtin_alloca(int n) {
23   volatile void *mem = __builtin_alloca(n);
24 }
25 
26 // CHECK: attributes #[[A]] = {{.*}}"probe-stack"="inline-asm" {{.*}}"stack-probe-size"="8192"
27 
28 // CHECK: !{i32 4, !"probe-stack", !"inline-asm"}
29 // CHECK: !{i32 8, !"stack-probe-size", i32 8192}
30