diff options
author | Gokturk Yuksek <gokturk@binghamton.edu> | 2020-02-17 18:36:18 +0000 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-02-20 15:22:06 +0100 |
commit | a572a8a147c76b9d31585c2d4257a5db566c9a9d (patch) | |
tree | 1dc46dd78664fc1f2c51e9e78e3ce190f5fccdd3 /llvm/cmake/modules | |
parent | 4bcdac8d762794d822819eb6d207a0630c345d0b (diff) | |
download | bcm5719-llvm-a572a8a147c76b9d31585c2d4257a5db566c9a9d.tar.gz bcm5719-llvm-a572a8a147c76b9d31585c2d4257a5db566c9a9d.zip |
[CMake] CheckAtomic.cmake: catch false positives in RISC-V
The check for 'HAVE_CXX_ATOMICS_WITHOUT_LIB' may create false
positives in RISC-V. This is reproducible when compiling LLVM natively
using GCC on a rv64gc (rv64imafdgc) host. Due to the 'A' (atomic)
extension, g++ replaces calls to libatomic operations on the
std::atomic<int> type with the native hardware instructions. As a
result, the compilation succeeds and the build system thinks it
doesn't need to pass '-latomic'.
Improve the reliability of the 'HAVE_CXX_ATOMICS_WITHOUT_LIB' test in
two steps:
1. Force a pre-increment on x (++x), which should force a call to a
libatomic function;
2. Because step 1 would resolve the increment to 'amoadd.w.aq' under
the 'A' extension, force the same operation on sub-word types, for
which there is no hardware support.
Reviewers: jfb, hintonda, smeenai, mgorny, JDevlieghere, jyknight
Reviewed By: jfb
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68964
(cherry picked from commit cef85193b2cc1817ca43199a0ae9c6f25723997d)
Diffstat (limited to 'llvm/cmake/modules')
-rw-r--r-- | llvm/cmake/modules/CheckAtomic.cmake | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/cmake/modules/CheckAtomic.cmake b/llvm/cmake/modules/CheckAtomic.cmake index 29f3bdd57f0..34ab8e98de4 100644 --- a/llvm/cmake/modules/CheckAtomic.cmake +++ b/llvm/cmake/modules/CheckAtomic.cmake @@ -12,8 +12,12 @@ function(check_working_cxx_atomics varname) CHECK_CXX_SOURCE_COMPILES(" #include <atomic> std::atomic<int> x; +std::atomic<short> y; +std::atomic<char> z; int main() { - return x; + ++z; + ++y; + return ++x; } " ${varname}) set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |