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