cmake: Disable ctime_tests if build with -fsanitize=memory
Clang >= 16 has `-fsanitize-memory-param-retval` turned on by default, which is incompatible with
This commit is contained in:
@@ -263,6 +263,17 @@ endif()
|
|||||||
|
|
||||||
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
||||||
|
|
||||||
|
set(print_msan_notice)
|
||||||
|
if(SECP256K1_BUILD_CTIME_TESTS)
|
||||||
|
include(CheckMemorySanitizer)
|
||||||
|
check_memory_sanitizer(msan_enabled)
|
||||||
|
if(msan_enabled)
|
||||||
|
try_append_c_flags(-fno-sanitize-memory-param-retval)
|
||||||
|
set(print_msan_notice YES)
|
||||||
|
endif()
|
||||||
|
unset(msan_enabled)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Ask CTest to create a "check" target (e.g., make check) as alias for the "test" target.
|
# Ask CTest to create a "check" target (e.g., make check) as alias for the "test" target.
|
||||||
# CTEST_TEST_TARGET_ALIAS is not documented but supposed to be user-facing.
|
# CTEST_TEST_TARGET_ALIAS is not documented but supposed to be user-facing.
|
||||||
# See: https://gitlab.kitware.com/cmake/cmake/-/commit/816c9d1aa1f2b42d40c81a991b68c96eb12b6d2
|
# See: https://gitlab.kitware.com/cmake/cmake/-/commit/816c9d1aa1f2b42d40c81a991b68c96eb12b6d2
|
||||||
@@ -358,7 +369,14 @@ endif()
|
|||||||
if(SECP256K1_LATE_CFLAGS)
|
if(SECP256K1_LATE_CFLAGS)
|
||||||
message("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS}")
|
message("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS}")
|
||||||
endif()
|
endif()
|
||||||
message("\n")
|
message("")
|
||||||
|
if(print_msan_notice)
|
||||||
|
message(
|
||||||
|
"Note:\n"
|
||||||
|
" MemorySanitizer detected, tried to add -fno-sanitize-memory-param-retval to compile options\n"
|
||||||
|
" to avoid false positives in ctime_tests. Pass -DSECP256K1_BUILD_CTIME_TESTS=OFF to avoid this.\n"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
if(SECP256K1_EXPERIMENTAL)
|
if(SECP256K1_EXPERIMENTAL)
|
||||||
message(
|
message(
|
||||||
" ******\n"
|
" ******\n"
|
||||||
|
|||||||
18
cmake/CheckMemorySanitizer.cmake
Normal file
18
cmake/CheckMemorySanitizer.cmake
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
include(CheckCSourceCompiles)
|
||||||
|
|
||||||
|
function(check_memory_sanitizer output)
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
|
check_c_source_compiles("
|
||||||
|
#if defined(__has_feature)
|
||||||
|
# if __has_feature(memory_sanitizer)
|
||||||
|
/* MemorySanitizer is enabled. */
|
||||||
|
# elif
|
||||||
|
# error \"MemorySanitizer is disabled.\"
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# error \"__has_feature is not defined.\"
|
||||||
|
#endif
|
||||||
|
" HAVE_MSAN)
|
||||||
|
set(${output} ${HAVE_MSAN} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
Reference in New Issue
Block a user