-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISCV] Make parseNormalizedArchString only accept [a-z0-9_]. #90815
Conversation
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/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesPreviously 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:
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");
|
@@ -21,10 +21,11 @@ bool operator==(const RISCVISAUtils::ExtensionVersion &A, | |||
} | |||
|
|||
TEST(ParseNormalizedArchString, RejectsUpperCase) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change the test name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with @4vtomat's issue addressed.
Previously we only rejected upper case characters. We should instead reject anything we don't accept. Other characters will likely confuse the extension sorting.