[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

Nick Desaulniers via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 29 11:06:40 PST 2024


================
@@ -173,6 +167,13 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
               diag::warn_target_unsupported_branch_protection_attribute)
               << Attr.CPU;
       }
+    } else if (CGM.getTarget().isBranchProtectionSupportedArch(
+                   CGM.getTarget().getTargetOpts().CPU)) {
+      TargetInfo::BranchProtectionInfo BPI(CGM.getLangOpts());
+      if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None)
+        Fn->addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
+      if (BPI.BranchTargetEnforcement)
+        Fn->addFnAttr("branch-target-enforcement", "true");
----------------
nickdesaulniers wrote:

> Consider adding a `getBranchTargetEnforcementStr` method to `BranchProtectionInfo` to encapsulate this.

Looks like that might also be useful in the child commit https://github.com/llvm/llvm-project/pull/83277 ?

https://github.com/llvm/llvm-project/pull/82819


More information about the cfe-commits mailing list