]> granicus.if.org Git - clang/commitdiff
[Frontend] Avoid running plugins during code completion parse
authorIvan Donchevskii <ivan.donchevskii@qt.io>
Wed, 16 May 2018 13:50:05 +0000 (13:50 +0000)
committerIvan Donchevskii <ivan.donchevskii@qt.io>
Wed, 16 May 2018 13:50:05 +0000 (13:50 +0000)
The parsing that is done for code completion is a special case that will
discard any generated diagnostics, so avoid running plugins for this
case in the first place to avoid performance penalties due to the
plugins.

A scenario for this is for example libclang with extra plugins like tidy.

Patch by Nikolai Kosjar

Differential Revision: https://reviews.llvm.org/D46050

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

lib/Frontend/FrontendAction.cpp
test/Index/complete-and-plugins.c [new file with mode: 0644]

index e4fb022c2a140508e53eeaf3bc32e10b8e046c29..1ebc37310de167dc38dfbb1cdf6e8b266607f5d8 100644 (file)
@@ -150,12 +150,16 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
     return nullptr;
 
   // If there are no registered plugins we don't need to wrap the consumer
-  if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
-    return Consumer;
-
-  // Collect the list of plugins that go before the main action (in Consumers)
-  // or after it (in AfterConsumers)
-  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
+  if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())\r
+    return Consumer;\r
+\r
+  // If this is a code completion run, avoid invoking the plugin consumers\r
+  if (CI.hasCodeCompletionConsumer())\r
+    return Consumer;\r
+\r
+  // Collect the list of plugins that go before the main action (in Consumers)\r
+  // or after it (in AfterConsumers)\r
+  std::vector<std::unique_ptr<ASTConsumer>> Consumers;\r
   std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers;
   for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
                                         ie = FrontendPluginRegistry::end();
diff --git a/test/Index/complete-and-plugins.c b/test/Index/complete-and-plugins.c
new file mode 100644 (file)
index 0000000..60c9214
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: c-index-test -code-completion-at=%s:7:1 -load %llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck %s\r
+// REQUIRES: plugins, examples\r
+// CHECK: macro definition:{{.*}}\r
+// CHECK-NOT: top-level-decl: "x"\r
+\r
+void x();\r