From 3dce29b8e9002d1295918fd56de8b263f89c2f5e Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 26 Mar 2019 03:12:41 +0000 Subject: [PATCH] X86AsmParser: Do not process a non-existent token This error can only happen if an unfinished operation is at Eof. Patch by Brandon Jones Differential Revision: https://reviews.llvm.org/D57379 llvm-svn: 356972 --- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 5 +++++ llvm/test/MC/AsmParser/unfinished-op.s | 4 ++++ llvm/test/MC/X86/x86_operands.s | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 llvm/test/MC/AsmParser/unfinished-op.s diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 75db48928c9c0..273edadb06151 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -2992,6 +2992,11 @@ bool X86AsmParser::MatchAndEmitATTInstruction(SMLoc IDLoc, unsigned &Opcode, case Match_MnemonicFail: break; } + if (Op.getToken().empty()) { + Error(IDLoc, "instruction must have size higher than 0", EmptyRange, + MatchingInlineAsm); + return true; + } // FIXME: Ideally, we would only attempt suffix matches for things which are // valid prefixes, and we could just infer the right unambiguous diff --git a/llvm/test/MC/AsmParser/unfinished-op.s b/llvm/test/MC/AsmParser/unfinished-op.s new file mode 100644 index 0000000000000..079e036b160df --- /dev/null +++ b/llvm/test/MC/AsmParser/unfinished-op.s @@ -0,0 +1,4 @@ +# RUN: not llvm-mc -triple i386-unknown-unknown %s 2>&1 > /dev/null| FileCheck %s --check-prefix=CHECK-ERROR + +#CHECK-ERROR: error: instruction must have size higher than 0 + .byte 64;"" diff --git a/llvm/test/MC/X86/x86_operands.s b/llvm/test/MC/X86/x86_operands.s index 3aa1b8d7fb8fd..70b11faf003e3 100644 --- a/llvm/test/MC/X86/x86_operands.s +++ b/llvm/test/MC/X86/x86_operands.s @@ -9,7 +9,7 @@ addl $a, %eax # CHECK: addl $3, %eax addl $1 + 2, %eax - + # Disambiguation # CHECK: addl $1, 8 @@ -26,7 +26,7 @@ addl $1, (%eax) # CHECK: addl $1, 8(,%eax) addl $1, (4+4)(,%eax) - + # Indirect Memory Operands # CHECK: addl $1, 1(%eax) addl $1, 1(%eax)