Skip to content

Commit ca06c33

Browse files
authored
[libc++] Allow running the test suite with optimizations (#68753)
This patch adds a configuration of the libc++ test suite that enables optimizations when building the tests. It also adds a new CI configuration to exercise this on a regular basis. This is added in the context of [1], which requires building with optimizations in order to hit the bug. [1]: #68552
1 parent 07c9189 commit ca06c33

File tree

31 files changed

+157
-74
lines changed

31 files changed

+157
-74
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ jobs:
161161
'generic-no-unicode',
162162
'generic-no-wide-characters',
163163
'generic-no-rtti',
164+
'generic-optimized-speed',
164165
'generic-static',
165166
'generic-with_llvm_unwinder',
166167
# TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
2+
set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "")
3+
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
4+
set(LIBUNWIND_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.cxx2a.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void test_aligned() {
6060
{
6161
globalMemCounter.last_new_size = 0;
6262
globalMemCounter.last_new_align = 0;
63-
T* volatile ap2 = a.allocate(11, (const void*)5);
63+
T* ap2 = a.allocate(11, (const void*)5);
6464
DoNotOptimize(ap2);
6565
assert(globalMemCounter.checkOutstandingNewEq(1));
6666
assert(globalMemCounter.checkNewCalledEq(1));

libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ void test_allocator_and_new_match() {
187187
stats.reset();
188188
#if defined(NO_SIZE) && defined(NO_ALIGN)
189189
{
190-
int* x = new int(42);
190+
int* x = DoNotOptimize(new int(42));
191191
delete x;
192192
assert(stats.expect_plain());
193193
}
194194
stats.reset();
195195
{
196-
AlignedType* a = new AlignedType();
196+
AlignedType* a = DoNotOptimize(new AlignedType());
197197
delete a;
198198
assert(stats.expect_plain());
199199
}
@@ -202,42 +202,42 @@ void test_allocator_and_new_match() {
202202
stats.reset();
203203
#if TEST_STD_VER >= 11
204204
{
205-
int* x = new int(42);
205+
int* x = DoNotOptimize(new int(42));
206206
delete x;
207207
assert(stats.expect_plain());
208208
}
209209
#endif
210210
stats.reset();
211211
{
212-
AlignedType* a = new AlignedType();
212+
AlignedType* a = DoNotOptimize(new AlignedType());
213213
delete a;
214214
assert(stats.expect_align(TEST_ALIGNOF(AlignedType)));
215215
}
216216
stats.reset();
217217
#elif defined(NO_ALIGN)
218218
stats.reset();
219219
{
220-
int* x = new int(42);
220+
int* x = DoNotOptimize(new int(42));
221221
delete x;
222222
assert(stats.expect_size(sizeof(int)));
223223
}
224224
stats.reset();
225225
{
226-
AlignedType* a = new AlignedType();
226+
AlignedType* a = DoNotOptimize(new AlignedType());
227227
delete a;
228228
assert(stats.expect_size(sizeof(AlignedType)));
229229
}
230230
stats.reset();
231231
#else
232232
stats.reset();
233233
{
234-
int* x = new int(42);
234+
int* x = DoNotOptimize(new int(42));
235235
delete x;
236236
assert(stats.expect_size(sizeof(int)));
237237
}
238238
stats.reset();
239239
{
240-
AlignedType* a = new AlignedType();
240+
AlignedType* a = DoNotOptimize(new AlignedType());
241241
delete a;
242242
assert(stats.expect_size_align(sizeof(AlignedType),
243243
TEST_ALIGNOF(AlignedType)));

libcxx/test/std/experimental/simd/simd.class/simd_ctor_conversion.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
// UNSUPPORTED: c++03, c++11, c++14
1010
// XFAIL: target=powerpc{{.*}}le-unknown-linux-gnu
1111

12+
// TODO: This test makes incorrect assumptions about floating point conversions.
13+
// See https://github.com/llvm/llvm-project/issues/74327.
14+
// XFAIL: optimization=speed
15+
1216
// <experimental/simd>
1317
//
1418
// [simd.class]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(int, char**) {
3131
const std::string s("we really really really really really really really "
3232
"really really long string so that we allocate");
3333
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(
34-
globalMemCounter.checkOutstandingNewEq(1));
34+
globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
3535
const fs::path::string_type ps(s.begin(), s.end());
3636
path p(s);
3737
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(int, char**) {
3131
const std::string s("we really really really really really really really "
3232
"really really long string so that we allocate");
3333
ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(
34-
globalMemCounter.checkOutstandingNewEq(1));
34+
globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
3535
const fs::path::string_type ps(s.begin(), s.end());
3636
path p(s);
3737
{

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size.replace.indirect.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void operator delete(void* p) TEST_NOEXCEPT {
4242

4343
int main(int, char**) {
4444
new_called = delete_called = 0;
45-
int* x = new int[3];
45+
int* x = DoNotOptimize(new int[3]);
4646
assert(x != nullptr);
4747
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
4848

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size.replace.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void operator delete[](void* p) TEST_NOEXCEPT {
4040

4141
int main(int, char**) {
4242
new_called = delete_called = 0;
43-
int* x = new int[3];
43+
int* x = DoNotOptimize(new int[3]);
4444
assert(x != nullptr);
4545
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
4646

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.replace.indirect.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int main(int, char**) {
5151
// Test with an overaligned type
5252
{
5353
new_called = delete_called = 0;
54-
OverAligned* x = new OverAligned[3];
54+
OverAligned* x = DoNotOptimize(new OverAligned[3]);
5555
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
5656
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
5757

@@ -62,7 +62,7 @@ int main(int, char**) {
6262
// Test with a type that is right on the verge of being overaligned
6363
{
6464
new_called = delete_called = 0;
65-
MaxAligned* x = new MaxAligned[3];
65+
MaxAligned* x = DoNotOptimize(new MaxAligned[3]);
6666
assert(x != nullptr);
6767
assert(new_called == 0);
6868

@@ -73,7 +73,7 @@ int main(int, char**) {
7373
// Test with a type that is clearly not overaligned
7474
{
7575
new_called = delete_called = 0;
76-
int* x = new int[3];
76+
int* x = DoNotOptimize(new int[3]);
7777
assert(x != nullptr);
7878
assert(new_called == 0);
7979

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align_nothrow.replace.indirect.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int main(int, char**) {
5151
// Test with an overaligned type
5252
{
5353
new_called = delete_called = 0;
54-
OverAligned* x = new (std::nothrow) OverAligned[3];
54+
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned[3]);
5555
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
5656
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
5757

@@ -62,7 +62,7 @@ int main(int, char**) {
6262
// Test with a type that is right on the verge of being overaligned
6363
{
6464
new_called = delete_called = 0;
65-
MaxAligned* x = new (std::nothrow) MaxAligned[3];
65+
MaxAligned* x = DoNotOptimize(new (std::nothrow) MaxAligned[3]);
6666
assert(x != nullptr);
6767
assert(new_called == 0);
6868

@@ -73,7 +73,7 @@ int main(int, char**) {
7373
// Test with a type that is clearly not overaligned
7474
{
7575
new_called = delete_called = 0;
76-
int* x = new (std::nothrow) int[3];
76+
int* x = DoNotOptimize(new (std::nothrow) int[3]);
7777
assert(x != nullptr);
7878
assert(new_called == 0);
7979

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align_nothrow.replace.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int, char**) {
4848
// Test with an overaligned type
4949
{
5050
new_nothrow_called = delete_called = 0;
51-
OverAligned* x = new (std::nothrow) OverAligned[3];
51+
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned[3]);
5252
assert(static_cast<void*>(x) == DummyData);
5353
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_nothrow_called == 1);
5454

@@ -59,7 +59,7 @@ int main(int, char**) {
5959
// Test with a type that is right on the verge of being overaligned
6060
{
6161
new_nothrow_called = delete_called = 0;
62-
MaxAligned* x = new (std::nothrow) MaxAligned[3];
62+
MaxAligned* x = DoNotOptimize(new (std::nothrow) MaxAligned[3]);
6363
assert(x != nullptr);
6464
assert(new_nothrow_called == 0);
6565

@@ -70,7 +70,7 @@ int main(int, char**) {
7070
// Test with a type that is clearly not overaligned
7171
{
7272
new_nothrow_called = delete_called = 0;
73-
int* x = new (std::nothrow) int[3];
73+
int* x = DoNotOptimize(new (std::nothrow) int[3]);
7474
assert(x != nullptr);
7575
assert(new_nothrow_called == 0);
7676

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_nothrow.replace.indirect.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void operator delete(void* p) TEST_NOEXCEPT {
4646

4747
int main(int, char**) {
4848
new_called = delete_called = 0;
49-
int* x = new (std::nothrow) int[3];
49+
int* x = DoNotOptimize(new (std::nothrow) int[3]);
5050
assert(x != nullptr);
5151
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
5252

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_nothrow.replace.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void operator delete[](void* p) TEST_NOEXCEPT {
3535

3636
int main(int, char**) {
3737
new_nothrow_called = delete_called = 0;
38-
int* x = new (std::nothrow) int[3];
38+
int* x = DoNotOptimize(new (std::nothrow) int[3]);
3939
assert(x != nullptr);
4040
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_nothrow_called == 1);
4141

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size.replace.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void operator delete(void* p) TEST_NOEXCEPT {
3838

3939
int main(int, char**) {
4040
new_called = delete_called = 0;
41-
int* x = new int(3);
41+
int* x = DoNotOptimize(new int(3));
4242
assert(x != nullptr);
4343
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
4444

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.replace.indirect.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main(int, char**) {
5050
// Test with an overaligned type
5151
{
5252
new_called = delete_called = 0;
53-
OverAligned* x = new (std::nothrow) OverAligned;
53+
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned);
5454
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
5555
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
5656

@@ -61,7 +61,7 @@ int main(int, char**) {
6161
// Test with a type that is right on the verge of being overaligned
6262
{
6363
new_called = delete_called = 0;
64-
MaxAligned* x = new (std::nothrow) MaxAligned;
64+
MaxAligned* x = DoNotOptimize(new (std::nothrow) MaxAligned);
6565
assert(x != nullptr);
6666
assert(new_called == 0);
6767

@@ -72,7 +72,7 @@ int main(int, char**) {
7272
// Test with a type that is clearly not overaligned
7373
{
7474
new_called = delete_called = 0;
75-
int* x = new (std::nothrow) int;
75+
int* x = DoNotOptimize(new (std::nothrow) int);
7676
assert(x != nullptr);
7777
assert(new_called == 0);
7878

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_nothrow.replace.indirect.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void operator delete(void* p) TEST_NOEXCEPT {
4141

4242
int main(int, char**) {
4343
new_called = delete_called = 0;
44-
int* x = new (std::nothrow) int(3);
44+
int* x = DoNotOptimize(new (std::nothrow) int(3));
4545
assert(x != nullptr);
4646
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
4747

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ int main(int, char**)
6969
static_assert(noexcept(swap(f1, f2)), "" );
7070
#endif
7171
assert(A::count == 2);
72-
assert(globalMemCounter.checkOutstandingNewEq(2));
72+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(2));
7373
RTTI_ASSERT(f1.target<A>()->id() == 1);
7474
RTTI_ASSERT(f2.target<A>()->id() == 2);
7575
swap(f1, f2);
7676
assert(A::count == 2);
77-
assert(globalMemCounter.checkOutstandingNewEq(2));
77+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(2));
7878
RTTI_ASSERT(f1.target<A>()->id() == 2);
7979
RTTI_ASSERT(f2.target<A>()->id() == 1);
8080
}
@@ -87,12 +87,12 @@ int main(int, char**)
8787
static_assert(noexcept(swap(f1, f2)), "" );
8888
#endif
8989
assert(A::count == 1);
90-
assert(globalMemCounter.checkOutstandingNewEq(1));
90+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
9191
RTTI_ASSERT(f1.target<A>()->id() == 1);
9292
RTTI_ASSERT(*f2.target<int(*)(int)>() == g);
9393
swap(f1, f2);
9494
assert(A::count == 1);
95-
assert(globalMemCounter.checkOutstandingNewEq(1));
95+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
9696
RTTI_ASSERT(*f1.target<int(*)(int)>() == g);
9797
RTTI_ASSERT(f2.target<A>()->id() == 1);
9898
}
@@ -105,12 +105,12 @@ int main(int, char**)
105105
static_assert(noexcept(swap(f1, f2)), "" );
106106
#endif
107107
assert(A::count == 1);
108-
assert(globalMemCounter.checkOutstandingNewEq(1));
108+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
109109
RTTI_ASSERT(*f1.target<int(*)(int)>() == g);
110110
RTTI_ASSERT(f2.target<A>()->id() == 1);
111111
swap(f1, f2);
112112
assert(A::count == 1);
113-
assert(globalMemCounter.checkOutstandingNewEq(1));
113+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
114114
RTTI_ASSERT(f1.target<A>()->id() == 1);
115115
RTTI_ASSERT(*f2.target<int(*)(int)>() == g);
116116
}
@@ -123,12 +123,12 @@ int main(int, char**)
123123
static_assert(noexcept(swap(f1, f2)), "" );
124124
#endif
125125
assert(A::count == 0);
126-
assert(globalMemCounter.checkOutstandingNewEq(0));
126+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(0));
127127
RTTI_ASSERT(*f1.target<int(*)(int)>() == g);
128128
RTTI_ASSERT(*f2.target<int(*)(int)>() == h);
129129
swap(f1, f2);
130130
assert(A::count == 0);
131-
assert(globalMemCounter.checkOutstandingNewEq(0));
131+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(0));
132132
RTTI_ASSERT(*f1.target<int(*)(int)>() == h);
133133
RTTI_ASSERT(*f2.target<int(*)(int)>() == g);
134134
}

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main(int, char**)
6969
{
7070
std::function<int(int)> f = A();
7171
assert(A::count == 1);
72-
assert(globalMemCounter.checkOutstandingNewEq(1));
72+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
7373
RTTI_ASSERT(f.target<A>());
7474
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
7575
}

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ int main(int, char**) {
5757
{
5858
std::function<int(int)> f = A();
5959
assert(A::count == 1);
60-
assert(globalMemCounter.checkOutstandingNewEq(1));
60+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
6161
RTTI_ASSERT(f.target<A>());
6262
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
6363
std::function<int(int)> f2;
6464
f2 = f;
6565
assert(A::count == 2);
66-
assert(globalMemCounter.checkOutstandingNewEq(2));
66+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(2));
6767
RTTI_ASSERT(f2.target<A>());
6868
RTTI_ASSERT(f2.target<int (*)(int)>() == 0);
6969
}
@@ -125,13 +125,13 @@ int main(int, char**) {
125125
{
126126
std::function<int(int)> f = A();
127127
assert(A::count == 1);
128-
assert(globalMemCounter.checkOutstandingNewEq(1));
128+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
129129
RTTI_ASSERT(f.target<A>());
130130
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
131131
std::function<int(int)> f2;
132132
f2 = std::move(f);
133133
assert(A::count == 1);
134-
assert(globalMemCounter.checkOutstandingNewEq(1));
134+
assert(globalMemCounter.checkOutstandingNewLessThanOrEqual(1));
135135
RTTI_ASSERT(f2.target<A>());
136136
RTTI_ASSERT(f2.target<int (*)(int)>() == 0);
137137
RTTI_ASSERT(f.target<A>() == 0);

0 commit comments

Comments
 (0)