DemangleConfig.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-FileCopyrightText: Part of the LLVM Project
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains a variety of feature test macros copied from
  11. // include/llvm/Support/Compiler.h so that LLVMDemangle does not need to take
  12. // a dependency on LLVMSupport.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
  16. #define LLVM_DEMANGLE_DEMANGLECONFIG_H
  17. #ifndef __has_feature
  18. #define __has_feature(x) 0
  19. #endif
  20. #ifndef __has_cpp_attribute
  21. #define __has_cpp_attribute(x) 0
  22. #endif
  23. #ifndef __has_attribute
  24. #define __has_attribute(x) 0
  25. #endif
  26. #ifndef __has_builtin
  27. #define __has_builtin(x) 0
  28. #endif
  29. #ifndef DEMANGLE_GNUC_PREREQ
  30. #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
  31. #define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
  32. ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
  33. ((maj) << 20) + ((min) << 10) + (patch))
  34. #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
  35. #define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
  36. ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
  37. #else
  38. #define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
  39. #endif
  40. #endif
  41. #if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
  42. #define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
  43. #else
  44. #define DEMANGLE_ATTRIBUTE_USED
  45. #endif
  46. #if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
  47. #define DEMANGLE_UNREACHABLE __builtin_unreachable()
  48. #elif defined(_MSC_VER)
  49. #define DEMANGLE_UNREACHABLE __assume(false)
  50. #else
  51. #define DEMANGLE_UNREACHABLE
  52. #endif
  53. #if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
  54. #define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
  55. #elif defined(_MSC_VER)
  56. #define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
  57. #else
  58. #define DEMANGLE_ATTRIBUTE_NOINLINE
  59. #endif
  60. #if !defined(NDEBUG)
  61. #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
  62. #else
  63. #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
  64. #endif
  65. #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
  66. #define DEMANGLE_FALLTHROUGH [[fallthrough]]
  67. #elif __has_cpp_attribute(gnu::fallthrough)
  68. #define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
  69. #elif !__cplusplus
  70. // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
  71. // error when __has_cpp_attribute is given a scoped attribute in C mode.
  72. #define DEMANGLE_FALLTHROUGH
  73. #elif __has_cpp_attribute(clang::fallthrough)
  74. #define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
  75. #else
  76. #define DEMANGLE_FALLTHROUGH
  77. #endif
  78. #define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
  79. #define DEMANGLE_NAMESPACE_END } }
  80. #endif