From patchwork Thu Mar 19 13:52:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1258246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jpHh6Dntz9sSX for ; Fri, 20 Mar 2020 00:52:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 420F53861C58; Thu, 19 Mar 2020 13:52:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 3762A385E830 for ; Thu, 19 Mar 2020 13:52:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3762A385E830 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 10BE1ACDF; Thu, 19 Mar 2020 13:52:05 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [stage1][PATCH] Provide hint for misspelled -fdump-foo options. To: gcc-patches@gcc.gnu.org Message-ID: <9861dde7-95e3-9f8c-e170-b5764eff3530@suse.cz> Date: Thu, 19 Mar 2020 14:52:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-25.0 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Hi. The patch is about basic hint support for -fdump-foo options where one can newly get something like: $ ./xgcc -B. /tmp/foo.c -fdump-ipa-ynline -c cc1: error: unrecognized command-line option ‘-fdump-ipa-ynline’; did you mean ‘-fdump-ipa-inline’? $ ./xgcc -B. /tmp/foo.c -fdump-tree-switchlowe -c cc1: error: unrecognized command-line option ‘-fdump-tree-switchlowe’; did you mean ‘-fdump-tree-switchlower1’? $ ./xgcc -B. /tmp/foo.c -fdump-rtl-sched -c cc1: error: unrecognized command-line option ‘-fdump-rtl-sched’; did you mean ‘-fdump-rtl-sched1’? I also considered the same support for --completion option but it's more problematic as the --completion is handled in driver. In driver we do not instantiate pass_manager where we have listed all passes (and their corresponding dump options). Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed in next stage1? Thanks, Martin gcc/ChangeLog: 2020-03-19 Martin Liska * dumpfile.c (dump_switch_p): Change return type and print option suggestion. * dumpfile.h: Change return type. * opts-global.c (handle_common_deferred_options): Move error into dump_switch_p function. gcc/testsuite/ChangeLog: 2020-03-19 Martin Liska * gcc.dg/spellcheck-options-22.c: New test. --- gcc/dumpfile.c | 21 +++++++++++++++++--- gcc/dumpfile.h | 2 +- gcc/opts-global.c | 3 +-- gcc/testsuite/gcc.dg/spellcheck-options-22.c | 3 +++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/spellcheck-options-22.c diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c index 468ffab6cce..e820f72edc3 100644 --- a/gcc/dumpfile.c +++ b/gcc/dumpfile.c @@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-pass.h" /* for "current_pass". */ #include "optinfo-emit-json.h" #include "stringpool.h" /* for get_identifier. */ +#include "opts.h" /* If non-NULL, return one past-the-end of the matching SUBPART of the WHOLE string. */ @@ -1874,7 +1875,7 @@ dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob) return 1; } -int +void gcc::dump_manager:: dump_switch_p (const char *arg) { @@ -1896,8 +1897,22 @@ dump_switch_p (const char *arg) for (i = 0; i < m_extra_dump_files_in_use; i++) any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true); - - return any; + if (!any) + { + char *s; + auto_vec candidates; + for (size_t i = TDI_none + 1; i != TDI_end; i++) + candidates.safe_push (dump_files[i].swtch); + for (size_t i = 0; i < m_extra_dump_files_in_use; i++) + candidates.safe_push (m_extra_dump_files[i].swtch); + const char *hint = candidates_list_and_hint (arg, s, candidates); + if (hint) + error ("unrecognized command-line option %<-fdump-%s%>; " + "did you mean %<-fdump-%s%>?", arg, hint); + else + error ("unrecognized command-line option %<-fdump-%s%>", arg); + XDELETEVEC (s); + } } /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h index 840ae4d55d5..00e175a4737 100644 --- a/gcc/dumpfile.h +++ b/gcc/dumpfile.h @@ -691,7 +691,7 @@ public: char * get_dump_file_name (struct dump_file_info *dfi, int part = -1) const; - int + void dump_switch_p (const char *arg); /* Start a dump for PHASE. Store user-supplied dump flags in diff --git a/gcc/opts-global.c b/gcc/opts-global.c index c658805470e..b1a8429dc3c 100644 --- a/gcc/opts-global.c +++ b/gcc/opts-global.c @@ -385,8 +385,7 @@ handle_common_deferred_options (void) break; case OPT_fdump_: - if (!g->get_dumps ()->dump_switch_p (opt->arg)) - error ("unrecognized command-line option %<-fdump-%s%>", opt->arg); + g->get_dumps ()->dump_switch_p (opt->arg); break; case OPT_fopt_info_: diff --git a/gcc/testsuite/gcc.dg/spellcheck-options-22.c b/gcc/testsuite/gcc.dg/spellcheck-options-22.c new file mode 100644 index 00000000000..b0ddae2e78e --- /dev/null +++ b/gcc/testsuite/gcc.dg/spellcheck-options-22.c @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-ipa-ynline" } */ +/* { dg-error "unrecognized command-line option '-fdump-ipa-ynline'; did you mean '-fdump-ipa-inline'?" "" { target *-*-* } 0 } */