File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -2030,6 +2030,22 @@ static void getTrivialDefaultFunctionAttributes(
2030
2030
std::tie (Var, Value) = Attr.split (' =' );
2031
2031
FuncAttrs.addAttribute (Var, Value);
2032
2032
}
2033
+
2034
+ TargetInfo::BranchProtectionInfo BPI (LangOpts);
2035
+
2036
+ if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
2037
+ FuncAttrs.addAttribute (" sign-return-address" , BPI.getSignReturnAddrStr ());
2038
+ FuncAttrs.addAttribute (
2039
+ " sign-return-address-key" ,
2040
+ BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? " a_key"
2041
+ : " b_key" );
2042
+ }
2043
+ if (BPI.BranchTargetEnforcement )
2044
+ FuncAttrs.addAttribute (" branch-target-enforcement" , " true" );
2045
+ if (BPI.BranchProtectionPAuthLR )
2046
+ FuncAttrs.addAttribute (" branch-protection-pauth-lr" , " true" );
2047
+ if (BPI.GuardedControlStack )
2048
+ FuncAttrs.addAttribute (" guarded-control-stack" , " true" );
2033
2049
}
2034
2050
2035
2051
// / Merges `target-features` from \TargetOpts and \F, and sets the result in
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce -msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK
2
+
3
+ // Check that functions generated by clang have the correct attributes
4
+
5
+ class Example {
6
+ public:
7
+ Example ();
8
+ int fn ();
9
+ };
10
+
11
+ // Initialization of var1 causes __cxx_global_var_init and __tls_init to be generated
12
+ thread_local Example var1;
13
+ extern thread_local Example var2;
14
+ extern void fn ();
15
+
16
+ int testfn () noexcept {
17
+ // Calling fn in a noexcept function causes __clang_call_terminate to be generated
18
+ fn ();
19
+ // Use of var1 and var2 causes TLS wrapper functions to be generated
20
+ return var1.fn () + var2.fn ();
21
+ }
22
+
23
+ // CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
24
+ // CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
25
+ // CHECK: define {{.*}} @_ZTW4var1() [[ATTR1]]
26
+ // CHECK: define {{.*}} @_ZTW4var2() [[ATTR1]]
27
+ // CHECK: define {{.*}} @__tls_init() [[ATTR1]]
28
+
29
+ // CHECK: attributes [[ATTR1]] = { {{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" "sign-return-address-key"="a_key"
30
+ // CHECK: attributes [[ATTR2]] = { {{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" "sign-return-address-key"="a_key"
You can’t perform that action at this time.
0 commit comments