This is an archive of the discontinued LLVM Phabricator instance.

[CommandLine] Remove `may only occur zero or one times!` error
ClosedPublic

Authored by MaskRay on Feb 23 2022, 10:57 PM.

Details

Summary

Early adoption of new technologies or adjusting certain code generation/IR optimization thresholds
is often available through some cl::opt options (which have unstable surfaces).
Specifying such an option twice will lead to an error.

% clang -c a.c -mllvm -disable-binop-extract-shuffle -mllvm -disable-binop-extract-shuffle
clang (LLVM option parsing): for the --disable-binop-extract-shuffle option: may only occur zero or one times!
% clang -c a.c -mllvm -hwasan-instrument-reads=0 -mllvm -hwasan-instrument-reads=0
clang (LLVM option parsing): for the --hwasan-instrument-reads option: may only occur zero or one times!
% clang -c a.c -mllvm --scalar-evolution-max-arith-depth=32 -mllvm --scalar-evolution-max-arith-depth=16
clang (LLVM option parsing): for the --scalar-evolution-max-arith-depth option: may only occur zero or one times!

The option is specified twice, because there is sometimes a global setting and
a specific file or project may need to override (or duplicately specify) the
value.

The error is contrary to the common practice of getopt/getopt_long command line
utilities that let the last option win and the getLastArg behavior used by
Clang driver options. I have seen such errors for several times. I think the
error just makes users inconvenient, while providing very little value on
discouraging production usage of unstable surfaces (this goal is itself
controversial, because developers might not want to commit to a stable surface
too early, or there is just some subtle codegen toggle which is infeasible to
have a driver option). Therefore, I suggest we drop the diagnostic, at least
before the diagnostic gets sufficiently better support for the overridding needs.

Removing the error is a degraded error checking experience. I think this error
checking behavior, if desirable, should be enabled explicitly by tools. Users
preferring the behavior can figure out a way to do so.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 23 2022, 10:57 PM
MaskRay requested review of this revision.Feb 23 2022, 10:57 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 23 2022, 10:57 PM
MaskRay edited the summary of this revision. (Show Details)
MaskRay updated this revision to Diff 411013.Feb 23 2022, 11:05 PM

add a unittest

jhenderson accepted this revision.Feb 24 2022, 12:47 AM

I can't say I really care about the existing behaviour, so LGTM, but I'd like to give others a chance to look at it.

llvm/test/tools/llvm-libtool-darwin/deterministic-library.test
27–28

Why |&?

This revision is now accepted and ready to land.Feb 24 2022, 12:47 AM

I'd probably prefer that we don't do this since we're looking primarily at options that shouldn't be used outside of development, e.g. clang has a driver that does accept these kinds of things as does lld. Open to arguments for and against though :)

MaskRay added a comment.EditedFeb 24 2022, 9:37 AM

I'd probably prefer that we don't do this since we're looking primarily at options that shouldn't be used outside of development, e.g. clang has a driver that does accept these kinds of things as does lld. Open to arguments for and against though :)

Keep a diagnostic to discourage -mllvm users? For 99.9% use cases the user doesn't specify a cl::opt option twice, removing the diagnostic does no discouragement to them.
In the case that a user wants a workaround, the error prevents them from doing so: adding a new driver option and cherry picking a commit into a release is significant hassle for many groups.

I am going to so I am probably against adding a new driver option just so that some cl::opt options can be overridden. Driver options have stronger stability guarantee. Many cl::opt optimization and code generation are considered unstable and the developer has various reasons that it is not mature enough to justify a driver option.

rnk accepted this revision.Feb 24 2022, 9:49 AM

I'm in favor of this change, and the code looks good, but there is some disagreement, so we should get more consensus.

@dexonsmith, any thoughts on this change, or is there a better person who can give some perspective on the usability of LLVM options at Apple?

