]> granicus.if.org Git - clang/commitdiff
Reapply r276856 "Adjust Registry interface to not require plugins to export a registry"
authorJohn Brawn <john.brawn@arm.com>
Thu, 28 Jul 2016 12:48:17 +0000 (12:48 +0000)
committerJohn Brawn <john.brawn@arm.com>
Thu, 28 Jul 2016 12:48:17 +0000 (12:48 +0000)
This version has two fixes compared to the original:
 * In Registry.h the template static members are instantiated before they are
   used, as clang gives an error if you do it the other way around.
 * The use of the Registry template in clang-tidy is updated in the same way as
   has been done everywhere else.

Original commit message:

Currently the Registry class contains the vestiges of a previous attempt to
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a
plugin would have its own copy of a registry and export it to be imported by
the tool that's loading the plugin. This only works if the plugin is entirely
self-contained with the only interface between the plugin and tool being the
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry
is exported by the tool and then imported by the plugin, which solves this
problem and also means that instead of every plugin having to export every
registry they use instead LLVM only has to export the add_node functions. This
allows plugins that use a registry to work on Windows if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276973 91177308-0d34-0410-b5e6-96231b3b80d8

examples/AnnotateFunctions/CMakeLists.txt
examples/PrintFunctionNames/CMakeLists.txt
include/clang/Frontend/FrontendPluginRegistry.h
include/clang/Lex/Preprocessor.h
lib/Frontend/FrontendAction.cpp
lib/Lex/Preprocessor.cpp
lib/Tooling/CompilationDatabase.cpp

index cf564d527d6a8f692599024eed62a4578c3d83ff..5684abf2380d14ccea063a5629737560fc36cd36 100644 (file)
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp)
+add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE
index 5a00d5036fb1631be836365652f40851eece869c..f5f818866ca60e9f89489d04b23532c87a076f4e 100644 (file)
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols differently, and
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE
index ecab630c1228c9adac60a33319c9615c82e9a142..9d7ee08d95d4b5dcab31d97e0177d35782337ede 100644 (file)
@@ -13,9 +13,6 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/Support/Registry.h"
 
-// Instantiated in FrontendAction.cpp.
-extern template class llvm::Registry<clang::PluginASTAction>;
-
 namespace clang {
 
 /// The frontend plugin registry.
index c9b712504e108f932478fa7a068baf3884a39393..000df6647fe6c4d9324ca2c2fda26116af59aaa8 100644 (file)
@@ -1972,6 +1972,4 @@ typedef llvm::Registry<PragmaHandler> PragmaHandlerRegistry;
 
 }  // end namespace clang
 
-extern template class llvm::Registry<clang::PragmaHandler>;
-
 #endif
index d2c2a80394db860578abd112506f309da305de83..2945b8925f9b2404349a6c314ba13224a312155d 100644 (file)
@@ -33,7 +33,7 @@
 #include <system_error>
 using namespace clang;
 
-template class llvm::Registry<clang::PluginASTAction>;
+LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
 
 namespace {
 
index 8832c7f80c451ab80eed295a8df79f94d8f77159..f0d68725462086dc413609e59fd887c2296b68db 100644 (file)
@@ -54,7 +54,7 @@
 #include <utility>
 using namespace clang;
 
-template class llvm::Registry<clang::PragmaHandler>;
+LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
 
 //===----------------------------------------------------------------------===//
 ExternalPreprocessorSource::~ExternalPreprocessorSource() { }
index 8fc4a1fe5beb0d2d8b022aaf25c179114420954e..6f95bf01f690bd827da820fe4fbe5f39bae95470 100644 (file)
@@ -32,6 +32,8 @@
 using namespace clang;
 using namespace tooling;
 
+LLVM_INSTANTIATE_REGISTRY(CompilationDatabasePluginRegistry)
+
 CompilationDatabase::~CompilationDatabase() {}
 
 std::unique_ptr<CompilationDatabase>