[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)
Daniel Kiss via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 10 09:02:43 PDT 2024
https://github.com/DanielKristofKiss updated https://github.com/llvm/llvm-project/pull/98329
>From b1e113f76b289aa8a7d4459314a0dbffb313cb51 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Wed, 10 Jul 2024 16:23:11 +0200
Subject: [PATCH 1/2] [NFC][Clang] Move functions of BranchProtectionInfo out
of line.
Also let's add const to the setFnAttributes.
---
clang/include/clang/Basic/TargetInfo.h | 20 ++------------------
clang/lib/Basic/TargetInfo.cpp | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..5a6a0cdbd316a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -34,7 +34,6 @@
#include "llvm/Frontend/OpenMP/OMPGridValues.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/Function.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"
@@ -1450,24 +1449,9 @@ class TargetInfo : public TransferrableTargetInfo,
GuardedControlStack = LangOpts.GuardedControlStack;
}
- void setFnAttributes(llvm::Function &F) {
- llvm::AttrBuilder FuncAttrs(F.getContext());
- setFnAttributes(FuncAttrs);
- F.addFnAttrs(FuncAttrs);
- }
+ void setFnAttributes(llvm::Function &F) const;
- void setFnAttributes(llvm::AttrBuilder &FuncAttrs) {
- if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
- FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
- FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
- }
- if (BranchTargetEnforcement)
- FuncAttrs.addAttribute("branch-target-enforcement");
- if (BranchProtectionPAuthLR)
- FuncAttrs.addAttribute("branch-protection-pauth-lr");
- if (GuardedControlStack)
- FuncAttrs.addAttribute("guarded-control-stack");
- }
+ void setFnAttributes(llvm::AttrBuilder &FuncAttrs) const;
};
/// Determine if the Architecture in this TargetInfo supports branch
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 29f5cd14e46e1..a99ddd081ae28 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -18,6 +18,7 @@
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/Function.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/TargetParser/TargetParser.h"
#include <cstdlib>
@@ -1005,3 +1006,22 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
*Target = *Src;
}
+
+void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::Function &F) const {
+ llvm::AttrBuilder FuncAttrs(F.getContext());
+ setFnAttributes(FuncAttrs);
+ F.addFnAttrs(FuncAttrs);
+}
+
+void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::AttrBuilder &FuncAttrs) const {
+ if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+ FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
+ FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
+ }
+ if (BranchTargetEnforcement)
+ FuncAttrs.addAttribute("branch-target-enforcement");
+ if (BranchProtectionPAuthLR)
+ FuncAttrs.addAttribute("branch-protection-pauth-lr");
+ if (GuardedControlStack)
+ FuncAttrs.addAttribute("guarded-control-stack");
+}
>From 4ecad898afea255f22c23babed20da305cbd43eb Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Wed, 10 Jul 2024 18:02:21 +0200
Subject: [PATCH 2/2] clangformnat
---
clang/lib/Basic/TargetInfo.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index a99ddd081ae28..cc4b79b4334af 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -1007,13 +1007,15 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
*Target = *Src;
}
-void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::Function &F) const {
+void TargetInfo::BranchProtectionInfo::setFnAttributes(
+ llvm::Function &F) const {
llvm::AttrBuilder FuncAttrs(F.getContext());
setFnAttributes(FuncAttrs);
F.addFnAttrs(FuncAttrs);
}
-void TargetInfo::BranchProtectionInfo::setFnAttributes(llvm::AttrBuilder &FuncAttrs) const {
+void TargetInfo::BranchProtectionInfo::setFnAttributes(
+ llvm::AttrBuilder &FuncAttrs) const {
if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
More information about the cfe-commits
mailing list