From f215a2dba1dd257477c52946863c914454369ce4 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 13 Oct 2015 18:55:34 +0000 Subject: [PATCH] [AArch64] Check the size of the vector before accessing its elements. This fixes an assert in AArch64AsmParser::MatchAndEmitInstruction. rdar://problem/23081753 llvm-svn: 250207 --- lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 2 +- test/MC/AArch64/arm64-diags.s | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index e3af43d1948..3980d3698c1 100644 --- a/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -3967,7 +3967,7 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, // suffix token operand. The short-form match failure is probably more // relevant: use it instead. if (MatchResult == Match_InvalidOperand && ErrorInfo == 1 && - ((AArch64Operand &)*Operands[1]).isToken() && + Operands.size() > 1 && ((AArch64Operand &)*Operands[1]).isToken() && ((AArch64Operand &)*Operands[1]).isTokenSuffix()) { MatchResult = ShortFormNEONMatchResult; ErrorInfo = ShortFormNEONErrorInfo; diff --git a/test/MC/AArch64/arm64-diags.s b/test/MC/AArch64/arm64-diags.s index e368d50f3b2..3510193a71f 100644 --- a/test/MC/AArch64/arm64-diags.s +++ b/test/MC/AArch64/arm64-diags.s @@ -480,3 +480,12 @@ tlbi vale3 ; CHECK-ERRORS: error: invalid operand for instruction ; CHECK-ERRORS: b.eq 0, 0 ; CHECK-ERRORS: ^ + +; Check that we give the proper "too few operands" diagnostic instead of +; asserting. + + ldr + +; CHECK-ERRORS: error: too few operands for instruction +; CHECK-ERRORS: ldr +; CHECK-ERRORS: ^