tbaeder created this revision. Herald added a subscriber: dang. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
>From GCC's manpage: -fplugin-arg-name-key=value Define an argument called key with a value of value for the plugin called name. Since we don't have a key-value pair similar to gcc's plugin_argument struct, simply accept key=value here anyway and pass it along as-is to plugins. This translates to the already existing '-plugin-arg-pluginname arg' that clang cc1 accepts. There is an ambiguity here because in clang, both the plugin name as well as the option name can contain dashes, so when e.g. passing -fplugin-arg-foo-bar-foo it is not clear whether the plugin is foo-bar and the option is foo, or the plugin is foo and the option is bar-foo. GCC solves this by interpreting all dashes as part of the option name. So dashes can't be part of the plugin name in this case. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D113250 Files: clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6612,6 +6612,25 @@ A->claim(); } + // Turn -fplugin-arg-pluginname-key=value into + // -plugin-arg-pluginname key=value + // GCC has an actual plugin_argument struct with key/value pairs that it + // passes to its plugins, but we don't, so just pass it on as-is. + // + // The syntax for -fplugin-arg- is ambiguous if both plugin name and + // argument key are allowed to contain dashes. GCC therefore only + // allows dashes in the key. We do the same. + for (const Arg *A : Args.filtered(options::OPT_fplugin_arg)) { + auto ArgValue = StringRef(A->getValue()); + auto FirstDashIndex = ArgValue.find('-'); + auto Arg = ArgValue.substr(FirstDashIndex + 1); + auto PluginName = ArgValue.substr(0, FirstDashIndex); + + CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-arg-") + PluginName)); + CmdArgs.push_back(Args.MakeArgString(Arg)); + A->claim(); + } + // Forward -fpass-plugin=name.so to -cc1. for (const Arg *A : Args.filtered(options::OPT_fpass_plugin_EQ)) { CmdArgs.push_back( Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2501,6 +2501,9 @@ NegFlag<SetFalse>>; def fplugin_EQ : Joined<["-"], "fplugin=">, Group<f_Group>, Flags<[NoXarchOption]>, MetaVarName<"<dsopath>">, HelpText<"Load the named plugin (dynamic shared object)">; +def fplugin_arg : Joined<["-"], "fplugin-arg-">, + MetaVarName<"<name>-<arg>">, + HelpText<"Pass <arg> to plugin <name>">; def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">, Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<dsopath>">, HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">, Index: clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp =================================================================== --- clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp +++ clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp @@ -145,6 +145,14 @@ bool ParseArgs(const CompilerInstance &CI, const std::vector<std::string> &args) override { + if (!args.empty()) { + if (args[0] == "help") { + llvm::errs() << "Help text for CallSuper plugin goes here\n"; + } else if (args[0] == "help-long") { + llvm::errs() << "A longer help text describing what the CallSuper " + << "plugin does goes here\n"; + } + } return true; }
Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6612,6 +6612,25 @@ A->claim(); } + // Turn -fplugin-arg-pluginname-key=value into + // -plugin-arg-pluginname key=value + // GCC has an actual plugin_argument struct with key/value pairs that it + // passes to its plugins, but we don't, so just pass it on as-is. + // + // The syntax for -fplugin-arg- is ambiguous if both plugin name and + // argument key are allowed to contain dashes. GCC therefore only + // allows dashes in the key. We do the same. + for (const Arg *A : Args.filtered(options::OPT_fplugin_arg)) { + auto ArgValue = StringRef(A->getValue()); + auto FirstDashIndex = ArgValue.find('-'); + auto Arg = ArgValue.substr(FirstDashIndex + 1); + auto PluginName = ArgValue.substr(0, FirstDashIndex); + + CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-arg-") + PluginName)); + CmdArgs.push_back(Args.MakeArgString(Arg)); + A->claim(); + } + // Forward -fpass-plugin=name.so to -cc1. for (const Arg *A : Args.filtered(options::OPT_fpass_plugin_EQ)) { CmdArgs.push_back( Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2501,6 +2501,9 @@ NegFlag<SetFalse>>; def fplugin_EQ : Joined<["-"], "fplugin=">, Group<f_Group>, Flags<[NoXarchOption]>, MetaVarName<"<dsopath>">, HelpText<"Load the named plugin (dynamic shared object)">; +def fplugin_arg : Joined<["-"], "fplugin-arg-">, + MetaVarName<"<name>-<arg>">, + HelpText<"Pass <arg> to plugin <name>">; def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">, Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<dsopath>">, HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">, Index: clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp =================================================================== --- clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp +++ clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp @@ -145,6 +145,14 @@ bool ParseArgs(const CompilerInstance &CI, const std::vector<std::string> &args) override { + if (!args.empty()) { + if (args[0] == "help") { + llvm::errs() << "Help text for CallSuper plugin goes here\n"; + } else if (args[0] == "help-long") { + llvm::errs() << "A longer help text describing what the CallSuper " + << "plugin does goes here\n"; + } + } return true; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits