LLVM 22.0.0git
DemangleConfig.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8//
9// This file contains a variety of feature test macros copied from
10// include/llvm/Support/Compiler.h so that LLVMDemangle does not need to take
11// a dependency on LLVMSupport.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
16#define LLVM_DEMANGLE_DEMANGLECONFIG_H
17
18// llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
19#include "llvm/Config/llvm-config.h"
20
21#ifndef __has_feature
22#define __has_feature(x) 0
23#endif
24
25#ifndef __has_cpp_attribute
26#define __has_cpp_attribute(x) 0
27#endif
28
29#ifndef __has_attribute
30#define __has_attribute(x) 0
31#endif
32
33#ifndef __has_builtin
34#define __has_builtin(x) 0
35#endif
36
37#ifndef DEMANGLE_GNUC_PREREQ
38#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
39#define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
40 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
41 ((maj) << 20) + ((min) << 10) + (patch))
42#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
43#define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
44 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
45#else
46#define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
47#endif
48#endif
49
50#if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
51#define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
52#else
53#define DEMANGLE_ATTRIBUTE_USED
54#endif
55
56#if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
57#define DEMANGLE_UNREACHABLE __builtin_unreachable()
58#elif defined(_MSC_VER)
59#define DEMANGLE_UNREACHABLE __assume(false)
60#else
61#define DEMANGLE_UNREACHABLE
62#endif
63
64#if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
65#define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
66#elif defined(_MSC_VER)
67#define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
68#else
69#define DEMANGLE_ATTRIBUTE_NOINLINE
70#endif
71
72#if !defined(NDEBUG)
73#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
74#else
75#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
76#endif
77
78#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
79#define DEMANGLE_FALLTHROUGH [[fallthrough]]
80#elif __has_cpp_attribute(gnu::fallthrough)
81#define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
82#elif !__cplusplus
83// Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
84// error when __has_cpp_attribute is given a scoped attribute in C mode.
85#define DEMANGLE_FALLTHROUGH
86#elif __has_cpp_attribute(clang::fallthrough)
87#define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
88#else
89#define DEMANGLE_FALLTHROUGH
90#endif
91
92#ifndef DEMANGLE_ASSERT
93#include <cassert>
94#define DEMANGLE_ASSERT(__expr, __msg) assert((__expr) && (__msg))
95#endif
96
97#define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
98#define DEMANGLE_NAMESPACE_END } }
99
100/// DEMANGLE_ABI is the export/visibility macro used to mark symbols delcared in
101/// llvm/Demangle as exported when built as a shared library.
102#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
103#define DEMANGLE_ABI
104#else
105#if defined(_WIN32)
106#if defined(LLVM_EXPORTS)
107#define DEMANGLE_ABI __declspec(dllexport)
108#else
109#define DEMANGLE_ABI __declspec(dllimport)
110#endif
111#else
112#if __has_attribute(visibility)
113#define DEMANGLE_ABI __attribute__((__visibility__("default")))
114#else
115#define DEMANGLE_ABI
116#endif
117#endif
118#endif
119
120#endif