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

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 14:57:13 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-offload

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

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.


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


1 Files Affected:

- (modified) offload/DeviceRTL/src/State.cpp (+1-1) 


``````````diff
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); }

``````````

</details>


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


More information about the llvm-commits mailing list