Fix for atomic intrinsics detection when using MSVC.
[oota-llvm.git] / cmake / modules / CheckAtomic.cmake
1 # atomic builtins are required for threading support.
2
3 INCLUDE(CheckCXXSourceCompiles)
4
5 #ifdef _MSC_VER
6 #include <windows.h>
7 #endif
8         
9 CHECK_CXX_SOURCE_COMPILES("
10 int main() {
11 #ifdef _MSC_VER
12         volatile LONG val = 1;
13         MemoryBarrier();
14         InterlockedCompareExchange(&val, 0, 1);
15         InterlockedIncrement(&val);
16         InterlockedDecrement(&val);
17 #else
18         volatile unsigned long val = 1;
19         __sync_synchronize();
20         __sync_val_compare_and_swap(&val, 1, 0);
21         __sync_add_and_fetch(&val, 1);
22         __sync_sub_and_fetch(&val, 1);
23 #endif
24         return 0;
25       }
26 " LLVM_MULTITHREADED)
27
28 if( NOT LLVM_MULTITHREADED )
29   message(STATUS "Warning: LLVM will be built thread-unsafe because atomic builtins are missing")
30 endif()