Skip to content

Commit 870e4f9

Browse files
authored
[libc++][test] Use ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS in more places (#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.
1 parent 9811226 commit 870e4f9

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
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/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
// These tests require locale for non-char paths
1313
// UNSUPPORTED: no-localization
1414

15+
// In MinGW mode, with optimizations enabled with a DLL, the number of counted
16+
// allocations mismatches, as some ctor/dtor calls are generated in the
17+
// calling code, and some are called from the DLL.
18+
// ADDITIONAL_COMPILE_FLAGS: -DALLOW_MISMATCHING_LIBRRARY_INTERNAL_ALLOCATIONS
19+
1520
// <filesystem>
1621

1722
// class path

libcxx/test/std/input.output/filesystems/class.path/path.member/path.concat.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
// These tests require locale for non-char paths
1313
// UNSUPPORTED: no-localization
1414

15+
// In MinGW mode, with optimizations enabled with a DLL, the number of counted
16+
// allocations mismatches, as some ctor/dtor calls are generated in the
17+
// calling code, and some are called from the DLL.
18+
// ADDITIONAL_COMPILE_FLAGS: -DALLOW_MISMATCHING_LIBRRARY_INTERNAL_ALLOCATIONS
19+
1520
// <filesystem>
1621

1722
// class path

libcxx/test/support/count_new.h

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

628628
~RequireAllocationGuard() {
629+
#ifdef ALLOW_MISMATCHING_LIBRRARY_INTERNAL_ALLOCATIONS
630+
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
631+
#else
629632
assert(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
633+
#endif
630634
std::size_t Expect = m_new_count_on_init + m_req_alloc;
631635
assert(globalMemCounter.checkNewCalledEq(static_cast<int>(Expect)) ||
632636
(!m_exactly && globalMemCounter.checkNewCalledGreaterThan(static_cast<int>(Expect))));

0 commit comments

Comments
 (0)