From patchwork Mon Sep 5 19:42:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= X-Patchwork-Id: 666027 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 3sSgBC6qqfz9s9Y for ; Tue, 6 Sep 2016 05:42:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vAeippGZ; 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=P/UZnUPaoKxHwS/B5Q+W2ZTRIUger2rDFkiCTcq2Zkaxb5RH+uWLe laOhAmbs07cdMeLTNOtzbJlkBUoN8x28I5aMn7nVI/BGwpl7UASublYS5KP55d0C 4A5HRtDkWDBndcXEUEzTdXzsSTCzhkV3kP6iwyiQ5a6A10PK6YEmEA= 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=RQtfXHjppaJJybWJx8uKbCFmKDc=; b=vAeippGZhUvbB7ftxqxQ8Y4rUDT/ efRrwxwgvFsEBgFfH9yEkK/4USxO+0lFCfDPnvptqTxSP3sIOzeqS1D+Wi3/b3mx iHej9UWqZrxxVvpoe+/EGyxj8MOH92ugayz+qfWm7TEhZ9nyfrCuEtNj4iw9O/kG HHdC28G1zGPfWlQ= Received: (qmail 6515 invoked by alias); 5 Sep 2016 19:42:50 -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 6502 invoked by uid 89); 5 Sep 2016 19:42:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=optscommonc, opts-common.c, UD:opts-common.c X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Sep 2016 19:42:48 +0000 Received: by mail-wm0-f46.google.com with SMTP id w12so7660492wmf.0 for ; Mon, 05 Sep 2016 12:42:48 -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=hjWunPH+1w9rzJnkIApcCHHSFdMv0FpuUs2yvY49j+w=; b=miqtaOdeNHRvxQQuScchonvUii7sgDLSSG8NQTTl+dhyk2sKaEBmTFCo0wmXWBmXUh rCWn7ciBAH7QgwaVkhYede1RwND9BRmN8gLVscAr9kXiaagqQyCheiA/1uxD9Zh/+SVy adRclopvxvxW3rdIPHrmEmTbhyT5sv9C4vlcmWVRQC9kxV0UeoHo8Pm64XKSqidW5hfk hFbUYY9MPvw4vyrLtJrXpn7cLFkjMA+n92toI7XYHFGAc828XNcG55OtkF7WPFOrj1En cQxOB4VFUTlHqNzsdfD4LoRGsdPKcnkqcXbVzD2qpWQzRfqdaXu0+QZGw4HQwZjHLIGb uybQ== X-Gm-Message-State: AE9vXwNDqEoactgbbGDnERfAXoRsAvd8ucNAxSZ1aNmB+nC7MrKfCL7LpqyGxUFwiUcLTQ== X-Received: by 10.194.204.196 with SMTP id la4mr2877525wjc.7.1473104566527; Mon, 05 Sep 2016 12:42:46 -0700 (PDT) Received: from ?IPv6:2a02:c7d:2a2e:5500:896d:d6a2:7b1f:8f8b? ([2a02:c7d:2a2e:5500:896d:d6a2:7b1f:8f8b]) by smtp.googlemail.com with ESMTPSA id s184sm22420987wmb.11.2016.09.05.12.42.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Sep 2016 12:42:45 -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 20:42:37 +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: <20160905172545.GY14857@tucnak.redhat.com> 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): Index: opts-common.c =================================================================== --- opts-common.c (revision 239995) +++ opts-common.c (working copy) @@ -1069,6 +1069,40 @@ 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_error (location_t loc, const char *opt, const char *arg, + const auto_vec &candidates, + size_t total_len) +{ + error_at (loc, "argument %qs to %qs not recognized", arg, opt); + + 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 +1141,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); - - len = 0; - for (i = 0; e->values[i].arg != NULL; i++) - len += strlen (e->values[i].arg) + 1; - - 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; - candidates.safe_push (e->values[i].arg); + size_t len = 0; + unsigned int i; + auto_vec candidates; + for (i = 0; e->values[i].arg != NULL; i++) + { + if (!enum_arg_ok_for_language (&e->values[i], lang_mask)) + continue; + len += strlen (e->values[i].arg) + 1; + candidates.safe_push (e->values[i].arg); + } + unrecognized_argument_error (loc, opt, arg, candidates, len); } - 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); - return true; }