diff mbox

Do not suggest -fsanitize=all (PR driver/78863).

Message ID 726a6397-65a6-e8e2-1c55-abe04a56460a@suse.cz
State New
Headers show

Commit Message

Martin Liška Dec. 21, 2016, 9:34 a.m. UTC
As mentioned in the PR, we should not suggest option that is not allowed.
Fixed by explicit removal of suggestions that are not acceptable.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin
diff mbox

Patch

From 1a2d5614e9a0515659f50b457ef031c1f80f4a7c Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 20 Dec 2016 12:16:02 +0100
Subject: [PATCH] Do not suggest -fsanitize=all (PR driver/78863).

gcc/ChangeLog:

2016-12-20  Martin Liska  <mliska@suse.cz>

	PR driver/78863
	* gcc.c (driver::build_option_suggestions): Call
	remove_misspelling_candidate for -fsanitize=all.
	* opts-common.c (remove_misspelling_candidate): New function.
	* opts.h (remove_misspelling_candidate): Likewise.

gcc/testsuite/ChangeLog:

2016-12-20  Martin Liska  <mliska@suse.cz>

	PR driver/78863
	* gcc.dg/spellcheck-options-13.c: New test.
---
 gcc/gcc.c                                    |  4 ++++
 gcc/opts-common.c                            | 17 +++++++++++++++++
 gcc/opts.h                                   |  2 ++
 gcc/testsuite/gcc.dg/spellcheck-options-13.c |  5 +++++
 4 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/spellcheck-options-13.c

diff --git a/gcc/gcc.c b/gcc/gcc.c
index f78acd68606..1240e8a176b 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -7748,6 +7748,10 @@  driver::build_option_suggestions (void)
 	  break;
 	}
     }
+
+  /* PR driver/78863: skip -fsanitize=all.  */
+  remove_misspelling_candidate (m_option_suggestions, "fsanitize=all");
+  remove_misspelling_candidate (m_option_suggestions, "-sanitize=all");
 }
 
 /* Helper function for driver::handle_unrecognized_options.
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index e9d1c20a1f3..d5d81de8a5f 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -413,6 +413,23 @@  add_misspelling_candidates (auto_vec<char *> *candidates,
     }
 }
 
+/* Helper function for gcc.c's driver which removes OPT_TEXT from
+   list of CANDIDATES.  */
+
+void
+remove_misspelling_candidate (auto_vec<char *> *candidates,
+			      const char *opt_text)
+{
+  for (unsigned i = 0; i < candidates->length (); i++)
+    {
+      if (strcmp ((*candidates)[i], opt_text) == 0)
+	{
+	  candidates->ordered_remove (i);
+	  return;
+	}
+    }
+}
+
 /* Decode the switch beginning at ARGV for the language indicated by
    LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into
    the structure *DECODED.  Returns the number of switches
diff --git a/gcc/opts.h b/gcc/opts.h
index b3e64353c8a..052aa54cee4 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -420,6 +420,8 @@  extern const struct sanitizer_opts_s
 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
 					const struct cl_option *option,
 					const char *base_option);
+extern void remove_misspelling_candidate (auto_vec<char *> *candidates,
+					  const char *opt_text);
 extern const char *candidates_list_and_hint (const char *arg, char *&str,
 					     const auto_vec <const char *> &
 					     candidates);
diff --git a/gcc/testsuite/gcc.dg/spellcheck-options-13.c b/gcc/testsuite/gcc.dg/spellcheck-options-13.c
new file mode 100644
index 00000000000..19b63af565b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/spellcheck-options-13.c
@@ -0,0 +1,5 @@ 
+/* PR driver/78863.  */
+
+/* { dg-do compile } */
+/* { dg-options "-fsanitize" } */
+/* { dg-error "unrecognized command line option .-fsanitize..$" "" { target *-*-* } 0 } */
-- 
2.11.0