summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2023-07-14 12:16:23 +0300
committerMartin Storsjö <martin@martin.st>2023-07-28 23:51:27 +0300
commite346fd8a60d4969b29bdd1740a89b1ea43635331 (patch)
treec5e2271ef6f2ed17135a89407240e5e37bde05c9
parentc57d249cd917324917c4b56174ade3c4fbae57a6 (diff)
[libcxx] [test] Fix running tests with Clang-cl in Debug mode
When building in debug mode, the debug version of the MSVC CRT gets linked in. (This is the default in CMake in general. In the case of libcxx, we manually link the CRT though - and in debug mode, we pick the debug version of the CRT.) When building the tests, we need to use the same version of the CRT as was used for building the library. Additionally; the debug CRT defaults to pop up a dialog box when asserts fail, which blocks running tests. By including the set_windows_crt_report_mode.h helper header, we change the assert behaviour back to that of release mode - printing a message and exiting immediately. This was supported by the old libcxx test system, where support for it was added in 7e3ee09ad24cbca3ea7687c50b53be5269127fb1. When porting over to the newer test setup, this mechanism wasn't brought over (and the old test infrastructure was removed in a48f018bb7d8fadc67c08e71409c31713daa0071). Thus: In debug mode, link against the debug versions of msvcrt and msvcprt, define _DEBUG (enabling CRT debug mode code patterns), and include the set_windows_crt_report_mode.h header. Based on a patch by Andrew Ng. Linking of the debug version of the CRT can also be done by using the new -fms-runtime-lib= Clang option. However that option was added in Clang 16, and libcxx only requires Clang 15 for now; therefore doing the CRT linking entirely manually for now (just as before). Additionally, adjust set_windows_crt_report_mode.h to avoid including the body of the file when building in C mode or in C++03 mode. This fixes the following two tests: libcxx/include_as_c.sh.cpp libcxx/selftest/dsl/dsl.sh.py The former test is built in C mode. The latter tries compiling things as C++03. Some of the vcruntime headers that we include break in C++03 mode when MS CRT debug mode is enabled. Differential Revision: https://reviews.llvm.org/D155554
-rw-r--r--libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in11
-rw-r--r--libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in11
-rw-r--r--libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in11
-rw-r--r--libcxx/test/support/set_windows_crt_report_mode.h9
-rw-r--r--libcxx/utils/ci/buildkite-pipeline.yml13
-rwxr-xr-xlibcxx/utils/ci/run-buildbot7
6 files changed, 56 insertions, 6 deletions
diff --git a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
index fe406044223f..069e33ff2cb0 100644
--- a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
@@ -3,12 +3,19 @@
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+dbg_include = ''
+lib_suffix = ''
+
+if '@uppercase_CMAKE_BUILD_TYPE@' == 'DEBUG':
+ dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
+ lib_suffix = 'd'
+
config.substitutions.append(('%{flags}', '--driver-mode=g++'))
config.substitutions.append(('%{compile_flags}',
- '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX'
+ '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX' + dbg_include
))
config.substitutions.append(('%{link_flags}',
- '-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
+ '-nostdlib -L %%{lib} -lc++ -lmsvcrt%s -lmsvcprt%s -loldnames' % (lib_suffix, lib_suffix)
))
config.substitutions.append(('%{exec}',
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
diff --git a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
index 2dda3180f40e..7cff08d3e3bf 100644
--- a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
@@ -4,12 +4,19 @@
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+dbg_include = ''
+lib_suffix = ''
+
+if '@uppercase_CMAKE_BUILD_TYPE@' == 'DEBUG':
+ dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
+ lib_suffix = 'd'
+
config.substitutions.append(('%{flags}', '--driver-mode=g++'))
config.substitutions.append(('%{compile_flags}',
- '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -D_HAS_EXCEPTIONS=0'
+ '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -D_HAS_EXCEPTIONS=0' + dbg_include
))
config.substitutions.append(('%{link_flags}',
- '-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
+ '-nostdlib -L %%{lib} -lc++ -lmsvcrt%s -lmsvcprt%s -loldnames' % (lib_suffix, lib_suffix)
))
config.substitutions.append(('%{exec}',
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
diff --git a/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
index 6093ad569eb7..9edc22611ba1 100644
--- a/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
@@ -3,12 +3,19 @@
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+dbg_include = ''
+lib_suffix = ''
+
+if '@uppercase_CMAKE_BUILD_TYPE@' == 'DEBUG':
+ dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
+ lib_suffix = 'd'
+
config.substitutions.append(('%{flags}', '--driver-mode=g++'))
config.substitutions.append(('%{compile_flags}',
- '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX'
+ '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX' + dbg_include
))
config.substitutions.append(('%{link_flags}',
- '-nostdlib -L %{lib} -llibc++ -lmsvcrt -lmsvcprt -loldnames'
+ '-nostdlib -L %%{lib} -llibc++ -lmsvcrt%s -lmsvcprt%s -loldnames' % (lib_suffix, lib_suffix)
))
config.substitutions.append(('%{exec}',
'%{executor} --execdir %T -- '
diff --git a/libcxx/test/support/set_windows_crt_report_mode.h b/libcxx/test/support/set_windows_crt_report_mode.h
index 725f8a8ed319..b647eaf25bd7 100644
--- a/libcxx/test/support/set_windows_crt_report_mode.h
+++ b/libcxx/test/support/set_windows_crt_report_mode.h
@@ -10,6 +10,14 @@
#ifndef SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
#define SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
+// A few tests are built in C mode or in C++03 mode. The initialization
+// of init_crt_anchor is a C++ feature, and <crtdbg.h> ends up including
+// MSVC header code which breaks in C++03 mode. Therefore, only expand
+// the body of this header when included in C++ >= 11 mode. As this file
+// is included in every single translation unit, we're intentionally not
+// including test_macros.h (for TEST_STD_VER) but try to keep it to the
+// bare minimum.
+#if defined(__cplusplus) && __cplusplus > 199711L
#ifndef _DEBUG
#error _DEBUG must be defined when using this header
#endif
@@ -32,5 +40,6 @@ inline int init_crt_report_mode() {
}
static int init_crt_anchor = init_crt_report_mode();
+#endif // defined(__cplusplus) && __cplusplus > 199711L
#endif // SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
diff --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml
index ccf4b5e552ba..d8a1807ccfdd 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -764,6 +764,19 @@ steps:
- exit_status: -1 # Agent was lost
limit: 2
+ - label: "Clang-cl (Debug mode)"
+ command: "bash libcxx/utils/ci/run-buildbot clang-cl-debug"
+ artifact_paths:
+ - "**/test-results.xml"
+ - "**/*.abilist"
+ agents:
+ queue: "windows"
+ retry:
+ automatic:
+ - exit_status: -1 # Agent was lost
+ limit: 2
+ timeout_in_minutes: 120
+
- label: "MinGW (DLL, x86_64)"
command: "bash libcxx/utils/ci/run-buildbot mingw-dll"
artifact_paths:
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index e70a7d3dc713..d53a3a29ab0c 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -639,6 +639,13 @@ clang-cl-no-vcruntime)
echo "+++ Running the libc++ tests"
${NINJA} -vC "${BUILD_DIR}" check-cxx
;;
+clang-cl-debug)
+ clean
+ generate-cmake-libcxx-win -DLIBCXX_TEST_PARAMS="enable_experimental=False" \
+ -DCMAKE_BUILD_TYPE=Debug
+ echo "+++ Running the libc++ tests"
+ ${NINJA} -vC "${BUILD_DIR}" check-cxx
+;;
mingw-dll)
clean
# Explicitly specify the compiler with a triple prefix. The CI