Summary:
This fixes a crash when invalid -march options like `armv` are provided.
Based on a patch by Will Lovett.
Reviewers: rengolin, samparker, mcrosier
Reviewed By: samparker
Subscribers: aemerson, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D41429
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321166
91177308-0d34-0410-b5e6-
96231b3b80d8
}
unsigned llvm::AArch64::checkArchVersion(StringRef Arch) {
- if (Arch[0] == 'v' && std::isdigit(Arch[1]))
+ if (Arch.size() >= 2 && Arch[0] == 'v' && std::isdigit(Arch[1]))
return (Arch[1] - 48);
return 0;
}
// Only match non-marketing names
if (offset != StringRef::npos) {
// Must start with 'vN'.
- if (A[0] != 'v' || !std::isdigit(A[1]))
+ if (A.size() >= 2 && (A[0] != 'v' || !std::isdigit(A[1])))
return Error;
// Can't have an extra 'eb'.
if (A.find("eb") != StringRef::npos)
"7-S"));
}
+TEST(TargetParserTest, testInvalidARMArch) {
+ auto InvalidArchStrings = {"armv", "armv99", "noarm"};
+ for (const char* InvalidArch : InvalidArchStrings)
+ EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
+}
+
bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
unsigned ArchAttr) {
ARM::ArchKind AK = ARM::parseArch(Arch);