This is an archive of the discontinued LLVM Phabricator instance.

[CommandLine] Allow grouping options which can have values.
ClosedPublic

Authored by ikudrin on Feb 27 2019, 4:05 AM.

Details

Summary

This patch is a follow-up for D58499. It allows the remaining forms of providing values
for options to be used at the end of a group. This includes both prefix variants
of options and the "opt=val" form.

With this fix, it is possible to better follow the way GNU binutils tools handle grouping
options. For example, the -j option in objdump can be used in any of the following ways:

$ objdump -d -j .text a.o
$ objdump -d -j.text a.o
$ objdump -dj .text a.o
$ objdump -dj.text a.o

Diff Detail

Repository
rL LLVM

Event Timeline

ikudrin created this revision.Feb 27 2019, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2019, 4:05 AM
jhenderson added inline comments.
docs/CommandLine.rst
1201 ↗(On Diff #188515)

The indentation here looks off compared to the old style?

lib/Support/CommandLine.cpp
682–683 ↗(On Diff #188515)

Why has this changed?

692 ↗(On Diff #188515)

remaining -> remainder

unittests/Support/CommandLineTest.cpp
1176 ↗(On Diff #188515)

Maybe better to be explicit here instead of using "such", i.e. "if a ValueOptional option..."

1225 ↗(On Diff #188515)

The all -> All

The wrapping here looks a bit weird. I think "if a" should be on this line, not the next.

1270–1271 ↗(On Diff #188515)

Same as above comment re. "The all" and "if a".

1289 ↗(On Diff #188515)

What about a test case for "-fab" where "a", "f" and "b" are all options, and "a" is a Prefix/AlwaysPrefix option? I think that would clearly show that "b" would be the value of "a".

ikudrin updated this revision to Diff 188688.Feb 28 2019, 2:36 AM
ikudrin retitled this revision from [CommandLine] Allow grouping of options which can have values. to [CommandLine] Allow grouping options which can have values..
  • Fixed grammar and formatting issues.
  • Added test cases to check prefix options when their values are textually equal to another option.
This revision is now accepted and ready to land.Feb 28 2019, 2:46 AM
ikudrin marked 8 inline comments as done.Feb 28 2019, 3:00 AM

By the way, we have some inconsistency in how cl::Prefix and cl::AlwaysPrefix options work in case of -opt=val form. The former takes only val, while the latter keeps =. Moreover, prefix grouping options in GNU's binutils, like -j in objdump, work partially as ours cl::AlwaysPrefix, because they preserve =, and partially as cl::Prefix, because they allow passing the value in a separate argument. Thus, we still cannot fully reproduce that behavior.

Do you think it is worth adding a new modifier, say, cl::PreserveEqSign, to improve compatibility?

unittests/Support/CommandLineTest.cpp
1225 ↗(On Diff #188515)

I wanted not to split cl::Prefix + cl::Grouping, as well as not to separate an article from them.
So, I opted to rephrase the comment. How does it look now?

Do you think it is worth adding a new modifier, say, cl::PreserveEqSign, to improve compatibility?

I'm not really sure. I don't know enough about the background of the CommandLine library and its aims, so I'm reluctant to suggest adding more modifiers for what might be corner behaviours that aren't used. Perhaps worth putting up a small RFC on llvm-dev?

unittests/Support/CommandLineTest.cpp
1225 ↗(On Diff #188515)

Yes, it's fine.

rupprecht accepted this revision.Feb 28 2019, 11:05 AM

Great, thanks!

unittests/Support/CommandLineTest.cpp
1145 ↗(On Diff #188688)

Can these test cases also assert that OptF is true?

This revision was automatically updated to reflect the committed changes.
ikudrin marked an inline comment as done.