Skip to content

Commit a572a8a

Browse files
gktrkzmodem
authored andcommitted
[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 cef8519)
1 parent 4bcdac8 commit a572a8a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/cmake/modules/CheckAtomic.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ function(check_working_cxx_atomics varname)
1212
CHECK_CXX_SOURCE_COMPILES("
1313
#include <atomic>
1414
std::atomic<int> x;
15+
std::atomic<short> y;
16+
std::atomic<char> z;
1517
int main() {
16-
return x;
18+
++z;
19+
++y;
20+
return ++x;
1721
}
1822
" ${varname})
1923
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})

0 commit comments

Comments
 (0)