Skip to content

Commit b8882be

Browse files
committed
Revert "Update llvm::Registry to work for LLVM shared library builds on windows (#109024)"
This reverts commit 00cd1a0. This effectively reverts #109024
1 parent 682925e commit b8882be

File tree

9 files changed

+30
-76
lines changed

9 files changed

+30
-76
lines changed

clang/include/clang/Basic/ParsedAttrInfo.h

-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "clang/Basic/AttrSubjectMatchRules.h"
1919
#include "clang/Basic/AttributeCommonInfo.h"
20-
#include "clang/Support/Compiler.h"
2120
#include "llvm/ADT/ArrayRef.h"
2221
#include "llvm/Support/Registry.h"
2322
#include <climits>
@@ -176,8 +175,4 @@ const std::list<std::unique_ptr<ParsedAttrInfo>> &getAttributePluginInstances();
176175

177176
} // namespace clang
178177

179-
namespace llvm {
180-
extern template class CLANG_TEMPLATE_ABI Registry<clang::ParsedAttrInfo>;
181-
} // namespace llvm
182-
183178
#endif // LLVM_CLANG_BASIC_PARSEDATTRINFO_H

clang/include/clang/Frontend/FrontendPluginRegistry.h

-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H
1515

1616
#include "clang/Frontend/FrontendAction.h"
17-
#include "clang/Support/Compiler.h"
1817
#include "llvm/Support/Registry.h"
1918

2019
namespace clang {
@@ -24,8 +23,4 @@ using FrontendPluginRegistry = llvm::Registry<PluginASTAction>;
2423

2524
} // namespace clang
2625

27-
namespace llvm {
28-
extern template class CLANG_TEMPLATE_ABI Registry<clang::PluginASTAction>;
29-
} // namespace llvm
30-
3126
#endif // LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H

clang/include/clang/Lex/Preprocessor.h

-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "clang/Lex/PPEmbedParameters.h"
3333
#include "clang/Lex/Token.h"
3434
#include "clang/Lex/TokenLexer.h"
35-
#include "clang/Support/Compiler.h"
3635
#include "llvm/ADT/APSInt.h"
3736
#include "llvm/ADT/ArrayRef.h"
3837
#include "llvm/ADT/DenseMap.h"
@@ -3061,8 +3060,4 @@ using PragmaHandlerRegistry = llvm::Registry<PragmaHandler>;
30613060

30623061
} // namespace clang
30633062

3064-
namespace llvm {
3065-
extern template class CLANG_TEMPLATE_ABI Registry<clang::PragmaHandler>;
3066-
} // namespace llvm
3067-
30683063
#endif // LLVM_CLANG_LEX_PREPROCESSOR_H

clang/include/clang/Tooling/CompilationDatabasePluginRegistry.h

-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_CLANG_TOOLING_COMPILATIONDATABASEPLUGINREGISTRY_H
1010
#define LLVM_CLANG_TOOLING_COMPILATIONDATABASEPLUGINREGISTRY_H
1111

12-
#include "clang/Support/Compiler.h"
1312
#include "clang/Tooling/CompilationDatabase.h"
1413
#include "llvm/Support/Registry.h"
1514

@@ -43,9 +42,4 @@ using CompilationDatabasePluginRegistry =
4342
} // namespace tooling
4443
} // namespace clang
4544

46-
namespace llvm {
47-
extern template class CLANG_TEMPLATE_ABI
48-
Registry<clang::tooling::CompilationDatabasePlugin>;
49-
} // namespace llvm
50-
5145
#endif // LLVM_CLANG_TOOLING_COMPILATIONDATABASEPLUGINREGISTRY_H

clang/include/clang/Tooling/ToolExecutorPluginRegistry.h

-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_CLANG_TOOLING_TOOLEXECUTORPLUGINREGISTRY_H
1010
#define LLVM_CLANG_TOOLING_TOOLEXECUTORPLUGINREGISTRY_H
1111

12-
#include "clang/Support/Compiler.h"
1312
#include "clang/Tooling/Execution.h"
1413
#include "llvm/Support/Registry.h"
1514

@@ -21,9 +20,4 @@ using ToolExecutorPluginRegistry = llvm::Registry<ToolExecutorPlugin>;
2120
} // namespace tooling
2221
} // namespace clang
2322

24-
namespace llvm {
25-
extern template class CLANG_TEMPLATE_ABI
26-
Registry<clang::tooling::ToolExecutorPlugin>;
27-
} // namespace llvm
28-
2923
#endif // LLVM_CLANG_TOOLING_TOOLEXECUTORPLUGINREGISTRY_H

llvm/include/llvm/CodeGen/GCMetadataPrinter.h

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class StackMaps;
3434
/// defaults from Registry.
3535
using GCMetadataPrinterRegistry = Registry<GCMetadataPrinter>;
3636

