[llvm] [ORC] Fix LLJIT's __cxa_atexit declaration for clang-repl. (PR #113141)

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 02:51:48 PDT 2024


https://github.com/JonPsson1 created https://github.com/llvm/llvm-project/pull/113141

Add sign extension on i32 return value.


>From c50fcbd162a8215bbc1d67bc274740ba25996506 Mon Sep 17 00:00:00 2001
From: Jonas Paulsson <paulson1 at linux.ibm.com>
Date: Mon, 21 Oct 2024 11:31:38 +0200
Subject: [PATCH] Add sign extension on i32 return value for CxaAtExit().

---
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 401ed525fd5cfe..db39fec12e5fcb 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -477,12 +477,16 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
     auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
     auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
 
-    addHelperAndWrapper(
+    auto *CxaAtExit = addHelperAndWrapper(
         *M, "__cxa_atexit",
         FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
                           false),
         GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
         {PlatformInstanceDecl});
+    Attribute::AttrKind CxaAtExitExtAttr =
+        TargetLibraryInfo::getExtAttrForI32Return(J.getTargetTriple());
+    if (CxaAtExitExtAttr != Attribute::None)
+      CxaAtExit->addRetAttr(CxaAtExitExtAttr);
 
     return ThreadSafeModule(std::move(M), std::move(Ctx));
   }



More information about the llvm-commits mailing list