Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / tsan / tests / CMakeLists.txt
blobc02c2279583bd15fa05c100832b04af47136ee20
1 include_directories(../rtl)
3 add_custom_target(TsanUnitTests)
4 set_target_properties(TsanUnitTests PROPERTIES
5   FOLDER "Compiler-RT Tests")
7 set(TSAN_UNITTEST_CFLAGS
8   ${COMPILER_RT_UNITTEST_CFLAGS}
9   ${COMPILER_RT_GTEST_CFLAGS}
10   ${SANITIZER_TEST_CXX_CFLAGS}
11   -I${COMPILER_RT_SOURCE_DIR}/include
12   -I${COMPILER_RT_SOURCE_DIR}/lib
13   -I${COMPILER_RT_SOURCE_DIR}/lib/tsan/rtl
14   -DSANITIZER_COMMON_NO_REDEFINE_BUILTINS
15   -DGTEST_HAS_RTTI=0
16   -fno-rtti
19 if(COMPILER_RT_TSAN_DEBUG_OUTPUT)
20   # Need to match these flags with the runtime.
21   list(APPEND TSAN_UNITTEST_CFLAGS -DTSAN_COLLECT_STATS=1
22                                    -DTSAN_DEBUG_OUTPUT=2)
23 endif()
25 append_list_if(COMPILER_RT_HAS_MSSE4_2_FLAG -msse4.2 TSAN_UNITTEST_CFLAGS)
27 set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH})
29 set(TSAN_UNITTEST_LINK_FLAGS
30   ${COMPILER_RT_UNITTEST_LINK_FLAGS}
31   ${COMPILER_RT_UNWINDER_LINK_LIBS}
32   ${SANITIZER_TEST_CXX_LIBRARIES})
34 if(APPLE)
36   # Create a static library for test dependencies.
37   set(TSAN_TEST_RUNTIME_OBJECTS
38     $<TARGET_OBJECTS:RTTsan_dynamic.osx>
39     $<TARGET_OBJECTS:RTInterception.osx>
40     $<TARGET_OBJECTS:RTSanitizerCommon.osx>
41     $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx>
42     $<TARGET_OBJECTS:RTSanitizerCommonCoverage.osx>
43     $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.osx>
44     $<TARGET_OBJECTS:RTUbsan.osx>)
45   set(TSAN_TEST_RUNTIME RTTsanTest)
46   add_library(${TSAN_TEST_RUNTIME} STATIC ${TSAN_TEST_RUNTIME_OBJECTS})
47   set_target_properties(${TSAN_TEST_RUNTIME} PROPERTIES
48     ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
50   darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH)
51   list(APPEND TSAN_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS})
53   list(APPEND TSAN_UNITTEST_LINK_FLAGS ${DARWIN_osx_LINK_FLAGS})
54   add_weak_symbols("ubsan" TSAN_UNITTEST_LINK_FLAGS)
55   add_weak_symbols("sanitizer_common" TSAN_UNITTEST_LINK_FLAGS)
56 else()
57   list(APPEND TSAN_UNITTEST_LINK_FLAGS -fsanitize=thread)
58   list(APPEND TSAN_UNITTEST_LINK_FLAGS -lm)
59   list(APPEND TSAN_UNITTEST_LINK_FLAGS ${COMPILER_RT_TEST_LIBDISPATCH_CFLAGS})
60 endif()
62 set(TSAN_RTL_HEADERS)
63 foreach (header ${TSAN_HEADERS})
64   list(APPEND TSAN_RTL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
65 endforeach()
67 set(TSAN_DEPS llvm_gtest tsan)
68 # TSan uses C++ standard library headers.
69 if (TARGET cxx-headers OR HAVE_LIBCXX)
70   set(TSAN_DEPS cxx-headers)
71 endif()
73 # add_tsan_unittest(<name>
74 #                   SOURCES <sources list>
75 #                   HEADERS <extra headers list>)
76 macro(add_tsan_unittest testname)
77   cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
78   if(UNIX)
79     foreach(arch ${TSAN_TEST_ARCH})
80       set(TsanUnitTestsObjects)
81       generate_compiler_rt_tests(TsanUnitTestsObjects TsanUnitTests
82         "${testname}-${arch}-Test" ${arch}
83         SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
84         RUNTIME ${TSAN_TEST_RUNTIME}
85         COMPILE_DEPS ${TEST_HEADERS} ${TSAN_RTL_HEADERS}
86         DEPS ${TSAN_DEPS}
87         CFLAGS ${TSAN_UNITTEST_CFLAGS}
88         LINK_FLAGS ${TSAN_UNITTEST_LINK_FLAGS})
89     endforeach()
90   endif()
91 endmacro()
93 if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
94   add_subdirectory(rtl)
95   add_subdirectory(unit)
96 endif()