DemangleConfig.h 3.1 KB

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