Fix bogus option suggestions for RejectNegative options (PR driver/71651)
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 30 Jun 2016 14:28:50 +0000 (14:28 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 30 Jun 2016 14:28:50 +0000 (14:28 +0000)
gcc/ChangeLog:
PR driver/71651
* gcc.c (driver::build_option_suggestions): Pass "option" to
add_misspelling_candidates.
* opts-common.c (add_misspelling_candidates): Add "option" param;
use it to avoid adding negated forms for options marked with
RejectNegative.
* opts.h (add_misspelling_candidates): Add "option" param.

gcc/testsuite/ChangeLog:
PR driver/71651
* gcc.dg/spellcheck-options-12.c: New test case.

From-SVN: r237880

gcc/ChangeLog
gcc/gcc.c
gcc/opts-common.c
gcc/opts.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/spellcheck-options-12.c [new file with mode: 0644]

index 8d00f72c34d30b837280b214142884fb352622ff..28b938707318fb7ba225bcd349a10f0f9fa3eb87 100644 (file)
@@ -1,3 +1,13 @@
+2016-06-30  David Malcolm  <dmalcolm@redhat.com>
+
+       PR driver/71651
+       * gcc.c (driver::build_option_suggestions): Pass "option" to
+       add_misspelling_candidates.
+       * opts-common.c (add_misspelling_candidates): Add "option" param;
+       use it to avoid adding negated forms for options marked with
+       RejectNegative.
+       * opts.h (add_misspelling_candidates): Add "option" param.
+
 2016-06-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/71693
index ab113102bc6605d123046a3df5134c405faa4a25..634f8e6002a9d8ed7426942c0411a05562bbaf1d 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -7700,12 +7700,14 @@ driver::build_option_suggestions (void)
              for (unsigned j = 0; e->values[j].arg != NULL; j++)
                {
                  char *with_arg = concat (opt_text, e->values[j].arg, NULL);
-                 add_misspelling_candidates (m_option_suggestions, with_arg);
+                 add_misspelling_candidates (m_option_suggestions, option,
+                                             with_arg);
                  free (with_arg);
                }
            }
          else
-           add_misspelling_candidates (m_option_suggestions, opt_text);
+           add_misspelling_candidates (m_option_suggestions, option,
+                                       opt_text);
          break;
 
        case OPT_fsanitize_:
@@ -7729,7 +7731,8 @@ driver::build_option_suggestions (void)
                /* Add with_arg and all of its variant spellings e.g.
                   "-fno-sanitize=address" to candidates (albeit without
                   leading dashes).  */
-               add_misspelling_candidates (m_option_suggestions, with_arg);
+               add_misspelling_candidates (m_option_suggestions, option,
+                                           with_arg);
                free (with_arg);
              }
          }
index 4e1ef497ed8015155b0cc48f35d6aff523e761e2..8634b520ecf2009b64b9275798db05f1a7afe862 100644 (file)
@@ -374,8 +374,9 @@ static const struct option_map option_map[] =
    to specific options.  We want to do the reverse: to find all the ways
    that a user could validly spell an option.
 
-   Given valid OPT_TEXT (with a leading dash), add it and all of its valid
-   variant spellings to CANDIDATES, each without a leading dash.
+   Given valid OPT_TEXT (with a leading dash) for OPTION, add it and all
+   of its valid variant spellings to CANDIDATES, each without a leading
+   dash.
 
    For example, given "-Wabi-tag", the following are added to CANDIDATES:
      "Wabi-tag"
@@ -387,9 +388,11 @@ static const struct option_map option_map[] =
 
 void
 add_misspelling_candidates (auto_vec<char *> *candidates,
+                           const struct cl_option *option,
                            const char *opt_text)
 {
   gcc_assert (candidates);
+  gcc_assert (option);
   gcc_assert (opt_text);
   candidates->safe_push (xstrdup (opt_text + 1));
   for (unsigned i = 0; i < ARRAY_SIZE (option_map); i++)
@@ -398,6 +401,9 @@ add_misspelling_candidates (auto_vec<char *> *candidates,
       const char *new_prefix = option_map[i].new_prefix;
       size_t new_prefix_len = strlen (new_prefix);
 
+      if (option->cl_reject_negative && option_map[i].negated)
+       continue;
+
       if (strncmp (opt_text, new_prefix, new_prefix_len) == 0)
        {
          char *alternative = concat (opt0 + 1, opt_text + new_prefix_len,
index 1b5cf448a2969cb23a487ed94f1f6bed395be2ff..25d32c1ad49fff9c5beb073be32da80328c782a2 100644 (file)
@@ -417,6 +417,7 @@ extern const struct sanitizer_opts_s
 } sanitizer_opts[];
 
 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
+                                       const struct cl_option *option,
                                        const char *base_option);
 
 #endif
index 1828ca63fe4347ea571648d35dec5eefb1d99397..8527a2fed0142a4cdbb1d63fb0f227b118dd8306 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-30  David Malcolm  <dmalcolm@redhat.com>
+
+       PR driver/71651
+       * gcc.dg/spellcheck-options-12.c: New test case.
+
 2016-06-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/71693
diff --git a/gcc/testsuite/gcc.dg/spellcheck-options-12.c b/gcc/testsuite/gcc.dg/spellcheck-options-12.c
new file mode 100644 (file)
index 0000000..b5e65e5
--- /dev/null
@@ -0,0 +1,7 @@
+/* Verify that we don't include -Wno- variants for options marked
+   with RejectNegative when considering hints for misspelled options
+   (PR driver/71651).  */
+
+/* { dg-do compile } */
+/* { dg-options "-fno-stack-protector-explicit" } */
+/* { dg-error "unrecognized command line option .-fno-stack-protector-explicit.; did you mean .-fstack-protector-explicit.." "" { target *-*-* } 0 } */