[Mlir-commits] [mlir] [mlir][LLVM] Put personality pointer in program address space (PR #230848)

Arseniy Obolenskiy llvmlistbot at llvm.org
Sat Oct 10 13:01:33 PDT 2026


https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/230848

Avoid crashes on targets where functions are not in address space 0

>From 3401aec8b46f8acd4f3093d60648e5b19f7922e5 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Sat, 10 Oct 2026 21:57:18 +0200
Subject: [PATCH] [mlir][LLVM] Put personality pointer in program address space

Avoid crashes on targets where functions are not in address space 0
---
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp |  3 ++-
 mlir/test/Target/LLVMIR/llvmir.mlir          | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 4757a4ca43219..07b9d683d309d 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1697,7 +1697,8 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
 
   // Check the personality and set it.
   if (func.getPersonality()) {
-    llvm::Type *ty = llvm::PointerType::getUnqual(llvmFunc->getContext());
+    llvm::Type *ty = llvm::PointerType::get(
+        llvmContext, llvmModule->getDataLayout().getProgramAddressSpace());
     if (llvm::Constant *pfunc = getLLVMConstant(ty, func.getPersonalityAttr(),
                                                 func.getLoc(), *this))
       llvmFunc->setPersonalityFn(pfunc);
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index f29184beb6b4d..252e24d1da81b 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1817,6 +1817,18 @@ llvm.func @invoke_phis() -> i32 attributes { personality = @__gxx_personality_v0
 
 // -----
 
+module attributes {llvm.data_layout = "P4"} {
+  llvm.func @__gxx_personality_v0(...) -> i32
+
+  // CHECK-LABEL: @personality_program_as
+  // CHECK-SAME: personality ptr addrspace(4) @__gxx_personality_v0
+  llvm.func @personality_program_as() attributes { personality = @__gxx_personality_v0 } {
+    llvm.return
+  }
+}
+
+// -----
+
 // CHECK-LABEL: @hasGCFunction
 // CHECK-SAME: gc "statepoint-example"
 llvm.func @hasGCFunction() attributes { garbageCollector = "statepoint-example" } {



More information about the Mlir-commits mailing list