Skip to content

Commit

Permalink
[X86]: Correctly sign-extend 16-bit immediate in CALL instruction.
Browse files Browse the repository at this point in the history
Patch by Matthew Barney. Thanks!

Differential Revision: http://reviews.llvm.org/D9514

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240795 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
snuglas committed Jun 26, 2015
1 parent 064274d commit cd39f3c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Target/X86/Disassembler/X86Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/MC/Disassembler/X86/x86-16.txt
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,5 @@
# CHECK: lretl
0x66 0xcb

# CHECK: callw -1
0xe8 0xff 0xff
3 changes: 3 additions & 0 deletions test/MC/Disassembler/X86/x86-32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
# CHECK: calll -1234
0xe8 0x2e 0xfb 0xff 0xff

# CHECK: callw -1
0x66 0xe8 0xff 0xff

# CHECK: lfence
0x0f 0xae 0xe8

Expand Down
6 changes: 6 additions & 0 deletions test/MC/Disassembler/X86/x86-64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cd39f3c

Please sign in to comment.