This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Suggest correctly spelled driver options
ClosedPublic

Authored by modocache on Jan 4 2018, 10:07 AM.

Details

Summary

Depends on https://reviews.llvm.org/D41732.

Utilities such as opt, when invoked with arguments that are very
nearly spelled correctly, suggest the correctly spelled options:

bin/opt -hel
opt: Unknown command line argument '-hel'.  Try: 'bin/opt -help'
opt: Did you mean '-help'?

Clang, on the other hand, prior to this commit, does not:

bin/clang -hel
clang-6.0: error: unknown argument: '-hel'

This commit makes use of the new libLLVMOption API from
https://reviews.llvm.org/D41732 in order to provide correct suggestions:

bin/clang -hel
clang-6.0: error: unknown argument: '-hel', did you mean '-help'?

Test Plan: check-clang

Diff Detail

Event Timeline

modocache created this revision.Jan 4 2018, 10:07 AM
jroelofs added inline comments.
lib/Driver/Driver.cpp
191

No need for this variable.

218

Likewise.

bruno added a subscriber: bruno.Jan 4 2018, 12:56 PM

This is great!

I assume it also works for cc1 invocations, right? Can you also add a test for %clang_cc1?

Thank you, @bruno! Good idea, I'll add a -cc1 invocation test.

lib/Driver/Driver.cpp
191

There's a call below to Diags.getDiagnosticsLevel, which takes this ID as an argument. Are you suggesting I leave that line alone, and have it use the diagnostic level of err_drv_unsupported_opt, even if err_drv_unsupported_opt_with_suggestion is actually emitted here? That seems reasonable to me, but just want to make sure that's what you had in mind.

modocache updated this revision to Diff 128681.Jan 4 2018, 4:52 PM

Add 'did you mean' suggestions for -cc1 invocations as well.

jroelofs added inline comments.Jan 5 2018, 4:15 AM
lib/Driver/Driver.cpp
191

Oh, I didn't see that use... never mind.

v.g.vassilev added inline comments.Jan 5 2018, 4:46 AM
test/Frontend/unknown-arg.c
3 ↗(On Diff #128681)

Could we also make sure that things passed with -Xclang are also handled?

modocache updated this revision to Diff 128736.Jan 5 2018, 5:33 AM

Test -Xclang as well. Thanks, @v.g.vassilev!

bruno accepted this revision.Jan 5 2018, 1:55 PM

Thanks! LGTM.

This revision is now accepted and ready to land.Jan 5 2018, 1:55 PM
This revision was automatically updated to reflect the committed changes.