From ca27a2b037f149654057927973a6221e71cdf242 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 3 Jan 2019 18:26:06 +0000 Subject: [PATCH] Validate -add-plugin arguments. -plugin already prints an error if the name of an unknown plugin is passed. -add-plugin used to silently ignore that, now it errors too. Differential Revision: https://reviews.llvm.org/D56273 llvm-svn: 350340 --- clang/lib/Frontend/CompilerInvocation.cpp | 16 +++++++++++++++- clang/test/Frontend/plugin-unknown.c | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 clang/test/Frontend/plugin-unknown.c diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 220cad2738b8..39152fda9987 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/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 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, 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)); diff --git a/clang/test/Frontend/plugin-unknown.c b/clang/test/Frontend/plugin-unknown.c new file mode 100644 index 000000000000..5b225ae6639e --- /dev/null +++ b/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'