Index: clang/include/clang/Frontend/CompilerInstance.h =================================================================== --- clang/include/clang/Frontend/CompilerInstance.h +++ clang/include/clang/Frontend/CompilerInstance.h @@ -219,6 +219,8 @@ // of the context or else not CompilerInstance specific. bool ExecuteAction(FrontendAction &Act); + void LoadRequestedPlugins(); + /// } /// @name Compiler Invocation and Options /// { Index: clang/lib/Frontend/CompilerInstance.cpp =================================================================== --- clang/lib/Frontend/CompilerInstance.cpp +++ clang/lib/Frontend/CompilerInstance.cpp @@ -23,6 +23,7 @@ #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/LogDiagnosticPrinter.h" #include "clang/Frontend/SerializedDiagnosticPrinter.h" #include "clang/Frontend/TextDiagnosticPrinter.h" @@ -1029,6 +1030,27 @@ return !getDiagnostics().getClient()->getNumErrors(); } +void CompilerInstance::LoadRequestedPlugins() { + // Load any requested plugins. + for (const std::string &Path : getFrontendOpts().Plugins) { + std::string Error; + if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error)) + getDiagnostics().Report(diag::err_fe_unable_to_load_plugin) + << Path << Error; + } + + // Check if any of the loaded plugins replaces the main AST action + for (const FrontendPluginRegistry::entry &Plugin : + FrontendPluginRegistry::entries()) { + std::unique_ptr P(Plugin.instantiate()); + if (P->getActionType() == PluginASTAction::ReplaceAction) { + getFrontendOpts().ProgramAction = clang::frontend::PluginAction; + getFrontendOpts().ActionName = Plugin.getName().str(); + break; + } + } +} + /// Determine the appropriate source input kind based on language /// options. static Language getLanguageFromOptions(const LangOptions &LangOpts) { Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp =================================================================== --- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -203,24 +203,7 @@ return true; } - // Load any requested plugins. - for (const std::string &Path : Clang->getFrontendOpts().Plugins) { - std::string Error; - if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error)) - Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin) - << Path << Error; - } - - // Check if any of the loaded plugins replaces the main AST action - for (const FrontendPluginRegistry::entry &Plugin : - FrontendPluginRegistry::entries()) { - std::unique_ptr P(Plugin.instantiate()); - if (P->getActionType() == PluginASTAction::ReplaceAction) { - Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction; - Clang->getFrontendOpts().ActionName = Plugin.getName().str(); - break; - } - } + Clang->LoadRequestedPlugins(); // Honor -mllvm. // Index: clang/lib/Interpreter/IncrementalParser.cpp =================================================================== --- clang/lib/Interpreter/IncrementalParser.cpp +++ clang/lib/Interpreter/IncrementalParser.cpp @@ -65,6 +65,8 @@ case frontend::ParseSyntaxOnly: Act = CreateFrontendAction(CI); break; + case frontend::PluginAction: + LLVM_FALLTHROUGH; case frontend::EmitAssembly: LLVM_FALLTHROUGH; case frontend::EmitObj: Index: clang/tools/clang-repl/CMakeLists.txt =================================================================== --- clang/tools/clang-repl/CMakeLists.txt +++ clang/tools/clang-repl/CMakeLists.txt @@ -16,3 +16,8 @@ clangInterpreter clangTooling ) + +# Support plugins. +if(CLANG_PLUGIN_SUPPORT) + export_executable_symbols_for_plugins(clang-repl) +endif() Index: clang/tools/clang-repl/ClangRepl.cpp =================================================================== --- clang/tools/clang-repl/ClangRepl.cpp +++ clang/tools/clang-repl/ClangRepl.cpp @@ -80,6 +80,9 @@ llvm::install_fatal_error_handler(LLVMErrorHandler, static_cast(&CI->getDiagnostics())); + // Load any requested plugins. + CI->LoadRequestedPlugins(); + auto Interp = ExitOnErr(clang::Interpreter::create(std::move(CI))); for (const std::string &input : OptInputs) { if (auto Err = Interp->ParseAndExecute(input))