From eabf1d367f661bda1ab1a075e5382769e9cfefcf Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Wed, 31 May 2023 20:24:03 -0700 Subject: [PATCH] [RISCV] check pointer before dereference Encountered ASAN crash and found it dereference without check pointer. Reviewed By: kito-cheng, eklepilkina Differential Revision: https://reviews.llvm.org/D151716 --- llvm/lib/Support/RISCVISAInfo.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp index c5b4284..4e4a5c0 100644 --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -699,9 +699,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, auto StdExtsItr = StdExts.begin(); auto StdExtsEnd = StdExts.end(); - auto GoToNextExt = [](StringRef::iterator &I, unsigned ConsumeLength) { + auto GoToNextExt = [](StringRef::iterator &I, unsigned ConsumeLength, + StringRef::iterator E) { I += 1 + ConsumeLength; - if (*I == '_') + if (I != E && *I == '_') ++I; }; for (auto I = Exts.begin(), E = Exts.end(); I != E;) { @@ -737,7 +738,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) { if (IgnoreUnknown) { consumeError(std::move(E)); - GoToNextExt(I, ConsumeLength); + GoToNextExt(I, ConsumeLength, Exts.end()); continue; } return std::move(E); @@ -747,7 +748,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // Currently LLVM supports only "mafdcvh". if (!isSupportedExtension(StringRef(&C, 1))) { if (IgnoreUnknown) { - GoToNextExt(I, ConsumeLength); + GoToNextExt(I, ConsumeLength, Exts.end()); continue; } return createStringError(errc::invalid_argument, @@ -758,7 +759,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // Consume full extension name and version, including any optional '_' // between this extension and the next - GoToNextExt(I, ConsumeLength); + GoToNextExt(I, ConsumeLength, Exts.end()); } // Handle other types of extensions other than the standard -- 2.7.4