121 lines · plain
1set(BUILTINS_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})2 3set(BUILTINS_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} builtins)4set(BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/TestCases)5 6# Test cases.7configure_lit_site_cfg(8 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in9 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py10)11 12#Unit tests.13 14include(builtin-config-ix)15 16if (COMPILER_RT_BUILD_CRT)17 list(APPEND BUILTINS_TEST_DEPS crt)18endif()19pythonize_bool(COMPILER_RT_BUILD_CRT)20 21# Indicate if this is an MSVC environment.22pythonize_bool(MSVC)23 24# Indicate if the compiler for the builtins library was MSVC. If the builtins25# compiler was clang-cl, we will enable some features that the host compiler26# will not, like C99 _Complex and int128.27set(BUILTINS_IS_MSVC OFF)28if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")29 set(BUILTINS_IS_MSVC ON)30endif()31pythonize_bool(BUILTINS_IS_MSVC)32 33set(BUILTIN_TEST_ARCH ${BUILTIN_SUPPORTED_ARCH})34if(APPLE)35 darwin_filter_host_archs(BUILTIN_SUPPORTED_ARCH BUILTIN_TEST_ARCH)36endif()37 38if(COMPILER_RT_ARM_OPTIMIZED_FP)39 list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_ARM_OPTIMIZED_FP)40endif()41 42foreach(arch ${BUILTIN_TEST_ARCH})43 set(BUILTINS_TEST_TARGET_ARCH ${arch})44 string(TOLOWER "-${arch}-${OS_NAME}" BUILTINS_TEST_CONFIG_SUFFIX)45 get_test_cc_for_arch(${arch} BUILTINS_TEST_TARGET_CC BUILTINS_TEST_TARGET_CFLAGS)46 if (${arch} STREQUAL "armhf")47 list(APPEND BUILTINS_TEST_TARGET_CFLAGS -fomit-frame-pointer -DCOMPILER_RT_ARMHF_TARGET)48 string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")49 endif()50 51 if (COMPILER_RT_ENABLE_SOFTWARE_INT128 OR ("${arch}" MATCHES "riscv32|sparc$"52 AND NOT CMAKE_COMPILER_IS_GNUCC))53 list(APPEND BUILTINS_TEST_TARGET_CFLAGS -fforce-enable-int128)54 string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")55 endif()56 57 if(APPLE)58 # TODO: Support the new ABI on Apple platforms.59 if (${arch} MATCHES "arm|armhf|aarch64|arm64" AND COMPILER_RT_HAS_${arch}_FLOAT16)60 list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)61 string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")62 endif()63 else()64 if (${arch} MATCHES "arm|armhf|aarch64|arm64|i?86|x86_64|AMD64|riscv32|riscv64|s390x" AND COMPILER_RT_HAS_${arch}_FLOAT16)65 list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)66 string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")67 endif()68 endif()69 70 if(COMPILER_RT_ENABLE_CET)71 if(NOT arch MATCHES "i?86|x86_64|AMD64")72 message(SEND_ERROR "${arch} does not support CET")73 endif()74 if(COMPILER_RT_HAS_FCF_PROTECTION_FLAG)75 list(APPEND BUILTINS_TEST_TARGET_CFLAGS -fcf-protection=full)76 string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")77 endif()78 endif()79 80 # Compute builtins available in library and add them as lit features.81 if(APPLE)82 # TODO: Support other Apple platforms.83 set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins_${arch}_osx")84 else()85 set(BUILTIN_LIB_TARGET_NAME "clang_rt.builtins-${arch}")86 endif()87 if (NOT TARGET "${BUILTIN_LIB_TARGET_NAME}")88 message(FATAL_ERROR "Target ${BUILTIN_LIB_TARGET_NAME} does not exist")89 endif()90 get_target_property(BUILTIN_LIB_SOURCES "${BUILTIN_LIB_TARGET_NAME}" SOURCES)91 list(LENGTH BUILTIN_LIB_SOURCES BUILTIN_LIB_SOURCES_LENGTH)92 if (BUILTIN_LIB_SOURCES_LENGTH EQUAL 0)93 message(FATAL_ERROR "Failed to find source files for ${arch} builtin library")94 endif()95 set(BUILTINS_LIT_SOURCE_FEATURES "")96 foreach (file_name ${BUILTIN_LIB_SOURCES})97 # Strip off any directories and file extensions. This approach means we add98 # add a single feature if there is a C source file or assembly override99 # present in the builtin library.100 # E.g.101 # "hexagon/udivsi3.S" => "udivsi3"102 # "udivsi3.c" => "udivsi3"103 get_filename_component(FILE_NAME_FILTERED "${file_name}" NAME_WE)104 list(APPEND BUILTINS_LIT_SOURCE_FEATURES "librt_has_${FILE_NAME_FILTERED}")105 endforeach()106 107 string(TOUPPER ${arch} ARCH_UPPER_CASE)108 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)109 configure_lit_site_cfg(110 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in111 ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py112 )113 list(APPEND BUILTINS_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})114endforeach()115 116# TODO: Add support for running tests on iOS and iOS simulator.117 118add_lit_testsuite(check-builtins "Running the Builtins tests"119 ${BUILTINS_TESTSUITES}120 DEPENDS ${BUILTINS_TEST_DEPS})121