[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 19 08:42:59 PDT 2024
================
@@ -116,37 +116,22 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
if (!FD)
return;
- const auto *TA = FD->getAttr<TargetAttr>();
- if (TA == nullptr)
- return;
-
- ParsedTargetAttr Attr =
- CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
- if (Attr.BranchProtection.empty())
- return;
-
- TargetInfo::BranchProtectionInfo BPI;
- StringRef Error;
- (void)CGM.getTarget().validateBranchProtection(Attr.BranchProtection,
- Attr.CPU, BPI, Error);
- assert(Error.empty());
-
- auto *Fn = cast<llvm::Function>(GV);
- Fn->addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
-
- if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
- Fn->addFnAttr("sign-return-address-key",
- BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey
- ? "a_key"
- : "b_key");
+ TargetInfo::BranchProtectionInfo BPI(CGM.getLangOpts());
+
+ if (const auto *TA = FD->getAttr<TargetAttr>()) {
+ ParsedTargetAttr Attr =
+ CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
+ if (!Attr.BranchProtection.empty()) {
+ StringRef Error;
+ (void)CGM.getTarget().validateBranchProtection(Attr.BranchProtection,
+ Attr.CPU, BPI, Error);
+#ifndef NDEBUG
+ assert(Error.empty());
+#endif
----------------
nickdesaulniers wrote:
No need for the preprocessor guard here, as `assert` only does anything if NDEBUG is not defined.
[My earlier suggestion](https://github.com/llvm/llvm-project/pull/82819#discussion_r1508064741) was to put it around this if statement, but I think that's a bad suggestion now since we want validateBranchProtection to run regardless of NDEBUG.
https://github.com/llvm/llvm-project/pull/82819
More information about the cfe-commits
mailing list