[libcxx-commits] [libcxx] 037a052 - [libc++] Handle 0 size case for testing support operator new (#93834)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 3 13:23:11 PDT 2024


Author: Jake Egan
Date: 2024-06-03T16:23:08-04:00
New Revision: 037a0528bbb4606388fb0805c34a413abbedea13

URL: https://github.com/llvm/llvm-project/commit/037a0528bbb4606388fb0805c34a413abbedea13
DIFF: https://github.com/llvm/llvm-project/commit/037a0528bbb4606388fb0805c34a413abbedea13.diff

LOG: [libc++] Handle 0 size case for testing support operator new (#93834)

The return of malloc is implementation defined when the requested size
is 0. On platforms (such as AIX) that return a null pointer for 0 size,
operator new will throw a bad_alloc exception. operator new should
return a non null pointer for 0 size instead.

Added: 
    

Modified: 
    libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
    libcxx/test/support/count_new.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
index 44f2868af3693..87bf9dc3854b3 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp
@@ -14,8 +14,6 @@
 //   void
 //   inplace_merge(Iter first, Iter middle, Iter last);
 
-// XFAIL: LIBCXX-AIX-FIXME
-
 #include <algorithm>
 #include <cassert>
 #include <random>

diff  --git a/libcxx/test/support/count_new.h b/libcxx/test/support/count_new.h
index dd8c0e54cae7f..0a95e05b72421 100644
--- a/libcxx/test/support/count_new.h
+++ b/libcxx/test/support/count_new.h
@@ -385,6 +385,8 @@ MemCounter &globalMemCounter = *getGlobalMemCounter();
 // operator new(size_t[, nothrow_t]) and operator delete(size_t[, nothrow_t])
 void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc) {
   getGlobalMemCounter()->newCalled(s);
+  if (s == 0)
+    ++s;
   void* p = std::malloc(s);
   if (p == nullptr)
     detail::throw_bad_alloc_helper();
@@ -417,6 +419,8 @@ void operator delete(void* p, std::nothrow_t const&) TEST_NOEXCEPT {
 // operator new[](size_t[, nothrow_t]) and operator delete[](size_t[, nothrow_t])
 void* operator new[](std::size_t s) TEST_THROW_SPEC(std::bad_alloc) {
   getGlobalMemCounter()->newArrayCalled(s);
+  if (s == 0)
+    s++;
   void* p = std::malloc(s);
   if (p == nullptr)
     detail::throw_bad_alloc_helper();


        


More information about the libcxx-commits mailing list