[RISCV] Fix gaps in IgnoreUnknown=true for RISCVISAInfo::parseArchString
authorAlex Bradbury <asb@igalia.com>
Mon, 13 Mar 2023 10:53:05 +0000 (10:53 +0000)
committerAlex Bradbury <asb@igalia.com>
Mon, 13 Mar 2023 10:53:05 +0000 (10:53 +0000)
Prior to this patch, unrecognised z/s/sx/x prefixed extensions were not
ignored when IgnoreUnknown=true.

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

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

index 8a12744..50bce78 100644 (file)
@@ -804,6 +804,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
                                  Desc.str().c_str(), Name.str().c_str());
       }
 
+      if (IgnoreUnknown && !isSupportedExtension(Ext))
+        continue;
+
       ISAInfo->addExtension(Name, Major, Minor);
       // Extension format is correct, keep parsing the extensions.
       // TODO: Save Type, Name, Major, Minor to avoid parsing them later.
index 2dce4df..0e167ca 100644 (file)
@@ -230,7 +230,8 @@ TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
 }
 
 TEST(ParseArchString, IgnoresUnrecognizedExtensionNamesWithIgnoreUnknown) {
-  for (StringRef Input : {"rv32ib"}) {
+  for (StringRef Input : {"rv32ib", "rv32i_zmadeup", "rv64i_smadeup",
+                          "rv32i_sxmadeup", "rv64i_xmadeup"}) {
     auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true, false, true);
     ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
     RISCVISAInfo &Info = **MaybeISAInfo;
@@ -238,13 +239,6 @@ TEST(ParseArchString, IgnoresUnrecognizedExtensionNamesWithIgnoreUnknown) {
     EXPECT_EQ(Exts.size(), 1UL);
     EXPECT_TRUE(Exts.at("i") == (RISCVExtensionInfo{"i", 2, 0}));
   }
-  // FIXME: These unrecognized extensions should be ignored just as in the
-  // case above. The below captures the current (incorrect) behaviour.
-  for (StringRef Input :
-       {"rv32i_zmadeup", "rv64i_smadeup", "rv32i_sxmadeup", "rv64i_xmadeup"}) {
-    auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true, false, true);
-    EXPECT_THAT_EXPECTED(MaybeISAInfo, Failed());
-  }
 }
 
 TEST(ParseArchString, AcceptsVersionInLongOrShortForm) {