[PATCH] D56273: Validate -add-plugin arguments.

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 3 08:21:01 PST 2019


thakis updated this revision to Diff 180085.
thakis added a comment.

remove require


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

https://reviews.llvm.org/D56273

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Frontend/plugin-unknown.c


Index: clang/test/Frontend/plugin-unknown.c
===================================================================
--- /dev/null
+++ clang/test/Frontend/plugin-unknown.c
@@ -0,0 +1,5 @@
+// RUN: not %clang_cc1 -plugin asdf %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -add-plugin asdf %s 2>&1 | FileCheck --check-prefix=ADD %s
+
+// CHECK: unable to find plugin 'asdf'
+// ADD: unable to find plugin 'asdf'
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -33,6 +33,7 @@
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/FrontendOptions.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
 #include "clang/Frontend/LangStandard.h"
 #include "clang/Frontend/MigratorOptions.h"
 #include "clang/Frontend/PreprocessorOutputOptions.h"
@@ -1663,7 +1664,20 @@
     Opts.ProgramAction = frontend::PluginAction;
     Opts.ActionName = A->getValue();
   }
-  Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin);
+  for (const std::string &Arg : Args.getAllArgValues(OPT_add_plugin)) {
+    bool Found = false;
+    for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
+                                          ie = FrontendPluginRegistry::end();
+         it != ie; ++it) {
+      if (it->getName() == Arg)
+        Found = true;
+    }
+    if (!Found) {
+      Diags.Report(diag::err_fe_invalid_plugin_name) << Arg;
+      continue;
+    }
+    Opts.AddPluginActions.push_back(Arg);
+  }
   for (const auto *AA : Args.filtered(OPT_plugin_arg))
     Opts.PluginArgs[AA->getValue(0)].emplace_back(AA->getValue(1));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56273.180085.patch
Type: text/x-patch
Size: 1783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190103/9cbbbb0d/attachment.bin>


More information about the cfe-commits mailing list