[llvm] [OpenMP] Use the `libc` malloc for AMDGPU if available (PR #151241)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 14:56:41 PDT 2025


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/151241

Summary:
This patch enables the OpenMP runtime to use the general-purpose
`malloc` interface in `libc` if the user built OpenMP with it enabled.
All this requires is keeping `malloc` as an external function so it will
be resolved later by the linker.


>From 3e6767fcdb10296ec10805faecb5633d2607000f Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 29 Jul 2025 16:54:06 -0500
Subject: [PATCH] [OpenMP] Use the `libc` malloc for AMDGPU if available

Summary:
This patch enables the OpenMP runtime to use the general-purpose
`malloc` interface in `libc` if the user built OpenMP with it enabled.
All this requires is keeping `malloc` as an external function so it will
be resolved later by the linker.
---
 offload/DeviceRTL/src/State.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/offload/DeviceRTL/src/State.cpp b/offload/DeviceRTL/src/State.cpp
index 62b03e7bba720..475395102f47b 100644
--- a/offload/DeviceRTL/src/State.cpp
+++ b/offload/DeviceRTL/src/State.cpp
@@ -50,7 +50,7 @@ namespace {
 ///
 ///{
 extern "C" {
-#ifdef __AMDGPU__
+#if defined(__AMDGPU__) && !defined(OMPTARGET_HAS_LIBC)
 
 [[gnu::weak]] void *malloc(size_t Size) { return allocator::alloc(Size); }
 [[gnu::weak]] void free(void *Ptr) { allocator::free(Ptr); }



More information about the llvm-commits mailing list