My biggest concern is llvm developing a gcc-esque "--params" style set of options which is what this would give. If we want these to be a support surface we should enable and test them as such. Just allowing it without that gives the entire ecosystem another set of support surface that we actually don't want people to use. Workarounds downstream should be handled by downstream as much as possible or via coordination with developers on a "hey, can we actually wait here" on options.

Just allowing it without that gives the entire ecosystem another set of support surface that we actually don't want people to use.

+1.

So maybe hide it under cmake flag?

rnk added a comment.Feb 24 2022, 10:15 AM

I'm not familiar with gcc --param, but if this is it, then it doesn't seem so bad. Nobody is suggesting that this be a stable, supported interface where we make long term commitments for LLVM option stability.

In any case, -mllvm already exists, and cl::opt is used by other components (MLIR). This change by itself is reasonable, and it doesn't stop us from working to reduce the exposed support surface of clang in the future. Having a slightly bad user experience for mllvm options doesn't actually reduce the support surface area of clang. We may have to agree to disagree here. :)

MaskRay updated this revision to Diff 411316.Feb 24 2022, 10:16 PM
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision. (Show Details)

|& -> |

Update justification

MaskRay added a comment.EditedFeb 28 2022, 7:48 PM

I'm not familiar with gcc --param, but if this is it, then it doesn't seem so bad. Nobody is suggesting that this be a stable, supported interface where we make long term commitments for LLVM option stability.

In any case, -mllvm already exists, and cl::opt is used by other components (MLIR). This change by itself is reasonable, and it doesn't stop us from working to reduce the exposed support surface of clang in the future. Having a slightly bad user experience for mllvm options doesn't actually reduce the support surface area of clang. We may have to agree to disagree here. :)

@echristo What do you think of my updated summary?

I'm in favor of this change, and the code looks good, but there is some disagreement, so we should get more consensus.

@dexonsmith, any thoughts on this change, or is there a better person who can give some perspective on the usability of LLVM options at Apple?

⬆️

I'm in favor of this change, and the code looks good, but there is some disagreement, so we should get more consensus.

@dexonsmith, any thoughts on this change, or is there a better person who can give some perspective on the usability of LLVM options at Apple?

⬆️

Sorry I missed before!

I don't have a strong opinion; IMO -mllvm options shouldn't get used (except by compiler developers) since they're unstable, although I'm sure they get used a little anyway. IMO, if this makes it easier for the intended users (compiler developers) then there isn't a real downside to it.

@ab @t.p.northover @Gerolf , any thoughts from you?

Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 2:26 PM
ab added a comment.Mar 2 2022, 1:43 PM

I don't have a strong opinion; IMO -mllvm options shouldn't get used (except by compiler developers) since they're unstable, although I'm sure they get used a little anyway. IMO, if this makes it easier for the intended users (compiler developers) then there isn't a real downside to it.

@ab @t.p.northover @Gerolf , any thoughts from you?

Yeah, this seems reasonable, but no strong opinions either. I totally empathize with the concerns, and ideally we wouldn't have all this exposed surface, but I'm not sure this meaningfully changes that.

In D120455#3355507, @ab wrote:

I don't have a strong opinion; IMO -mllvm options shouldn't get used (except by compiler developers) since they're unstable, although I'm sure they get used a little anyway. IMO, if this makes it easier for the intended users (compiler developers) then there isn't a real downside to it.

@ab @t.p.northover @Gerolf , any thoughts from you?

Yeah, this seems reasonable, but no strong opinions either. I totally empathize with the concerns, and ideally we wouldn't have all this exposed surface, but I'm not sure this meaningfully changes that.

Thanks for the feedback so far!

@echristo Do you still have concerns with this specific change after my updated summary?

echristo: I mean, yes, but I'm also happy to be outvoted here :)

Thanks for all of the discussion, it's really appreciated!

Thanks! I will push this in 2 days if nobody objects.

This revision was landed with ongoing or failed builds.Mar 11 2022, 11:25 AM
This revision was automatically updated to reflect the committed changes.