public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1128] opts: improve option suggestion Date: Thu, 16 Jun 2022 06:23:20 +0000 (GMT) [thread overview] Message-ID: <20220616062320.20C433858407@sourceware.org> (raw) https://gcc.gnu.org/g:ab66fd016d8efa250c471692f826b07e4a55e237 commit r13-1128-gab66fd016d8efa250c471692f826b07e4a55e237 Author: Martin Liska <mliska@suse.cz> Date: Wed May 11 16:07:25 2022 +0200 opts: improve option suggestion In case where we have 2 equally good candidates like -ftrivial-auto-var-init= -Wtrivial-auto-var-init for -ftrivial-auto-var-init, we should take the candidate that has a difference in trailing sign symbol. PR driver/105564 gcc/ChangeLog: * spellcheck.cc (test_find_closest_string): Add new test. * spellcheck.h (class best_match): Prefer a difference in trailing sign symbol. Diff: --- gcc/spellcheck.cc | 9 +++++++++ gcc/spellcheck.h | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gcc/spellcheck.cc b/gcc/spellcheck.cc index c7bb0122545..6930c0ed903 100644 --- a/gcc/spellcheck.cc +++ b/gcc/spellcheck.cc @@ -464,6 +464,15 @@ test_find_closest_string () ASSERT_STREQ ("DWARF_GNAT_ENCODINGS_ALL", find_closest_string ("DWARF_GNAT_ENCODINGS_all", &candidates)); + + /* Example from PR 105564 where option name with missing equal + sign should win. */ + candidates.truncate (0); + candidates.safe_push ("-Wtrivial-auto-var-init"); + candidates.safe_push ("-ftrivial-auto-var-init="); + ASSERT_STREQ ("-ftrivial-auto-var-init=", + find_closest_string ("-ftrivial-auto-var-init", + &candidates)); } /* Test data for test_metric_conditions. */ diff --git a/gcc/spellcheck.h b/gcc/spellcheck.h index 9b6223695be..3706de38a9d 100644 --- a/gcc/spellcheck.h +++ b/gcc/spellcheck.h @@ -128,11 +128,29 @@ class best_match /* Otherwise, compute the distance and see if the candidate has beaten the previous best value. */ + const char *candidate_str = candidate_traits::get_string (candidate); edit_distance_t dist - = get_edit_distance (m_goal, m_goal_len, - candidate_traits::get_string (candidate), - candidate_len); + = get_edit_distance (m_goal, m_goal_len, candidate_str, candidate_len); + + bool is_better = false; if (dist < m_best_distance) + is_better = true; + else if (dist == m_best_distance) + { + /* Prefer a candidate that inserts a trailing '=', + so that for + "-ftrivial-auto-var-init" + we suggest + "-ftrivial-auto-var-init=" + rather than + "-Wtrivial-auto-var-init". */ + /* Prefer a candidate has a difference in trailing sign character. */ + if (candidate_str[candidate_len - 1] == '=' + && m_goal[m_goal_len - 1] != '=') + is_better = true; + } + + if (is_better) { m_best_distance = dist; m_best_candidate = candidate;
reply other threads:[~2022-06-16 6:23 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220616062320.20C433858407@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).