From patchwork Wed May 11 14:49:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 53810 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 93822383541D for ; Wed, 11 May 2022 14:49:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 93836386EC38 for ; Wed, 11 May 2022 14:49:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 93836386EC38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6806621D13; Wed, 11 May 2022 14:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1652280569; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xkg377GKW+iPU0N7SVx1u8jNqB92YyPtFyhMbY+QPl8=; b=iYoBI4VSc0yfYOJbDSci/dlp6gRxRTqBLhsxJ22aF9MrY5QIqKj2csCBtIv0LLmjaGdzyS Ywkn6whNjqX5cvf9coHixHNmVa1FAzH7aI4AFKF+P9uhB7ESrsGQrjFFZliZZhTHZEsg69 D1jAGQYZCWIVmokf6kCDR13Z8DLCDQk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1652280569; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xkg377GKW+iPU0N7SVx1u8jNqB92YyPtFyhMbY+QPl8=; b=AkeAPEJNDRc4NbyuoLyVn+yDRySJBL3TuYcrh+yRuch/V9vav8B1BMGybO1yMToCXytkqj dNMqvlkmualVdUDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 55889139F9; Wed, 11 May 2022 14:49:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +X3WE/nMe2IHKAAAMHmgww (envelope-from ); Wed, 11 May 2022 14:49:29 +0000 Message-ID: Date: Wed, 11 May 2022 16:49:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] opts: improve option suggestion To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin 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. --- gcc/spellcheck.cc | 9 +++++++++ gcc/spellcheck.h | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/spellcheck.cc b/gcc/spellcheck.cc index 3e58344f510..f728573331f 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..9111ea08fc3 100644 --- a/gcc/spellcheck.h +++ b/gcc/spellcheck.h @@ -128,11 +128,22 @@ 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 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;