Skip to content

Commit eb073ea

Browse files
committed
Fix Clang-cl Address Sanitizer
1 parent 4c5adc2 commit eb073ea

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,30 @@ message(STATUS "Sanitizers: ASan=${WITH_ADDRESS_SANITIZER} TSan=${WITH_THREAD_SA
3232
if (WITH_ADDRESS_SANITIZER)
3333
if (MSVC)
3434
add_compile_options(/fsanitize=address)
35+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
36+
execute_process(
37+
COMMAND ${CMAKE_CXX_COMPILER} -print-resource-dir
38+
OUTPUT_VARIABLE CLANG_RESOURCE_DIR
39+
OUTPUT_STRIP_TRAILING_WHITESPACE
40+
)
41+
add_link_options("/LIBPATH:${CLANG_RESOURCE_DIR}/lib/windows")
42+
link_libraries(
43+
"clang_rt.asan_dynamic-x86_64.lib"
44+
"clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"
45+
)
46+
endif()
3547
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
36-
# also enable UndefinedBehaviorSanitizer
37-
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
3848
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
39-
link_libraries(-fsanitize=address)
49+
link_libraries(-fsanitize=address,undefined)
4050
endif ()
41-
message("Address Sanitizer enabled")
51+
message(STATUS "Address Sanitizer enabled")
4252
endif ()
4353

4454
if (WITH_THREAD_SANITIZER)
4555
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
4656
add_compile_options(-fsanitize=thread -g -fno-omit-frame-pointer)
4757
link_libraries(-fsanitize=thread)
48-
message("Thread Sanitizer enabled")
58+
message(STATUS "Thread Sanitizer enabled")
4959
endif ()
5060
endif ()
5161

0 commit comments

Comments
 (0)