Skip to content

Commit 17b01b6

Browse files
committed
Add memory sanitizer support for Clang in CMake configuration
1 parent f0a8635 commit 17b01b6

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

test/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ file(GLOB XTENSOR_PREPROCESS_FILES files/cppy_source/*.cppy)
234234
# Sanitizer support
235235
include(${CMAKE_SOURCE_DIR}/cmake/sanitizers.cmake)
236236

237+
if(USE_SANITIZER MATCHES "memory" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
238+
set(XTENSOR_MSAN_IGNORELIST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/msan_ignorelist.txt")
239+
set_source_files_properties(
240+
main.cpp
241+
PROPERTIES
242+
COMPILE_OPTIONS "-fsanitize-ignorelist=${XTENSOR_MSAN_IGNORELIST_FILE}"
243+
)
244+
endif()
245+
237246
# This target should only be run when the test source files have been changed.
238247
add_custom_target(
239248
preprocess_cppy
@@ -289,13 +298,6 @@ endif()
289298

290299
target_compile_options(test_xtensor_lib PRIVATE $<$<BOOL:USE_SANITIZER>:${SANITIZER_COMPILE_OPTIONS}>)
291300
target_link_options(test_xtensor_lib PRIVATE $<$<BOOL:USE_SANITIZER>:${SANITIZER_LINK_OPTIONS}>)
292-
# if(USE_SANITIZER MATCHES "memory" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
293-
# target_compile_options(test_xtensor_lib PRIVATE -ftrivial-auto-var-init=zero)
294-
# endif()
295-
# if(USE_SANITIZER MATCHES "memory")
296-
# target_compile_options(test_xtensor_lib PRIVATE -fno-sanitize=memory)
297-
# target_link_options(test_xtensor_lib PRIVATE -fno-sanitize=memory)
298-
# endif()
299301

300302
target_include_directories(test_xtensor_lib PRIVATE ${XTENSOR_INCLUDE_DIR})
301303
target_link_libraries(test_xtensor_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})

test/msan_ignorelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src:*doctest/doctest.h

0 commit comments

Comments
 (0)