-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Don't crash if parseNormalizedArchString encounters a multi-letter extension with an unknown prefix. #91398
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
Conversation
…etter extension with an unknown prefix. The sorting code previously asserted if a prefix was multiple letters, but didn't start with s, x, or z. Replace the assert with an explicit check and sort the multi-letter extension after the known multi-letter prefixes.
@llvm/pr-subscribers-llvm-support Author: Craig Topper (topperc) ChangesThe sorting code previously asserted if a prefix was multiple letters, but didn't start with s, x, or z. Replace the assert with an explicit check and sort the multi-letter extension after the known multi-letter prefixes. Full diff: https://github.com/llvm/llvm-project/pull/91398.diff 2 Files Affected:
diff --git a/llvm/lib/Support/RISCVISAUtils.cpp b/llvm/lib/Support/RISCVISAUtils.cpp
index 46efe93695074..d6b002e66e7ab 100644
--- a/llvm/lib/Support/RISCVISAUtils.cpp
+++ b/llvm/lib/Support/RISCVISAUtils.cpp
@@ -24,13 +24,15 @@ using namespace llvm;
// -Multi-letter extensions starting with 's' in alphabetical order.
// -(TODO) Multi-letter extensions starting with 'zxm' in alphabetical order.
// -X extensions in alphabetical order.
+// -Unknown multi-letter extensions in alphabetical order.
// These flags are used to indicate the category. The first 6 bits store the
// single letter extension rank for single letter and multi-letter extensions
// starting with 'z'.
enum RankFlags {
RF_Z_EXTENSION = 1 << 6,
- RF_S_EXTENSION = 1 << 7,
- RF_X_EXTENSION = 1 << 8,
+ RF_S_EXTENSION = 2 << 6,
+ RF_X_EXTENSION = 3 << 6,
+ RF_UNKNOWN_MULTILETTER_EXTENSION = 4 << 6,
};
// Get the rank for single-letter extension, lower value meaning higher
@@ -68,8 +70,9 @@ static unsigned getExtensionRank(const std::string &ExtName) {
case 'x':
return RF_X_EXTENSION;
default:
- assert(ExtName.size() == 1);
- return singleLetterExtensionRank(ExtName[0]);
+ if (ExtName.size() == 1)
+ return singleLetterExtensionRank(ExtName[0]);
+ return RF_UNKNOWN_MULTILETTER_EXTENSION;
}
}
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 83b52d0527c3a..a4296c691f887 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -142,6 +142,14 @@ TEST(ParseNormalizedArchString, UpdatesFLenMinVLenMaxELen) {
EXPECT_EQ(Info.getMaxELenFp(), 64U);
}
+TEST(ParseNormalizedArchString, AcceptsUnknownMultiletter) {
+ auto MaybeISAInfo = RISCVISAInfo::parseNormalizedArchString(
+ "rv64i2p0_f2p0_d2p0_zicsr2p0_ykk1p0");
+ ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
+ RISCVISAInfo &Info = **MaybeISAInfo;
+ EXPECT_EQ(Info.toString(), "rv64i2p0_f2p0_d2p0_zicsr2p0_ykk1p0");
+}
+
TEST(ParseArchString, RejectsInvalidChars) {
for (StringRef Input : {"RV32", "rV64", "rv32i2P0", "rv64i2p0_A2p0"}) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
|
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesThe sorting code previously asserted if a prefix was multiple letters, but didn't start with s, x, or z. Replace the assert with an explicit check and sort the multi-letter extension after the known multi-letter prefixes. Full diff: https://github.com/llvm/llvm-project/pull/91398.diff 2 Files Affected:
diff --git a/llvm/lib/Support/RISCVISAUtils.cpp b/llvm/lib/Support/RISCVISAUtils.cpp
index 46efe93695074..d6b002e66e7ab 100644
--- a/llvm/lib/Support/RISCVISAUtils.cpp
+++ b/llvm/lib/Support/RISCVISAUtils.cpp
@@ -24,13 +24,15 @@ using namespace llvm;
// -Multi-letter extensions starting with 's' in alphabetical order.
// -(TODO) Multi-letter extensions starting with 'zxm' in alphabetical order.
// -X extensions in alphabetical order.
+// -Unknown multi-letter extensions in alphabetical order.
// These flags are used to indicate the category. The first 6 bits store the
// single letter extension rank for single letter and multi-letter extensions
// starting with 'z'.
enum RankFlags {
RF_Z_EXTENSION = 1 << 6,
- RF_S_EXTENSION = 1 << 7,
- RF_X_EXTENSION = 1 << 8,
+ RF_S_EXTENSION = 2 << 6,
+ RF_X_EXTENSION = 3 << 6,
+ RF_UNKNOWN_MULTILETTER_EXTENSION = 4 << 6,
};
// Get the rank for single-letter extension, lower value meaning higher
@@ -68,8 +70,9 @@ static unsigned getExtensionRank(const std::string &ExtName) {
case 'x':
return RF_X_EXTENSION;
default:
- assert(ExtName.size() == 1);
- return singleLetterExtensionRank(ExtName[0]);
+ if (ExtName.size() == 1)
+ return singleLetterExtensionRank(ExtName[0]);
+ return RF_UNKNOWN_MULTILETTER_EXTENSION;
}
}
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 83b52d0527c3a..a4296c691f887 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -142,6 +142,14 @@ TEST(ParseNormalizedArchString, UpdatesFLenMinVLenMaxELen) {
EXPECT_EQ(Info.getMaxELenFp(), 64U);
}
+TEST(ParseNormalizedArchString, AcceptsUnknownMultiletter) {
+ auto MaybeISAInfo = RISCVISAInfo::parseNormalizedArchString(
+ "rv64i2p0_f2p0_d2p0_zicsr2p0_ykk1p0");
+ ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
+ RISCVISAInfo &Info = **MaybeISAInfo;
+ EXPECT_EQ(Info.toString(), "rv64i2p0_f2p0_d2p0_zicsr2p0_ykk1p0");
+}
+
TEST(ParseArchString, RejectsInvalidChars) {
for (StringRef Input : {"RV32", "rV64", "rv32i2P0", "rv64i2p0_A2p0"}) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
|
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.
The sorting code previously asserted if a prefix was multiple letters, but didn't start with s, x, or z.
Replace the assert with an explicit check and sort the multi-letter extension after the known multi-letter prefixes.