22
33function (apply_address_sanitizer TARGET_NAME)
44 target_compile_options (${TARGET_NAME} PRIVATE -fsanitize=address -fno-omit-frame-pointer)
5- if (NOT APPLE )
5+ if (NOT APPLE )
66 target_link_options (${TARGET_NAME} PRIVATE -fsanitize=address -static -libasan)
77 else ()
88 target_link_options (${TARGET_NAME} PRIVATE -fsanitize=address)
@@ -12,7 +12,7 @@ endfunction()
1212
1313function (apply_undefined_sanitizer TARGET_NAME)
1414 target_compile_options (${TARGET_NAME} PRIVATE -fsanitize=undefined)
15- if (NOT APPLE )
15+ if (NOT APPLE )
1616 target_link_options (${TARGET_NAME} PRIVATE -fsanitize=undefined -static -libubsan)
1717 else ()
1818 target_link_options (${TARGET_NAME} PRIVATE -fsanitize=undefined)
@@ -21,20 +21,25 @@ endfunction()
2121
2222function (apply_thread_sanitizer TARGET_NAME)
2323 target_compile_options (${TARGET_NAME} PRIVATE -fsanitize=thread)
24- if (NOT APPLE )
24+ if (NOT APPLE )
2525 target_link_options (${TARGET_NAME} PRIVATE -fsanitize=thread -static -libtsan)
2626 else ()
2727 target_link_options (${TARGET_NAME} PRIVATE -fsanitize=thread -static -libtsan)
2828 endif ()
2929endfunction ()
3030
3131function (apply_memory_sanitizer TARGET_NAME)
32- target_compile_options (${TARGET_NAME} PRIVATE -fsanitize=memory)
33- if (NOT APPLE )
34- target_link_options (${TARGET_NAME} PRIVATE -fsanitize=memory -static -libmsan)
35- else ()
36- target_link_options (${TARGET_NAME} PRIVATE -fsanitize=memory -static -libmsan)
32+ # MSan requires Clang/LLVM and is not generally supported on Apple platforms
33+ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
34+ message (
35+ FATAL_ERROR "MemorySanitizer requires Clang/LLVM (set CMAKE_CXX_COMPILER to clang++)" )
36+ endif ()
37+ if (APPLE )
38+ message (FATAL_ERROR "MemorySanitizer is not supported on Apple platforms in this project" )
3739 endif ()
40+ target_compile_options (${TARGET_NAME} PRIVATE -fsanitize=memory -fno-omit-frame-pointer)
41+ target_link_options (${TARGET_NAME} PRIVATE -fsanitize=memory)
42+ set (ENV{MSAN_OPTIONS} "verbosity=1:log_threads=1" )
3843endfunction ()
3944
4045function (apply_sanitizers TARGET_NAME)
@@ -59,12 +64,14 @@ function(apply_sanitizers TARGET_NAME)
5964
6065 if (SANITIZE_MEMORY)
6166 if (SANITIZE_ADDRESS OR SANITIZE_THREAD)
62- message (FATAL_ERROR "Memory sanitizer is not compatible with Address or Thread sanitizer" )
67+ message (
68+ FATAL_ERROR
69+ "Memory sanitizer is not compatible with Address or Thread sanitizer" )
6370 endif ()
6471 apply_memory_sanitizer(${TARGET_NAME} )
6572 endif ()
6673
6774 else ()
6875 message (WARNING "Sanitizers are only supported for GCC and Clang" )
6976 endif ()
70- endfunction ()
77+ endfunction ()
0 commit comments