From patchwork Wed Sep 6 13:47:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 111780 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp900175qge; Wed, 6 Sep 2017 06:47:58 -0700 (PDT) X-Google-Smtp-Source: ADKCNb597ufeEXmRS8phPig2pB1WrZDyrnM+vDwRGAjczdL0IxKewaGDMK7071a0C94x02EvJCbC X-Received: by 10.98.64.138 with SMTP id f10mr7342461pfd.246.1504705678771; Wed, 06 Sep 2017 06:47:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504705678; cv=none; d=google.com; s=arc-20160816; b=pCWipS10mwcyGg7f1MQZ1O5FHPHks8o4oU7H/OGjFKuep43iNR8XAeYr00MAPk0Ptm nydpbE+i/8rrGyEsdn4xGyO9JaklLJi/Sv6trjqdvDj7hSp5KMCAmyuCFdKw2TY9P1Rr 7bPnAoP6LFWl9A8a+i9DbAp5cmYdGPet6JBq6dqGZxggNyJBvh1gxZW6xfKzq2bxrAX3 5o0/vfl4FgVWSnMQUI46tePcqZ7/X/vw3Fz4/wm+yz8fO2lDXZb2nQotA+J805jHfdYp ZrnB9Z/P4Kl8j7sMMf4XdkpYnvp+hXxHZkBFCsTc9t1nojadxHqsubN/1ux2oKX1D9pA QOOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:date:message-id:to:subject:from :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=zMD2FkAMJBXbH/CoSg7vvKY8mx83UvCAxKKKwHDpKio=; b=KI2ineZEOZjqaJKnvY2XtN0+KmngLUn/zPotfjmTXk86DX0JxgX5ikG2ndrZkBCQma BP5uXEjsO3/+Fvk8ePHp8JmrOJyB2SQEpZeu5gs1Oh221a4fZUOcguIEAz3I0XoItbeT sdocCfvLqsOryj1oJvNsPAUnSXuddy3L8EXN589E+x2uV4xCxEjrN/OauqsxnPsOTxqP xtx97x+idE+w7MXgLby7F3Gz0Y5muYaKVOl1mxKEYITzCLvrXUJhz9+XctyOgGrVhr+G T8bx7uINknka9UzwVNyYmFTVooE3fFTNBZQCZDUKkjEJPniSphYJzu6ilHrvKigIv95I Kf6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YibOUB+S; spf=pass (google.com: domain of gcc-patches-return-461614-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-461614-patch=linaro.org@gcc.gnu.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k70si1219220pgc.445.2017.09.06.06.47.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 06:47:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-461614-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YibOUB+S; spf=pass (google.com: domain of gcc-patches-return-461614-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-461614-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=DYQdQYiAzmHhvZbr/v7cDadp+7VSIApsNgxgfngTn7QuCv6XMDEtd bz3mAnSfunaDKFiKkBMOhpHK9TBgyGqLlzUXNx5X7g3DJBBpgd4Nmx+P3j75qdj8 iZrCdSI7MIijx7+WzyaUCyCqYW1TvlBAfAicPdzTmxH1NhyyhmYfZE= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=eddrcR8zU76QavBGznNEz1Drjio=; b=YibOUB+SPf0849PEe+cP ThS5Jg2wFOIQOZDAaJeQ7++iFtQUopcj+s0rvqUppeqZel7YhjMvk/trW3kSjrG0 uxfTZWVDCaf5Z4/l6Ki7z2Pv6Gx7Wh7WPAoMF/7XBC7d3NDdq+hfKGkzbppxUCjQ rbZnZ3l/4YxxHzehIRbtyRc= Received: (qmail 57069 invoked by alias); 6 Sep 2017 13:47:42 -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 56362 invoked by uid 89); 6 Sep 2017 13:47:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=6246, 6966 X-HELO: foss.arm.com Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Sep 2017 13:47:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BD4515AD for ; Wed, 6 Sep 2017 06:47:35 -0700 (PDT) Received: from [192.168.1.19] (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 543F63F578; Wed, 6 Sep 2017 06:47:34 -0700 (PDT) From: "Richard Earnshaw (lists)" Subject: [PATCH 2/2] [arm] Improve error checking in parsecpu.awk To: GCC Patches Message-ID: <7a2a8a2e-9a3d-7a5b-2ee1-710554d15968@arm.com> Date: Wed, 6 Sep 2017 14:47:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 This patch adds a bit more error checking to parsecpu.awk to ensure that statements are not missing arguments or have excess arguments beyond those permitted. It also slightly improves the handling of errors so that we terminate properly if parsing fails and be as helpful as we can while in the parsing phase. * config/arm/parsecpu.awk (fatal): Note that we've encountered an error. Only quit immediately if parsing is complete. (BEGIN): Initialize fatal_err and parse_done. (begin fpu, end fpu): Check number of arguments. (begin arch, end arch): Likewise. (begin cpu, end cpu): Likewise. (cname, tune for, tune flags, architecture, fpu, option): Likewise. (optalias): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@251800 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 11 +++++++++++ gcc/config/arm/parsecpu.awk | 26 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cab5166..69713c1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,16 @@ 2017-09-06 Richard Earnshaw + * config/arm/parsecpu.awk (fatal): Note that we've encountered an + error. Only quit immediately if parsing is complete. + (BEGIN): Initialize fatal_err and parse_done. + (begin fpu, end fpu): Check number of arguments. + (begin arch, end arch): Likewise. + (begin cpu, end cpu): Likewise. + (cname, tune for, tune flags, architecture, fpu, option): Likewise. + (optalias): Likewise. + +2017-09-06 Richard Earnshaw + * config.gcc (arm*-*-*): Don't add arm-isa.h to tm_p_file. * config/arm/arm-isa.h: Delete. Move definitions to ... * arm-cpus.in: ... here. Use new feature and fgroup values. diff --git a/gcc/config/arm/parsecpu.awk b/gcc/config/arm/parsecpu.awk index d07d3fc..0b4fc68 100644 --- a/gcc/config/arm/parsecpu.awk +++ b/gcc/config/arm/parsecpu.awk @@ -32,7 +32,8 @@ function fatal (m) { print "error ("lineno"): " m > "/dev/stderr" - exit 1 + fatal_err = 1 + if (parse_done) exit 1 } function toplevel () { @@ -502,14 +503,18 @@ BEGIN { arch_name = "" fpu_name = "" lineno = 0 + fatal_err = 0 + parse_done = 0 if (cmd == "") fatal("Usage parsecpu.awk -v cmd=") } +# New line. Reset parse status and increment line count for error messages // { lineno++ parse_ok = 0 } +# Comments must be on a line on their own. /^#/ { parse_ok = 1 } @@ -552,12 +557,14 @@ BEGIN { } /^begin fpu / { + if (NF != 3) fatal("syntax: begin fpu ") toplevel() fpu_name = $3 parse_ok = 1 } /^end fpu / { + if (NF != 3) fatal("syntax: end fpu ") if (fpu_name != $3) fatal("mimatched end fpu") if (! (fpu_name in fpu_isa)) { fatal("fpu definition \"" fpu_name "\" lacks an \"isa\" statement") @@ -570,24 +577,28 @@ BEGIN { } /^begin arch / { + if (NF != 3) fatal("syntax: begin arch ") toplevel() arch_name = $3 parse_ok = 1 } /^[ ]*base / { + if (NF != 2) fatal("syntax: base ") if (arch_name == "") fatal("\"base\" statement outside of arch block") arch_base[arch_name] = $2 parse_ok = 1 } /^[ ]*profile / { + if (NF != 2) fatal("syntax: profile ") if (arch_name == "") fatal("\"profile\" statement outside of arch block") arch_prof[arch_name] = $2 parse_ok = 1 } /^end arch / { + if (NF != 3) fatal("syntax: end arch ") if (arch_name != $3) fatal("mimatched end arch") if (! arch_name in arch_tune_for) { fatal("arch definition lacks a \"tune for\" statement") @@ -603,18 +614,21 @@ BEGIN { } /^begin cpu / { + if (NF != 3) fatal("syntax: begin cpu ") toplevel() cpu_name = $3 parse_ok = 1 } /^[ ]*cname / { + if (NF != 2) fatal("syntax: cname ") if (cpu_name == "") fatal("\"cname\" outside of cpu block") cpu_cnames[cpu_name] = $2 parse_ok = 1 } /^[ ]*tune for / { + if (NF != 3) fatal("syntax: tune for ") if (cpu_name != "") { cpu_tune_for[cpu_name] = $3 } else if (arch_name != "") { @@ -624,6 +638,7 @@ BEGIN { } /^[ ]*tune flags / { + if (NF < 3) fatal("syntax: tune flags []*") flags="" flag_count = NF for (n = 3; n <= flag_count; n++) { @@ -640,18 +655,21 @@ BEGIN { } /^[ ]*architecture / { + if (NF != 2) fatal("syntax: architecture ") if (cpu_name == "") fatal("\"architecture\" outside of cpu block") cpu_arch[cpu_name] = $2 parse_ok = 1 } /^[ ]*fpu / { + if (NF != 2) fatal("syntax: fpu ") if (cpu_name == "") fatal("\"fpu\" outside of cpu block") cpu_fpu[cpu_name] = $2 parse_ok = 1 } /^[ ]*isa / { + if (NF < 2) fatal("syntax: isa []*") flags="" flag_count = NF for (n = 2; n <= flag_count; n++) { @@ -670,6 +688,7 @@ BEGIN { } /^[ ]*option / { + if (NF < 4) fatal("syntax: option add|remove +") name=$2 if ($3 == "add") { remove = "false" @@ -696,6 +715,7 @@ BEGIN { } /^[ ]*optalias / { + if (NF != 3) fatal("syntax: optalias ") name=$2 alias=$3 if (cpu_name != "") { @@ -709,12 +729,14 @@ BEGIN { } /^[ ]*costs / { + if (NF != 2) fatal("syntax: costs ") if (cpu_name == "") fatal("\"costs\" outside of cpu block") cpu_cost[cpu_name] = $2 parse_ok = 1 } /^end cpu / { + if (NF != 3) fatal("syntax: end cpu ") if (cpu_name != $3) fatal("mimatched end cpu") if (! (cpu_name in cpu_cnames)) { cpu_cnames[cpu_name] = cpu_name @@ -731,6 +753,8 @@ BEGIN { } END { + parse_done = 1 + if (fatal_err) exit 1 toplevel() if (cmd == "data") { gen_data()