[AArch64] Check the size of the vector before accessing its elements.
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 13 Oct 2015 18:55:34 +0000 (18:55 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 13 Oct 2015 18:55:34 +0000 (18:55 +0000)
This fixes an assert in AArch64AsmParser::MatchAndEmitInstruction.

rdar://problem/23081753

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250207 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
test/MC/AArch64/arm64-diags.s

index e3af43d1948c66975da6f6accc723d29858fe147..3980d3698c12ad17ca4dd6ffd5801e25806e4bb5 100644 (file)
@@ -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;
index e368d50f3b26c01f63d8c13b0eb7e94349c9776c..3510193a71ffeaeae06f9808e2888ca0e5beb92c 100644 (file)
@@ -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:   ^