diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index b3888ebde6737..0511b8fd0f63c 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -1688,6 +1688,14 @@ if(BUILD_TEST) if(USE_FBGEMM) target_link_libraries(${test_name}_${CPU_CAPABILITY} fbgemm) endif() + if(USE_ASAN) + if(TARGET Sanitizer::address) + target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::address) + endif() + if(TARGET Sanitizer::undefined) + target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::undefined) + endif() + endif() else() add_executable(${test_name}_${CPU_CAPABILITY} "${test_src}") target_link_libraries(${test_name}_${CPU_CAPABILITY} torch_library gtest_main) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 503895aa4b152..0602d534dc4c1 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -815,6 +815,9 @@ if(USE_FBGEMM) else() set(FBGEMM_LIBRARY_TYPE "static" CACHE STRING "") endif() + if(USE_ASAN) + set(USE_SANITIZER "address,undefined" CACHE STRING "-fsanitize options for FBGEMM") + endif() add_subdirectory("${FBGEMM_SOURCE_DIR}") set_property(TARGET fbgemm_generic PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET fbgemm_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON)