diff options
-rw-r--r-- | gcc/common/config/riscv/riscv-common.c | 68 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/arch-12.c | 4 | ||||
-rw-r--r-- | 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 d17bea6..10868fd4 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 0000000..29e16c3 --- /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 0000000..18f68d9 --- /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\"" } } */ |