phmap_config.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. #if !defined(phmap_config_h_guard_)
  2. #define phmap_config_h_guard_
  3. // ---------------------------------------------------------------------------
  4. // Copyright (c) 2019, Gregory Popovitch - [email protected]
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. //
  10. // https://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. // Includes work from abseil-cpp (https://github.com/abseil/abseil-cpp)
  19. // with modifications.
  20. //
  21. // Copyright 2018 The Abseil Authors.
  22. //
  23. // Licensed under the Apache License, Version 2.0 (the "License");
  24. // you may not use this file except in compliance with the License.
  25. // You may obtain a copy of the License at
  26. //
  27. // https://www.apache.org/licenses/LICENSE-2.0
  28. //
  29. // Unless required by applicable law or agreed to in writing, software
  30. // distributed under the License is distributed on an "AS IS" BASIS,
  31. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32. // See the License for the specific language governing permissions and
  33. // limitations under the License.
  34. // ---------------------------------------------------------------------------
  35. #define PHMAP_VERSION_MAJOR 1
  36. #define PHMAP_VERSION_MINOR 3
  37. #define PHMAP_VERSION_PATCH 12
  38. // Included for the __GLIBC__ macro (or similar macros on other systems).
  39. #include <limits.h>
  40. #ifdef __cplusplus
  41. // Included for __GLIBCXX__, _LIBCPP_VERSION
  42. #include <cstddef>
  43. #endif // __cplusplus
  44. #if defined(__APPLE__)
  45. // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
  46. // __IPHONE_8_0.
  47. #include <Availability.h>
  48. #include <TargetConditionals.h>
  49. #endif
  50. #define PHMAP_XSTR(x) PHMAP_STR(x)
  51. #define PHMAP_STR(x) #x
  52. #define PHMAP_VAR_NAME_VALUE(var) #var "=" PHMAP_STR(var)
  53. // -----------------------------------------------------------------------------
  54. // Some sanity checks
  55. // -----------------------------------------------------------------------------
  56. //#if defined(__CYGWIN__)
  57. // #error "Cygwin is not supported."
  58. //#endif
  59. #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918 && !defined(__clang__)
  60. #error "phmap requires Visual Studio 2015 Update 2 or higher."
  61. #endif
  62. // We support gcc 4.7 and later.
  63. #if defined(__GNUC__) && !defined(__clang__)
  64. #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
  65. #error "phmap requires gcc 4.7 or higher."
  66. #endif
  67. #endif
  68. // We support Apple Xcode clang 4.2.1 (version 421.11.65) and later.
  69. // This corresponds to Apple Xcode version 4.5.
  70. #if defined(__apple_build_version__) && __apple_build_version__ < 4211165
  71. #error "phmap requires __apple_build_version__ of 4211165 or higher."
  72. #endif
  73. // Enforce C++11 as the minimum.
  74. #if defined(__cplusplus) && !defined(_MSC_VER)
  75. #if __cplusplus < 201103L
  76. #error "C++ versions less than C++11 are not supported."
  77. #endif
  78. #endif
  79. // We have chosen glibc 2.12 as the minimum
  80. #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
  81. #if !__GLIBC_PREREQ(2, 12)
  82. #error "Minimum required version of glibc is 2.12."
  83. #endif
  84. #endif
  85. #if defined(_STLPORT_VERSION)
  86. #error "STLPort is not supported."
  87. #endif
  88. #if CHAR_BIT != 8
  89. #warning "phmap assumes CHAR_BIT == 8."
  90. #endif
  91. // phmap currently assumes that an int is 4 bytes.
  92. #if INT_MAX < 2147483647
  93. #error "phmap assumes that int is at least 4 bytes. "
  94. #endif
  95. // -----------------------------------------------------------------------------
  96. // Compiler Feature Checks
  97. // -----------------------------------------------------------------------------
  98. #ifdef __has_builtin
  99. #define PHMAP_HAVE_BUILTIN(x) __has_builtin(x)
  100. #else
  101. #define PHMAP_HAVE_BUILTIN(x) 0
  102. #endif
  103. #if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703) || __cplusplus >= 201703
  104. #define PHMAP_HAVE_CC17 1
  105. #else
  106. #define PHMAP_HAVE_CC17 0
  107. #endif
  108. #define PHMAP_BRANCHLESS 1
  109. #ifdef __has_feature
  110. #define PHMAP_HAVE_FEATURE(f) __has_feature(f)
  111. #else
  112. #define PHMAP_HAVE_FEATURE(f) 0
  113. #endif
  114. // Portable check for GCC minimum version:
  115. // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
  116. #if defined(__GNUC__) && defined(__GNUC_MINOR__)
  117. #define PHMAP_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))
  118. #else
  119. #define PHMAP_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) 0
  120. #endif
  121. #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
  122. #define PHMAP_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) (__clang_major__ > (x) || __clang_major__ == (x) && __clang_minor__ >= (y))
  123. #else
  124. #define PHMAP_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) 0
  125. #endif
  126. // -------------------------------------------------------------------
  127. // Checks whether C++11's `thread_local` storage duration specifier is
  128. // supported.
  129. // -------------------------------------------------------------------
  130. #ifdef PHMAP_HAVE_THREAD_LOCAL
  131. #error PHMAP_HAVE_THREAD_LOCAL cannot be directly set
  132. #elif defined(__APPLE__) && defined(__clang__)
  133. #if __has_feature(cxx_thread_local) && \
  134. !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
  135. #define PHMAP_HAVE_THREAD_LOCAL 1
  136. #endif
  137. #else // !defined(__APPLE__)
  138. #define PHMAP_HAVE_THREAD_LOCAL 1
  139. #endif
  140. #if defined(__ANDROID__) && defined(__clang__)
  141. #if __has_include(<android/ndk-version.h>)
  142. #include <android/ndk-version.h>
  143. #endif // __has_include(<android/ndk-version.h>)
  144. #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
  145. defined(__NDK_MINOR__) && \
  146. ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
  147. #undef PHMAP_HAVE_TLS
  148. #undef PHMAP_HAVE_THREAD_LOCAL
  149. #endif
  150. #endif
  151. // ------------------------------------------------------------
  152. // Checks whether the __int128 compiler extension for a 128-bit
  153. // integral type is supported.
  154. // ------------------------------------------------------------
  155. #ifdef PHMAP_HAVE_INTRINSIC_INT128
  156. #error PHMAP_HAVE_INTRINSIC_INT128 cannot be directly set
  157. #elif defined(__SIZEOF_INT128__)
  158. #if (defined(__clang__) && !defined(_WIN32) && !defined(__aarch64__)) || \
  159. (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
  160. (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
  161. #define PHMAP_HAVE_INTRINSIC_INT128 1
  162. #elif defined(__CUDACC__)
  163. #if __CUDACC_VER__ >= 70000
  164. #define PHMAP_HAVE_INTRINSIC_INT128 1
  165. #endif // __CUDACC_VER__ >= 70000
  166. #endif // defined(__CUDACC__)
  167. #endif
  168. // ------------------------------------------------------------------
  169. // Checks whether the compiler both supports and enables exceptions.
  170. // ------------------------------------------------------------------
  171. #ifdef PHMAP_HAVE_EXCEPTIONS
  172. #error PHMAP_HAVE_EXCEPTIONS cannot be directly set.
  173. #elif defined(__clang__)
  174. #if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
  175. #define PHMAP_HAVE_EXCEPTIONS 1
  176. #endif // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
  177. #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
  178. !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
  179. !(defined(_MSC_VER) && !defined(_CPPUNWIND))
  180. #define PHMAP_HAVE_EXCEPTIONS 1
  181. #endif
  182. // -----------------------------------------------------------------------
  183. // Checks whether the platform has an mmap(2) implementation as defined in
  184. // POSIX.1-2001.
  185. // -----------------------------------------------------------------------
  186. #ifdef PHMAP_HAVE_MMAP
  187. #error PHMAP_HAVE_MMAP cannot be directly set
  188. #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
  189. defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
  190. defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
  191. defined(__ASYLO__)
  192. #define PHMAP_HAVE_MMAP 1
  193. #endif
  194. // -----------------------------------------------------------------------
  195. // Checks the endianness of the platform.
  196. // -----------------------------------------------------------------------
  197. #if defined(PHMAP_IS_BIG_ENDIAN)
  198. #error "PHMAP_IS_BIG_ENDIAN cannot be directly set."
  199. #endif
  200. #if defined(PHMAP_IS_LITTLE_ENDIAN)
  201. #error "PHMAP_IS_LITTLE_ENDIAN cannot be directly set."
  202. #endif
  203. #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  204. __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  205. #define PHMAP_IS_LITTLE_ENDIAN 1
  206. #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
  207. __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  208. #define PHMAP_IS_BIG_ENDIAN 1
  209. #elif defined(_WIN32)
  210. #define PHMAP_IS_LITTLE_ENDIAN 1
  211. #else
  212. #error "phmap endian detection needs to be set up for your compiler"
  213. #endif
  214. #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
  215. defined(__MAC_OS_X_VERSION_MIN_REQUIRED__) && \
  216. __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400
  217. #define PHMAP_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 1
  218. #else
  219. #define PHMAP_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE 0
  220. #endif
  221. // ---------------------------------------------------------------------------
  222. // Checks whether C++17 std::any is available by checking whether <any> exists.
  223. // ---------------------------------------------------------------------------
  224. #ifdef PHMAP_HAVE_STD_ANY
  225. #error "PHMAP_HAVE_STD_ANY cannot be directly set."
  226. #endif
  227. #ifdef __has_include
  228. #if __has_include(<any>) && __cplusplus >= 201703L && \
  229. !PHMAP_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE
  230. #define PHMAP_HAVE_STD_ANY 1
  231. #endif
  232. #endif
  233. #ifdef PHMAP_HAVE_STD_OPTIONAL
  234. #error "PHMAP_HAVE_STD_OPTIONAL cannot be directly set."
  235. #endif
  236. #ifdef __has_include
  237. #if __has_include(<optional>) && __cplusplus >= 201703L && \
  238. !PHMAP_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE
  239. #define PHMAP_HAVE_STD_OPTIONAL 1
  240. #endif
  241. #endif
  242. #ifdef PHMAP_HAVE_STD_VARIANT
  243. #error "PHMAP_HAVE_STD_VARIANT cannot be directly set."
  244. #endif
  245. #ifdef __has_include
  246. #if __has_include(<variant>) && __cplusplus >= 201703L && \
  247. !PHMAP_INTERNAL_MACOS_CXX17_TYPES_UNAVAILABLE
  248. #define PHMAP_HAVE_STD_VARIANT 1
  249. #endif
  250. #endif
  251. #ifdef PHMAP_HAVE_STD_STRING_VIEW
  252. #error "PHMAP_HAVE_STD_STRING_VIEW cannot be directly set."
  253. #endif
  254. #ifdef __has_include
  255. #if __has_include(<string_view>) && __cplusplus >= 201703L && \
  256. (!defined(_MSC_VER) || _MSC_VER >= 1920) // vs2019
  257. #define PHMAP_HAVE_STD_STRING_VIEW 1
  258. #endif
  259. #endif
  260. // #pragma message(PHMAP_VAR_NAME_VALUE(_MSVC_LANG))
  261. #if defined(_MSC_VER) && _MSC_VER >= 1910 && PHMAP_HAVE_CC17
  262. // #define PHMAP_HAVE_STD_ANY 1
  263. #define PHMAP_HAVE_STD_OPTIONAL 1
  264. #define PHMAP_HAVE_STD_VARIANT 1
  265. #if !defined(PHMAP_HAVE_STD_STRING_VIEW) && _MSC_VER >= 1920
  266. #define PHMAP_HAVE_STD_STRING_VIEW 1
  267. #endif
  268. #endif
  269. #if PHMAP_HAVE_CC17
  270. #ifdef __has_include
  271. #if __has_include(<shared_mutex>)
  272. #define PHMAP_HAVE_SHARED_MUTEX 1
  273. #endif
  274. #endif
  275. #endif
  276. #ifndef PHMAP_HAVE_STD_STRING_VIEW
  277. #define PHMAP_HAVE_STD_STRING_VIEW 0
  278. #endif
  279. // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
  280. // SEH exception from emplace for variant<SomeStruct> when constructing the
  281. // struct can throw. This defeats some of variant_test and
  282. // variant_exception_safety_test.
  283. #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
  284. #define PHMAP_INTERNAL_MSVC_2017_DBG_MODE
  285. #endif
  286. // ---------------------------------------------------------------------------
  287. // Checks whether wchar_t is treated as a native type
  288. // (MSVC: /Zc:wchar_t- treats wchar_t as unsigned short)
  289. // ---------------------------------------------------------------------------
  290. #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
  291. #define PHMAP_HAS_NATIVE_WCHAR_T
  292. #endif
  293. // -----------------------------------------------------------------------------
  294. // Sanitizer Attributes
  295. // -----------------------------------------------------------------------------
  296. //
  297. // Sanitizer-related attributes are not "defined" in this file (and indeed
  298. // are not defined as such in any file). To utilize the following
  299. // sanitizer-related attributes within your builds, define the following macros
  300. // within your build using a `-D` flag, along with the given value for
  301. // `-fsanitize`:
  302. //
  303. // * `ADDRESS_SANITIZER` + `-fsanitize=address` (Clang, GCC 4.8)
  304. // * `MEMORY_SANITIZER` + `-fsanitize=memory` (Clang-only)
  305. // * `THREAD_SANITIZER + `-fsanitize=thread` (Clang, GCC 4.8+)
  306. // * `UNDEFINED_BEHAVIOR_SANITIZER` + `-fsanitize=undefined` (Clang, GCC 4.9+)
  307. // * `CONTROL_FLOW_INTEGRITY` + -fsanitize=cfi (Clang-only)
  308. // -----------------------------------------------------------------------------
  309. // -----------------------------------------------------------------------------
  310. // A function-like feature checking macro that is a wrapper around
  311. // `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a
  312. // nonzero constant integer if the attribute is supported or 0 if not.
  313. //
  314. // It evaluates to zero if `__has_attribute` is not defined by the compiler.
  315. // -----------------------------------------------------------------------------
  316. #ifdef __has_attribute
  317. #define PHMAP_HAVE_ATTRIBUTE(x) __has_attribute(x)
  318. #else
  319. #define PHMAP_HAVE_ATTRIBUTE(x) 0
  320. #endif
  321. // -----------------------------------------------------------------------------
  322. // A function-like feature checking macro that accepts C++11 style attributes.
  323. // It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6
  324. // (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't
  325. // find `__has_cpp_attribute`, will evaluate to 0.
  326. // -----------------------------------------------------------------------------
  327. #if defined(__cplusplus) && defined(__has_cpp_attribute)
  328. #define PHMAP_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
  329. #else
  330. #define PHMAP_HAVE_CPP_ATTRIBUTE(x) 0
  331. #endif
  332. // -----------------------------------------------------------------------------
  333. // Function Attributes
  334. // -----------------------------------------------------------------------------
  335. #if PHMAP_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__))
  336. #define PHMAP_PRINTF_ATTRIBUTE(string_index, first_to_check) \
  337. __attribute__((__format__(__printf__, string_index, first_to_check)))
  338. #define PHMAP_SCANF_ATTRIBUTE(string_index, first_to_check) \
  339. __attribute__((__format__(__scanf__, string_index, first_to_check)))
  340. #else
  341. #define PHMAP_PRINTF_ATTRIBUTE(string_index, first_to_check)
  342. #define PHMAP_SCANF_ATTRIBUTE(string_index, first_to_check)
  343. #endif
  344. #if PHMAP_HAVE_ATTRIBUTE(disable_tail_calls)
  345. #define PHMAP_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
  346. #define PHMAP_ATTRIBUTE_NO_TAIL_CALL __attribute__((disable_tail_calls))
  347. #elif defined(__GNUC__) && !defined(__clang__)
  348. #define PHMAP_HAVE_ATTRIBUTE_NO_TAIL_CALL 1
  349. #define PHMAP_ATTRIBUTE_NO_TAIL_CALL \
  350. __attribute__((optimize("no-optimize-sibling-calls")))
  351. #else
  352. #define PHMAP_ATTRIBUTE_NO_TAIL_CALL
  353. #define PHMAP_HAVE_ATTRIBUTE_NO_TAIL_CALL 0
  354. #endif
  355. #if (PHMAP_HAVE_ATTRIBUTE(weak) || \
  356. (defined(__GNUC__) && !defined(__clang__))) && \
  357. !(defined(__llvm__) && defined(_WIN32))
  358. #undef PHMAP_ATTRIBUTE_WEAK
  359. #define PHMAP_ATTRIBUTE_WEAK __attribute__((weak))
  360. #define PHMAP_HAVE_ATTRIBUTE_WEAK 1
  361. #else
  362. #define PHMAP_ATTRIBUTE_WEAK
  363. #define PHMAP_HAVE_ATTRIBUTE_WEAK 0
  364. #endif
  365. #if PHMAP_HAVE_ATTRIBUTE(nonnull) || (defined(__GNUC__) && !defined(__clang__))
  366. #define PHMAP_ATTRIBUTE_NONNULL(arg_index) __attribute__((nonnull(arg_index)))
  367. #else
  368. #define PHMAP_ATTRIBUTE_NONNULL(...)
  369. #endif
  370. #if PHMAP_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__))
  371. #define PHMAP_ATTRIBUTE_NORETURN __attribute__((noreturn))
  372. #elif defined(_MSC_VER)
  373. #define PHMAP_ATTRIBUTE_NORETURN __declspec(noreturn)
  374. #else
  375. #define PHMAP_ATTRIBUTE_NORETURN
  376. #endif
  377. #if defined(__GNUC__) && defined(ADDRESS_SANITIZER)
  378. #define PHMAP_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
  379. #else
  380. #define PHMAP_ATTRIBUTE_NO_SANITIZE_ADDRESS
  381. #endif
  382. #if defined(__GNUC__) && defined(MEMORY_SANITIZER)
  383. #define PHMAP_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
  384. #else
  385. #define PHMAP_ATTRIBUTE_NO_SANITIZE_MEMORY
  386. #endif
  387. #if defined(__GNUC__) && defined(THREAD_SANITIZER)
  388. #define PHMAP_ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
  389. #else
  390. #define PHMAP_ATTRIBUTE_NO_SANITIZE_THREAD
  391. #endif
  392. #if defined(__GNUC__) && \
  393. (defined(UNDEFINED_BEHAVIOR_SANITIZER) || defined(ADDRESS_SANITIZER))
  394. #define PHMAP_ATTRIBUTE_NO_SANITIZE_UNDEFINED \
  395. __attribute__((no_sanitize("undefined")))
  396. #else
  397. #define PHMAP_ATTRIBUTE_NO_SANITIZE_UNDEFINED
  398. #endif
  399. #if defined(__GNUC__) && defined(CONTROL_FLOW_INTEGRITY)
  400. #define PHMAP_ATTRIBUTE_NO_SANITIZE_CFI __attribute__((no_sanitize("cfi")))
  401. #else
  402. #define PHMAP_ATTRIBUTE_NO_SANITIZE_CFI
  403. #endif
  404. #if defined(__GNUC__) && defined(SAFESTACK_SANITIZER)
  405. #define PHMAP_ATTRIBUTE_NO_SANITIZE_SAFESTACK \
  406. __attribute__((no_sanitize("safe-stack")))
  407. #else
  408. #define PHMAP_ATTRIBUTE_NO_SANITIZE_SAFESTACK
  409. #endif
  410. #if PHMAP_HAVE_ATTRIBUTE(returns_nonnull) || \
  411. (defined(__GNUC__) && \
  412. (__GNUC__ > 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) && \
  413. !defined(__clang__))
  414. #define PHMAP_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
  415. #else
  416. #define PHMAP_ATTRIBUTE_RETURNS_NONNULL
  417. #endif
  418. #ifdef PHMAP_HAVE_ATTRIBUTE_SECTION
  419. #error PHMAP_HAVE_ATTRIBUTE_SECTION cannot be directly set
  420. #elif (PHMAP_HAVE_ATTRIBUTE(section) || \
  421. (defined(__GNUC__) && !defined(__clang__))) && \
  422. !defined(__APPLE__) && PHMAP_HAVE_ATTRIBUTE_WEAK
  423. #define PHMAP_HAVE_ATTRIBUTE_SECTION 1
  424. #ifndef PHMAP_ATTRIBUTE_SECTION
  425. #define PHMAP_ATTRIBUTE_SECTION(name) \
  426. __attribute__((section(#name))) __attribute__((noinline))
  427. #endif
  428. #ifndef PHMAP_ATTRIBUTE_SECTION_VARIABLE
  429. #define PHMAP_ATTRIBUTE_SECTION_VARIABLE(name) __attribute__((section(#name)))
  430. #endif
  431. #ifndef PHMAP_DECLARE_ATTRIBUTE_SECTION_VARS
  432. #define PHMAP_DECLARE_ATTRIBUTE_SECTION_VARS(name) \
  433. extern char __start_##name[] PHMAP_ATTRIBUTE_WEAK; \
  434. extern char __stop_##name[] PHMAP_ATTRIBUTE_WEAK
  435. #endif
  436. #ifndef PHMAP_DEFINE_ATTRIBUTE_SECTION_VARS
  437. #define PHMAP_INIT_ATTRIBUTE_SECTION_VARS(name)
  438. #define PHMAP_DEFINE_ATTRIBUTE_SECTION_VARS(name)
  439. #endif
  440. #define PHMAP_ATTRIBUTE_SECTION_START(name) \
  441. (reinterpret_cast<void *>(__start_##name))
  442. #define PHMAP_ATTRIBUTE_SECTION_STOP(name) \
  443. (reinterpret_cast<void *>(__stop_##name))
  444. #else // !PHMAP_HAVE_ATTRIBUTE_SECTION
  445. #define PHMAP_HAVE_ATTRIBUTE_SECTION 0
  446. #define PHMAP_ATTRIBUTE_SECTION(name)
  447. #define PHMAP_ATTRIBUTE_SECTION_VARIABLE(name)
  448. #define PHMAP_INIT_ATTRIBUTE_SECTION_VARS(name)
  449. #define PHMAP_DEFINE_ATTRIBUTE_SECTION_VARS(name)
  450. #define PHMAP_DECLARE_ATTRIBUTE_SECTION_VARS(name)
  451. #define PHMAP_ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void *>(0))
  452. #define PHMAP_ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void *>(0))
  453. #endif // PHMAP_ATTRIBUTE_SECTION
  454. #if PHMAP_HAVE_ATTRIBUTE(force_align_arg_pointer) || \
  455. (defined(__GNUC__) && !defined(__clang__))
  456. #if defined(__i386__)
  457. #define PHMAP_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC \
  458. __attribute__((force_align_arg_pointer))
  459. #define PHMAP_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
  460. #elif defined(__x86_64__)
  461. #define PHMAP_REQUIRE_STACK_ALIGN_TRAMPOLINE (1)
  462. #define PHMAP_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
  463. #else // !__i386__ && !__x86_64
  464. #define PHMAP_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
  465. #define PHMAP_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
  466. #endif // __i386__
  467. #else
  468. #define PHMAP_ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
  469. #define PHMAP_REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
  470. #endif
  471. #if PHMAP_HAVE_ATTRIBUTE(nodiscard)
  472. #define PHMAP_MUST_USE_RESULT [[nodiscard]]
  473. #elif defined(__clang__) && PHMAP_HAVE_ATTRIBUTE(warn_unused_result)
  474. #define PHMAP_MUST_USE_RESULT __attribute__((warn_unused_result))
  475. #else
  476. #define PHMAP_MUST_USE_RESULT
  477. #endif
  478. #if PHMAP_HAVE_ATTRIBUTE(hot) || (defined(__GNUC__) && !defined(__clang__))
  479. #define PHMAP_ATTRIBUTE_HOT __attribute__((hot))
  480. #else
  481. #define PHMAP_ATTRIBUTE_HOT
  482. #endif
  483. #if PHMAP_HAVE_ATTRIBUTE(cold) || (defined(__GNUC__) && !defined(__clang__))
  484. #define PHMAP_ATTRIBUTE_COLD __attribute__((cold))
  485. #else
  486. #define PHMAP_ATTRIBUTE_COLD
  487. #endif
  488. #if defined(__clang__)
  489. #if PHMAP_HAVE_CPP_ATTRIBUTE(clang::reinitializes)
  490. #define PHMAP_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
  491. #else
  492. #define PHMAP_ATTRIBUTE_REINITIALIZES
  493. #endif
  494. #else
  495. #define PHMAP_ATTRIBUTE_REINITIALIZES
  496. #endif
  497. #if PHMAP_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__))
  498. #undef PHMAP_ATTRIBUTE_UNUSED
  499. #define PHMAP_ATTRIBUTE_UNUSED __attribute__((__unused__))
  500. #else
  501. #define PHMAP_ATTRIBUTE_UNUSED
  502. #endif
  503. #if PHMAP_HAVE_ATTRIBUTE(tls_model) || (defined(__GNUC__) && !defined(__clang__))
  504. #define PHMAP_ATTRIBUTE_INITIAL_EXEC __attribute__((tls_model("initial-exec")))
  505. #else
  506. #define PHMAP_ATTRIBUTE_INITIAL_EXEC
  507. #endif
  508. #if PHMAP_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__))
  509. #define PHMAP_ATTRIBUTE_PACKED __attribute__((__packed__))
  510. #else
  511. #define PHMAP_ATTRIBUTE_PACKED
  512. #endif
  513. #if PHMAP_HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
  514. #define PHMAP_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__((aligned(bytes)))
  515. #else
  516. #define PHMAP_ATTRIBUTE_FUNC_ALIGN(bytes)
  517. #endif
  518. // ----------------------------------------------------------------------
  519. // Figure out SSE support
  520. // ----------------------------------------------------------------------
  521. #ifndef PHMAP_HAVE_SSE2
  522. #if defined(__SSE2__) || SSE2NEON || \
  523. (defined(_MSC_VER) && \
  524. (defined(_M_X64) || (defined(_M_IX86) && _M_IX86_FP >= 2)))
  525. #define PHMAP_HAVE_SSE2 1
  526. #else
  527. #define PHMAP_HAVE_SSE2 0
  528. #endif
  529. #endif
  530. #ifndef PHMAP_HAVE_SSSE3
  531. #if defined(__SSSE3__) || defined(__AVX2__) || SSE2NEON
  532. #define PHMAP_HAVE_SSSE3 1
  533. #else
  534. #define PHMAP_HAVE_SSSE3 0
  535. #endif
  536. #endif
  537. #if PHMAP_HAVE_SSSE3 && !PHMAP_HAVE_SSE2
  538. #error "Bad configuration!"
  539. #endif
  540. #if SSE2NEON
  541. # define SSE2NEON_ALLOC_DEFINED
  542. # include "sse2neon.h"
  543. #else
  544. # include <immintrin.h>
  545. #endif
  546. // ----------------------------------------------------------------------
  547. // constexpr if
  548. // ----------------------------------------------------------------------
  549. #if PHMAP_HAVE_CC17
  550. #define PHMAP_IF_CONSTEXPR(expr) if constexpr ((expr))
  551. #else
  552. #define PHMAP_IF_CONSTEXPR(expr) if ((expr))
  553. #endif
  554. // ----------------------------------------------------------------------
  555. // builtin unreachable
  556. // ----------------------------------------------------------------------
  557. #if PHMAP_HAVE_BUILTIN(__builtin_unreachable)
  558. #define PHMAP_BUILTIN_UNREACHABLE() __builtin_unreachable()
  559. #else
  560. #define PHMAP_BUILTIN_UNREACHABLE() (void)0
  561. #endif
  562. // ----------------------------------------------------------------------
  563. // base/macros.h
  564. // ----------------------------------------------------------------------
  565. // PHMAP_ARRAYSIZE()
  566. //
  567. // Returns the number of elements in an array as a compile-time constant, which
  568. // can be used in defining new arrays. If you use this macro on a pointer by
  569. // mistake, you will get a compile-time error.
  570. #define PHMAP_ARRAYSIZE(array) \
  571. (sizeof(::phmap::macros_internal::ArraySizeHelper(array)))
  572. namespace phmap {
  573. namespace macros_internal {
  574. // Note: this internal template function declaration is used by PHMAP_ARRAYSIZE.
  575. // The function doesn't need a definition, as we only use its type.
  576. template <typename T, size_t N>
  577. auto ArraySizeHelper(const T (&array)[N]) -> char (&)[N];
  578. } // namespace macros_internal
  579. } // namespace phmap
  580. // TODO(zhangxy): Use c++17 standard [[fallthrough]] macro, when supported.
  581. #if defined(__clang__) && defined(__has_warning)
  582. #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
  583. #define PHMAP_FALLTHROUGH_INTENDED [[clang::fallthrough]]
  584. #endif
  585. #elif defined(__GNUC__) && __GNUC__ >= 7
  586. #define PHMAP_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
  587. #endif
  588. #ifndef PHMAP_FALLTHROUGH_INTENDED
  589. #define PHMAP_FALLTHROUGH_INTENDED \
  590. do { } while (0)
  591. #endif
  592. // PHMAP_DEPRECATED()
  593. //
  594. // Marks a deprecated class, struct, enum, function, method and variable
  595. // declarations. The macro argument is used as a custom diagnostic message (e.g.
  596. // suggestion of a better alternative).
  597. //
  598. // Example:
  599. //
  600. // class PHMAP_DEPRECATED("Use Bar instead") Foo {...};
  601. // PHMAP_DEPRECATED("Use Baz instead") void Bar() {...}
  602. //
  603. // Every usage of a deprecated entity will trigger a warning when compiled with
  604. // clang's `-Wdeprecated-declarations` option. This option is turned off by
  605. // default, but the warnings will be reported by clang-tidy.
  606. #if defined(__clang__) && __cplusplus >= 201103L
  607. #define PHMAP_DEPRECATED(message) __attribute__((deprecated(message)))
  608. #endif
  609. #ifndef PHMAP_DEPRECATED
  610. #define PHMAP_DEPRECATED(message)
  611. #endif
  612. // PHMAP_BAD_CALL_IF()
  613. //
  614. // Used on a function overload to trap bad calls: any call that matches the
  615. // overload will cause a compile-time error. This macro uses a clang-specific
  616. // "enable_if" attribute, as described at
  617. // http://clang.llvm.org/docs/AttributeReference.html#enable-if
  618. //
  619. // Overloads which use this macro should be bracketed by
  620. // `#ifdef PHMAP_BAD_CALL_IF`.
  621. //
  622. // Example:
  623. //
  624. // int isdigit(int c);
  625. // #ifdef PHMAP_BAD_CALL_IF
  626. // int isdigit(int c)
  627. // PHMAP_BAD_CALL_IF(c <= -1 || c > 255,
  628. // "'c' must have the value of an unsigned char or EOF");
  629. // #endif // PHMAP_BAD_CALL_IF
  630. #if defined(__clang__)
  631. #if __has_attribute(enable_if)
  632. #define PHMAP_BAD_CALL_IF(expr, msg) \
  633. __attribute__((enable_if(expr, "Bad call trap"), unavailable(msg)))
  634. #endif
  635. #endif
  636. // PHMAP_ASSERT()
  637. //
  638. // In C++11, `assert` can't be used portably within constexpr functions.
  639. // PHMAP_ASSERT functions as a runtime assert but works in C++11 constexpr
  640. // functions. Example:
  641. //
  642. // constexpr double Divide(double a, double b) {
  643. // return PHMAP_ASSERT(b != 0), a / b;
  644. // }
  645. //
  646. // This macro is inspired by
  647. // https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
  648. #if defined(NDEBUG)
  649. #define PHMAP_ASSERT(expr) (false ? (void)(expr) : (void)0)
  650. #else
  651. #define PHMAP_ASSERT(expr) \
  652. (PHMAP_PREDICT_TRUE((expr)) ? (void)0 \
  653. : [] { assert(false && #expr); }()) // NOLINT
  654. #endif
  655. #ifdef PHMAP_HAVE_EXCEPTIONS
  656. #define PHMAP_INTERNAL_TRY try
  657. #define PHMAP_INTERNAL_CATCH_ANY catch (...)
  658. #define PHMAP_INTERNAL_RETHROW do { throw; } while (false)
  659. #else // PHMAP_HAVE_EXCEPTIONS
  660. #define PHMAP_INTERNAL_TRY if (true)
  661. #define PHMAP_INTERNAL_CATCH_ANY else if (false)
  662. #define PHMAP_INTERNAL_RETHROW do {} while (false)
  663. #endif // PHMAP_HAVE_EXCEPTIONS
  664. #endif // phmap_config_h_guard_