[libcxx-commits] [libcxx] e346fd8 - [libcxx] [test] Fix running tests with Clang-cl in Debug mode
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 28 13:51:39 PDT 2023
Author: Martin Storsjö
Date: 2023-07-28T23:51:27+03:00
New Revision: e346fd8a60d4969b29bdd1740a89b1ea43635331
URL: https://github.com/llvm/llvm-project/commit/e346fd8a60d4969b29bdd1740a89b1ea43635331
DIFF: https://github.com/llvm/llvm-project/commit/e346fd8a60d4969b29bdd1740a89b1ea43635331.diff
LOG: [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
Added:
Modified:
libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in
libcxx/test/support/set_windows_crt_report_mode.h
libcxx/utils/ci/buildkite-pipeline.yml
libcxx/utils/ci/run-buildbot
Removed:
################################################################################
diff --git a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
index fe406044223f86..069e33ff2cb0b0 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 2dda3180f40e83..7cff08d3e3bf3b 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 6093ad569eb7cc..9edc22611ba167 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 725f8a8ed3194b..b647eaf25bd769 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 ccf4b5e552bab8..d8a1807ccfdd03 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 e70a7d3dc7139a..d53a3a29ab0c61 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
More information about the libcxx-commits
mailing list