Index: lib/asan/tests/CMakeLists.txt =================================================================== --- lib/asan/tests/CMakeLists.txt +++ lib/asan/tests/CMakeLists.txt @@ -28,10 +28,29 @@ -I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/tests -Wno-format -Werror=sign-compare - -g -O2) append_if(COMPILER_RT_HAS_WNO_VARIADIC_MACROS_FLAG -Wno-variadic-macros ASAN_UNITTEST_COMMON_CFLAGS) +if(NOT MSVC) + list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -g) +else() + list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -Zi) + + # System headers and gtest use a lot of deprecated stuff. + list(APPEND ASAN_UNITTEST_COMMON_CFLAGS + -Wno-deprecated-declarations) + + # clang-cl doesn't support exceptions yet. + list(APPEND ASAN_UNITTEST_COMMON_CFLAGS + /fallback + -D_HAS_EXCEPTIONS=0) + + # We should teach clang-cl to understand more pragmas. + list(APPEND ASAN_UNITTEST_COMMON_CFLAGS + -Wno-unknown-pragmas + -Wno-undefined-inline) +endif() + # Use -D instead of definitions to please custom compile command. list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -DASAN_HAS_BLACKLIST=1 @@ -39,16 +58,26 @@ -DASAN_UAR=0) set(ASAN_BLACKLIST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore") + +# On Windows, we use clang-cl rather than clang, +# so have to prefix some flags with an extra -Xclang at times. +if(MSVC) + set(XCLANG "-Xclang") +else() + set(XCLANG "") +endif() + set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS ${ASAN_UNITTEST_COMMON_CFLAGS} -fsanitize=address - "-fsanitize-blacklist=${ASAN_BLACKLIST_FILE}" - -mllvm -asan-stack=1 - -mllvm -asan-globals=1 + ${XCLANG} "-fsanitize-blacklist=${ASAN_BLACKLIST_FILE}" ) # Unit tests require libstdc++. -set(ASAN_UNITTEST_COMMON_LINKFLAGS -lstdc++) +if(NOT MSVC) + set(ASAN_UNITTEST_COMMON_LINKFLAGS -lstdc++) +endif() + # x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE") list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS "-lc++") @@ -74,8 +103,10 @@ ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS} -shared-libasan) -set(ASAN_UNITTEST_NOINST_LINKFLAGS - ${ASAN_UNITTEST_COMMON_LINKFLAGS} -lm) +if(NOT MSVC) + set(ASAN_UNITTEST_NOINST_LINKFLAGS + ${ASAN_UNITTEST_COMMON_LINKFLAGS} -lm) +endif() append_if(COMPILER_RT_HAS_LIBDL -ldl ASAN_UNITTEST_NOINST_LINKFLAGS) append_if(COMPILER_RT_HAS_LIBPTHREAD -lpthread ASAN_UNITTEST_NOINST_LINKFLAGS) append_if(COMPILER_RT_HAS_LIBPTHREAD -lpthread @@ -108,7 +139,11 @@ endif() if(TEST_WITH_TEST_RUNTIME) list(APPEND TEST_DEPS ${ASAN_TEST_RUNTIME}) - list(APPEND TEST_OBJECTS lib${ASAN_TEST_RUNTIME}.a) + if(NOT MSVC) + list(APPEND TEST_OBJECTS lib${ASAN_TEST_RUNTIME}.a) + else() + list(APPEND TEST_OBJECTS ${ASAN_TEST_RUNTIME}.lib) + endif() endif() add_compiler_rt_test(${test_suite} ${test_name} OBJECTS ${TEST_OBJECTS} @@ -182,9 +217,12 @@ set(ASAN_TEST_RUNTIME_OBJECTS $ $ - $ $ $) + if(NOT MSVC) + list(APPEND ASAN_TEST_RUNTIME_OBJECTS + $) + endif() endif() add_library(${ASAN_TEST_RUNTIME} STATIC ${ASAN_TEST_RUNTIME_OBJECTS}) set_target_properties(${ASAN_TEST_RUNTIME} PROPERTIES @@ -220,7 +258,7 @@ foreach(arch ${ASAN_SUPPORTED_ARCH}) add_asan_tests_for_arch_and_kind(${arch} "-inline") add_asan_tests_for_arch_and_kind(${arch} "-with-calls" - -mllvm -asan-instrumentation-with-call-threshold=0) + ${XCLANG} -mllvm ${XCLANG} -asan-instrumentation-with-call-threshold=0) endforeach() endif()