From patchwork Tue Sep 6 20:40:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 666738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sTJQH1lfVz9sBR for ; Wed, 7 Sep 2016 06:40:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=pw+du7R6; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=VL89zvhvUSrus9PZr xd1iXUSfqRYhrY2aJCXdcV2ASAi30zIb9XCucKliWrqGaSDttCTDoqaNjp4zsQtY mOC5NQYcoU+5uPCVvXyhYLv+l/OxPCYo9gf+TsuWyQuq6dcP1Qqg2CmlsIYeyD1P 1joIW1h3xXbzhQoHEsDFKIJ8/0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=iVpRZQOhq+5Ttfi6nABl1ji bKIs=; b=pw+du7R6u0iIetHD2miceAcnb7p89UTRUKLoRyHoDUWDdrNp9kFYyfR ztMyt4ySgt4tdkV0MDrYIw9nKRI5oYVdTySw2PfVRu/9NbARPPU9F6d7JiDQ/cyf lzW98cvXnf0Iv5wHYp1TohTC5gM5dbqLlVr4RJAlLA0yN3EiwykY= Received: (qmail 43833 invoked by alias); 6 Sep 2016 20:40:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 43752 invoked by uid 89); 6 Sep 2016 20:40:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:i386.c.jj, 35524605779, i386.c.jj, 35.524605779 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Sep 2016 20:40:18 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE7096666; Tue, 6 Sep 2016 20:40:16 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-43.brq.redhat.com [10.40.204.43]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u86KeFp2004823 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 6 Sep 2016 16:40:16 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u86KeDjs028611; Tue, 6 Sep 2016 22:40:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u86KeDih028610; Tue, 6 Sep 2016 22:40:13 +0200 Date: Tue, 6 Sep 2016 22:40:13 +0200 From: Jakub Jelinek To: Uros Bizjak , David Malcolm Cc: gcc-patches@gcc.gnu.org Subject: [PATCH, i386] Spellcheck hints for the i386 backend option handling (PR middle-end/77475, take 2, i386 part) Message-ID: <20160906204013.GP14857@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20160905172545.GY14857@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi! On Mon, Sep 05, 2016 at 09:00:30PM +0200, Uros Bizjak wrote: > OK as far as x86 target is concerned, but please allow a day for David > to eventually comment on the implementation. And here is the updated i386 patch, on top of the generic patch I've just posted. Compared to the last patch, this one now includes diagnostics, uses the new opts-common.c helper and also stops using the perhaps fancy, but absolutely l10n incompatible technique with prefix/suffix/sw variables in various diagnostics - the words switch and attribute couldn't be translated and would appear somewhere in a translated sequence. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-09-05 Jakub Jelinek PR middle-end/77475 * config/i386/i386.c (ix86_parse_stringop_strategy_string): Simplify, use %qs instead of %s where desirable, use argument instead of arg in the diagnostic wording, add list of supported strategies and spellcheck hint. (ix86_option_override_internal): Emit target("m...") instead of option("m...") in the diagnostic. Use %qs instead of %s in invalid -march/-mtune option diagnostic. Add list of supported arches/tunings and spellcheck hint. Remove prefix, suffix and sw variables, use main_args_p ? "..." : "..." in diagnostics to make translation possible. * gcc.target/i386/pr65990.c: Adjust expected diagnostics. * gcc.dg/march-generic.c: Likewise. * gcc.target/i386/spellcheck-options-1.c: New test. * gcc.target/i386/spellcheck-options-2.c: New test. * gcc.target/i386/spellcheck-options-3.c: New test. * gcc.target/i386/spellcheck-options-4.c: New test. Jakub --- gcc/config/i386/i386.c.jj 2016-09-06 16:55:35.524605779 +0200 +++ gcc/config/i386/i386.c 2016-09-06 19:45:03.126299652 +0200 @@ -4516,6 +4517,7 @@ ix86_parse_stringop_strategy_string (cha const struct stringop_algs *default_algs; stringop_size_range input_ranges[MAX_STRINGOP_ALGS]; char *curr_range_str, *next_range_str; + const char *opt = is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="; int i = 0, n = 0; if (is_memset) @@ -4537,15 +4539,13 @@ ix86_parse_stringop_strategy_string (cha if (3 != sscanf (curr_range_str, "%20[^:]:%d:%10s", alg_name, &maxs, align)) { - error ("wrong arg %s to option %s", curr_range_str, - is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + error ("wrong argument %qs to option %qs", curr_range_str, opt); return; } if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1)) { - error ("size ranges of option %s should be increasing", - is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + error ("size ranges of option %qs should be increasing", opt); return; } @@ -4555,9 +4555,25 @@ ix86_parse_stringop_strategy_string (cha if (i == last_alg) { - error ("wrong stringop strategy name %s specified for option %s", - alg_name, - is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + error ("wrong strategy name %qs specified for option %qs", + alg_name, opt); + + auto_vec candidates; + for (i = 0; i < last_alg; i++) + if ((stringop_alg) i != rep_prefix_8_byte || TARGET_64BIT) + candidates.safe_push (stringop_alg_names[i]); + + char *s; + const char *hint + = candidates_list_and_hint (alg_name, s, candidates); + if (hint) + inform (input_location, + "valid arguments to %qs are: %s; did you mean %qs?", + opt, s, hint); + else + inform (input_location, "valid arguments to %qs are: %s", + opt, s); + XDELETEVEC (s); return; } @@ -4565,10 +4581,8 @@ ix86_parse_stringop_strategy_string (cha && !TARGET_64BIT) { /* rep; movq isn't available in 32-bit code. */ - error ("stringop strategy name %s specified for option %s " - "not supported for 32-bit code", - alg_name, - is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + error ("strategy name %qs specified for option %qs " + "not supported for 32-bit code", alg_name, opt); return; } @@ -4580,8 +4594,7 @@ ix86_parse_stringop_strategy_string (cha input_ranges[n].noalign = true; else { - error ("unknown alignment %s specified for option %s", - align, is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + error ("unknown alignment %qs specified for option %qs", align, opt); return; } n++; @@ -4592,15 +4605,13 @@ ix86_parse_stringop_strategy_string (cha if (input_ranges[n - 1].max != -1) { error ("the max value for the last size range should be -1" - " for option %s", - is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + " for option %qs", opt); return; } if (n > MAX_STRINGOP_ALGS) { - error ("too many size ranges specified in option %s", - is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy="); + error ("too many size ranges specified in option %qs", opt); return; } @@ -4731,9 +4742,6 @@ ix86_option_override_internal (bool main int i; unsigned int ix86_arch_mask; const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL); - const char *prefix; - const char *suffix; - const char *sw; #define PTA_3DNOW (HOST_WIDE_INT_1 << 0) #define PTA_3DNOW_A (HOST_WIDE_INT_1 << 1) @@ -5031,21 +5039,6 @@ ix86_option_override_internal (bool main int const pta_size = ARRAY_SIZE (processor_alias_table); - /* Set up prefix/suffix so the error messages refer to either the command - line argument, or the attribute(target). */ - if (main_args_p) - { - prefix = "-m"; - suffix = ""; - sw = "switch"; - } - else - { - prefix = "option(\""; - suffix = "\")"; - sw = "attribute"; - } - /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false. */ if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags)) @@ -5118,9 +5111,13 @@ ix86_option_override_internal (bool main opts->x_ix86_tune_string = "generic"; } else if (!strcmp (opts->x_ix86_tune_string, "x86-64")) - warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated; use " - "%stune=k8%s or %stune=generic%s instead as appropriate", - prefix, suffix, prefix, suffix, prefix, suffix); + warning (OPT_Wdeprecated, + main_args_p + ? "%<-mtune=x86-64%> is deprecated; use %<-mtune=k8%> " + "or %<-mtune=generic%> instead as appropriate" + : "% is deprecated; use " + "% or % " + "instead as appropriate"); } else { @@ -5474,14 +5471,48 @@ ix86_option_override_internal (bool main error ("Intel MPX does not support x32"); if (!strcmp (opts->x_ix86_arch_string, "generic")) - error ("generic CPU can be used only for %stune=%s %s", - prefix, suffix, sw); + error (main_args_p + ? "% CPU can be used only for %<-mtune=%> switch" + : "% CPU can be used only for " + "% attribute"); else if (!strcmp (opts->x_ix86_arch_string, "intel")) - error ("intel CPU can be used only for %stune=%s %s", - prefix, suffix, sw); + error (main_args_p + ? "% CPU can be used only for %<-mtune=%> switch" + : "% CPU can be used only for " + "% attribute"); else if (i == pta_size) - error ("bad value (%s) for %sarch=%s %s", - opts->x_ix86_arch_string, prefix, suffix, sw); + { + error (main_args_p + ? "bad value (%qs) for %<-march=%> switch" + : "bad value (%qs) for % attribute", + opts->x_ix86_arch_string); + + auto_vec candidates; + for (i = 0; i < pta_size; i++) + if (strcmp (processor_alias_table[i].name, "generic") + && strcmp (processor_alias_table[i].name, "intel") + && (!TARGET_64BIT_P (opts->x_ix86_isa_flags) + || (processor_alias_table[i].flags & PTA_64BIT))) + candidates.safe_push (processor_alias_table[i].name); + + char *s; + const char *hint + = candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates); + if (hint) + inform (input_location, + main_args_p + ? "valid arguments to %<-march=%> switch are: " + "%s; did you mean %qs?" + : "valid arguments to % attribute are: " + "%s; did you mean %qs?", s, hint); + else + inform (input_location, + main_args_p + ? "valid arguments to %<-march=%> switch are: %s" + : "valid arguments to % attribute are: %s", + s); + XDELETEVEC (s); + } ix86_arch_mask = 1u << ix86_arch; for (i = 0; i < X86_ARCH_LAST; ++i) @@ -5523,8 +5554,36 @@ ix86_option_override_internal (bool main } if (ix86_tune_specified && i == pta_size) - error ("bad value (%s) for %stune=%s %s", - opts->x_ix86_tune_string, prefix, suffix, sw); + { + error (main_args_p + ? "bad value (%qs) for %<-mtune=%> switch" + : "bad value (%qs) for % attribute", + opts->x_ix86_tune_string); + + auto_vec candidates; + for (i = 0; i < pta_size; i++) + if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) + || (processor_alias_table[i].flags & PTA_64BIT)) + candidates.safe_push (processor_alias_table[i].name); + + char *s; + const char *hint + = candidates_list_and_hint (opts->x_ix86_tune_string, s, candidates); + if (hint) + inform (input_location, + main_args_p + ? "valid arguments to %<-mtune=%> switch are: " + "%s; did you mean %qs?" + : "valid arguments to % attribute are: " + "%s; did you mean %qs?", s, hint); + else + inform (input_location, + main_args_p + ? "valid arguments to %<-mtune=%> switch are: %s" + : "valid arguments to % attribute are: %s", + s); + XDELETEVEC (s); + } set_ix86_tune_features (ix86_tune, opts->x_ix86_dump_tunes); @@ -5623,7 +5682,9 @@ ix86_option_override_internal (bool main & ~opts->x_ix86_isa_flags_explicit); if (TARGET_RTD_P (opts->x_target_flags)) - warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix); + warning (0, + main_args_p ? "%<-mrtd%> is ignored in 64bit mode" + : "% is ignored in 64bit mode"); } else { @@ -5744,7 +5805,9 @@ ix86_option_override_internal (bool main /* Accept -msseregparm only if at least SSE support is enabled. */ if (TARGET_SSEREGPARM_P (opts->x_target_flags) && ! TARGET_SSE_P (opts->x_ix86_isa_flags)) - error ("%ssseregparm%s used without SSE enabled", prefix, suffix); + error (main_args_p + ? "%<-msseregparm%> used without SSE enabled" + : "% used without SSE enabled"); if (opts_set->x_ix86_fpmath) { @@ -5809,8 +5872,12 @@ ix86_option_override_internal (bool main && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)) { if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS) - warning (0, "stack probing requires %saccumulate-outgoing-args%s " - "for correctness", prefix, suffix); + warning (0, + main_args_p + ? "stack probing requires %<-maccumulate-outgoing-args%> " + "for correctness" + : "stack probing requires " + "% for correctness"); opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS; } @@ -5820,8 +5887,11 @@ ix86_option_override_internal (bool main && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)) { if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS) - warning (0, "fixed ebp register requires %saccumulate-outgoing-args%s", - prefix, suffix); + warning (0, + main_args_p + ? "fixed ebp register requires %<-maccumulate-outgoing-args%>" + : "fixed ebp register requires " + "%"); opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS; } --- gcc/testsuite/gcc.target/i386/pr65990.c.jj 2016-09-05 19:27:03.016674736 +0200 +++ gcc/testsuite/gcc.target/i386/pr65990.c 2016-09-06 17:47:11.812776172 +0200 @@ -1,7 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-mtune=btver2 -mmemcpy-strategy=rep_8byte:-1:noalign" } -/* { dg-error "stringop strategy name rep_8byte specified for option -mmemcpy_strategy= not supported for 32-bit code" "" { target ia32 } 0 } */ +/* { dg-error "stringop strategy name 'rep_8byte' specified for option '-mmemcpy_strategy=' not supported for 32-bit code" "" { target ia32 } 0 } */ struct U9 { --- gcc/testsuite/gcc.dg/march-generic.c.jj 2014-11-11 00:06:08.000000000 +0100 +++ gcc/testsuite/gcc.dg/march-generic.c 2016-09-06 22:19:32.278111025 +0200 @@ -1,6 +1,6 @@ /* { dg-do compile { target i?86-*-* x86_64-*-* } } */ /* { dg-skip-if "" { *-*-* } { "-march=*" } { "" } } */ /* { dg-options "-march=generic" } */ -/* { dg-error "generic CPU can be used only for -mtune" "" { target *-*-* } 0 } */ +/* { dg-error "'generic' CPU can be used only for '-mtune=' switch" "" { target *-*-* } 0 } */ /* { dg-bogus "march" "" { target *-*-* } 0 } */ int i; --- gcc/testsuite/gcc.target/i386/spellcheck-options-1.c.jj 2016-09-06 19:33:10.134236964 +0200 +++ gcc/testsuite/gcc.target/i386/spellcheck-options-1.c 2016-09-06 19:39:21.623580368 +0200 @@ -0,0 +1,7 @@ +/* Verify that we provide a hint if the user misspells an option argument + (PR middle-end/77475). */ + +/* { dg-do compile } */ +/* { dg-options "-march=hasvel" } */ +/* { dg-error "bad value .'hasvel'. for '-march=' switch" "" { target *-*-* } 0 } */ +/* { dg-message "valid arguments to '-march=' switch are: \[^\n\r]*; did you mean 'haswell'?" "" { target *-*-* } 0 } */ --- gcc/testsuite/gcc.target/i386/spellcheck-options-2.c.jj 2016-09-06 19:39:39.433357123 +0200 +++ gcc/testsuite/gcc.target/i386/spellcheck-options-2.c 2016-09-06 19:40:02.367069650 +0200 @@ -0,0 +1,7 @@ +/* Verify that we provide a hint if the user misspells an option argument + (PR middle-end/77475). */ + +/* { dg-do compile } */ +/* { dg-options "-mtune=hasvel" } */ +/* { dg-error "bad value .'hasvel'. for '-mtune=' switch" "" { target *-*-* } 0 } */ +/* { dg-message "valid arguments to '-mtune=' switch are: \[^\n\r]*; did you mean 'haswell'?" "" { target *-*-* } 0 } */ --- gcc/testsuite/gcc.target/i386/spellcheck-options-3.c.jj 2016-09-06 19:40:13.177934137 +0200 +++ gcc/testsuite/gcc.target/i386/spellcheck-options-3.c 2016-09-06 19:46:25.200270859 +0200 @@ -0,0 +1,7 @@ +/* Verify that we provide a hint if the user misspells an option argument + (PR middle-end/77475). */ + +/* { dg-do compile } */ +/* { dg-options "-mmemcpy-strategy=unroled_looop:8:align" } */ +/* { dg-error "wrong strategy name 'unroled_looop' specified for option '-mmemcpy_strategy='" "" { target *-*-* } 0 } */ +/* { dg-message "valid arguments to '-mmemcpy_strategy=' are: \[^\n\r]*; did you mean 'unrolled_loop'?" "" { target *-*-* } 0 } */ --- gcc/testsuite/gcc.target/i386/spellcheck-options-4.c.jj 2016-09-06 19:46:37.500116681 +0200 +++ gcc/testsuite/gcc.target/i386/spellcheck-options-4.c 2016-09-06 19:48:04.486026318 +0200 @@ -0,0 +1,7 @@ +/* Verify that we provide a hint if the user misspells an option argument + (PR middle-end/77475). */ + +/* { dg-do compile } */ + +__attribute__((target ("arch=hasvel"))) void foo (void) {} /* { dg-error "bad value .'hasvel'. for 'target..arch=..' attribute" } */ +/* { dg-message "valid arguments to 'target..arch=..' attribute are: \[^\n\r]*; did you mean 'haswell'?" "" { target *-*-* } 6 } */