Skip to content

Commit dd6ec68

Browse files
committed
[x86][MC] Fix data32 push.
1 parent eef79c8 commit dd6ec68

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,14 +4538,26 @@ bool X86AsmParser::matchAndEmitIntelInstruction(
45384538
if (X86Op->isImm()) {
45394539
// If it's not a constant fall through and let remainder take care of it.
45404540
const auto *CE = dyn_cast<MCConstantExpr>(X86Op->getImm());
4541-
unsigned Size = getPointerWidth();
4541+
// Determine the size. Prioritize the ForcedDataPrefix flag if it was set
4542+
// by a 'data32' prefix. Otherwise, fall back to the pointer width of the
4543+
// current mode.
4544+
unsigned Size = (ForcedDataPrefix == X86::Is32Bit) ? 32
4545+
: (ForcedDataPrefix == X86::Is16Bit) ? 16
4546+
: getPointerWidth();
4547+
ForcedDataPrefix = 0;
45424548
if (CE &&
45434549
(isIntN(Size, CE->getValue()) || isUIntN(Size, CE->getValue()))) {
45444550
SmallString<16> Tmp;
45454551
Tmp += Base;
4546-
Tmp += (is64BitMode())
4547-
? "q"
4548-
: (is32BitMode()) ? "l" : (is16BitMode()) ? "w" : " ";
4552+
// Append the suffix corresponding to the determined size.
4553+
if (Size == 64)
4554+
Tmp += "q";
4555+
else if (Size == 32)
4556+
Tmp += "l";
4557+
else if (Size == 16)
4558+
Tmp += "w";
4559+
else
4560+
Tmp += " ";
45494561
Op.setTokenValue(Tmp);
45504562
// Do match in ATT mode to allow explicit suffix usage.
45514563
Match.push_back(MatchInstruction(Operands, Inst, ErrorInfo,

llvm/test/MC/X86/x86-16-intel.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: llvm-mc -triple i386-unknown-unknown-code16 --x86-asm-syntax=intel --show-encoding %s | FileCheck %s
2+
3+
// CHECK: pushl $8
4+
// CHECK: encoding: [0x66,0x6a,0x08]
5+
data32 push 8
6+
7+
// CHECK: pushw $8
8+
// CHECK: encoding: [0x6a,0x08]
9+
push 8
10+
11+
// CHECK: lretl
12+
// CHECK: encoding: [0x66,0xcb]
13+
data32 retf

llvm/test/MC/X86/x86-16.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,3 +1060,15 @@ xresldtrk
10601060
// CHECK: encoding: [0x66,0x8b,0x1e,A,A]
10611061
// CHECK: fixup A - offset: 3, value: nearer, kind: FK_Data_2
10621062
movl nearer, %ebx
1063+
1064+
// CHECK: pushl $8
1065+
// CHECK: encoding: [0x66,0x6a,0x08]
1066+
data32 push $8
1067+
1068+
// CHECK: pushl $8
1069+
// CHECK: encoding: [0x66,0x6a,0x08]
1070+
pushl $8
1071+
1072+
// CHECK: pushw $8
1073+
// CHECK: encoding: [0x6a,0x08]
1074+
push $8

0 commit comments

Comments
 (0)