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

source code of libcxxabi/src/demangle/DemangleConfig.h