This is an archive of the discontinued LLVM Phabricator instance.

[clang][driver] Add -fplugin-arg- to pass arguments to plugins
ClosedPublic

Authored by tbaeder on Nov 5 2021, 2:43 AM.

Details

Summary

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.

Diff Detail

Event Timeline

tbaeder created this revision.Nov 5 2021, 2:43 AM
tbaeder requested review of this revision.Nov 5 2021, 2:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2021, 2:43 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay requested changes to this revision.Nov 17 2021, 6:43 PM

The idea LGTM. You need a test in test/Driver checking how the driver option maps to the CC1 option.

You may check whether REQUIRES: plugins, examples is needed.

clang/lib/Driver/ToolChains/Clang.cpp
6672

What if FirstDashIndex == std::string::npos?

This revision now requires changes to proceed.Nov 17 2021, 6:43 PM

Then please also update docs/ClangPlugins.rst to use driver option instead of CC1 -plugin-arg

tbaeder updated this revision to Diff 388129.Nov 18 2021, 1:31 AM

I already had a test but forgot to add the file to my local git commit, sorry.

tbaeder added inline comments.Nov 18 2021, 1:33 AM
clang/lib/Driver/ToolChains/Clang.cpp
6672

Things still "work", but the plugin name then gets parsed incorrectly. I've decided to skip this case now.

MaskRay added inline comments.Nov 18 2021, 11:23 AM
clang/docs/ClangPlugins.rst
133

Mention whether <argument> can contain -

clang/test/Frontend/plugin-driver-args.cpp
2 ↗(On Diff #388129)

Move to test/Driver and use use -### to test CC1 options.

Check whether REQUIRES: plugins, examples is really needed. Many driver options don't need frontend feature availability.

Change plugin-call-super.cpp to use %clang_cc1 to test CC1 options.

tbaeder updated this revision to Diff 388417.Nov 19 2021, 1:35 AM
MaskRay added inline comments.Nov 19 2021, 9:44 AM
clang/docs/ClangPlugins.rst
131
141
clang/lib/Driver/ToolChains/Clang.cpp
6675

This probably should be an error. See elsewhere in the file for error reporting.

6678
clang/test/Driver/plugin-driver-args.cpp
6

CHECK-SAME

tbaeder updated this revision to Diff 388853.Nov 22 2021, 3:24 AM

Added two new warning types and used them for diagnosing malformed -fplugin-arg options. Also added tests for that.

MaskRay accepted this revision.Nov 22 2021, 3:12 PM
MaskRay added inline comments.
clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
150
clang/include/clang/Basic/DiagnosticDriverKinds.td
193

don't capitalize messages. See other diagnostics and https://llvm.org/docs/CodingStandards.html#error-and-warning-messages

clang/lib/Driver/ToolChains/Clang.cpp
6677

empty()

6678
clang/test/Driver/plugin-driver-args.cpp
2

I usually use /// for non-RUN non-CHECK lines to make comments stand out (in some editors the highlight will even be different). That is a rule in some directories (llvm/test/tools lld/test) but not so consistent in other directories.

12

I assume that you have checked // REQUIRES: plugins, examples is not needed, i.e. the test still passes if -DLLVM_ENABLE_PLUGINS=off

This revision is now accepted and ready to land.Nov 22 2021, 3:12 PM
tbaeder marked 13 inline comments as done.Nov 23 2021, 1:32 AM
tbaeder added inline comments.
clang/test/Driver/plugin-driver-args.cpp
12

I did, but I didn't delete the local CallSuperAttr.so. After doing that, they failed. I hope using -### as well here is fine.

tbaeder updated this revision to Diff 389121.Nov 23 2021, 1:33 AM
tbaeder marked an inline comment as done.

Addressed review comments and fixed the tests

Hey @MaskRay, I know you've already approved but just to be sure: does the last round of changes look good?

Thanks

MaskRay accepted this revision.Nov 24 2021, 11:34 PM

Thanks!