Skip to content

Commit 9c5e209

Browse files
committed
[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.
1 parent ca9a09d commit 9c5e209

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libcxx/test/std/containers/sequences/vector/common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ struct throwing_iterator {
214214
};
215215

216216
inline void check_new_delete_called() {
217-
assert(globalMemCounter.new_called == globalMemCounter.delete_called);
218-
assert(globalMemCounter.new_array_called == globalMemCounter.delete_array_called);
219-
assert(globalMemCounter.aligned_new_called == globalMemCounter.aligned_delete_called);
220-
assert(globalMemCounter.aligned_new_array_called == globalMemCounter.aligned_delete_array_called);
217+
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.new_called == globalMemCounter.delete_called);
218+
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.new_array_called == globalMemCounter.delete_array_called);
219+
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.aligned_new_called == globalMemCounter.aligned_delete_called);
220+
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.aligned_new_array_called == globalMemCounter.aligned_delete_array_called);
221221
}
222222

223223
template <class T, typename Alloc>

libcxx/test/support/count_new.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ struct RequireAllocationGuard {
626626
void requireExactly(std::size_t N) { m_req_alloc = N; m_exactly = true; }
627627

628628
~RequireAllocationGuard() {
629-
assert(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
629+
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
630630
std::size_t Expect = m_new_count_on_init + m_req_alloc;
631631
assert(globalMemCounter.checkNewCalledEq(static_cast<int>(Expect)) ||
632632
(!m_exactly && globalMemCounter.checkNewCalledGreaterThan(static_cast<int>(Expect))));

0 commit comments

Comments
 (0)