Skip to content

Revert "[libc] make integration test malloc work properly when threaded" #152096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025

Conversation

jplehr
Copy link
Contributor

@jplehr jplehr commented Aug 5, 2025

Reverts #151622

This broke our libc on GPU bot: https://lab.llvm.org/buildbot/#/builders/10/builds/10864

@jplehr jplehr requested a review from SchrodingerZhu August 5, 2025 06:45
@llvmbot llvmbot added the libc label Aug 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2025

@llvm/pr-subscribers-libc

Author: Jan Patrick Lehr (jplehr)

Changes

Reverts llvm/llvm-project#151622

This broke our libc on GPU bot: https://lab.llvm.org/buildbot/#/builders/10/builds/10864


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

2 Files Affected:

  • (modified) libc/test/IntegrationTest/CMakeLists.txt (-1)
  • (modified) libc/test/IntegrationTest/test.cpp (+5-10)
diff --git a/libc/test/IntegrationTest/CMakeLists.txt b/libc/test/IntegrationTest/CMakeLists.txt
index 235e9fe2f55ee..3afe354eca986 100644
--- a/libc/test/IntegrationTest/CMakeLists.txt
+++ b/libc/test/IntegrationTest/CMakeLists.txt
@@ -13,6 +13,5 @@ add_object_library(
   DEPENDS
     libc.hdr.stdint_proxy
     libc.src.__support.OSUtil.osutil
-    libc.src.__support.CPP.atomic
     ${arch_specific_deps}
 )
diff --git a/libc/test/IntegrationTest/test.cpp b/libc/test/IntegrationTest/test.cpp
index ec45e28a4e7a6..8baf74637b309 100644
--- a/libc/test/IntegrationTest/test.cpp
+++ b/libc/test/IntegrationTest/test.cpp
@@ -5,8 +5,8 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+
 #include "hdr/stdint_proxy.h"
-#include "src/__support/CPP/atomic.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include <stddef.h>
@@ -65,19 +65,14 @@ int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
 
 static constexpr uint64_t MEMORY_SIZE = 16384;
 static uint8_t memory[MEMORY_SIZE];
-static LIBC_NAMESPACE::cpp::Atomic<size_t> used = 0;
+static uint8_t *ptr = memory;
 
 extern "C" {
 
-// For simple test purposes.
 void *malloc(size_t s) {
-  // Emulate the alignment of std::max_align_t.
-  constexpr size_t DEFAULT_ALIGNMENT = alignof(long double);
-  s += (-s) & (DEFAULT_ALIGNMENT - 1); // Align to default alignment.
-  auto res = used.fetch_add(s, LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED);
-  if (res + s > MEMORY_SIZE)
-    return nullptr; // Out of memory.
-  return &memory[res];
+  void *mem = ptr;
+  ptr += s;
+  return static_cast<uint64_t>(ptr - memory) >= MEMORY_SIZE ? nullptr : mem;
 }
 
 void free(void *) {}

@jplehr jplehr merged commit 6393a9e into main Aug 5, 2025
21 checks passed
@jplehr jplehr deleted the revert-151622-libc-fix-integeration-alloc branch August 5, 2025 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants