public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-921] RISC-V: Properly parse the letter 'p' in '-march'.
@ 2021-05-19 14:40 Kito Cheng
  0 siblings, 0 replies; only message in thread
From: Kito Cheng @ 2021-05-19 14:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1e6648076498a4644aabbfe3ec74b3b2a5b67772

commit r12-921-g1e6648076498a4644aabbfe3ec74b3b2a5b67772
Author: Geng Qi <gengqi@linux.alibaba.com>
Date:   Tue May 18 11:16:14 2021 +0800

    RISC-V: Properly parse the letter 'p' in '-march'.
    
    gcc/ChangeLog:
            * common/config/riscv/riscv-common.c
            (riscv_subset_list::parsing_subset_version): Properly parse the letter
            'p' in '-march'.
            (riscv_subset_list::parse_std_ext,
             riscv_subset_list::parse_multiletter_ext): To handle errors generated
            in riscv_subset_list::parsing_subset_version.
    
    gcc/testsuite/ChangeLog:
            * gcc.target/riscv/arch-12.c: New.
            * gcc.target/riscv/attribute-19.c: New.

Diff:
---
 gcc/common/config/riscv/riscv-common.c        | 68 ++++++++++++++-------------
 gcc/testsuite/gcc.target/riscv/arch-12.c      |  4 ++
 gcc/testsuite/gcc.target/riscv/attribute-19.c |  4 ++
 3 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index d17bea687e0..10868fd417d 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -518,40 +518,39 @@ riscv_subset_list::parsing_subset_version (const char *ext,
   unsigned version = 0;
   unsigned major = 0;
   unsigned minor = 0;
-  char np;
   *explicit_version_p = false;
 
-  for (; *p; ++p)
-    {
-      if (*p == 'p')
-	{
-	  np = *(p + 1);
-
-	  if (!ISDIGIT (np))
-	    {
-	      /* Might be beginning of `p` extension.  */
-	      if (std_ext_p)
-		{
-		  get_default_version (ext, major_version, minor_version);
-		  return p;
-		}
-	      else
-		{
-		  error_at (m_loc, "%<-march=%s%>: Expect number "
-			    "after %<%dp%>.", m_arch, version);
-		  return NULL;
-		}
-	    }
-
-	  major = version;
-	  major_p = false;
-	  version = 0;
-	}
-      else if (ISDIGIT (*p))
-	version = (version * 10) + (*p - '0');
-      else
-	break;
-    }
+  /* If we got `p`, that means we are still parsing standard extension.  */
+  gcc_assert (std_ext_p || *p != 'p');
+
+  if (*p != 'p') {
+    for (; *p; ++p)
+      {
+	if (*p == 'p')
+	  {
+	    if (!ISDIGIT (*(p+1)))
+	      {
+		error_at (m_loc, "%<-march=%s%>: Expect number "
+			  "after %<%dp%>.", m_arch, version);
+		return NULL;
+	      }
+	    if (!major_p)
+	      {
+		error_at (m_loc, "%<-march=%s%>: For %<%s%dp%dp?%>, version "
+			  "number with more than 2 level is not supported.",
+			  m_arch, ext, major, version);
+		return NULL;
+	      }
+	    major = version;
+	    major_p = false;
+	    version = 0;
+	  }
+	else if (ISDIGIT (*p))
+	  version = (version * 10) + (*p - '0');
+	else
+	  break;
+      }
+  }
 
   if (major_p)
     major = version;
@@ -643,7 +642,7 @@ riscv_subset_list::parse_std_ext (const char *p)
       return NULL;
     }
 
-  while (*p)
+  while (p != NULL && *p)
     {
       char subset[2] = {0, 0};
 
@@ -771,6 +770,9 @@ riscv_subset_list::parse_multiletter_ext (const char *p,
 				  /* std_ext_p= */ false, &explicit_version_p);
       free (ext);
 
+      if (end_of_version == NULL)
+	return NULL;
+
       *q = '\0';
 
       if (strlen (subset) == 1)
diff --git a/gcc/testsuite/gcc.target/riscv/arch-12.c b/gcc/testsuite/gcc.target/riscv/arch-12.c
new file mode 100644
index 00000000000..29e16c30815
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-12.c
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv64im1p2p3 -mabi=lp64" } */
+int foo() {}
+/* { dg-error "'-march=rv64im1p2p3': For 'm1p2p\\?', version number with more than 2 level is not supported." "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/riscv/attribute-19.c b/gcc/testsuite/gcc.target/riscv/attribute-19.c
new file mode 100644
index 00000000000..18f68d98561
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/attribute-19.c
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-mriscv-attribute -march=rv64imp0p9 -mabi=lp64" } */
+int foo() {}
+/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p0_m2p0_p0p9\"" } } */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-19 14:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 14:40 [gcc r12-921] RISC-V: Properly parse the letter 'p' in '-march' Kito Cheng

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).