Skip to content

Commit e346fd8

Browse files
committed
[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 7e3ee09. When porting over to the newer test setup, this mechanism wasn't brought over (and the old test infrastructure was removed in a48f018). 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
1 parent c57d249 commit e346fd8

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33

44
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
55

6+
dbg_include = ''
7+
lib_suffix = ''
8+
9+
if '@uppercase_CMAKE_BUILD_TYPE@' == 'DEBUG':
10+
dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
11+
lib_suffix = 'd'
12+
613
config.substitutions.append(('%{flags}', '--driver-mode=g++'))
714
config.substitutions.append(('%{compile_flags}',
8-
'-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'
15+
'-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
916
))
1017
config.substitutions.append(('%{link_flags}',
11-
'-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
18+
'-nostdlib -L %%{lib} -lc++ -lmsvcrt%s -lmsvcprt%s -loldnames' % (lib_suffix, lib_suffix)
1219
))
1320
config.substitutions.append(('%{exec}',
1421
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '

libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44

55
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
66

7+
dbg_include = ''
8+
lib_suffix = ''
9+
10+
if '@uppercase_CMAKE_BUILD_TYPE@' == 'DEBUG':
11+
dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
12+
lib_suffix = 'd'
13+
714
config.substitutions.append(('%{flags}', '--driver-mode=g++'))
815
config.substitutions.append(('%{compile_flags}',
9-
'-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'
16+
'-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
1017
))
1118
config.substitutions.append(('%{link_flags}',
12-
'-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
19+
'-nostdlib -L %%{lib} -lc++ -lmsvcrt%s -lmsvcprt%s -loldnames' % (lib_suffix, lib_suffix)
1320
))
1421
config.substitutions.append(('%{exec}',
1522
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '

libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33

44
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
55

6+
dbg_include = ''
7+
lib_suffix = ''
8+
9+
if '@uppercase_CMAKE_BUILD_TYPE@' == 'DEBUG':
10+
dbg_include = ' -D_DEBUG -include set_windows_crt_report_mode.h'
11+
lib_suffix = 'd'
12+
613
config.substitutions.append(('%{flags}', '--driver-mode=g++'))
714
config.substitutions.append(('%{compile_flags}',
8-
'-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'
15+
'-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
916
))
1017
config.substitutions.append(('%{link_flags}',
11-
'-nostdlib -L %{lib} -llibc++ -lmsvcrt -lmsvcprt -loldnames'
18+
'-nostdlib -L %%{lib} -llibc++ -lmsvcrt%s -lmsvcprt%s -loldnames' % (lib_suffix, lib_suffix)
1219
))
1320
config.substitutions.append(('%{exec}',
1421
'%{executor} --execdir %T -- '

libcxx/test/support/set_windows_crt_report_mode.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
#ifndef SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
1111
#define SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
1212

13+
// A few tests are built in C mode or in C++03 mode. The initialization
14+
// of init_crt_anchor is a C++ feature, and <crtdbg.h> ends up including
15+
// MSVC header code which breaks in C++03 mode. Therefore, only expand
16+
// the body of this header when included in C++ >= 11 mode. As this file
17+
// is included in every single translation unit, we're intentionally not
18+
// including test_macros.h (for TEST_STD_VER) but try to keep it to the
19+
// bare minimum.
20+
#if defined(__cplusplus) && __cplusplus > 199711L
1321
#ifndef _DEBUG
1422
#error _DEBUG must be defined when using this header
1523
#endif
@@ -32,5 +40,6 @@ inline int init_crt_report_mode() {
3240
}
3341

3442
static int init_crt_anchor = init_crt_report_mode();
43+
#endif // defined(__cplusplus) && __cplusplus > 199711L
3544

3645
#endif // SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H

libcxx/utils/ci/buildkite-pipeline.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,19 @@ steps:
764764
- exit_status: -1 # Agent was lost
765765
limit: 2
766766

767+
- label: "Clang-cl (Debug mode)"
768+
command: "bash libcxx/utils/ci/run-buildbot clang-cl-debug"
769+
artifact_paths:
770+
- "**/test-results.xml"
771+
- "**/*.abilist"
772+
agents:
773+
queue: "windows"
774+
retry:
775+
automatic:
776+
- exit_status: -1 # Agent was lost
777+
limit: 2
778+
timeout_in_minutes: 120
779+
767780
- label: "MinGW (DLL, x86_64)"
768781
command: "bash libcxx/utils/ci/run-buildbot mingw-dll"
769782
artifact_paths:

libcxx/utils/ci/run-buildbot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ clang-cl-no-vcruntime)
639639
echo "+++ Running the libc++ tests"
640640
${NINJA} -vC "${BUILD_DIR}" check-cxx
641641
;;
642+
clang-cl-debug)
643+
clean
644+
generate-cmake-libcxx-win -DLIBCXX_TEST_PARAMS="enable_experimental=False" \
645+
-DCMAKE_BUILD_TYPE=Debug
646+
echo "+++ Running the libc++ tests"
647+
${NINJA} -vC "${BUILD_DIR}" check-cxx
648+
;;
642649
mingw-dll)
643650
clean
644651
# Explicitly specify the compiler with a triple prefix. The CI

0 commit comments

Comments
 (0)