From patchwork Thu Mar 30 10:23:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 77051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1028048vqo; Thu, 30 Mar 2023 03:40:28 -0700 (PDT) X-Google-Smtp-Source: AKy350ZHIUIqnEaylegMXKM9lyuwCfc6j/YuZkm8l8Wo8SmmuQTBRAcsfbctUCy9Z3UitOrHXS8h X-Received: by 2002:a17:907:2063:b0:933:3814:e0f4 with SMTP id qp3-20020a170907206300b009333814e0f4mr24307487ejb.16.1680172828786; Thu, 30 Mar 2023 03:40:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680172828; cv=none; d=google.com; s=arc-20160816; b=yVpTUsVjNnYPWMb8Z136vvpsRszzMzaaqrU5pb4Q0KOcWkn1ARomXjuUWnlCrDlloR 7KQ4mjxCMus8c6Ajl0cKwwXasoHwQ//MoOkZfNKsDIgNae1qDI7E3ouCOdP7SZUV2+Px 0JJ/co8sUt3m239GdSwYf7onrDCWhZLDVGOU+xkXzc1GiSpMoq+f2fiY5NHGa13WL/PD WxJWPaCiZATu4rikUMQsYai55XYJTJ9LnhS+u81pAiy1J1XfktTYr1iI+fxx1qU4NIWY cJP6dpBT/oVOnm0qwecF2Fu2WSLqVsR3Zs+AaPHbnXd54URmuFbp7ZCYwcwTTvuP5cPM bDjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=HmpfRt7N3hy5EdAHJIagE5gRrUFCPqc604+cfiEGBks=; b=y+UrdnAp3OS7ZcGzogyFJ6jBvnPzFKmbAM1hYVeYGD0eYD9UBBeKLs2YwZw9eTepmA 7bjiK+teoLWm9g5ibLp3QXZwyl8PlB7TrTWE10CscAAK3qNnOyAVHRlmy33EpQz9ZYup YfKTDoTNOjFWa84BF2dxL/tKVsCBFYFPQZsssTIrb93kFr2fQp9gTZYw/Kt4l0ShEVop wecFLAbV3V+ovL6Pm73gtBU1vw2mVrfQndfWOhk1Tw741McFfeURv3MEFao84mu4OZap rCoQNVfhPDfi6pu83eMTW0QmUHlb5nhuX5Iffso34gsuC9MB7Jp39+FB3cHIMDjVkcGI O6pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=QB1nNkTW; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t2-20020a1709063e4200b0092d55987bcesi29623319eji.268.2023.03.30.03.40.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 03:40:28 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=QB1nNkTW; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47794385559E for ; Thu, 30 Mar 2023 10:31:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47794385559E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680172312; bh=HmpfRt7N3hy5EdAHJIagE5gRrUFCPqc604+cfiEGBks=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QB1nNkTWqQfwtf9fv9IvSWqx5DgsU+7HVsmkR7nhcT5CcTee10X7O346ChfHd+VFN 1cFkYUGc+dPertuARe/YNH5JC/2UZlV1mqO/7a2P5vmx66+Mkx2UXq5vpzmfFIfO75 XOzc47gnCdq4pSCOc5rAHVQoqmBhv/6FHy+Qhk4Y= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id C365D38582A3 for ; Thu, 30 Mar 2023 10:24:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C365D38582A3 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 075EA2F4; Thu, 30 Mar 2023 03:25:23 -0700 (PDT) Received: from e121540-lin.manchester.arm.com (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3EA333F663; Thu, 30 Mar 2023 03:24:38 -0700 (PDT) To: binutils@sourceware.org Cc: Richard Sandiford Subject: [PATCH 34/43] aarch64: Tweak priorities of parsing-related errors Date: Thu, 30 Mar 2023 11:23:50 +0100 Message-Id: <20230330102359.3327695-35-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230330102359.3327695-1-richard.sandiford@arm.com> References: <20230330102359.3327695-1-richard.sandiford@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-32.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Sandiford via Binutils From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761788904010059616?= X-GMAIL-MSGID: =?utf-8?q?1761788904010059616?= There are three main kinds of error reported during parsing, in increasing order of priority: - AARCH64_OPDE_RECOVERABLE (register seen instead of immediate) - AARCH64_OPDE_SYNTAX_ERROR - AARCH64_OPDE_FATAL_SYNTAX_ERROR This priority makes sense when comparing errors reported against the same operand. But if we get to operand 3 (say) and see a register instead of an immediate, that's likely to be a better match than something that fails with a syntax error at operand 1. The idea of this patch is to prioritise parsing-related errors based on operand index first, then by error code. Post-parsing errors still win over parsing errors, and their relative priorities don't change. --- gas/config/tc-aarch64.c | 50 ++++++++++++++++++++--- gas/testsuite/gas/aarch64/sme-8-illegal.l | 12 +++--- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 1851f83ad05..c8e37623d9e 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -5769,6 +5769,44 @@ output_operand_error_record (const operand_error_record *record, char *str) } } +/* Return true if the presence of error A against an instruction means + that error B should not be reported. This is only used as a first pass, + to pick the kind of error that we should report. */ + +static bool +better_error_p (operand_error_record *a, operand_error_record *b) +{ + /* For errors reported during parsing, prefer errors that relate to + later operands, since that implies that the earlier operands were + syntactically valid. + + For example, if we see a register R instead of an immediate in + operand N, we'll report that as a recoverable "immediate operand + required" error. This is because there is often another opcode + entry that accepts a register operand N, and any errors about R + should be reported against the register forms of the instruction. + But if no such register form exists, the recoverable error should + still win over a syntax error against operand N-1. + + For these purposes, count an error reported at the end of the + assembly string as equivalent to an error reported against the + final operand. This means that opcode entries that expect more + operands win over "unexpected characters following instruction". */ + if (a->detail.kind <= AARCH64_OPDE_FATAL_SYNTAX_ERROR + && b->detail.kind <= AARCH64_OPDE_FATAL_SYNTAX_ERROR) + { + int a_index = (a->detail.index < 0 + ? aarch64_num_of_operands (a->opcode) - 1 + : a->detail.index); + int b_index = (b->detail.index < 0 + ? aarch64_num_of_operands (b->opcode) - 1 + : b->detail.index); + if (a_index != b_index) + return a_index > b_index; + } + return operand_error_higher_severity_p (a->detail.kind, b->detail.kind); +} + /* Process and output the error message about the operand mismatching. When this function is called, the operand error information had @@ -5787,7 +5825,7 @@ output_operand_error_report (char *str, bool non_fatal_only) enum aarch64_operand_error_kind kind; operand_error_record *curr; operand_error_record *head = operand_error_report.head; - operand_error_record *record = NULL; + operand_error_record *record; /* No error to report. */ if (head == NULL) @@ -5811,7 +5849,7 @@ output_operand_error_report (char *str, bool non_fatal_only) /* Find the error kind of the highest severity. */ DEBUG_TRACE ("multiple opcode entries with error kind"); - kind = AARCH64_OPDE_NIL; + record = NULL; for (curr = head; curr != NULL; curr = curr->next) { gas_assert (curr->detail.kind != AARCH64_OPDE_NIL); @@ -5832,14 +5870,16 @@ output_operand_error_report (char *str, bool non_fatal_only) { DEBUG_TRACE ("\t%s", operand_mismatch_kind_names[curr->detail.kind]); } - if (operand_error_higher_severity_p (curr->detail.kind, kind) - && (!non_fatal_only || (non_fatal_only && curr->detail.non_fatal))) - kind = curr->detail.kind; + if ((!non_fatal_only || curr->detail.non_fatal) + && (!record || better_error_p (curr, record))) + record = curr; } + kind = (record ? record->detail.kind : AARCH64_OPDE_NIL); gas_assert (kind != AARCH64_OPDE_NIL || non_fatal_only); /* Pick up one of errors of KIND to report. */ + record = NULL; for (curr = head; curr != NULL; curr = curr->next) { /* If we don't want to print non-fatal errors then don't consider them diff --git a/gas/testsuite/gas/aarch64/sme-8-illegal.l b/gas/testsuite/gas/aarch64/sme-8-illegal.l index ee9f76f3b9c..7123e8d9eac 100644 --- a/gas/testsuite/gas/aarch64/sme-8-illegal.l +++ b/gas/testsuite/gas/aarch64/sme-8-illegal.l @@ -1,7 +1,7 @@ [^:]*: Assembler messages: -[^:]*:[0-9]+: Error: unexpected characters following instruction -- `smstart x0' -[^:]*:[0-9]+: Error: unexpected characters following instruction -- `smstart sa' -[^:]*:[0-9]+: Error: unexpected characters following instruction -- `smstart zm' -[^:]*:[0-9]+: Error: unexpected characters following instruction -- `smstop x0' -[^:]*:[0-9]+: Error: unexpected characters following instruction -- `smstop sa' -[^:]*:[0-9]+: Error: unexpected characters following instruction -- `smstop zm' +[^:]*:[0-9]+: Error: unknown or missing PSTATE field name at operand 1 -- `smstart x0' +[^:]*:[0-9]+: Error: unknown or missing PSTATE field name at operand 1 -- `smstart sa' +[^:]*:[0-9]+: Error: unknown or missing PSTATE field name at operand 1 -- `smstart zm' +[^:]*:[0-9]+: Error: unknown or missing PSTATE field name at operand 1 -- `smstop x0' +[^:]*:[0-9]+: Error: unknown or missing PSTATE field name at operand 1 -- `smstop sa' +[^:]*:[0-9]+: Error: unknown or missing PSTATE field name at operand 1 -- `smstop zm'