[PATCH] [llvm-mc] Fix bad sign extension on callw immediate

Matthew Barney m4b.github.io at gmail.com
Fri May 8 08:46:07 PDT 2015


[llvm-mc] final commit with unit tests and callw fix for 32-bit mode


http://reviews.llvm.org/D9514

Files:
  lib/Target/X86/Disassembler/X86Disassembler.cpp
  test/MC/Disassembler/X86/x86-16.txt
  test/MC/Disassembler/X86/x86-32.txt
  test/MC/Disassembler/X86/x86-64.txt

Index: lib/Target/X86/Disassembler/X86Disassembler.cpp
===================================================================
--- lib/Target/X86/Disassembler/X86Disassembler.cpp
+++ lib/Target/X86/Disassembler/X86Disassembler.cpp
@@ -553,6 +553,12 @@
     if(immediate & 0x80)
       immediate |= ~(0xffull);
     break;
+  case TYPE_REL16:
+    isBranch = true;
+    pcrel = insn.startLocation + insn.immediateOffset + insn.immediateSize;
+    if(immediate & 0x8000)
+      immediate |= ~(0xffffull);
+    break;
   case TYPE_REL32:
   case TYPE_REL64:
     isBranch = true;
Index: test/MC/Disassembler/X86/x86-16.txt
===================================================================
--- test/MC/Disassembler/X86/x86-16.txt
+++ test/MC/Disassembler/X86/x86-16.txt
@@ -786,3 +786,5 @@
 # CHECK: lretl
 0x66 0xcb
 
+# CHECK: callw	-1
+0xe8 0xff 0xff
Index: test/MC/Disassembler/X86/x86-32.txt
===================================================================
--- test/MC/Disassembler/X86/x86-32.txt
+++ test/MC/Disassembler/X86/x86-32.txt
@@ -54,6 +54,9 @@
 # CHECK: calll	-1234
 0xe8 0x2e 0xfb 0xff 0xff
 
+# CHECK: callw	-1
+0x66 0xe8 0xff 0xff
+
 # CHECK: lfence
 0x0f 0xae 0xe8
 
Index: test/MC/Disassembler/X86/x86-64.txt
===================================================================
--- test/MC/Disassembler/X86/x86-64.txt
+++ test/MC/Disassembler/X86/x86-64.txt
@@ -301,3 +301,9 @@
 
 # CHECK: movq %rax, 1515870810
 0x67, 0x48 0xa3 0x5a 0x5a 0x5a 0x5a
+
+# CHECK: callq 32767
+0xe8 0xff 0x7f 0x00 0x00
+
+# CHECK: callq -32769
+0xe8 0xff 0x7f 0xff 0xff

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9514.25336.patch
Type: text/x-patch
Size: 1567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150508/07748163/attachment.bin>


More information about the llvm-commits mailing list