brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · f0b84f4 Raw
141 lines · plain
1set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})2 3set(UBSAN_TESTSUITES)4set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})5 6macro(add_ubsan_testsuite test_mode sanitizer arch lld thinlto)7  set(UBSAN_LIT_TEST_MODE "${test_mode}")8  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE})9  if (${lld})10    set(CONFIG_NAME ${CONFIG_NAME}-lld)11    if ("lld" IN_LIST LLVM_ENABLE_PROJECTS)12      list(APPEND UBSAN_TEST_DEPS lld)13    endif()14  endif()15  if (${thinlto})16    set(CONFIG_NAME ${CONFIG_NAME}-thinlto)17    list(APPEND UBSAN_TEST_DEPS LTO)18  endif()19  set(UBSAN_TEST_USE_LLD ${lld})20  set(UBSAN_TEST_USE_THINLTO ${thinlto})21  set(CONFIG_NAME ${CONFIG_NAME}-${arch})22  configure_lit_site_cfg(23    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in24    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)25  list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})26  list(APPEND UBSAN_TEST_DEPS ${sanitizer})27endmacro()28 29macro(add_ubsan_testsuites test_mode sanitizer arch)30  add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} False False)31 32  if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32))33    add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} True False)34  endif()35endmacro()36 37set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})38if(APPLE)39  darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)40endif()41 42foreach(arch ${UBSAN_TEST_ARCH})43  set(UBSAN_TEST_TARGET_ARCH ${arch})44  if (APPLE)45    set(UBSAN_TEST_APPLE_PLATFORM "osx")46    set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")47  endif()48  get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)49  add_ubsan_testsuites("Standalone" ubsan ${arch})50 51  if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")52    # Disable ubsan with AddressSanitizer tests for 64-bit Solaris/x86 and53    # 64-bit SPARC.54    if((NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND55       (NOT ${arch} MATCHES sparcv9))56      add_ubsan_testsuites("AddressSanitizer" asan ${arch})57    endif()58  endif()59  if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")60    add_ubsan_testsuites("MemorySanitizer" msan ${arch})61  endif()62  if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)63    add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})64  endif()65  if(COMPILER_RT_HAS_TYSAN AND ";${TYSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")66    add_ubsan_testsuites("TypeSanitizer" tysan ${arch})67  endif()68endforeach()69 70macro(add_ubsan_device_testsuite test_mode sanitizer platform arch)71  # Note we expect the caller to have already set UBSAN_TEST_TARGET_CFLAGS72  set(UBSAN_LIT_TEST_MODE "${test_mode}")73  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${platform}-${arch})74  set(UBSAN_TEST_TARGET_ARCH ${arch})75  set(UBSAN_TEST_USE_LLD "False")76  set(UBSAN_TEST_USE_THINLTO "False")77  if (APPLE)78    set(UBSAN_TEST_APPLE_PLATFORM "${platform}")79    set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")80  else()81    unset(UBSAN_TEST_APPLE_PLATFORM)82    unset(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG)83  endif()84  configure_lit_site_cfg(85    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in86    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)87  #list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})88  list(APPEND UBSAN_TEST_DEPS ${sanitizer})89  add_lit_testsuite(check-ubsan-${test_mode}-${platform}-${arch}90    "UBSan ${CONFIG_NAME} tests"91    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/92    EXCLUDE_FROM_CHECK_ALL93    DEPENDS ${UBSAN_TEST_DEPS})94endmacro()95 96if(APPLE)97  foreach(arch ${UBSAN_TEST_ARCH})98    set(UBSAN_TEST_TARGET_ARCH ${arch})99    get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)100    set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")101  endforeach()102 103  # Device and simulator test suites.104  # These are not added into "check-all", in order to run these tests, use105  # "check-asan-iossim-x86_64" and similar. They also require that an extra env106  # variable to select which iOS device or simulator to use, e.g.:107  # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"108  set(UBSAN_APPLE_PLATFORMS ${UBSAN_SUPPORTED_OS})109  foreach(platform ${UBSAN_APPLE_PLATFORMS})110    list_intersect(111      UBSAN_TEST_${platform}_ARCHS112      UBSAN_SUPPORTED_ARCH113      DARWIN_${platform}_ARCHS114      )115    foreach(arch ${UBSAN_TEST_${platform}_ARCHS})116      get_test_cflags_for_apple_platform(117        "${platform}"118        "${arch}"119        UBSAN_TEST_TARGET_CFLAGS120      )121      add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch})122 123      if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")124        add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch})125      endif()126 127      if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")128        add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})129      endif()130 131      if(COMPILER_RT_HAS_TYSAN AND ";${TYSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")132        add_ubsan_device_testsuite("TypeSanitizer" tysan ${platform} ${arch})133      endif()134    endforeach()135  endforeach()136endif()137 138add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"139  ${UBSAN_TESTSUITES}140  DEPENDS ${UBSAN_TEST_DEPS})141