[PATCH] D92155: Load plugins when creating a CompilerInvocation.

Yafei Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 23:06:54 PST 2020


psionic12 updated this revision to Diff 307763.
psionic12 added a comment.

Fix some syntax


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92155/new/

https://reviews.llvm.org/D92155

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/tools/clang-check/CMakeLists.txt


Index: clang/tools/clang-check/CMakeLists.txt
===================================================================
--- clang/tools/clang-check/CMakeLists.txt
+++ clang/tools/clang-check/CMakeLists.txt
@@ -19,3 +19,8 @@
   clangStaticAnalyzerFrontend
   clangTooling
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+    export_executable_symbols_for_plugins(clang-check)
+endif()
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===================================================================
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -203,25 +203,6 @@
     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<PluginASTAction> P(Plugin.instantiate());
-    if (P->getActionType() == PluginASTAction::ReplaceAction) {
-      Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
-      Clang->getFrontendOpts().ActionName = Plugin.getName().str();
-      break;
-    }
-  }
-
   // Honor -mllvm.
   //
   // FIXME: Remove this, one day.
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3899,6 +3899,24 @@
   Res.getCodeGenOpts().Argv0 = Argv0;
   Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
 
+  // Load any requested plugins.
+  for (const std::string &Path : Res.getFrontendOpts().Plugins) {
+    std::string Error;
+    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+      Diags.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<PluginASTAction> P(Plugin.instantiate());
+    if (P->getActionType() == PluginASTAction::ReplaceAction) {
+      Res.getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
+      Res.getFrontendOpts().ActionName = Plugin.getName().str();
+      break;
+    }
+  }
+
   return Success;
 }
 
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -39,3 +39,8 @@
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clangd)
+endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92155.307763.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201126/9ad87cf1/attachment.bin>


More information about the cfe-commits mailing list