summaryrefslogtreecommitdiff
path: root/gcc/opts-common.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-05-19 00:52:08 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-05-19 00:52:08 +0000
commit70f25790a1effc8f1cba3cb8a368b129c66a87b0 (patch)
tree9a1079536c4e30ba3cb0ff1e7cf8ebb14bdadd92 /gcc/opts-common.c
parent69e95fa03cda406fe61e94371244f0ba9b59339e (diff)
PR driver/69265: add hint for options with misspelled arguments
opts-common.c's cmdline_handle_error handles invalid arguments for options with CL_ERR_ENUM_ARG by building a string listing the valid arguments. By also building a vec of valid arguments, we can use find_closest_string and provide a hint if we see a close misspelling. gcc/ChangeLog: PR driver/69265 * Makefile.in (GCC_OBJS): Move spellcheck.o to... (OBJS-libcommon-target): ...here. * opts-common.c: Include spellcheck.h. (cmdline_handle_error): Build a vec of valid options and use it to suggest provide hints for misspelled arguments. gcc/testsuite/ChangeLog: PR driver/69265 * gcc.dg/spellcheck-options-11.c: New test case. From-SVN: r236439
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r--gcc/opts-common.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index bb689827227..4e1ef497ed8 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "opts.h"
#include "options.h"
#include "diagnostic.h"
+#include "spellcheck.h"
static void prune_options (struct cl_decoded_option **, unsigned int *);
@@ -1113,6 +1114,7 @@ cmdline_handle_error (location_t loc, const struct cl_option *option,
for (i = 0; e->values[i].arg != NULL; i++)
len += strlen (e->values[i].arg) + 1;
+ auto_vec <const char *> candidates;
s = XALLOCAVEC (char, len);
p = s;
for (i = 0; e->values[i].arg != NULL; i++)
@@ -1123,9 +1125,16 @@ cmdline_handle_error (location_t loc, const struct cl_option *option,
memcpy (p, e->values[i].arg, arglen);
p[arglen] = ' ';
p += arglen + 1;
+ candidates.safe_push (e->values[i].arg);
}
p[-1] = 0;
- inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
+ const char *hint = find_closest_string (arg, &candidates);
+ if (hint)
+ inform (loc, "valid arguments to %qs are: %s; did you mean %qs?",
+ option->opt_text, s, hint);
+ else
+ inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
+
return true;
}