123 lines · c
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-exception6//7// This file is contains a subset of macros copied from8// llvm/include/llvm/Demangle/DemangleConfig.h9//===----------------------------------------------------------------------===//10 11#ifndef LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H12#define LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H13 14// Must be defined before pulling in headers from libc++. Allow downstream15// build systems to override this value.16// https://libcxx.llvm.org/UsingLibcxx.html#enabling-the-safe-libc-mode17#ifndef _LIBCPP_VERBOSE_ABORT18#define _LIBCPP_VERBOSE_ABORT(...) __abort_message(__VA_ARGS__)19#include "../abort_message.h"20#endif21 22#ifndef _LIBCPP_LOG_HARDENING_FAILURE23// Libc++abi does not have any functionality to log and continue, so we drop24// 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#endif29 30#include <version>31 32#ifdef _MSC_VER33// snprintf is implemented in VS 201534#if _MSC_VER < 190035#define snprintf _snprintf_s36#endif37#endif38 39#ifndef __has_feature40#define __has_feature(x) 041#endif42 43#ifndef __has_cpp_attribute44#define __has_cpp_attribute(x) 045#endif46 47#ifndef __has_attribute48#define __has_attribute(x) 049#endif50 51#ifndef __has_builtin52#define __has_builtin(x) 053#endif54 55#ifndef DEMANGLE_GNUC_PREREQ56#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#else64#define DEMANGLE_GNUC_PREREQ(maj, min, patch) 065#endif66#endif67 68#if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)69#define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))70#else71#define DEMANGLE_ATTRIBUTE_USED72#endif73 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#else79#define DEMANGLE_UNREACHABLE80#endif81 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#else87#define DEMANGLE_ATTRIBUTE_NOINLINE88#endif89 90#if !defined(NDEBUG)91#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED92#else93#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE94#endif95 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 !__cplusplus101// Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious102// error when __has_cpp_attribute is given a scoped attribute in C mode.103#define DEMANGLE_FALLTHROUGH104#elif __has_cpp_attribute(clang::fallthrough)105#define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]106#else107#define DEMANGLE_FALLTHROUGH108#endif109 110#ifndef DEMANGLE_ASSERT111#include <cassert>112#define DEMANGLE_ASSERT(__expr, __msg) assert((__expr) && (__msg))113#endif114 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. Only119// the llvm copy defines DEMANGLE_ABI as a visibility attribute.120#define DEMANGLE_ABI121 122#endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H123