aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Function.cpp
diff options
context:
space:
mode:
authorDaniel Kiss <daniel.kiss@arm.com>2024-07-10 10:06:43 +0200
committerGitHub <noreply@github.com>2024-07-10 10:06:43 +0200
commit4c7fd7eec04da86f5453969b19ad55122b281211 (patch)
tree6f3d2efb083fe056e362722203b521c67706c4f5 /llvm/lib/IR/Function.cpp
parente15d67cfc2e5775cc79281aa860f3ad3be628f39 (diff)
downloadllvm-4c7fd7eec04da86f5453969b19ad55122b281211.zip
llvm-4c7fd7eec04da86f5453969b19ad55122b281211.tar.gz
llvm-4c7fd7eec04da86f5453969b19ad55122b281211.tar.bz2
[llvm][ARM][AArch64] Add attributes to synthetic functions. (#83153)
Module flags represent the original intention. Depends on #82819
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r--llvm/lib/IR/Function.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 5fb348a8..2087198 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -407,6 +407,35 @@ Function *Function::createWithDefaultAttr(FunctionType *Ty,
StringRef DefaultFeatures = F->getContext().getDefaultTargetFeatures();
if (!DefaultFeatures.empty())
B.addAttribute("target-features", DefaultFeatures);
+
+ // Check if the module attribute is present and not zero.
+ auto isModuleAttributeSet = [&](const StringRef &ModAttr) -> bool {
+ const auto *Attr =
+ mdconst::extract_or_null<ConstantInt>(M->getModuleFlag(ModAttr));
+ return Attr && !Attr->isZero();
+ };
+
+ auto AddAttributeIfSet = [&](const StringRef &ModAttr) {
+ if (isModuleAttributeSet(ModAttr))
+ B.addAttribute(ModAttr);
+ };
+
+ StringRef SignType = "none";
+ if (isModuleAttributeSet("sign-return-address"))
+ SignType = "non-leaf";
+ if (isModuleAttributeSet("sign-return-address-all"))
+ SignType = "all";
+ if (SignType != "none") {
+ B.addAttribute("sign-return-address", SignType);
+ B.addAttribute("sign-return-address-key",
+ isModuleAttributeSet("sign-return-address-with-bkey")
+ ? "b_key"
+ : "a_key");
+ }
+ AddAttributeIfSet("branch-target-enforcement");
+ AddAttributeIfSet("branch-protection-pauth-lr");
+ AddAttributeIfSet("guarded-control-stack");
+
F->addFnAttrs(B);
return F;
}