From patchwork Mon Sep 5 20:00:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= X-Patchwork-Id: 666035 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 3sSgZR6Yy3z9s3v for ; Tue, 6 Sep 2016 06:00:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=IXd/FDIh; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=CLjaTrfs3vQtQiJ+grI40dSxjFNSrYLY0zXkkIw1UypZGGpIWeD1+ STd1elGs6q0ERl7OPoD7QcL/+pbVgReCI5jhEDuPllDoeK2YwYh2ilPe7L+X1qu+ GFTX2i2yGq/EKtoNcy6KHQ6J0dMowTtmUzlNiQ9wHv7VuDnndWSPtk= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=default; bh=XClpxOicrHDejar3RdJ/5s+rDT0=; b=IXd/FDIhkj6Hiik69h02Y6njL1zy gH8Uqr2qKC9vkboSbZn3Xsa+n90G08Kii+cPKwFF/xJ6kRS/6+WvBFvUYdcT+wg8 T9zEumkRRmoFjeUV/n6AISV1ztEyQ63G8aGKO1c9xkEaRDtjeQybiDBPgjpULpKj X/IZA2VCiFV54Lk= Received: (qmail 75561 invoked by alias); 5 Sep 2016 20:00:23 -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 75548 invoked by uid 89); 5 Sep 2016 20:00:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:3480, H*M:9176 X-HELO: mail-wm0-f65.google.com Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Sep 2016 20:00:21 +0000 Received: by mail-wm0-f65.google.com with SMTP id a6so3843946wmc.2 for ; Mon, 05 Sep 2016 13:00:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=s3lkIybpVc38l5vsiOiWfe3u33Cp1c9M9/Wv6vdyqNo=; b=Ebi+O7tSzSsk5nVoJFz3hPU8YM3msssaSry6870+G7jnefCMl0/iAtNGgvJ9UHIDKy Gf5cMCTGPUVGjvn+/xjO/MsEv6j2n8Pr6/0mdeVzuaSYtH4er/j2xRrV9g9iVI0TKVNW coMe58H0kLRCqOp3SZ9lmMXm5alyZ/4r3vGXmWjs87VsbgorIfHnRW8LvLIhPPcaH9w+ 3gQknLa19Q0TbPYiCVBphItaxYs7nE+ZUvOPs/pP40l+qfK7+2HbYBDoA+ElBH3haPwk n9HVHOrsbMhhn1CMPzdglvO8ARHoeEysoCl6ohk+qrW2XekGCqzDdjMHjwGWuocXdD18 g22A== X-Gm-Message-State: AE9vXwM4F/C0ESOu3OAt/tsJWW8gLc67hk8mDQQ2IOMquEQBw9x9vBNGlOEV1BLvePGd5A== X-Received: by 10.28.170.197 with SMTP id t188mr16364679wme.42.1473105619160; Mon, 05 Sep 2016 13:00:19 -0700 (PDT) Received: from [192.168.0.3] ([90.214.167.18]) by smtp.googlemail.com with ESMTPSA id 4sm22416481wmu.2.2016.09.05.13.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Sep 2016 13:00:17 -0700 (PDT) Subject: Re: [PATCH, i386] Spellcheck hints for the i386 backend option handling (PR middle-end/77475) To: Jakub Jelinek , Uros Bizjak , David Malcolm References: <20160905172545.GY14857@tucnak.redhat.com> Cc: GCC Patches From: =?UTF-8?B?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= Message-ID: Date: Mon, 5 Sep 2016 21:00:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: On 05/09/16 20:42, Manuel López-Ibáñez wrote: > On 05/09/16 18:25, Jakub Jelinek wrote: >> Hi! >> >> While most of the i386.opt -m....= options have enum args and thus >> cmdline_handle_error handles those, -march=/-mtune=/-m*-strategy= (and also >> -mrecip=) don't use that, with the CPU strings being maintained inside of a >> function rather than in some *.def file that could be also sourced into the >> *.opt or something (and similarly for the strategies). >> >> This patch adds inform calls that handle those similarly to what >> cmdline_handle_error does for the options with enum values. >> In addition, it adds %qs instead of %s in a couple of spaces, and >> stops reporting incorrect attribute option("march=...") when it is >> target("march=...") etc. > > Something like the following should avoid a lot of (future) duplication > (untested): My proposal had an obvious regression if (e->unknown_error). This one might be better: Index: opts-common.c =================================================================== --- opts-common.c (revision 239995) +++ opts-common.c (working copy) @@ -1069,6 +1069,38 @@ decoded->errors = 0; } +static void +candidates_to_string (char *s, const auto_vec *candidates) +{ + int i; + const char *candidate; + char *p = s; + FOR_EACH_VEC_ELT (*candidates, i, candidate) + { + gcc_assert (candidate); + size_t arglen = strlen (candidate); + memcpy (p, candidate, arglen); + p[arglen] = ' '; + p += arglen + 1; + } + p[-1] = 0; +} + +void +unrecognized_argument_hint (location_t loc, const char *opt, const char *arg, + const auto_vec &candidates, + size_t total_len) +{ + char *s = XALLOCAVEC (char, total_len); + candidates_to_string (s, &candidates); + const char *hint = find_closest_string (arg, &candidates); + if (hint) + inform (loc, "valid arguments to %qs are: %s; did you mean %qs?", + opt, s, hint); + else + inform (loc, "valid arguments to %qs are: %s", opt, s); +} + /* Perform diagnostics for read_cmdline_option and control_warning_option functions. Returns true if an error has been diagnosed. LOC and LANG_MASK arguments like in read_cmdline_option. @@ -1107,40 +1139,22 @@ if (errors & CL_ERR_ENUM_ARG) { const struct cl_enum *e = &cl_enums[option->var_enum]; - unsigned int i; - size_t len; - char *s, *p; - if (e->unknown_error) error_at (loc, e->unknown_error, arg); else - error_at (loc, "unrecognized argument in option %qs", opt); + error_at (loc, "argument %qs to %qs not recognized", arg, opt); - len = 0; - for (i = 0; e->values[i].arg != NULL; i++) - len += strlen (e->values[i].arg) + 1; - + size_t len = 0; + unsigned int i; auto_vec candidates; - s = XALLOCAVEC (char, len); - p = s; for (i = 0; e->values[i].arg != NULL; i++) { if (!enum_arg_ok_for_language (&e->values[i], lang_mask)) - continue; - size_t arglen = strlen (e->values[i].arg); - memcpy (p, e->values[i].arg, arglen); - p[arglen] = ' '; - p += arglen + 1; + continue; + len += strlen (e->values[i].arg) + 1; candidates.safe_push (e->values[i].arg); } - p[-1] = 0; - const char *hint = find_closest_string (arg, &candidates); - if (hint) - inform (loc, "valid arguments to %qs are: %s; did you mean %qs?", - option->opt_text, s, hint); - else - inform (loc, "valid arguments to %qs are: %s", option->opt_text, s); - + unrecognized_argument_hint (loc, opt, arg, candidates, len); return true; }