On 1/22/19 10:55 AM, David Malcolm wrote:
> PR driver/88911 reports an issue where the user couldn't remember the spelling
> of the "-dumpspecs" option, and attempted various similar spellings, but many
> of them failed to contain a suggestion of the correct spelling:
> 
>   $ gcc q.c -dump-spec
>   cc1: warning: unrecognized gcc debugging option: u
>   cc1: warning: unrecognized gcc debugging option: m
>   cc1: warning: unrecognized gcc debugging option: -
>   cc1: warning: unrecognized gcc debugging option: s
>   cc1: warning: unrecognized gcc debugging option: e
>   cc1: warning: unrecognized gcc debugging option: c
>   $ gcc q.c -dump-specs
>   cc1: warning: unrecognized gcc debugging option: u
>   cc1: warning: unrecognized gcc debugging option: m
>   cc1: warning: unrecognized gcc debugging option: -
>   cc1: warning: unrecognized gcc debugging option: s
>   cc1: warning: unrecognized gcc debugging option: e
>   cc1: warning: unrecognized gcc debugging option: c
>   cc1: warning: unrecognized gcc debugging option: s
>   $ gcc q.c -fdump-spec
>   cc1: error: unrecognized command line option '-fdump-spec'
>   $ gcc q.c -fdump-specs
>   cc1: error: unrecognized command line option '-fdump-specs'
>   $ gcc q.c -fdumpspecs
>   gcc: error: unrecognized command line option '-fdumpspecs'; did you
>   mean '-dumpspecs'?
>   [Aha!]
> 
> There are two issues here:
> 
> (a) unmatched options beginning with "-d" are treated as part of the
> "-d" option, leading to a warning from decode_d_option, but no
> suggestion.
> 
> (b) options beginning with "-fdump-" are also passed to a special
> handler, and this doesn't offer suggestions for unmatched options
> either.
> 
> This patch uses option_proposer::suggest_option to add suggestions
> in both places, leading to useful suggestions for all of the cases
> given above.  For the case of "-d" it only offers a suggestion for
> the first unrecognized character.  I also added quotes around the
> character in the message, and indicate the full option for context,
> so that the first example above becomes:
> 
>   $ gcc q.c -dump-spec
>   cc1: warning: unrecognized gcc debugging option: 'u' (as part of 
> '-dump-spec'); did you mean '-dumpspecs'?
>   cc1: warning: unrecognized gcc debugging option: 'm' (as part of 
> '-dump-spec')
>   cc1: warning: unrecognized gcc debugging option: '-' (as part of 
> '-dump-spec')
>   cc1: warning: unrecognized gcc debugging option: 's' (as part of 
> '-dump-spec')
>   cc1: warning: unrecognized gcc debugging option: 'e' (as part of 
> '-dump-spec')
>   cc1: warning: unrecognized gcc debugging option: 'c' (as part of 
> '-dump-spec')
> 
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> 
> Is this patch OK for trunk?
> (it's not a regression, but it's fairly self-contained, so would this be
> acceptable now, or should I queue it for when stage 1 reopens?)
> 
> gcc/ChangeLog:
>       PR driver/88911
>       * opts-global.c: Include "opt-suggestions.h".
>       (handle_common_deferred_options) <OPT_fdump_>: If the argument is
>       unrecognized, attempt to provide a hint.
>       * opts.c: Include "opt-suggestions.h".
>       (common_handle_option) <OPT_d>: Pass original option argument text
>       to decode_d_option.
>       (decode_d_option): Add parameter "orig_arg".  Use it to provide a
>       hint within the first unrecognized character.  Wrap the character
>       in quotes, and indicate the original argument it belongs to.
> 
> gcc/testsuite/ChangeLog:
>       PR driver/88911
>       * gcc.dg/spellcheck-options-pr88911-1.c: New test.
>       * gcc.dg/spellcheck-options-pr88911-2.c: New test.
>       * gcc.dg/spellcheck-options-pr88911-3.c: New test.
>       * gcc.dg/spellcheck-options-pr88911-4.c: New test.
>       * gcc.dg/spellcheck-options-pr88911-5.c: New test.
A "pocket veto" for gcc-9 :-)  However it makes a lot of sense to me for
gcc-10.

It looks reasonable to me.  Can't hurt to spin it again before committing.

jeff

Reply via email to