Skip to content

[RISCV] Don't pre-split before the loop in parseNormalizedArchString. #91684

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

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions llvm/lib/TargetParser/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,18 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
// Each extension is of the form ${name}${major_version}p${minor_version}
// and separated by _. Split by _ and then extract the name and version
// information for each extension.
SmallVector<StringRef, 8> Split;
Arch.split(Split, '_');
for (StringRef Ext : Split) {
while (!Arch.empty()) {
if (Arch[0] == '_') {
if (Arch.size() == 1 || Arch[1] == '_')
return createStringError(errc::invalid_argument,
"extension name missing after separator '_'");
Arch = Arch.drop_front();
}

size_t Idx = Arch.find('_');
StringRef Ext = Arch.slice(0, Idx);
Arch = Arch.slice(Idx, StringRef::npos);

StringRef Prefix, MinorVersionStr;
std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
if (MinorVersionStr.empty())
Expand Down
9 changes: 7 additions & 2 deletions llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ 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");
}

for (StringRef Input : {"rv64i2p0_", "rv32i2p0__a2p0"}) {
EXPECT_EQ(
toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
"extension name missing after separator '_'");
}
}

TEST(ParseNormalizedArchString, RejectsOnlyVersion) {
Expand Down