[llvm] [llvm][ARM][AArch64] Don't use module attr as function attr. (PR #83154)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 11:19:39 PST 2024


================
@@ -93,24 +79,19 @@ AArch64FunctionInfo::AArch64FunctionInfo(const Function &F,
   // TODO: skip functions that have no instrumented allocas for optimization
   IsMTETagged = F.hasFnAttribute(Attribute::SanitizeMemTag);
 
-  // BTI/PAuthLR may be set either on the function or the module. Set Bool from
-  // either the function attribute or module attribute, depending on what is
-  // set.
-  // Note: the module attributed is numeric (0 or 1) but the function attribute
-  // is stringy ("true" or "false").
-  auto TryFnThenModule = [&](StringRef AttrName, bool &Bool) {
+  // BTI/PAuthLR are set on the function attribute.
+  auto TryFnAttr = [&](StringRef AttrName, bool &Bool) {
     if (F.hasFnAttribute(AttrName)) {
       const StringRef V = F.getFnAttribute(AttrName).getValueAsString();
       assert(V.equals_insensitive("true") || V.equals_insensitive("false"));
       Bool = V.equals_insensitive("true");
-    } else if (const auto *ModVal = mdconst::extract_or_null<ConstantInt>(
-                   F.getParent()->getModuleFlag(AttrName))) {
-      Bool = ModVal->getZExtValue();
+    } else {
+      Bool = false;
     }
   };
 
-  TryFnThenModule("branch-target-enforcement", BranchTargetEnforcement);
-  TryFnThenModule("branch-protection-pauth-lr", BranchProtectionPAuthLR);
+  TryFnAttr("branch-target-enforcement", BranchTargetEnforcement);
+  TryFnAttr("branch-protection-pauth-lr", BranchProtectionPAuthLR);
----------------
nickdesaulniers wrote:

Rather than have the lambda take a bool reference, can we simply return a bool then do:

```c++
BranchTargetEnforcement = TryFnAttr("branch-target-enforcement");
BranchProtectionPAuthLR = TryFnAttr("branch-protection-pauth-lr");
```

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


More information about the llvm-commits mailing list