Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix push word behavior in x86 #578

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class X86AsmParser : public MCTargetAsmParser {
// PUSH i8 --> PUSH32i8
// PUSH word i8 --> PUSH16i8
bool push32;
bool push16;
SMLoc consumeToken() {
MCAsmParser &Parser = getParser();
SMLoc Result = Parser.getTok().getLoc();
Expand Down Expand Up @@ -2031,10 +2032,12 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseIntelOperand(std::string Mnem, un
Start, End, 0);
}

// dirty hacky way to deal with PUSH 0xd/PUSH word 0xd
// dirty hacky way to deal with PUSH 0xd/PUSH word 0xd/PUSH word 0x1122
if (Mnem == "push") {
if (Size == 0)
push32 = true;
if (Size == 16)
push16 = true;
}

const MCExpr *ImmExpr = MCConstantExpr::create(Imm, getContext());
Expand Down Expand Up @@ -2609,6 +2612,7 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
Name == "rex64" || Name == "data16";

push32 = false;
push16 = false;

// This does the actual operand parsing. Don't parse any more if we have a
// prefix juxtaposed with an operation like "lock incl 4(%rax)", because we
Expand Down Expand Up @@ -3216,8 +3220,15 @@ bool X86AsmParser::MatchAndEmitIntelInstruction(SMLoc IDLoc, unsigned &Opcode,
ErrorInfoMissingFeature = ErrorInfo;
}


if (push32 && Inst.getOpcode() == X86::PUSH16i8)
Inst.setOpcode(X86::PUSH32i8);

if (push16 && (Inst.getOpcode() == X86::PUSH64i8))
Inst.setOpcode(X86::PUSH16i8);

if (push16 && (Inst.getOpcode() == X86::PUSH64i32 || Inst.getOpcode() == X86::PUSHi32) )
Inst.setOpcode(X86::PUSHi16);

// Restore the size of the unsized memory operand if we modified it.
if (UnsizedMemOp)
Expand Down