diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -72,6 +72,18 @@ return Ext.consume_front("experimental-"); } +static size_t findFirstNonVersionCharacter(const StringRef &Ext) { + int Pos = Ext.size() - 1; + while (Pos >= 0 && isDigit(Ext[Pos])) + Pos--; + if (Pos > 0 && Ext[Pos] == 'p' && isDigit(Ext[Pos - 1])) { + Pos--; + while (Pos >= 0 && isDigit(Ext[Pos])) + Pos--; + } + return Pos; +} + void RISCVISAInfo::addExtension(StringRef ExtName, unsigned MajorVersion, unsigned MinorVersion) { RISCVExtensionInfo Ext; @@ -612,7 +624,7 @@ StringRef Type = getExtensionType(Ext); StringRef Desc = getExtensionTypeDesc(Ext); - auto Pos = Ext.find_if(isDigit); + auto Pos = findFirstNonVersionCharacter(Ext) + 1; StringRef Name(Ext.substr(0, Pos)); StringRef Vers(Ext.substr(Pos));