[gcc(refs/users/marxin/heads/option-hint-for-dump-options)] Provide hint for misspelled -fdump-foo options.
Martin Liska
marxin@gcc.gnu.org
Thu Mar 19 11:01:06 GMT 2020
https://gcc.gnu.org/g:0746e10efa0923b1b0a514e3387f084684bf14b2
commit 0746e10efa0923b1b0a514e3387f084684bf14b2
Author: Martin Liska <mliska@suse.cz>
Date: Thu Mar 19 11:58:53 2020 +0100
Provide hint for misspelled -fdump-foo options.
gcc/ChangeLog:
2020-03-19 Martin Liska <mliska@suse.cz>
* dumpfile.c (dump_switch_p): Change return type
and print option suggestion.
* dumpfile.h: Change return type.
* opts-global.c (handle_common_deferred_options):
Move error into dump_switch_p function.
gcc/testsuite/ChangeLog:
2020-03-19 Martin Liska <mliska@suse.cz>
* gcc.dg/spellcheck-options-22.c: New test.
Diff:
---
gcc/dumpfile.c | 21 ++++++++++++++++++---
gcc/dumpfile.h | 2 +-
gcc/opts-global.c | 3 +--
gcc/testsuite/gcc.dg/spellcheck-options-22.c | 3 +++
4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 468ffab6cce..e820f72edc3 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-pass.h" /* for "current_pass". */
#include "optinfo-emit-json.h"
#include "stringpool.h" /* for get_identifier. */
+#include "opts.h"
/* If non-NULL, return one past-the-end of the matching SUBPART of
the WHOLE string. */
@@ -1874,7 +1875,7 @@ dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
return 1;
}
-int
+void
gcc::dump_manager::
dump_switch_p (const char *arg)
{
@@ -1896,8 +1897,22 @@ dump_switch_p (const char *arg)
for (i = 0; i < m_extra_dump_files_in_use; i++)
any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true);
-
- return any;
+ if (!any)
+ {
+ char *s;
+ auto_vec<const char *> candidates;
+ for (size_t i = TDI_none + 1; i != TDI_end; i++)
+ candidates.safe_push (dump_files[i].swtch);
+ for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
+ candidates.safe_push (m_extra_dump_files[i].swtch);
+ const char *hint = candidates_list_and_hint (arg, s, candidates);
+ if (hint)
+ error ("unrecognized command-line option %<-fdump-%s%>; "
+ "did you mean %<-fdump-%s%>?", arg, hint);
+ else
+ error ("unrecognized command-line option %<-fdump-%s%>", arg);
+ XDELETEVEC (s);
+ }
}
/* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h
index 840ae4d55d5..00e175a4737 100644
--- a/gcc/dumpfile.h
+++ b/gcc/dumpfile.h
@@ -691,7 +691,7 @@ public:
char *
get_dump_file_name (struct dump_file_info *dfi, int part = -1) const;
- int
+ void
dump_switch_p (const char *arg);
/* Start a dump for PHASE. Store user-supplied dump flags in
diff --git a/gcc/opts-global.c b/gcc/opts-global.c
index c658805470e..b1a8429dc3c 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -385,8 +385,7 @@ handle_common_deferred_options (void)
break;
case OPT_fdump_:
- if (!g->get_dumps ()->dump_switch_p (opt->arg))
- error ("unrecognized command-line option %<-fdump-%s%>", opt->arg);
+ g->get_dumps ()->dump_switch_p (opt->arg);
break;
case OPT_fopt_info_:
diff --git a/gcc/testsuite/gcc.dg/spellcheck-options-22.c b/gcc/testsuite/gcc.dg/spellcheck-options-22.c
new file mode 100644
index 00000000000..ad45c659bd7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/spellcheck-options-22.c
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-ipa-ynline" } */
+/* { dg-error "unrecognized command-line option â-fdump-ipa-ynlineâ; did you mean â-fdump-ipa-inlineâ?" "" { target *-*-* } 0 } */
More information about the Gcc-cvs
mailing list