diff options
author | Hans Wennborg <hans@hanshq.net> | 2016-08-15 16:40:19 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2016-08-15 16:40:19 +0000 |
commit | 96f4e6709e2a5192576b0467fe3d7ce6dc646b38 (patch) | |
tree | 45c48fae804eb63b0d56d8a888006b0d493b0bd8 | |
parent | 2019f5e1c28038dd355b823008a09096055afb38 (diff) | |
download | compiler-rt-96f4e6709e2a5192576b0467fe3d7ce6dc646b38.tar.gz |
Merging r278454:
------------------------------------------------------------------------
r278454 | cbieneman | 2016-08-11 18:29:26 -0700 (Thu, 11 Aug 2016) | 3 lines
[CMake] If the compiler supports _Atomic include atomic.c in builtins libraries
This fixes a long-standing TODO by implementing a compiler check for supporting the _Atomic keyword. If the _Atomic keyword is supported by the compiler we should include it in the builtin library sources.
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_39@278679 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | cmake/Modules/BuiltinTests.cmake | 23 | ||||
-rw-r--r-- | cmake/builtin-config-ix.cmake | 10 | ||||
-rw-r--r-- | lib/builtins/CMakeLists.txt | 8 |
3 files changed, 36 insertions, 5 deletions
diff --git a/cmake/Modules/BuiltinTests.cmake b/cmake/Modules/BuiltinTests.cmake index 1b03e94ac..a229145d9 100644 --- a/cmake/Modules/BuiltinTests.cmake +++ b/cmake/Modules/BuiltinTests.cmake @@ -2,11 +2,15 @@ # This function takes an OS and a list of architectures and identifies the # subset of the architectures list that the installed toolchain can target. function(try_compile_only output) + cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN}) + if(NOT ARG_SOURCE) + set(ARG_SOURCE "int foo(int x, int y) { return x + y; }\n") + endif() set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c) - file(WRITE ${SIMPLE_C} "int foo(int x, int y) { return x + y; }\n") + file(WRITE ${SIMPLE_C} "${ARG_SOURCE}\n") string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions ${CMAKE_C_COMPILE_OBJECT}) - string(REPLACE ";" " " extra_flags "${ARGN}") + string(REPLACE ";" " " extra_flags "${ARG_FLAGS}") set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") foreach(substitution ${substitutions}) @@ -51,7 +55,20 @@ endfunction() function(builtin_check_c_compiler_flag flag output) if(NOT DEFINED ${output}) message(STATUS "Performing Test ${output}") - try_compile_only(result ${flag}) + try_compile_only(result FLAGS ${flag}) + set(${output} ${result} CACHE INTERNAL "Compiler supports ${flag}") + if(${result}) + message(STATUS "Performing Test ${output} - Success") + else() + message(STATUS "Performing Test ${output} - Failed") + endif() + endif() +endfunction() + +function(builtin_check_c_compiler_source output source) + if(NOT DEFINED ${output}) + message(STATUS "Performing Test ${output}") + try_compile_only(result SOURCE ${source}) set(${output} ${result} CACHE INTERNAL "Compiler supports ${flag}") if(${result}) message(STATUS "Performing Test ${output} - Success") diff --git a/cmake/builtin-config-ix.cmake b/cmake/builtin-config-ix.cmake index 432b1fadb..83466d81b 100644 --- a/cmake/builtin-config-ix.cmake +++ b/cmake/builtin-config-ix.cmake @@ -1,4 +1,5 @@ include(BuiltinTests) +include(CheckCSourceCompiles) # Make all the tests only check the compiler set(TEST_COMPILE_ONLY On) @@ -14,6 +15,15 @@ builtin_check_c_compiler_flag(-mfloat-abi=soft COMPILER_RT_HAS_FLOAT_ABI_SO builtin_check_c_compiler_flag(-mfloat-abi=hard COMPILER_RT_HAS_FLOAT_ABI_HARD_FLAG) builtin_check_c_compiler_flag(-static COMPILER_RT_HAS_STATIC_FLAG) +builtin_check_c_compiler_source(COMPILER_RT_SUPPORTS_ATOMIC_KEYWORD +" +int foo(int x, int y) { + _Atomic int result = x * y; + return result; +} +") + + set(ARM64 aarch64) set(ARM32 arm armhf) set(X86 i386 i686) diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt index d5a1efe79..44a660f5d 100644 --- a/lib/builtins/CMakeLists.txt +++ b/lib/builtins/CMakeLists.txt @@ -38,8 +38,6 @@ set(GENERIC_SOURCES ashlti3.c ashrdi3.c ashrti3.c - # FIXME: atomic.c may only be compiled if host compiler understands _Atomic - # atomic.c clear_cache.c clzdi2.c clzsi2.c @@ -162,6 +160,12 @@ set(GENERIC_SOURCES umodsi3.c umodti3.c) +if(COMPILER_RT_SUPPORTS_ATOMIC_KEYWORD) + set(GENERIC_SOURCES + ${GENERIC_SOURCES} + atomic.c) +endif() + set(MSVC_SOURCES divsc3.c divdc3.c |