[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Wed May 8 22:31:28 PDT 2024
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/91532
>From 0f5fcf5035d66fd4c1d1e97525e9266d8460b297 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 8 May 2024 13:40:31 -0700
Subject: [PATCH] [RISCV] Allow extra underscores in parseNormalizedArchString
and parseArchString.
Allow double underscores and trailing underscores. gcc and binutils
allow extra underscores without error.
---
clang/test/Driver/riscv-arch.c | 5 -----
llvm/lib/TargetParser/RISCVISAInfo.cpp | 16 +++-------------
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 15 +--------------
3 files changed, 4 insertions(+), 32 deletions(-)
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index ddf617bbb6237..418d8e91595de 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -308,11 +308,6 @@
// RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
// RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
-// RV32-XSEP: error: invalid arch name 'rv32ixabc_',
-// RV32-XSEP: extension name missing after separator '_'
-
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
// RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index c553e330a878b..14b757d04ce37 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -452,7 +452,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
// and separated by _. Split by _ and then extract the name and version
// information for each extension.
SmallVector<StringRef, 8> Split;
- Arch.split(Split, '_');
+ Arch.split(Split, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
for (StringRef Ext : Split) {
StringRef Prefix, MinorVersionStr;
std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
@@ -651,10 +651,6 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
break;
}
- if (Arch.back() == '_')
- return createStringError(errc::invalid_argument,
- "extension name missing after separator '_'");
-
// Skip baseline.
StringRef Exts = Arch.drop_front(1);
@@ -697,16 +693,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
Exts.consume_front("_");
SmallVector<StringRef, 8> SplitExts;
- // Only split if the string is not empty. Otherwise the split will push an
- // empty string into the vector.
- if (!Exts.empty())
- Exts.split(SplitExts, '_');
+ Exts.split(SplitExts, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
for (auto Ext : SplitExts) {
- if (Ext.empty())
- return createStringError(errc::invalid_argument,
- "extension name missing after separator '_'");
-
+ assert(!Ext.empty());
do {
if (RISCVISAUtils::AllStdExts.contains(Ext.front())) {
if (auto E = processSingleLetterExtension(
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index f9e386a85fea8..dc2a8b44cf15d 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -38,8 +38,7 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
}
TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
- for (StringRef Input :
- {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
+ for (StringRef Input : {"rv64e2p", "rv32i", "rv64ip1"}) {
EXPECT_EQ(
toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
"extension lacks version in expected format");
@@ -518,18 +517,6 @@ TEST(ParseArchString,
"unsupported standard user-level extension 'zba1p0m'");
}
-TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
- EXPECT_EQ(
- toString(RISCVISAInfo::parseArchString("rv64i__m", true).takeError()),
- "extension name missing after separator '_'");
-
- for (StringRef Input :
- {"rv32ezicsr__zifencei", "rv32i_", "rv32izicsr_", "rv64im_"}) {
- EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
- "extension name missing after separator '_'");
- }
-}
-
TEST(ParseArchString, RejectsDuplicateExtensionNames) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", true).takeError()),
"invalid standard user-level extension 'i'");
More information about the cfe-commits
mailing list