From 7447532596ad328831527e78d7e97c67954def21 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 22 Oct 2017 04:32:30 +0000 Subject: [PATCH] [X86] Don't allow gather/scatter to disassembler if memory operand does not use a SIB byte. Fixes PR34998. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316282 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp | 4 ++++ test/MC/Disassembler/X86/gather-novsib.txt | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 test/MC/Disassembler/X86/gather-novsib.txt diff --git a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp index 6884f2a80de..e781c98b0bc 100644 --- a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp +++ b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp @@ -1723,6 +1723,10 @@ static int readOperands(struct InternalInstruction* insn) { if (readModRM(insn)) return -1; + // Reject if SIB wasn't used. + if (insn->eaBase != EA_BASE_sib && insn->eaBase != EA_BASE_sib64) + return -1; + // If sibIndex was set to SIB_INDEX_NONE, index offset is 4. if (insn->sibIndex == SIB_INDEX_NONE) insn->sibIndex = (SIBIndex)4; diff --git a/test/MC/Disassembler/X86/gather-novsib.txt b/test/MC/Disassembler/X86/gather-novsib.txt new file mode 100644 index 00000000000..d14abc12807 --- /dev/null +++ b/test/MC/Disassembler/X86/gather-novsib.txt @@ -0,0 +1,4 @@ +# RUN: llvm-mc --disassemble %s -triple=x86_64-apple-darwin9 2>&1 | grep "invalid instruction encoding" + +// This corresponds to a gather, but doesn't use a SIB byte. +0xc4,0xe2,0xe9,0x92,0x08 -- 2.40.0