Debian Codegraph @

libcxxabi/src/demangle/DemangleConfig.h

raw
1 //===--- DemangleConfig.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 // This file is contains a subset of macros copied from
8 // llvm/include/llvm/Demangle/DemangleConfig.h
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
12 #define LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
13
14 // Must be defined before pulling in headers from libc++. Allow downstream
15 // build systems to override this value.
16 // https://libcxx.llvm.org/UsingLibcxx.html#enabling-the-safe-libc-mode
17 #ifndef _LIBCPP_VERBOSE_ABORT
18 #define _LIBCPP_VERBOSE_ABORT(...) __abort_message(__VA_ARGS__)
19 #include "../abort_message.h"
20 #endif
21
22 #ifndef _LIBCPP_LOG_HARDENING_FAILURE
23 // Libc++abi does not have any functionality to log and continue, so we drop
24 // error messages when we build the demangler with `observe` assertion semantic.
25 // Once the layering with libc++ is improved, this could use the libc++
26 // functionality to log hardening failures.
27 #define _LIBCPP_LOG_HARDENING_FAILURE(message) ((void)0)
28 #endif
29
30 #include <version>
31
32 #ifdef _MSC_VER
33 // snprintf is implemented in VS 2015
34 #if _MSC_VER < 1900
35 #define snprintf _snprintf_s
36 #endif
37 #endif
38
39 #ifndef __has_feature
40 #define __has_feature(x) 0
41 #endif
42
43 #ifndef __has_cpp_attribute
44 #define __has_cpp_attribute(x) 0
45 #endif
46
47 #ifndef __has_attribute
48 #define __has_attribute(x) 0
49 #endif
50
51 #ifndef __has_builtin
52 #define __has_builtin(x) 0
53 #endif
54
55 #ifndef DEMANGLE_GNUC_PREREQ
56 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
57 #define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
58 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
59 ((maj) << 20) + ((min) << 10) + (patch))
60 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
61 #define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
62 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
63 #else
64 #define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
65 #endif
66 #endif
67
68 #if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
69 #define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
70 #else
71 #define DEMANGLE_ATTRIBUTE_USED
72 #endif
73
74 #if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
75 #define DEMANGLE_UNREACHABLE __builtin_unreachable()
76 #elif defined(_MSC_VER)
77 #define DEMANGLE_UNREACHABLE __assume(false)
78 #else
79 #define DEMANGLE_UNREACHABLE
80 #endif
81
82 #if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
83 #define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
84 #elif defined(_MSC_VER)
85 #define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
86 #else
87 #define DEMANGLE_ATTRIBUTE_NOINLINE
88 #endif
89
90 #if !defined(NDEBUG)
91 #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
92 #else
93 #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
94 #endif
95
96 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
97 #define DEMANGLE_FALLTHROUGH [[fallthrough]]
98 #elif __has_cpp_attribute(gnu::fallthrough)
99 #define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
100 #elif !__cplusplus
101 // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
102 // error when __has_cpp_attribute is given a scoped attribute in C mode.
103 #define DEMANGLE_FALLTHROUGH
104 #elif __has_cpp_attribute(clang::fallthrough)
105 #define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
106 #else
107 #define DEMANGLE_FALLTHROUGH
108 #endif
109
110 #ifndef DEMANGLE_ASSERT
111 #include <cassert>
112 #define DEMANGLE_ASSERT(__expr, __msg) assert((__expr) && (__msg))
113 #endif
114
115 #define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {
116 #define DEMANGLE_NAMESPACE_END } }
117
118 // The DEMANGLE_ABI macro resolves to nothing when building libc++abi. Only
119 // the llvm copy defines DEMANGLE_ABI as a visibility attribute.
120 #define DEMANGLE_ABI
121
122 #endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H