[llvm] 5445a35 - [RISCV] Detect empty extension name after parsing MajorVersion in parseNormalizedArchString. (#90790)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 10:08:40 PDT 2024


Author: Craig Topper
Date: 2024-05-02T10:08:35-07:00
New Revision: 5445a35d6ef5e8b6d3aafd78c48167ef22eef0af

URL: https://github.com/llvm/llvm-project/commit/5445a35d6ef5e8b6d3aafd78c48167ef22eef0af
DIFF: https://github.com/llvm/llvm-project/commit/5445a35d6ef5e8b6d3aafd78c48167ef22eef0af.diff

LOG: [RISCV] Detect empty extension name after parsing MajorVersion in parseNormalizedArchString. (#90790)

If the string is just a version, we will end up adding an empty string
as an extension which crashes in the compare function for the std::map.

Added: 
    

Modified: 
    llvm/lib/TargetParser/RISCVISAInfo.cpp
    llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index e4ff4bcfe25a5c..c1d50afee09b08 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -476,6 +476,10 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
       return createStringError(errc::invalid_argument,
                                "extension lacks version in expected format");
 
+    if (VersionStart == 0)
+      return createStringError(errc::invalid_argument,
+                               "missing extension name");
+
     StringRef ExtName = Prefix.slice(0, VersionStart);
     StringRef MajorVersionStr = Prefix.slice(VersionStart, StringRef::npos);
     if (MajorVersionStr.getAsInteger(10, MajorVersion))

diff  --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index facaa75ad912a0..ec886bad4f67f7 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -46,6 +46,14 @@ TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
   }
 }
 
+TEST(ParseNormalizedArchString, OnlyVersion) {
+  for (StringRef Input : {"rv64i2p0_1p0", "rv32i2p0_1p0"}) {
+    EXPECT_EQ(
+        toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
+        "missing extension name");
+  }
+}
+
 TEST(ParseNormalizedArchString, AcceptsValidBaseISAsAndSetsXLen) {
   auto MaybeRV32I = RISCVISAInfo::parseNormalizedArchString("rv32i2p0");
   ASSERT_THAT_EXPECTED(MaybeRV32I, Succeeded());


        


More information about the llvm-commits mailing list