gcc
        PR c/65403
        * opts.c (enable_warning_as_error): Do not enable errors for
        negative options. Added parameter orig_text for better diagnose
        mistakes in options.

gcc/testsuite
        * gcc.dg/Werror-13.c: Check a note about misspelled no-warning
        tag rather than a hard error.
        * gcc.dg/Wno-error-1.c, gcc.dg/Wno-error-2.c: New group of tests
        for parametrized -Wno-error options.

Signed-off-by: Nicholas Guriev <nicho...@guriev.su>

---

I am CC'ing Alex Henrie because he already worked on fixing this bug and
he may be interested in my solution.

 gcc/opts.c                         | 48 ++++++++++++++++--------------
 gcc/testsuite/gcc.dg/Werror-13.c   |  2 +-
 gcc/testsuite/gcc.dg/Wno-error-1.c |  6 ++++
 gcc/testsuite/gcc.dg/Wno-error-2.c |  8 +++++
 4 files changed, 40 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wno-error-1.c
 create mode 100644 gcc/testsuite/gcc.dg/Wno-error-2.c

diff --git a/gcc/opts.c b/gcc/opts.c
index 52e9e3a9df9..9ec0846198c 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -291,12 +291,10 @@ static void decode_d_option (const char *arg, struct 
gcc_options *opts,
 static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
                                                 int set);
 static void enable_warning_as_error (const char *arg, int value,
-                                    unsigned int lang_mask,
-                                    const struct cl_option_handlers *handlers,
-                                    struct gcc_options *opts,
-                                    struct gcc_options *opts_set,
-                                    location_t loc,
-                                    diagnostic_context *dc);
+                                    const char *orig_text, unsigned lang_mask,
+                                    const cl_option_handlers *handlers,
+                                    gcc_options *opts, gcc_options *opts_set,
+                                    location_t loc, diagnostic_context *dc);
 
 /* Handle a back-end option; arguments and return value as for
    handle_option.  */
@@ -2526,8 +2524,8 @@ common_handle_option (struct gcc_options *opts,
       if (lang_mask == CL_DRIVER)
        break;
 
-      enable_warning_as_error (arg, value, lang_mask, handlers,
-                              opts, opts_set, loc, dc);
+      enable_warning_as_error (arg, value, decoded->orig_option_with_args_text,
+                              lang_mask, handlers, opts, opts_set, loc, dc);
       break;
 
     case OPT_Wfatal_errors:
@@ -3236,10 +3234,9 @@ decode_d_option (const char *arg, struct gcc_options 
*opts,
    NULL), location LOC.  This is used by -Werror=.  */
 
 static void
-enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
-                        const struct cl_option_handlers *handlers,
-                        struct gcc_options *opts,
-                        struct gcc_options *opts_set,
+enable_warning_as_error (const char *arg, int value, const char *orig_text,
+                        unsigned lang_mask, const cl_option_handlers *handlers,
+                        gcc_options *opts, gcc_options *opts_set,
                         location_t loc, diagnostic_context *dc)
 {
   char *new_option;
@@ -3251,19 +3248,24 @@ enable_warning_as_error (const char *arg, int value, 
unsigned int lang_mask,
   option_index = find_opt (new_option, lang_mask);
   if (option_index == OPT_SPECIAL_unknown)
     {
-      option_proposer op;
-      const char *hint = op.suggest_option (new_option);
-      if (hint)
-       error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>;"
-                 " did you mean %<-%s%>?", value ? "" : "no-",
-                 arg, new_option, hint);
-      else
-       error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>",
-                 value ? "" : "no-", arg, new_option);
+      cl_decoded_option fake_decoded = {};
+      fake_decoded.opt_index = OPT_SPECIAL_unknown;
+      fake_decoded.arg = orig_text;
+
+      if (handlers->unknown_option_callback (&fake_decoded))
+       {
+         option_proposer op;
+         const char *hint = op.suggest_option (new_option);
+         if (hint)
+           error_at (loc, _("%qs: no option %<-%s%>; did you mean %<-%s%>?"),
+                     orig_text, new_option, hint);
+         else
+           error_at (loc, _("%qs: no option %<-%s%>"), orig_text, new_option);
+       }
     }
   else if (!(cl_options[option_index].flags & CL_WARNING))
-    error_at (loc, "%<-Werror=%s%>: %<-%s%> is not an option that "
-             "controls warnings", arg, new_option);
+    error_at (loc, _("%qs: %<-%s%> is not an option that controls warnings"),
+             orig_text, new_option);
   else
     {
       const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
diff --git a/gcc/testsuite/gcc.dg/Werror-13.c b/gcc/testsuite/gcc.dg/Werror-13.c
index 3a02b7ea2b5..6c6c7c85447 100644
--- a/gcc/testsuite/gcc.dg/Werror-13.c
+++ b/gcc/testsuite/gcc.dg/Werror-13.c
@@ -5,6 +5,6 @@
 /* { dg-error "'-Werror' is not an option that controls warnings" "" { target 
*-*-* } 0 } */
 /* { dg-error "'-Wfatal-errors' is not an option that controls warnings" "" { 
target *-*-* } 0 } */
 /* { dg-error "'-Werror=vla2': no option '-Wvla2'; did you mean '-Wvla." "" { 
target *-*-* } 0 } */
-/* { dg-error "'-Wno-error=misleading-indentation2': no option 
'-Wmisleading-indentation2'; did you mean '-Wmisleading-indentation'" "" { 
target *-*-* } 0 } */
+/* { dg-note "unrecognized command-line option 
'-Wno-error=misleading-indentation2' may have been intended to silence earlier 
diagnostics" "" { target *-*-* } 0 } */
 
 int i;
diff --git a/gcc/testsuite/gcc.dg/Wno-error-1.c 
b/gcc/testsuite/gcc.dg/Wno-error-1.c
new file mode 100644
index 00000000000..db285370e01
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wno-error-1.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-error=some-future-option" } */
+
+/* Compiler should ignore -Wno-error option for unknown yet warnings. */
+
+int i;
diff --git a/gcc/testsuite/gcc.dg/Wno-error-2.c 
b/gcc/testsuite/gcc.dg/Wno-error-2.c
new file mode 100644
index 00000000000..cd474c18b79
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wno-error-2.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-error=error -Wno-error=fatal-errors -Wno-error=l, 
-Wno-error=p," } */
+/* { dg-error "'-Wno-error=error': '-Werror' is not an option that controls 
warnings" "" { target *-*-* } 0 } */
+/* { dg-error "'-Wno-error=fatal-errors': '-Wfatal-errors' is not an option 
that controls warnings" "" { target *-*-* } 0 } */
+/* { dg-error "'-Wno-error=l,': '-Wl,' is not an option that controls 
warnings" "" { target *-*-* } 0 } */
+/* { dg-error "'-Wno-error=p,': '-Wp,' is not an option that controls 
warnings" "" { target *-*-* } 0 } */
+
+int i;
-- 
2.30.2

Reply via email to