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 #include <ciso646>
15 
16 #ifdef _MSC_VER
17 // snprintf is implemented in VS 2015
18 #if _MSC_VER < 1900
19 #define snprintf _snprintf_s
20 #endif
21 #endif
22 
23 #ifndef __has_feature
24 #define __has_feature(x) 0
25 #endif
26 
27 #ifndef __has_cpp_attribute
28 #define __has_cpp_attribute(x) 0
29 #endif
30 
31 #ifndef __has_attribute
32 #define __has_attribute(x) 0
33 #endif
34 
35 #ifndef __has_builtin
36 #define __has_builtin(x) 0
37 #endif
38 
39 #ifndef DEMANGLE_GNUC_PREREQ
40 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
41 #define DEMANGLE_GNUC_PREREQ(maj, min, patch)                           \
42   ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >=          \
43    ((maj) << 20) + ((min) << 10) + (patch))
44 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
45 #define DEMANGLE_GNUC_PREREQ(maj, min, patch)                           \
46   ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
47 #else
48 #define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
49 #endif
50 #endif
51 
52 #if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
53 #define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
54 #else
55 #define DEMANGLE_ATTRIBUTE_USED
56 #endif
57 
58 #if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
59 #define DEMANGLE_UNREACHABLE __builtin_unreachable()
60 #elif defined(_MSC_VER)
61 #define DEMANGLE_UNREACHABLE __assume(false)
62 #else
63 #define DEMANGLE_UNREACHABLE
64 #endif
65 
66 #if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
67 #define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
68 #elif defined(_MSC_VER)
69 #define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
70 #else
71 #define DEMANGLE_ATTRIBUTE_NOINLINE
72 #endif
73 
74 #if !defined(NDEBUG)
75 #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
76 #else
77 #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
78 #endif
79 
80 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
81 #define DEMANGLE_FALLTHROUGH [[fallthrough]]
82 #elif __has_cpp_attribute(gnu::fallthrough)
83 #define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
84 #elif !__cplusplus
85 // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
86 // error when __has_cpp_attribute is given a scoped attribute in C mode.
87 #define DEMANGLE_FALLTHROUGH
88 #elif __has_cpp_attribute(clang::fallthrough)
89 #define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
90 #else
91 #define DEMANGLE_FALLTHROUGH
92 #endif
93 
94 #define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {
95 #define DEMANGLE_NAMESPACE_END } }
96 
97 #endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
98