1 // Check that we correctly set or did not set the attribute for each function.
2 // RUN: %clang_cc1 -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK1
3 // RUN: %clang_cc1 -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK2
4 
5 // Check that we correctly set or did not set the attribute on each function despite the
6 // -mspeculative-load-hardening flag.
7 // RUN: %clang_cc1 -mspeculative-load-hardening -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK3
8 // RUN: %clang_cc1 -mspeculative-load-hardening -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK4
9 
10 
11 // Check that we correctly set or did not set the attribute on each function despite the
12 // -mno-speculative-load-hardening flag.
13 // RUN: %clang -mno-speculative-load-hardening -S -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK5
14 // RUN: %clang -mno-speculative-load-hardening -S -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK6
15 
16 
17 [[clang::speculative_load_hardening]]
test1()18 int test1() {
19   return 42;
20 }
21 
test2()22 int __attribute__((speculative_load_hardening)) test2() {
23   return 42;
24 }
25 
26 [[clang::no_speculative_load_hardening]]
test3()27 int test3() {
28   return 42;
29 }
30 
test4()31 int __attribute__((no_speculative_load_hardening)) test4() {
32   return 42;
33 }
34 // CHECK1: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]]
35 // CHECK1: @{{.*}}test3{{.*}}[[NOSLH:#[0-9]+]]
36 // CHECK1: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
37 // CHECK1-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} }
38 
39 // CHECK2: @{{.*}}test2{{.*}}[[SLH:#[0-9]+]]
40 // CHECK2: @{{.*}}test4{{.*}}[[NOSLH:#[0-9]+]]
41 // CHECK2: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
42 // CHECK2-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} }
43 
44 // CHECK3: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]]
45 // CHECK3: @{{.*}}test3{{.*}}[[NOSLH:#[0-9]+]]
46 // CHECK3: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
47 // CHECK3-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} }
48 
49 // CHECK4: @{{.*}}test2{{.*}}[[SLH:#[0-9]+]]
50 // CHECK4: @{{.*}}test4{{.*}}[[NOSLH:#[0-9]+]]
51 // CHECK4: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
52 // CHECK4-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} }
53 
54 // CHECK5: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]]
55 // CHECK5: @{{.*}}test3{{.*}}[[NOSLH:#[0-9]+]]
56 // CHECK5: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
57 // CHECK5-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} }
58 
59 // CHECK6: @{{.*}}test2{{.*}}[[SLH:#[0-9]+]]
60 // CHECK6: @{{.*}}test4{{.*}}[[NOSLH:#[0-9]+]]
61 // CHECK6: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} }
62 // CHECK6-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} }
63