DemangleConfig.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
  15. #define LLVM_DEMANGLE_DEMANGLECONFIG_H
  16. #ifndef __has_feature
  17. #define __has_feature(x) 0
  18. #endif
  19. #ifndef __has_cpp_attribute
  20. #define __has_cpp_attribute(x) 0
  21. #endif
  22. #ifndef __has_attribute
  23. #define __has_attribute(x) 0
  24. #endif
  25. #ifndef __has_builtin
  26. #define __has_builtin(x) 0
  27. #endif
  28. #ifndef DEMANGLE_GNUC_PREREQ
  29. #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
  30. #define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
  31. ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
  32. ((maj) << 20) + ((min) << 10) + (patch))
  33. #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
  34. #define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
  35. ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
  36. #else
  37. #define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
  38. #endif
  39. #endif
  40. #if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
  41. #define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
  42. #else
  43. #define DEMANGLE_ATTRIBUTE_USED
  44. #endif
  45. #if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
  46. #define DEMANGLE_UNREACHABLE __builtin_unreachable()
  47. #elif defined(_MSC_VER)
  48. #define DEMANGLE_UNREACHABLE __assume(false)
  49. #else
  50. #define DEMANGLE_UNREACHABLE
  51. #endif
  52. #if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
  53. #define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
  54. #elif defined(_MSC_VER)
  55. #define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
  56. #else
  57. #define DEMANGLE_ATTRIBUTE_NOINLINE
  58. #endif
  59. #if !defined(NDEBUG)
  60. #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
  61. #else
  62. #define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
  63. #endif
  64. #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
  65. #define DEMANGLE_FALLTHROUGH [[fallthrough]]
  66. #elif __has_cpp_attribute(gnu::fallthrough)
  67. #define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
  68. #elif !__cplusplus
  69. // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
  70. // error when __has_cpp_attribute is given a scoped attribute in C mode.
  71. #define DEMANGLE_FALLTHROUGH
  72. #elif __has_cpp_attribute(clang::fallthrough)
  73. #define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
  74. #else
  75. #define DEMANGLE_FALLTHROUGH
  76. #endif
  77. #define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
  78. #define DEMANGLE_NAMESPACE_END } }
  79. #endif