OSDN Git Service

[X86] Don't allow gather/scatter to disassembler if memory operand does not use a...
authorCraig Topper <craig.topper@intel.com>
Sun, 22 Oct 2017 04:32:30 +0000 (04:32 +0000)
committerCraig Topper <craig.topper@intel.com>
Sun, 22 Oct 2017 04:32:30 +0000 (04:32 +0000)
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
test/MC/Disassembler/X86/gather-novsib.txt [new file with mode: 0644]

index 6884f2a..e781c98 100644 (file)
@@ -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 (file)
index 0000000..d14abc1
--- /dev/null
@@ -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