[llvm] [RISCV] Make parseNormalizedArchString only accept [a-z0-9_]. (PR #90815)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 09:19:23 PDT 2024
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/90815
>From 97b747783dfeb61c561a1e49527c36eb6bbacab3 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 1 May 2024 19:36:12 -0700
Subject: [PATCH 1/2] [RISCV] Make parseNormalizedArchString only accept
[a-z0-9_].
Previously we only rejected upper case characters. We should instead
reject anything we don't accept. Other characters will likely
confuse the extension sorting.
---
llvm/lib/TargetParser/RISCVISAInfo.cpp | 6 ++++--
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 9 +++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index e8172ebb259720..6d073f7604b573 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -425,9 +425,11 @@ RISCVISAInfo::parseFeatures(unsigned XLen,
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
- if (llvm::any_of(Arch, isupper))
+ // RISC-V ISA strings must be [a-z0-9_]
+ if (!llvm::all_of(
+ Arch, [](char C) { return isDigit(C) || isLower(C) || C == '_'; }))
return createStringError(errc::invalid_argument,
- "string must be lowercase");
+ "string may only contain [a-z0-9_]");
// Must start with a valid base ISA name.
unsigned XLen = 0;
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 3aa0178100abf4..4f561cd423a27f 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -21,10 +21,11 @@ bool operator==(const RISCVISAUtils::ExtensionVersion &A,
}
TEST(ParseNormalizedArchString, RejectsUpperCase) {
- for (StringRef Input : {"RV32", "rV64", "rv32i2P0", "rv64i2p0_A2p0"}) {
+ for (StringRef Input :
+ {"RV32", "rV64", "rv32i2P0", "rv64i2p0_A2p0", "rv32e2.0"}) {
EXPECT_EQ(
toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
- "string must be lowercase");
+ "string may only contain [a-z0-9_]");
}
}
@@ -37,8 +38,8 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
}
TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
- for (StringRef Input : {"rv64i2p0_", "rv32i2p0__a2p0", "rv32e2.0", "rv64e2p",
- "rv32i", "rv64ip1"}) {
+ for (StringRef Input :
+ {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
EXPECT_EQ(
toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
"extension lacks version in expected format");
>From beffc910521308ad4b4e945e9de514fa6a4c911b Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 2 May 2024 09:18:50 -0700
Subject: [PATCH 2/2] fixup! rename test
---
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 4f561cd423a27f..d08ba1ce6c90ac 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -20,7 +20,7 @@ bool operator==(const RISCVISAUtils::ExtensionVersion &A,
return A.Major == B.Major && A.Minor == B.Minor;
}
-TEST(ParseNormalizedArchString, RejectsUpperCase) {
+TEST(ParseNormalizedArchString, RejectsInvalidChars) {
for (StringRef Input :
{"RV32", "rV64", "rv32i2P0", "rv64i2p0_A2p0", "rv32e2.0"}) {
EXPECT_EQ(
More information about the llvm-commits
mailing list