public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jeff Law <law@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] RISC-V: Fix ICE in non-canonical march parsing
Date: Tue, 21 Nov 2023 04:09:39 +0000 (GMT)	[thread overview]
Message-ID: <20231121040939.ABF763858C29@sourceware.org> (raw)

https://gcc.gnu.org/g:4ff088f95b4ad0b5f6db0355e34329ce1bd2fc89

commit 4ff088f95b4ad0b5f6db0355e34329ce1bd2fc89
Author: Patrick O'Neill <patrick@rivosinc.com>
Date:   Tue Nov 14 15:08:31 2023 -0800

    RISC-V: Fix ICE in non-canonical march parsing
    
    Passing in a base extension in non-canonical order (i, e, g) causes GCC
    to ICE:
    xgcc: error: '-march=rv64ge': ISA string is not in canonical order. 'e'
    xgcc: internal compiler error: in add, at common/config/riscv/riscv-common.cc:671
    ...
    
    This is fixed by skipping to the next extension when a non-canonical
    order is detected.
    
    gcc/ChangeLog:
    
            * common/config/riscv/riscv-common.cc
            (riscv_subset_list::parse_std_ext): Emit an error and skip to
            the next extension when a non-canonical ordering is detected.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/arch-27.c: New test.
            * gcc.target/riscv/arch-28.c: New test.
    
    Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
    (cherry picked from commit 026d9454b1d9971061ad2e7d47c3ef4b0b96495d)

Diff:
---
 gcc/common/config/riscv/riscv-common.cc  | 17 +++++++++++++----
 gcc/testsuite/gcc.target/riscv/arch-27.c |  7 +++++++
 gcc/testsuite/gcc.target/riscv/arch-28.c |  7 +++++++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index 526dbb7603b..5111626157b 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -1017,15 +1017,24 @@ riscv_subset_list::parse_std_ext (const char *p)
       std_ext = *p;
 
       /* Checking canonical order.  */
+      const char *prior_std_exts = std_exts;
+
       while (*std_exts && std_ext != *std_exts)
 	std_exts++;
 
       subset[0] = std_ext;
       if (std_ext != *std_exts && standard_extensions_p (subset))
-	error_at (m_loc,
-		  "%<-march=%s%>: ISA string is not in canonical order. "
-		  "%<%c%>",
-		  m_arch, *p);
+	{
+	  error_at (m_loc,
+		    "%<-march=%s%>: ISA string is not in canonical order. "
+		    "%<%c%>",
+		    m_arch, *p);
+	  /* Extension ordering is invalid.  Ignore this extension and keep
+	     searching for other issues with remaining extensions.  */
+	  std_exts = prior_std_exts;
+	  p++;
+	  continue;
+	}
 
       std_exts++;
 
diff --git a/gcc/testsuite/gcc.target/riscv/arch-27.c b/gcc/testsuite/gcc.target/riscv/arch-27.c
new file mode 100644
index 00000000000..70143b2156f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-27.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64ge -mabi=lp64d" } */
+int foo()
+{
+}
+
+/* { dg-error "ISA string is not in canonical order. 'e'" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/riscv/arch-28.c b/gcc/testsuite/gcc.target/riscv/arch-28.c
new file mode 100644
index 00000000000..934399a7b3a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-28.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64imaefcv -mabi=lp64d" } */
+int foo()
+{
+}
+
+/* { dg-error "ISA string is not in canonical order. 'e'" "" { target *-*-* } 0 } */

                 reply	other threads:[~2023-11-21  4:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231121040939.ABF763858C29@sourceware.org \
    --to=law@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).