Skip to content

Commit 749aef6

Browse files
committed
Add Windows CI variant for sanitizer CI jobs
For Windows, add jobs testing the address sanitizer for MSVC, as no sanitizer is known to work with Clang or Clang-CL.
1 parent 3d30823 commit 749aef6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.gitlab-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,18 @@ macOS/Clang/UndefinedSanitizer:
623623
CXX: clang++
624624
CMAKE_OPTIONS: -D EXAMPLE_USE_SANITIZER=undefined
625625
<<: *macos_success_template
626+
627+
Windows/MSVC/Address Sanitizer:
628+
image: stabletec/build-core:windows-2019
629+
stage: Sanitizers
630+
parallel:
631+
matrix:
632+
- ARCH: [amd64]
633+
tags:
634+
- container
635+
- windows
636+
- ${ARCH}
637+
script:
638+
- cmake example/all/ -B build -GNinja -D EXAMPLE_USE_SANITIZER=address
639+
- ninja -C build
640+
- ninja -C build test ; if ($? -ne 0) { return 0 } else { return 1 }

sanitizers.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
# functional until then, either by defining `USE_SANITIZER` or
8888
# `SANITIZER_ENABLE_LEGACY_SUPPORT` before including the script file.
8989

90+
include(CheckCXXCompilerFlag)
9091
include(CheckCXXSourceCompiles)
9192

9293
function(append_quoteless value)
@@ -100,13 +101,23 @@ endfunction()
100101
function(test_san_flags RETURN_VAR)
101102
set(QUIET_BACKUP ${CMAKE_REQUIRED_QUIET})
102103
set(CMAKE_REQUIRED_QUIET TRUE)
103-
unset(${return_var} CACHE)
104+
unset(${RETURN_VAR} CACHE)
104105
set(FLAGS_BACKUP ${CMAKE_REQUIRED_FLAGS})
105106
unset(CMAKE_REQUIRED_FLAGS)
107+
unset(test_san_flags_OPTION_TEST CACHE)
106108
foreach(ARG ${ARGN})
109+
if(WIN32)
110+
unset(test_san_flags_OPTION_TEST CACHE)
111+
check_cxx_compiler_flag(${ARG} test_san_flags_OPTION_TEST)
112+
if(NOT test_san_flags_OPTION_TEST)
113+
break()
114+
endif()
115+
endif()
107116
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${ARG}")
108117
endforeach()
109-
check_cxx_source_compiles("int main() { return 0; }" ${RETURN_VAR})
118+
if(NOT DEFINED test_san_flags_OPTION_TEST OR test_san_flags_OPTION_TEST)
119+
check_cxx_source_compiles("int main() { return 0; }" ${RETURN_VAR})
120+
endif()
110121
set(CMAKE_REQUIRED_FLAGS "${FLAGS_BACKUP}")
111122
set(CMAKE_REQUIRED_QUIET "${QUIET_BACKUP}")
112123
endfunction()

0 commit comments

Comments
 (0)