[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
Wed Mar 6 11:06:19 PST 2024


================
@@ -93,24 +79,16 @@ 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) {
-    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();
-    }
+  // BTI/PAuthLR are set on the function attribute.
+  auto TryFnAttr = [&](StringRef AttrName) -> bool {
+    if (F.hasFnAttribute(AttrName))
+      return F.getFnAttribute(AttrName).getValueAsBool();
+    else
+      return false;
   };
 
-  TryFnThenModule("branch-target-enforcement", BranchTargetEnforcement);
-  TryFnThenModule("branch-protection-pauth-lr", BranchProtectionPAuthLR);
+  BranchTargetEnforcement = TryFnAttr("branch-target-enforcement");
+  BranchProtectionPAuthLR = TryFnAttr("branch-protection-pauth-lr");
----------------
nickdesaulniers wrote:

What happens if you just call
```c++
F.getFnAttribute(AttrName).getValueAsBool();
```
without first checking `F.hasFnAttribute`? If you don't hit an assert, I think these can be as simple as:
```c++
BranchTargetEnforcement = F.getFnAttribute("branch-target-enforcement").getValueAsBool();
BranchProtectionPAuthLR = F.getFnAttribute("branch-protection-pauth-lr").getValueAsBool();
```
Maybe not, but can you give it a shot?

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


More information about the llvm-commits mailing list