From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id E74783832B84 for ; Wed, 14 Dec 2022 09:26:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E74783832B84 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oi1-x22b.google.com with SMTP id e205so2104931oif.11 for ; Wed, 14 Dec 2022 01:26:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NCK8BfynHqE/ebUobfk98KUMOJGO891JoO5xXrwFGo4=; b=77iwFuRaaIjmfS1VSo0me7W0dVGn0k9jaSZ5DG3Jl2bXh390tv72T9yzbZ0YdPess1 eOAemW8afpwHCEl1mNKiIdnrHeMsc5KHXXLnZjRfYxjVJ7/W1Ng5BU62EA7GWkdGrt7X 1nh3XHYndRhx3c2ACQJDjZCujWwD3WxYOczNAAP2k3ocdoVl2bVO2bhT4Rh3IaHJRHiC c6OHFHvwj8qd8hUoIVYgmWt4oS5MfMagRMkz2kJ1gimDpWpD/N8uzuk4jzQhCvAT3hOX b09h6XZ2S/yTzUx3FM6kV0PbL/UzyGzerNs2Z0TAEwloutGPKHxhZ8B3CwDOAReXB/x5 jxZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NCK8BfynHqE/ebUobfk98KUMOJGO891JoO5xXrwFGo4=; b=ZK+KrYykSkbM0U/6i0WubXr5izBlvG7SXQ0yPKtU3W9fZ3s4vZdGB5Y78KjZQr29gZ 54K+n8V2zp09fAVpro0LNyQ1egR2jaYdGBR+8/8hbepxKwg/6FfPeztpz7mHvVJyoV+2 UkMdx58AQ+8y/A1v1++l2NisO6N4WAnvXvi5MCAxE1n57OFmoSN6mtUr1QEOylxwUTO3 3MBWdLToWGYl1zRKmLmRGG+tBwGSZetGcxoIULZoChgG+06u3JWZZkN7/7U+YkKr4h1Q n8PuIqmAgCGDF/y+Ebi9V4ofkhNL66buMNWi/GhMdsjNpyfKZuAm5S1IhGtCK899Lj4U gCpg== X-Gm-Message-State: ANoB5pm22sSuUbdU1Af/e0uHDpsqk+cb3X4fZwJ8ZTPm4lU+MPo2dMon nB0QMMjKSWV79cW71rU32B47bI9uG2LYNfKAQSo9KA== X-Google-Smtp-Source: AA0mqf5Keu7x1/4x6xoQMNDcARMoyL/eez2kTIJg70LDERFSonv9UjntwbtsneUdxERkLoRfuv3aSWvswe5xkFnYdQ8= X-Received: by 2002:aca:2815:0:b0:35a:83c1:ce7 with SMTP id 21-20020aca2815000000b0035a83c10ce7mr72417oix.107.1671009976163; Wed, 14 Dec 2022 01:26:16 -0800 (PST) MIME-Version: 1.0 References: <20221214073240.24973-1-xuli1@eswincomputing.com> In-Reply-To: <20221214073240.24973-1-xuli1@eswincomputing.com> From: Nelson Chu Date: Wed, 14 Dec 2022 17:26:05 +0800 Message-ID: Subject: Re: [PATCH v2] RISC-V: Add string length check for operands in AS To: Li Xu Cc: binutils@sourceware.org, kito.cheng@gmail.com, palmer@dabbelt.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: Looks reasonable so committed with passing binutils testsuites. On Wed, Dec 14, 2022 at 3:33 PM Li Xu wrote: > > The patch I previously submitted: > | Date: Tue Dec 13 04:34:28 GMT 2022 > | Subject: [PATCH] RISC-V: Add string length check for operands in AS > | Message-ID: > > The current AS accepts invalid operands due to miss of operands length check. > For example, "e6" is an invalid operand in (vsetvli a0, a1, e6, mf8, tu, ma), > but it's still accepted by assembler. In detail, the condition check "strncmp > (array[i], *s, len) == 0" in arg_lookup function passes with "strncmp ("e64", > "e6", 2)" in the case above. So the generated encoding is same as that of > (vsetvli a0, a1, e64, mf8, tu, ma). > This patch fixes issue above by prompting an error in such case and also adds > a new testcase. > > gas/ChangeLog: > > * config/tc-riscv.c (arg_lookup): Add string length check for operands. > * testsuite/gas/riscv/vector-insns-fail-vsew.d: New testcase for an illegal vsew. > * testsuite/gas/riscv/vector-insns-fail-vsew.l: Likewise. > * testsuite/gas/riscv/vector-insns-fail-vsew.s: Likewise. > --- > gas/config/tc-riscv.c | 3 ++- > gas/testsuite/gas/riscv/vector-insns-fail-vsew.d | 3 +++ > gas/testsuite/gas/riscv/vector-insns-fail-vsew.l | 3 +++ > gas/testsuite/gas/riscv/vector-insns-fail-vsew.s | 1 + > 4 files changed, 9 insertions(+), 1 deletion(-) > create mode 100644 gas/testsuite/gas/riscv/vector-insns-fail-vsew.d > create mode 100644 gas/testsuite/gas/riscv/vector-insns-fail-vsew.l > create mode 100644 gas/testsuite/gas/riscv/vector-insns-fail-vsew.s > > diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c > index 0682eb35524..42c041155c5 100644 > --- a/gas/config/tc-riscv.c > +++ b/gas/config/tc-riscv.c > @@ -1206,7 +1206,8 @@ arg_lookup (char **s, const char *const *array, size_t size, unsigned *regnop) > return false; > > for (i = 0; i < size; i++) > - if (array[i] != NULL && strncmp (array[i], *s, len) == 0) > + if (array[i] != NULL && strncmp (array[i], *s, len) == 0 > + && array[i][len] == '\0') It is minor that 8 spaces should be replaced by a tab. Otherwise it looks good. Thanks Nelson > { > *regnop = i; > *s += len; > diff --git a/gas/testsuite/gas/riscv/vector-insns-fail-vsew.d b/gas/testsuite/gas/riscv/vector-insns-fail-vsew.d > new file mode 100644 > index 00000000000..c0c81579741 > --- /dev/null > +++ b/gas/testsuite/gas/riscv/vector-insns-fail-vsew.d > @@ -0,0 +1,3 @@ > +#as: -march=rv32ifv > +#source: vector-insns-fail-vsew.s > +#error_output: vector-insns-fail-vsew.l > diff --git a/gas/testsuite/gas/riscv/vector-insns-fail-vsew.l b/gas/testsuite/gas/riscv/vector-insns-fail-vsew.l > new file mode 100644 > index 00000000000..87a2c22a805 > --- /dev/null > +++ b/gas/testsuite/gas/riscv/vector-insns-fail-vsew.l > @@ -0,0 +1,3 @@ > +.*: Assembler messages: > +.*: Error: instruction vsetvli requires absolute expression > +.*: Error: illegal operands `vsetvli a0,a1,e6,mf8,tu,ma' > diff --git a/gas/testsuite/gas/riscv/vector-insns-fail-vsew.s b/gas/testsuite/gas/riscv/vector-insns-fail-vsew.s > new file mode 100644 > index 00000000000..b8f3242406f > --- /dev/null > +++ b/gas/testsuite/gas/riscv/vector-insns-fail-vsew.s > @@ -0,0 +1 @@ > + vsetvli a0, a1, e6, mf8, tu, ma # unrecognized vsew > -- > 2.17.1 >