[libcxx-commits] [libcxx] [libc++] Handle 0 size case for testing support operator new (PR #93834)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 30 08:16:22 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Jake Egan (jakeegan)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/93834.diff
2 Files Affected:
- (modified) libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp (-2)
- (modified) libcxx/test/support/count_new.h (+4)
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/93834
More information about the libcxx-commits
mailing list