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