37-
extern template class LLVM_TEMPLATE_ABI Registry<GCMetadataPrinter>;
38-
3937
/// GCMetadataPrinter - Emits GC metadata as assembly code. Instances are
4038
/// created, managed, and owned by the AsmPrinter.
4139
class GCMetadataPrinter {

llvm/include/llvm/IR/GCStrategy.h

-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ class GCStrategy {
141141
/// GCMetadataPrinterRegistery as well.
142142
using GCRegistry = Registry<GCStrategy>;
143143

144-
extern template class LLVM_TEMPLATE_ABI Registry<GCStrategy>;
145-
146144
/// Lookup the GCStrategy object associated with the given gc name.
147145
std::unique_ptr<GCStrategy> getGCStrategy(const StringRef Name);
148146

llvm/include/llvm/Support/Compiler.h

-11
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@
153153
/// exported when llvm is built as a shared library with everything else that is
154154
/// unannotated will have internal visibility.
155155
///
156-
/// LLVM_ABI_EXPORT is for the special case for things like plugin symbol
157-
/// declarations or definitions where we don't want the macro to be switching
158-
/// between dllexport and dllimport on windows based on what codebase is being
159-
/// built, it will only be dllexport. For non windows platforms this macro
160-
/// behaves the same as LLVM_ABI.
161-
///
162156
/// LLVM_EXPORT_TEMPLATE is used on explicit template instantiations in source
163157
/// files that were declared extern in a header. This macro is only set as a
164158
/// compiler export attribute on windows, on other platforms it does nothing.
@@ -185,7 +179,6 @@
185179
#define LLVM_ABI
186180
#define LLVM_TEMPLATE_ABI
187181
#define LLVM_EXPORT_TEMPLATE
188-
#define LLVM_ABI_EXPORT
189182
#elif defined(_WIN32) && !defined(__MINGW32__)
190183
#if defined(LLVM_EXPORTS)
191184
#define LLVM_ABI __declspec(dllexport)
@@ -196,23 +189,19 @@
196189
#define LLVM_TEMPLATE_ABI __declspec(dllimport)
197190
#define LLVM_EXPORT_TEMPLATE
198191
#endif
199-
#define LLVM_ABI_EXPORT __declspec(dllexport)
200192
#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX)
201193
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
202194
#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
203195
#define LLVM_EXPORT_TEMPLATE
204-
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
205196
#elif defined(__MACH__) || defined(__WASM__)
206197
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
207198
#define LLVM_TEMPLATE_ABI
208199
#define LLVM_EXPORT_TEMPLATE
209-
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
210200
#endif
211201
#else
212202
#define LLVM_ABI
213203
#define LLVM_TEMPLATE_ABI
214204
#define LLVM_EXPORT_TEMPLATE
215-
#define LLVM_ABI_EXPORT
216205
#endif
217206
#define LLVM_C_ABI LLVM_ABI
218207
#endif

llvm/include/llvm/Support/Registry.h

+30-34
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ namespace llvm {
5353
Registry() = delete;
5454

5555
friend class node;
56-
// These must be must two separate declarations to workaround a 20 year
57-
// old MSVC bug with dllexport and multiple static fields in the same
58-
// declaration causing error C2487 "member of dll interface class may not
59-
// be declared with dll interface".
60-
// https://developercommunity.visualstudio.com/t/c2487-in-dllexport-class-with-static-members/69878
61-
static node *Head;
62-
static node *Tail;
56+
static node *Head, *Tail;
6357

6458
public:
6559
/// Node in linked list of entries.
@@ -82,13 +76,7 @@ namespace llvm {
8276
/// add a node to the executable's registry. Therefore it's not defined here
8377
/// to avoid it being instantiated in the plugin and is instead defined in
8478
/// the executable (see LLVM_INSTANTIATE_REGISTRY below).
85-
static void add_node(node *N) {
86-
if (Tail)
87-
Tail->Next = N;
88-
else
89-
Head = N;
90-
Tail = N;
91-
}
79+
static void add_node(node *N);
9280

9381
/// Iterators for registry entries.
9482
///
@@ -107,7 +95,7 @@ namespace llvm {
10795

10896
// begin is not defined here in order to avoid usage of an undefined static
10997
// data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
110-
static iterator begin() { return iterator(Head); }
98+
static iterator begin();
11199
static iterator end() { return iterator(nullptr); }
112100

113101
static iterator_range<iterator> entries() {
@@ -136,28 +124,36 @@ namespace llvm {
136124
}
137125
};
138126
};
139-
140127
} // end namespace llvm
141128

142-
#ifdef _WIN32
143129
/// Instantiate a registry class.
144-
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
145-
namespace llvm { \
146-
template <typename T> \
147-
typename Registry<T>::node *Registry<T>::Head = nullptr; \
148-
template <typename T> \
149-
typename Registry<T>::node *Registry<T>::Tail = nullptr; \
150-
template class LLVM_ABI_EXPORT Registry<REGISTRY_CLASS::type>; \
151-
}
152-
#else
153-
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
154-
namespace llvm { \
155-
template <typename T> \
156-
typename Registry<T>::node *Registry<T>::Head = nullptr; \
157-
template <typename T> \
158-
typename Registry<T>::node *Registry<T>::Tail = nullptr; \
159-
template class Registry<REGISTRY_CLASS::type>; \
130+
///
131+
/// This provides template definitions of add_node, begin, and the Head and Tail
132+
/// pointers, then explicitly instantiates them. We could explicitly specialize
133+
/// them, instead of the two-step process of define then instantiate, but
134+
/// strictly speaking that's not allowed by the C++ standard (we would need to
135+
/// have explicit specialization declarations in all translation units where the
136+
/// specialization is used) so we don't.
137+
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
138+
namespace llvm { \
139+
template<typename T> typename Registry<T>::node *Registry<T>::Head = nullptr;\
140+
template<typename T> typename Registry<T>::node *Registry<T>::Tail = nullptr;\
141+
template<typename T> \
142+
void Registry<T>::add_node(typename Registry<T>::node *N) { \
143+
if (Tail) \
144+
Tail->Next = N; \
145+
else \
146+
Head = N; \
147+
Tail = N; \
148+
} \
149+
template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150+
return iterator(Head); \
151+
} \
152+
template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Head; \
153+
template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Tail; \
154+
template \
155+
void Registry<REGISTRY_CLASS::type>::add_node(REGISTRY_CLASS::node*); \
156+
template REGISTRY_CLASS::iterator Registry<REGISTRY_CLASS::type>::begin(); \
160157
}
161-
#endif
162158

163159
#endif // LLVM_SUPPORT_REGISTRY_H

0 commit comments

Comments
 (0)