xref: /llvm-project/clang/test/CodeGen/stack-protector.c (revision 39db5e1ed87363a9ffea81e53520b542201b3262)
1 // RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 0 | FileCheck -check-prefix=DEF -check-prefix=NOSSP %s
2 // RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 1 | FileCheck -check-prefix=DEF -check-prefix=SSP %s
3 // RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 2 | FileCheck -check-prefix=DEF -check-prefix=SSPSTRONG %s
4 // RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 3 | FileCheck -check-prefix=DEF -check-prefix=SSPREQ %s
5 
6 // RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-NOSSP %s
7 // RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 0 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-NOSSP %s
8 // RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 1 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSP %s
9 // RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 2 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSPSTRONG %s
10 // RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 3 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSPREQ %s
11 
12 typedef __SIZE_TYPE__ size_t;
13 
14 int printf(const char * _Format, ...);
15 size_t strlen(const char *s);
16 char *strcpy(char *s1, const char *s2);
17 
18 // DEF: define {{.*}}void @test1(ptr noundef %msg) #[[A:.*]] {
test1(const char * msg)19 void test1(const char *msg) {
20   char a[strlen(msg) + 1];
21   strcpy(a, msg);
22   printf("%s\n", a);
23 }
24 
25 // DEF: define {{.*}}void @test2(ptr noundef %msg) #[[B:.*]] {
26 __attribute__((no_stack_protector))
test2(const char * msg)27 void test2(const char *msg) {
28   char a[strlen(msg) + 1];
29   strcpy(a, msg);
30   printf("%s\n", a);
31 }
32 
33 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
34 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
35 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
36 // SSPREQ: attributes #[[A]] = {{.*}} sspreq
37 
38 // SAFESTACK-NOSSP: attributes #[[A]] = {{.*}} safestack
39 // SAFESTACK-NOSSP-NOT: ssp
40 
41 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
42 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
43 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
44 
45 // NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
46 // SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
47 // SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
48 // SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
49 
50 // SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
51 // SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
52 // SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
53 // SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
54 // SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
55 // SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
56