[llvm] e9a03f3 - [RISCV] Reject 'g' with explicit version in parseArchString

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 14 05:47:12 PDT 2023


Author: Alex Bradbury
Date: 2023-03-14T12:46:13Z
New Revision: e9a03f360fa964d90a4c55884ac8ac8a00abc896

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

LOG: [RISCV] Reject 'g' with explicit version in parseArchString

There is no versioning scheme for the 'g' shorthand for imafd (or in
current ISA specs, imafd_zifencei_zicsr). As such, the only sensible
behaviour to me seems to be to reject a version for it.

Differential Revision: https://reviews.llvm.org/D145954

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index 9bd9313350ce..ed91a41c56c0 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -622,6 +622,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
     break;
   case 'g':
     // g = imafd
+    if (Arch.size() > 5 && isdigit(Arch[5]))
+      return createStringError(errc::invalid_argument,
+                               "version not supported for 'g'");
     StdExts = StdExts.drop_front(4);
     break;
   }

diff  --git a/llvm/unittests/Support/RISCVISAInfoTest.cpp b/llvm/unittests/Support/RISCVISAInfoTest.cpp
index 64c557be33fe..ce1db1933ee6 100644
--- a/llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -397,14 +397,11 @@ TEST(ParseArchString, RejectsUnrecognizedVersionForExperimentalExtension) {
       "(this compiler supports 0.2)");
 }
 
-TEST(ParseArchString, AcceptsExtensionVersionForG) {
-  // FIXME: As there is no versioning scheme for G, arguably an error should
-  // be produced.
-  auto MaybeISAInfo = RISCVISAInfo::parseArchString("rv64g9p9", true, false);
-  ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
-  RISCVISAInfo::OrderedExtensionMap Exts = (*MaybeISAInfo)->getExtensions();
-  EXPECT_EQ(Exts.size(), 5UL);
-  EXPECT_TRUE(Exts.at("i") == (RISCVExtensionInfo{"i", 2, 0}));
+TEST(ParseArchString, RejectsExtensionVersionForG) {
+  for (StringRef Input : {"rv32g1c", "rv64g2p0"}) {
+    EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
+              "version not supported for 'g'");
+  }
 }
 
 TEST(ParseArchString, AddsImpliedExtensions) {


        


More information about the llvm-commits mailing list