diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index 96590745b2ebcfa..c553e330a878b2f 100644 --- a/llvm/lib/TargetParser/RISCVISAInfo.cpp +++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp @@ -500,24 +500,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) { return std::move(ISAInfo); } -static Error splitExtsByUnderscore(StringRef Exts, - std::vector &SplitExts) { - SmallVector Split; - if (Exts.empty()) - return Error::success(); - - Exts.split(Split, "_"); - - for (auto Ext : Split) { - if (Ext.empty()) - return createStringError(errc::invalid_argument, - "extension name missing after separator '_'"); - - SplitExts.push_back(Ext.str()); - } - return Error::success(); -} - static Error processMultiLetterExtension( StringRef RawExt, MapVector SplitExts; - if (auto E = splitExtsByUnderscore(Exts, SplitExts)) - return std::move(E); + SmallVector SplitExts; + // Only split if the string is not empty. Otherwise the split will push an + // empty string into the vector. + if (!Exts.empty()) + Exts.split(SplitExts, '_'); + + for (auto Ext : SplitExts) { + if (Ext.empty()) + return createStringError(errc::invalid_argument, + "extension name missing after separator '_'"); - for (auto &Ext : SplitExts) { - StringRef CurrExt = Ext; - while (!CurrExt.empty()) { - if (RISCVISAUtils::AllStdExts.contains(CurrExt.front())) { + do { + if (RISCVISAUtils::AllStdExts.contains(Ext.front())) { if (auto E = processSingleLetterExtension( - CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension, + Ext, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) return std::move(E); - } else if (CurrExt.front() == 'z' || CurrExt.front() == 's' || - CurrExt.front() == 'x') { + } else if (Ext.front() == 'z' || Ext.front() == 's' || + Ext.front() == 'x') { // Handle other types of extensions other than the standard // general purpose and standard user-level extensions. // Parse the ISA string containing non-standard user-level @@ -737,7 +724,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // version number (major, minor) and are separated by a single // underscore '_'. We do not enforce a canonical order for them. if (auto E = processMultiLetterExtension( - CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension, + Ext, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) return std::move(E); // Multi-letter extension must be seperate following extension with @@ -747,9 +734,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // FIXME: Could it be ignored by IgnoreUnknown? return createStringError(errc::invalid_argument, "invalid standard user-level extension '" + - Twine(CurrExt.front()) + "'"); + Twine(Ext.front()) + "'"); } - } + } while (!Ext.empty()); } // Check all Extensions are supported.