]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Fix ICE in non-canonical march parsing
authorPatrick O'Neill <patrick@rivosinc.com>
Tue, 14 Nov 2023 23:08:31 +0000 (15:08 -0800)
committerPatrick O'Neill <patrick@rivosinc.com>
Wed, 15 Nov 2023 18:23:44 +0000 (10:23 -0800)
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>
gcc/common/config/riscv/riscv-common.cc
gcc/testsuite/gcc.target/riscv/arch-27.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/arch-28.c [new file with mode: 0644]

index 526dbb7603be1f7f323dc08bea71ddd8f006056d..5111626157b7e0602d9eed35b41cba44debacfb5 100644 (file)
@@ -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 (file)
index 0000000..70143b2
--- /dev/null
@@ -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 (file)
index 0000000..934399a
--- /dev/null
@@ -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 } */