[llvm] [RISCV] Make parseNormalizedArchString only accept [a-z0-9_]. (PR #90815)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 1 19:42:49 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
Previously we only rejected upper case characters. We should instead reject anything we don't accept. Other characters will likely confuse the extension sorting.
---
Full diff: https://github.com/llvm/llvm-project/pull/90815.diff
2 Files Affected:
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+4-2)
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+5-4)
``````````diff
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");
``````````
</details>
https://github.com/llvm/llvm-project/pull/90815
More information about the llvm-commits
mailing list