Skip to content

Commit

Permalink
Reapply r276973 "Adjust Registry interface to not require plugins to …
Browse files Browse the repository at this point in the history
…export a registry"

This differs from the previous version by being more careful about template
instantiation/specialization in order to prevent errors when building with
clang -Werror. Specifically:
 * begin is not defined in the template and is instead instantiated when Head
   is. I think the warning when we don't do that is wrong (PR28815) but for now
   at least do it this way to avoid the warning.
 * Instead of performing template specializations in LLVM_INSTANTIATE_REGISTRY
   instead provide a template definition then do explicit instantiation. No
   compiler I've tried has problems with doing it the other way, but strictly
   speaking it's not permitted by the C++ standard so better safe than sorry.

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@277806 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
john-brawn-arm committed Aug 5, 2016
1 parent 4cfe28c commit 0cfb8c8
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/AnnotateFunctions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/PrintFunctionNames/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions include/clang/Frontend/FrontendPluginRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,4 @@ typedef llvm::Registry<PragmaHandler> PragmaHandlerRegistry;

} // end namespace clang

extern template class llvm::Registry<clang::PragmaHandler>;

#endif
2 changes: 1 addition & 1 deletion lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <system_error>
using namespace clang;

template class llvm::Registry<clang::PluginASTAction>;
LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)

namespace {

Expand Down
2 changes: 1 addition & 1 deletion lib/Lex/Preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include <utility>
using namespace clang;

template class llvm::Registry<clang::PragmaHandler>;
LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)

//===----------------------------------------------------------------------===//
ExternalPreprocessorSource::~ExternalPreprocessorSource() { }
Expand Down
2 changes: 2 additions & 0 deletions lib/Tooling/CompilationDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using namespace clang;
using namespace tooling;

LLVM_INSTANTIATE_REGISTRY(CompilationDatabasePluginRegistry)

CompilationDatabase::~CompilationDatabase() {}

std::unique_ptr<CompilationDatabase>
Expand Down

0 comments on commit 0cfb8c8

Please sign in to comment.