[libunwind] [llvm] [libcxx] [libc++] Allow running the test suite with optimizations (PR #68753)
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/68753 >From 5e53337f16aa446d6a2dc764d347ea37b22c3a56 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 10 Oct 2023 16:35:11 -0700 Subject: [PATCH 1/5] [libc++] Allow running the test suite with optimizations 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]: https://github.com/llvm/llvm-project/issues/68552 --- .github/workflows/libcxx-build-and-test.yaml | 2 +- .../caches/Generic-optimized-speed.cmake | 4 +++ .../support.dynamic/libcpp_deallocate.sh.cpp | 17 +-- .../path.member/path.assign/move.pass.cpp | 2 +- .../path.member/path.construct/move.pass.cpp | 2 +- .../new.size.replace.indirect.pass.cpp| 3 +- .../new.size.replace.pass.cpp | 3 +- .../new.size_align.replace.indirect.pass.cpp | 7 +++-- ...ze_align_nothrow.replace.indirect.pass.cpp | 7 +++-- .../new.size_align_nothrow.replace.pass.cpp | 7 +++-- ...new.size_nothrow.replace.indirect.pass.cpp | 3 +- .../new.size_nothrow.replace.pass.cpp | 3 +- .../new.size.replace.pass.cpp | 3 +- ...ze_align_nothrow.replace.indirect.pass.cpp | 7 +++-- ...new.size_nothrow.replace.indirect.pass.cpp | 3 +- .../func.wrap.func.alg/swap.pass.cpp | 16 +-- .../func.wrap.func.con/F.pass.cpp | 2 +- .../func.wrap.func.con/copy_assign.pass.cpp | 8 +++--- .../func.wrap.func.con/copy_move.pass.cpp | 8 +++--- .../nullptr_t_assign.pass.cpp | 2 +- .../func.wrap.func.mod/swap.pass.cpp | 12 .../make_shared.pass.cpp | 4 +-- libcxx/test/support/count_new.h | 5 libcxx/test/support/do_not_optimize.h | 28 +++ libcxx/utils/ci/run-buildbot | 5 libcxx/utils/libcxx/test/params.py| 28 ++- libunwind/test/libunwind_02.pass.cpp | 26 + libunwind/test/unw_resume.pass.cpp| 2 +- libunwind/test/unwind_leaffunction.pass.cpp | 20 +++-- 29 files changed, 169 insertions(+), 70 deletions(-) create mode 100644 libcxx/cmake/caches/Generic-optimized-speed.cmake create mode 100644 libcxx/test/support/do_not_optimize.h diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml index 018f0e45a244..9c7adb808bcb 100644 --- a/.github/workflows/libcxx-build-and-test.yaml +++ b/.github/workflows/libcxx-build-and-test.yaml @@ -162,6 +162,7 @@ jobs: 'generic-no-tzdb', 'generic-no-unicode', 'generic-no-wide-characters', + 'generic-optimized-speed', 'generic-static', 'generic-with_llvm_unwinder', # TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive @@ -209,4 +210,3 @@ jobs: **/CMakeError.log **/CMakeOutput.log **/crash_diagnostics/* - diff --git a/libcxx/cmake/caches/Generic-optimized-speed.cmake b/libcxx/cmake/caches/Generic-optimized-speed.cmake new file mode 100644 index ..577a5de9f34c --- /dev/null +++ b/libcxx/cmake/caches/Generic-optimized-speed.cmake @@ -0,0 +1,4 @@ +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") +set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "") +set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "") +set(LIBUNWIND_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "") diff --git a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp index fb56ce4518a7..6e6229b752a7 100644 --- a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp +++ b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp @@ -34,6 +34,7 @@ #include #include +#include "do_not_optimize.h" #include "test_macros.h" TEST_DIAGNOSTIC_PUSH @@ -187,13 +188,13 @@ void test_allocator_and_new_match() { stats.reset(); #if defined(NO_SIZE) && defined(NO_ALIGN) { -int* x = new int(42); +int* x = support::do_not_optimize(new int(42)); delete x; assert(stats.expect_plain()); } stats.reset(); { -AlignedType* a = new AlignedType(); +AlignedType* a = support::do_not_optimize(new AlignedType()); delete a; assert(stats.expect_plain()); } @@ -202,14 +203,14 @@ void test_allocator_and_new_match() { stats.reset(); #if TEST_STD_VER >= 11 { -int* x = new int(42); +int* x = support::do_not_optimize(new int(42)); delete x; assert(stats.expect_plain()); } #endif stats.reset(); { -
[libunwind] [llvm] [libcxx] [libc++] Allow running the test suite with optimizations (PR #68753)
@@ -0,0 +1,28 @@ +// -*- C++ -*- +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef SUPPORT_DO_NOT_OPTIMIZE_H +#define SUPPORT_DO_NOT_OPTIMIZE_H + +#include "test_macros.h" + +namespace support { +// This function can be used to hide some objects from compiler optimizations. +// +// For example, this is useful to hide the result of a call to `new` and ensure +// that the compiler doesn't elide the call to new/delete. Otherwise, elliding +// calls to new/delete is allowed by the Standard and compilers actually do it +// when optimizations are enabled. +template +TEST_CONSTEXPR __attribute__((noinline)) T* do_not_optimize(T* ptr) TEST_NOEXCEPT { philnik777 wrote: We have `DoNotOptimize` already in `test_macros.h`(!?). I think we should use that version instead, since it properly clobbers things and works for more compilers. We'll have to make it `constexpr` though. https://github.com/llvm/llvm-project/pull/68753 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [llvm] [libcxx] [libc++] Allow running the test suite with optimizations (PR #68753)
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/68753 >From 2a5035e7b1db4b77ec30426c988478a35b077b7b Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 10 Oct 2023 16:35:11 -0700 Subject: [PATCH] [libc++] Allow running the test suite with optimizations 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]: https://github.com/llvm/llvm-project/issues/68552 --- .github/workflows/libcxx-build-and-test.yaml | 2 +- .../caches/Generic-optimized-speed.cmake | 4 +++ .../support.dynamic/libcpp_deallocate.sh.cpp | 17 +-- .../path.member/path.assign/move.pass.cpp | 2 +- .../path.member/path.construct/move.pass.cpp | 2 +- .../new.size.replace.indirect.pass.cpp| 3 +- .../new.size.replace.pass.cpp | 3 +- .../new.size_align.replace.indirect.pass.cpp | 7 +++-- ...ze_align_nothrow.replace.indirect.pass.cpp | 7 +++-- .../new.size_align_nothrow.replace.pass.cpp | 7 +++-- ...new.size_nothrow.replace.indirect.pass.cpp | 3 +- .../new.size_nothrow.replace.pass.cpp | 3 +- .../new.size.replace.pass.cpp | 3 +- ...ze_align_nothrow.replace.indirect.pass.cpp | 7 +++-- ...new.size_nothrow.replace.indirect.pass.cpp | 3 +- .../func.wrap.func.alg/swap.pass.cpp | 16 +-- .../func.wrap.func.con/F.pass.cpp | 2 +- .../func.wrap.func.con/copy_assign.pass.cpp | 8 +++--- .../func.wrap.func.con/copy_move.pass.cpp | 8 +++--- .../nullptr_t_assign.pass.cpp | 2 +- .../func.wrap.func.mod/swap.pass.cpp | 12 .../make_shared.pass.cpp | 4 +-- libcxx/test/support/count_new.h | 5 libcxx/test/support/do_not_optimize.h | 28 +++ libcxx/utils/ci/run-buildbot | 5 libcxx/utils/libcxx/test/params.py| 28 ++- libunwind/test/libunwind_02.pass.cpp | 26 + libunwind/test/unw_resume.pass.cpp| 2 +- libunwind/test/unwind_leaffunction.pass.cpp | 20 +++-- 29 files changed, 169 insertions(+), 70 deletions(-) create mode 100644 libcxx/cmake/caches/Generic-optimized-speed.cmake create mode 100644 libcxx/test/support/do_not_optimize.h diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml index a649993c65dc42f..f0bfd6db9503d75 100644 --- a/.github/workflows/libcxx-build-and-test.yaml +++ b/.github/workflows/libcxx-build-and-test.yaml @@ -151,6 +151,7 @@ jobs: 'generic-no-tzdb', 'generic-no-unicode', 'generic-no-wide-characters', + 'generic-optimized-speed', 'generic-static', 'generic-with_llvm_unwinder' ] @@ -193,4 +194,3 @@ jobs: **/CMakeError.log **/CMakeOutput.log **/crash_diagnostics/* - diff --git a/libcxx/cmake/caches/Generic-optimized-speed.cmake b/libcxx/cmake/caches/Generic-optimized-speed.cmake new file mode 100644 index 000..577a5de9f34c539 --- /dev/null +++ b/libcxx/cmake/caches/Generic-optimized-speed.cmake @@ -0,0 +1,4 @@ +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") +set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "") +set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "") +set(LIBUNWIND_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "") diff --git a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp index fb56ce4518a7182..6e6229b752a7a6e 100644 --- a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp +++ b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp @@ -34,6 +34,7 @@ #include #include +#include "do_not_optimize.h" #include "test_macros.h" TEST_DIAGNOSTIC_PUSH @@ -187,13 +188,13 @@ void test_allocator_and_new_match() { stats.reset(); #if defined(NO_SIZE) && defined(NO_ALIGN) { -int* x = new int(42); +int* x = support::do_not_optimize(new int(42)); delete x; assert(stats.expect_plain()); } stats.reset(); { -AlignedType* a = new AlignedType(); +AlignedType* a = support::do_not_optimize(new AlignedType()); delete a; assert(stats.expect_plain()); } @@ -202,14 +203,14 @@ void test_allocator_and_new_match() { stats.reset(); #if TEST_STD_VER >= 11 { -int* x = new int(42); +int* x = support::do_not_optimize(new int(42)); delete x; assert(stats.expect_plain()); } #endif stats.reset(); { -AlignedType* a = new AlignedType(); +AlignedType* a = support::do_not_optimize(new