[libcxx-commits] [libcxx] [libcxx] [test] Use ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS in more places (PR #144339)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 16 05:09:14 PDT 2025
https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/144339
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS allows waiving asserts, for cases when we can't count allocations that happen within the libc++ shared library.
When compiling with optimization, it is possible that some calls end up generated inline, where the overridden operator new/delete do get called (counting those calls), whereas the compiler may decide to leave some calls to the external definition (inside the shared library, where we can't count the calls).
In particular, in one case, a non-optimized build calls _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev from the DLL, while it gets inlined (including direct calls to operator delete) when built with optimization.
Therefore; for the cases where we can't count allocations internally within the library, waive these asserts.
This fixes all testcases in mingw mode, when built with optimization enabled.
>From 29e41b179c94db60438362187c6014f3b74b614e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Sun, 15 Jun 2025 01:38:15 +0300
Subject: [PATCH] [libcxx] [test] Use ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS
in more places
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS allows waiving asserts,
for cases when we can't count allocations that happen within
the libc++ shared library.
When compiling with optimization, it is possible that some calls
end up generated inline, where the overridden operator new/delete
do get called (counting those calls), whereas the compiler may
decide to leave some calls to the external definition (inside the
shared library, where we can't count the calls).
In particular, in one case, a non-optimized build calls
_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
from the DLL, while it gets inlined (including direct calls to
operator delete) when built with optimization.
Therefore; for the cases where we can't count allocations
internally within the library, waive these asserts.
This fixes all testcases in mingw mode, when built with optimization
enabled.
---
libcxx/test/std/containers/sequences/vector/common.h | 8 ++++----
libcxx/test/support/count_new.h | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libcxx/test/std/containers/sequences/vector/common.h b/libcxx/test/std/containers/sequences/vector/common.h
index 4af6559a06e73..34453f8889b73 100644
--- a/libcxx/test/std/containers/sequences/vector/common.h
+++ b/libcxx/test/std/containers/sequences/vector/common.h
@@ -214,10 +214,10 @@ struct throwing_iterator {
};
inline void check_new_delete_called() {
- assert(globalMemCounter.new_called == globalMemCounter.delete_called);
- assert(globalMemCounter.new_array_called == globalMemCounter.delete_array_called);
- assert(globalMemCounter.aligned_new_called == globalMemCounter.aligned_delete_called);
- assert(globalMemCounter.aligned_new_array_called == globalMemCounter.aligned_delete_array_called);
+ ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.new_called == globalMemCounter.delete_called);
+ ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.new_array_called == globalMemCounter.delete_array_called);
+ ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.aligned_new_called == globalMemCounter.aligned_delete_called);
+ ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.aligned_new_array_called == globalMemCounter.aligned_delete_array_called);
}
template <class T, typename Alloc>
diff --git a/libcxx/test/support/count_new.h b/libcxx/test/support/count_new.h
index c8169d3acceab..beb11ee4deae4 100644
--- a/libcxx/test/support/count_new.h
+++ b/libcxx/test/support/count_new.h
@@ -626,7 +626,7 @@ struct RequireAllocationGuard {
void requireExactly(std::size_t N) { m_req_alloc = N; m_exactly = true; }
~RequireAllocationGuard() {
- assert(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
+ ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
std::size_t Expect = m_new_count_on_init + m_req_alloc;
assert(globalMemCounter.checkNewCalledEq(static_cast<int>(Expect)) ||
(!m_exactly && globalMemCounter.checkNewCalledGreaterThan(static_cast<int>(Expect))));
More information about the libcxx-commits
mailing list