[llvm] [HWASan] Handle default attribute on personality function thunks. (PR #141917)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 02:05:32 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Daniel Kiss (DanielKristofKiss)

<details>
<summary>Changes</summary>

Function::createWithDefaultAttr deals with default attributes so no need to manually deal with them here.

---
Full diff: https://github.com/llvm/llvm-project/pull/141917.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+5-10) 


``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index e81a725c62ead..e38ee68ce0451 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1842,16 +1842,11 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
         Int32Ty, {Int32Ty, Int32Ty, Int64Ty, PtrTy, PtrTy}, false);
     bool IsLocal = P.first && (!isa<GlobalValue>(P.first) ||
                                cast<GlobalValue>(P.first)->hasLocalLinkage());
-    auto *ThunkFn = Function::Create(ThunkFnTy,
-                                     IsLocal ? GlobalValue::InternalLinkage
-                                             : GlobalValue::LinkOnceODRLinkage,
-                                     ThunkName, &M);
-    // TODO: think about other attributes as well.
-    if (any_of(P.second, [](const Function *F) {
-          return F->hasFnAttribute("branch-target-enforcement");
-        })) {
-      ThunkFn->addFnAttr("branch-target-enforcement");
-    }
+    auto *ThunkFn = Function::createWithDefaultAttr(
+        ThunkFnTy,
+        IsLocal ? GlobalValue::InternalLinkage
+                : GlobalValue::LinkOnceODRLinkage,
+        M.getDataLayout().getProgramAddressSpace(), ThunkName, &M);
     if (!IsLocal) {
       ThunkFn->setVisibility(GlobalValue::HiddenVisibility);
       ThunkFn->setComdat(M.getOrInsertComdat(ThunkName));

``````````

</details>


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


More information about the llvm-commits mailing list