From a81c79be2fb5791ffc535d808dda8480c3ec2298 Mon Sep 17 00:00:00 2001 From: "Andrew V. Tischenko" Date: Mon, 23 Oct 2017 09:36:33 +0000 Subject: [PATCH] Fix for Bug 30718 - Failure to disassemble certain MOV with rex.R. The issue was in illegal segment register index. Differential Revision: https://reviews.llvm.org/D38786 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316319 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp | 4 ++-- test/MC/Disassembler/X86/x86-64.txt | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp index 80acff22f7b..709fc630633 100644 --- a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp +++ b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp @@ -1453,9 +1453,9 @@ static int readModRM(struct InternalInstruction* insn) { case TYPE_MM64: \ return prefix##_MM0 + (index & 0x7); \ case TYPE_SEGMENTREG: \ - if (index > 5) \ + if ((index & 7) > 5) \ *valid = 0; \ - return prefix##_ES + index; \ + return prefix##_ES + (index & 7); \ case TYPE_DEBUGREG: \ return prefix##_DR0 + index; \ case TYPE_CONTROLREG: \ diff --git a/test/MC/Disassembler/X86/x86-64.txt b/test/MC/Disassembler/X86/x86-64.txt index 965d713e824..93026680e2a 100644 --- a/test/MC/Disassembler/X86/x86-64.txt +++ b/test/MC/Disassembler/X86/x86-64.txt @@ -482,6 +482,9 @@ # CHECK: xchgw %di, %ax 0x66 0x3e 0x97 +# CHECK: movq %rdx, %cs +0x4c 0x8e 0xca + # CHECK: movw %bx, %cs:(%rsi,%rbp) 0x2e 0x66 0x89 0x1c 0x2e # CHECK: movl %ebx, %cs:(%esi,%ebp) -- 2.40.0