summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Katzman <dougk@google.com>2015-06-26 16:58:59 +0000
committerDouglas Katzman <dougk@google.com>2015-06-26 16:58:59 +0000
commit289ec857d22c784af27b9b3d3c6b9c711e36284a (patch)
tree61fa1324214029bf739938f0b62105fb69f21027
parent1213dbf1fd97619ef1fbe8397cf71adcb8743f43 (diff)
downloadbcm5719-llvm-289ec857d22c784af27b9b3d3c6b9c711e36284a.tar.gz
bcm5719-llvm-289ec857d22c784af27b9b3d3c6b9c711e36284a.zip
[X86]: Correctly sign-extend 16-bit immediate in CALL instruction.
Patch by Matthew Barney. Thanks! Differential Revision: http://reviews.llvm.org/D9514 llvm-svn: 240795
-rw-r--r--llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp8
-rw-r--r--llvm/test/MC/Disassembler/X86/x86-16.txt2
-rw-r--r--llvm/test/MC/Disassembler/X86/x86-32.txt3
-rw-r--r--llvm/test/MC/Disassembler/X86/x86-64.txt6
4 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
index 6e99c37c2bc..cfc3ee2fb08 100644
--- a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
+++ b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
@@ -551,9 +551,15 @@ static void translateImmediate(MCInst &mcInst, uint64_t immediate,
case TYPE_REL8:
isBranch = true;
pcrel = insn.startLocation + insn.immediateOffset + insn.immediateSize;
- if(immediate & 0x80)
+ 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;
diff --git a/llvm/test/MC/Disassembler/X86/x86-16.txt b/llvm/test/MC/Disassembler/X86/x86-16.txt
index c6844cd3cef..021cb237181 100644
--- a/llvm/test/MC/Disassembler/X86/x86-16.txt
+++ b/llvm/test/MC/Disassembler/X86/x86-16.txt
@@ -786,3 +786,5 @@
# CHECK: lretl
0x66 0xcb
+# CHECK: callw -1
+0xe8 0xff 0xff
diff --git a/llvm/test/MC/Disassembler/X86/x86-32.txt b/llvm/test/MC/Disassembler/X86/x86-32.txt
index 830b8306630..c51e0a3dc37 100644
--- a/llvm/test/MC/Disassembler/X86/x86-32.txt
+++ b/llvm/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
diff --git a/llvm/test/MC/Disassembler/X86/x86-64.txt b/llvm/test/MC/Disassembler/X86/x86-64.txt
index 5699f40d2d3..065b2a57c84 100644
--- a/llvm/test/MC/Disassembler/X86/x86-64.txt
+++ b/llvm/test/MC/Disassembler/X86/x86-64.txt
@@ -339,3 +339,9 @@
# CHECK: vaddps (%rdx,%xmm1), %zmm20, %zmm15
# FIXME: vaddps (%rdx,%rcx), %zmm20, %zmm15
0x62 0x71 0x5c 0x40 0x58 0x3c 0x0a
+
+# CHECK: callq 32767
+0xe8 0xff 0x7f 0x00 0x00
+
+# CHECK: callq -32769
+0xe8 0xff 0x7f 0xff 0xff
OpenPOWER on IntegriCloud