HP and DHP SMR totally refactored
[libcds.git] / cds / compiler / clang / defs.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef CDSLIB_COMPILER_CLANG_DEFS_H
32 #define CDSLIB_COMPILER_CLANG_DEFS_H
33
34 /*
35     Known issues:
36         Error compiling 64bit boost.atomic on clang 3.4 - 3.5, see https://svn.boost.org/trac/boost/ticket/9610
37         Solution: use boost 1.56 +
38 */
39
40 // Compiler version
41 #define CDS_COMPILER_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
42
43 // Compiler name
44 #define  CDS_COMPILER__NAME    ("clang " __clang_version__)
45 #define  CDS_COMPILER__NICK    "clang"
46
47 #if CDS_COMPILER_VERSION < 30300
48 #   error "Compiler version error. Clang version 3.3.0 and above is supported"
49 #endif
50
51 #if defined(_LIBCPP_VERSION) && !defined(CDS_USE_BOOST_ATOMIC) && CDS_COMPILER_VERSION < 30700
52     // Note: Clang libc++ atomic leads to program crash.
53     // So, we use libcds atomic implementation
54 #   define CDS_USE_LIBCDS_ATOMIC
55 #endif
56
57 // clang for Windows
58 #if defined( _MSC_VER )
59 #   define CDS_OS_INTERFACE     CDS_OSI_WINDOWS
60 #   if defined(_WIN64)
61 #       define CDS_OS_TYPE      CDS_OS_WIN64
62 #       define CDS_OS__NAME     "Win64"
63 #       define CDS_OS__NICK     "Win64"
64 #   elif defined(_WIN32)
65 #       define CDS_OS_TYPE      CDS_OS_WIN32
66 #       define CDS_OS__NAME     "Win32"
67 #       define CDS_OS__NICK     "Win32"
68 #   endif
69 #endif
70
71 #include <cds/compiler/gcc/compiler_macro.h>
72
73 #define alignof __alignof__
74
75 // C++11 inline namespace
76 #define CDS_CXX11_INLINE_NAMESPACE_SUPPORT
77
78 #define CDS_CONSTEXPR    constexpr
79
80 #define CDS_NOEXCEPT_SUPPORT        noexcept
81 #define CDS_NOEXCEPT_SUPPORT_(expr) noexcept(expr)
82
83 // C++11 thread_local keyword
84 #if !(CDS_OS_TYPE == CDS_OS_OSX && CDS_COMPILER_VERSION < 30600)
85     // OS X error?
86     // See http://stackoverflow.com/questions/23791060/c-thread-local-storage-clang-503-0-40-mac-osx
87     // http://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports
88     // clang 3.6 ok?..
89 #   define CDS_CXX11_THREAD_LOCAL_SUPPORT
90 #endif
91
92 // Full SFINAE support
93 #define CDS_CXX11_SFINAE
94
95 // Inheriting constructors
96 #define CDS_CXX11_INHERITING_CTOR
97
98 // Attributes
99 #if CDS_COMPILER_VERSION >= 30400
100 #   if __cplusplus < 201103
101 #       define CDS_DEPRECATED( reason ) __attribute__((deprecated( reason )))
102 #   elif __cplusplus == 201103 // C++11
103 #       define CDS_DEPRECATED( reason ) [[gnu::deprecated(reason)]]
104 #   else  // C++14
105 #       define CDS_DEPRECATED( reason ) [[deprecated(reason)]]
106 #   endif
107 #else
108 #   define CDS_DEPRECATED( reason ) __attribute__((deprecated( reason )))
109 #endif
110
111 #define CDS_NORETURN __attribute__((__noreturn__))
112
113 // *************************************************
114 // Features
115 #if defined(__has_feature) && __has_feature(thread_sanitizer)
116 #   define CDS_THREAD_SANITIZER_ENABLED
117 #endif
118
119 // *************************************************
120 // Alignment macro
121
122 #define CDS_TYPE_ALIGNMENT(n)   __attribute__ ((aligned (n)))
123 #define CDS_CLASS_ALIGNMENT(n)  __attribute__ ((aligned (n)))
124 #define CDS_DATA_ALIGNMENT(n)   __attribute__ ((aligned (n)))
125
126
127 // likely/unlikely
128
129 #define cds_likely( expr )   __builtin_expect( !!( expr ), 1 )
130 #define cds_unlikely( expr ) __builtin_expect( !!( expr ), 0 )
131
132 // Exceptions
133
134 #if defined( __EXCEPTIONS ) && __EXCEPTIONS == 1
135 #   define CDS_EXCEPTION_ENABLED
136 #endif
137
138
139 // double-width CAS support - only for libc++
140 #ifdef _LIBCPP_VERSION
141 #   if CDS_BUILD_BITS == 64
142 #       ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
143 #           define CDS_DCAS_SUPPORT
144 #       endif
145 #   else
146 #       ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
147 #           define CDS_DCAS_SUPPORT
148 #       endif
149 #   endif
150 #endif
151
152 #include <cds/compiler/gcc/compiler_barriers.h>
153
154 #endif // #ifndef CDSLIB_COMPILER_GCC_DEFS_H