Skip to content

Commit efbe98d

Browse files
authored
[llvm] simplify and clean-up DemangleConfig.h (#149163)
## Purpose Simplify `DEMANGLE_` macro definitions in `llvm/Demangle/DemangleConfig.h` for clarity/maintainability. ## Overview * Alias `DEMANGLE_DUMP_METHOD`, `DEMANGLE_FALLTHROUGH`, and `DEMANGLE_UNREACHABLE` macros to their `LLVM_` counterparts defined in `llvm/Support/Compiler.h` * Remove several `DEMANGLE_`-prefixed macros that were only used within `DemangleConfig.h` ## Background * It should be safe for the `Demangle` component library to depend on `Support`, so there is no need for it to maintain copies of macros defined in `llvm/Support/Compiler.h`. * Since the canonical copy `llvm/Demangle/ItaniumDemangle.h` lives under `libcxxabi`, it cannot directly reference the `LLVM_`-prefixed macros so we define `DEMANGLE_`-prefixed aliases. ## Validation * Built llvm-project on Windows with `clang-cl` and MSVC `cl`. * Built llvm-project on Linux with `clang` and `gcc`.
1 parent 5eecbc0 commit efbe98d

File tree

1 file changed

+8
-68
lines changed

1 file changed

+8
-68
lines changed

llvm/include/llvm/Demangle/DemangleConfig.h

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,26 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
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.
9+
// Contains DEMANGLE_ aliases for LLVM_ definitions. The canonical copy of
10+
// ItaniumDemangle.h cannot depend on LLVM headers because lives in the
11+
// libcxxabi project.
1212
//
1313
//===----------------------------------------------------------------------===//
1414

1515
#ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
1616
#define LLVM_DEMANGLE_DEMANGLECONFIG_H
1717

18-
#ifndef __has_feature
19-
#define __has_feature(x) 0
20-
#endif
21-
22-
#ifndef __has_cpp_attribute
23-
#define __has_cpp_attribute(x) 0
24-
#endif
25-
26-
#ifndef __has_attribute
27-
#define __has_attribute(x) 0
28-
#endif
29-
30-
#ifndef __has_builtin
31-
#define __has_builtin(x) 0
32-
#endif
33-
34-
#ifndef DEMANGLE_GNUC_PREREQ
35-
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
36-
#define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
37-
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
38-
((maj) << 20) + ((min) << 10) + (patch))
39-
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
40-
#define DEMANGLE_GNUC_PREREQ(maj, min, patch) \
41-
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
42-
#else
43-
#define DEMANGLE_GNUC_PREREQ(maj, min, patch) 0
44-
#endif
45-
#endif
18+
#include "llvm/Support/Compiler.h"
4619

47-
#if __has_attribute(used) || DEMANGLE_GNUC_PREREQ(3, 1, 0)
48-
#define DEMANGLE_ATTRIBUTE_USED __attribute__((__used__))
49-
#else
50-
#define DEMANGLE_ATTRIBUTE_USED
51-
#endif
20+
#define DEMANGLE_DUMP_METHOD LLVM_DUMP_METHOD
21+
#define DEMANGLE_FALLTHROUGH LLVM_FALLTHROUGH
5222

53-
#if __has_builtin(__builtin_unreachable) || DEMANGLE_GNUC_PREREQ(4, 5, 0)
54-
#define DEMANGLE_UNREACHABLE __builtin_unreachable()
55-
#elif defined(_MSC_VER)
56-
#define DEMANGLE_UNREACHABLE __assume(false)
23+
#if defined(LLVM_BUILTIN_UNREACHABLE)
24+
#define DEMANGLE_UNREACHABLE LLVM_BUILTIN_UNREACHABLE
5725
#else
5826
#define DEMANGLE_UNREACHABLE
5927
#endif
6028

61-
#if __has_attribute(noinline) || DEMANGLE_GNUC_PREREQ(3, 4, 0)
62-
#define DEMANGLE_ATTRIBUTE_NOINLINE __attribute__((noinline))
63-
#elif defined(_MSC_VER)
64-
#define DEMANGLE_ATTRIBUTE_NOINLINE __declspec(noinline)
65-
#else
66-
#define DEMANGLE_ATTRIBUTE_NOINLINE
67-
#endif
68-
69-
#if !defined(NDEBUG)
70-
#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE DEMANGLE_ATTRIBUTE_USED
71-
#else
72-
#define DEMANGLE_DUMP_METHOD DEMANGLE_ATTRIBUTE_NOINLINE
73-
#endif
74-
75-
#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
76-
#define DEMANGLE_FALLTHROUGH [[fallthrough]]
77-
#elif __has_cpp_attribute(gnu::fallthrough)
78-
#define DEMANGLE_FALLTHROUGH [[gnu::fallthrough]]
79-
#elif !__cplusplus
80-
// Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
81-
// error when __has_cpp_attribute is given a scoped attribute in C mode.
82-
#define DEMANGLE_FALLTHROUGH
83-
#elif __has_cpp_attribute(clang::fallthrough)
84-
#define DEMANGLE_FALLTHROUGH [[clang::fallthrough]]
85-
#else
86-
#define DEMANGLE_FALLTHROUGH
87-
#endif
88-
8929
#ifndef DEMANGLE_ASSERT
9030
#include <cassert>
9131
#define DEMANGLE_ASSERT(__expr, __msg) assert((__expr) && (__msg))

0 commit comments

Comments
 (0)