From c9b4cfd4e51b93f789024e509a1a0d744e3556e2 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 1 Nov 2024 19:54:19 +0800 Subject: [PATCH] MC: Make POP imply pointer-size operands, as with PUSH On x86-32 the word PUSH (50+rd) and POP (58+rd) instructions assume only 32-bit operands, and on x86-64 they assume only 64-bit operands; in neither case should the absence of an operand size be ambiguous. Those special case were added in f6fb78089060818b4352b540abc44da4f62b95ef and lack of POP seemed an oversight. This closes https://github.com/llvm/llvm-project/issues/114531. Signed-off-by: LIU Hao --- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 2 +- llvm/test/MC/X86/intel-syntax-ambiguous.s | 1 + llvm/test/MC/X86/intel-syntax-ptr-sized.s | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index ae30d4dfc70f5..5a0d98da4146e 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -4495,7 +4495,7 @@ bool X86AsmParser::matchAndEmitIntelInstruction( // compatible with gas. StringRef Mnemonic = (static_cast(*Operands[0])).getToken(); if (UnsizedMemOp) { - static const char *const PtrSizedInstrs[] = {"call", "jmp", "push"}; + static const char *const PtrSizedInstrs[] = {"call", "jmp", "push", "pop"}; for (const char *Instr : PtrSizedInstrs) { if (Mnemonic == Instr) { UnsizedMemOp->Mem.Size = getPointerWidth(); diff --git a/llvm/test/MC/X86/intel-syntax-ambiguous.s b/llvm/test/MC/X86/intel-syntax-ambiguous.s index e90cca820043b..ea38feefe2459 100644 --- a/llvm/test/MC/X86/intel-syntax-ambiguous.s +++ b/llvm/test/MC/X86/intel-syntax-ambiguous.s @@ -30,6 +30,7 @@ sub [eax], 1 // gas assumes these instructions are pointer-sized by default, and we follow // suit. push [eax] +pop [eax] call [eax] jmp [eax] // CHECK-NOT: error: diff --git a/llvm/test/MC/X86/intel-syntax-ptr-sized.s b/llvm/test/MC/X86/intel-syntax-ptr-sized.s index a360557eaa6a4..0393d8c84dfba 100644 --- a/llvm/test/MC/X86/intel-syntax-ptr-sized.s +++ b/llvm/test/MC/X86/intel-syntax-ptr-sized.s @@ -6,6 +6,8 @@ push [eax] // CHECK: pushl (%eax) call [eax] // CHECK: calll *(%eax) +pop [eax] +// CHECK: popl (%eax) jmp [eax] // CHECK: jmpl *(%eax) @@ -25,6 +27,8 @@ push [eax] // CHECK: pushw (%eax) call [eax] // CHECK: callw *(%eax) +pop [eax] +// CHECK: popw (%eax) jmp [eax] // CHECK: jmpw *(%eax)