llvm.org GIT mirror llvm / c8f9ada
[X86] Fix intel syntax push parsing bug Change erroneous parsing of push immediate instructions in intel syntax to default to pointer size by rewriting into the ATT style for matching. This fixes PR22028. Reviewers: majnemer, rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25288 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283457 91177308-0d34-0410-b5e6-96231b3b80d8 Nirav Dave 4 years ago
2 changed file(s) with 52 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
27832783 assert(Op.isToken() && "Leading operand should always be a mnemonic!");
27842784 StringRef Mnemonic = Op.getToken();
27852785 SMRange EmptyRange = None;
2786 StringRef Base = Op.getToken();
27862787
27872788 // First, handle aliases that expand to multiple instructions.
27882789 MatchFPUWaitAlias(IDLoc, Op, Operands, Out, MatchingInlineAsm);
28092810 }
28102811 }
28112812
2813 SmallVector Match;
2814 uint64_t ErrorInfoMissingFeature = 0;
2815
2816 // If unsized push has immediate operand we should default the default pointer
2817 // size for the size.
2818 if (Mnemonic == "push" && Operands.size() == 2) {
2819 auto *X86Op = static_cast(Operands[1].get());
2820 if (X86Op->isImm()) {
2821 // If it's not a constant fall through and let remainder take care of it.
2822 const auto *CE = dyn_cast(X86Op->getImm());
2823 unsigned Size = getPointerWidth();
2824 if (CE &&
2825 (isIntN(Size, CE->getValue()) || isUIntN(Size, CE->getValue()))) {
2826 SmallString<16> Tmp;
2827 Tmp += Base;
2828 Tmp += (is64BitMode())
2829 ? "q"
2830 : (is32BitMode()) ? "l" : (is16BitMode()) ? "w" : " ";
2831 Op.setTokenValue(Tmp);
2832 // Do match in ATT mode to allow explicit suffix usage.
2833 Match.push_back(MatchInstruction(Operands, Inst, ErrorInfo,
2834 MatchingInlineAsm,
2835 false /*isParsingIntelSyntax()*/));
2836 Op.setTokenValue(Base);
2837 }
2838 }
2839 }
2840
28122841 // If an unsized memory operand is present, try to match with each memory
28132842 // operand size. In Intel assembly, the size is not part of the instruction
28142843 // mnemonic.
2815 SmallVector Match;
2816 uint64_t ErrorInfoMissingFeature = 0;
28172844 if (UnsizedMemOp && UnsizedMemOp->isMemUnsized()) {
28182845 static const unsigned MopSizes[] = {8, 16, 32, 64, 80, 128, 256, 512};
28192846 for (unsigned Size : MopSizes) {
0 // RUN: llvm-mc -triple i386-unknown-unknown-code16 -show-encoding %s | FileCheck --check-prefix=CHECK16 %s
1 // RUN: llvm-mc -triple i386-unknown-unknown -show-encoding %s | FileCheck --check-prefix=CHECK %s
2 // RUN: llvm-mc -triple i686-unknown-unknown -show-encoding %s | FileCheck --check-prefix=CHECK %s
3
4 .intel_syntax
5
6 push 0
7 push -1
8 push 30
9 push 257
10 push 65536
11
12 //CHECK16: pushw $0 # encoding: [0x6a,0x00]
13 //CHECK16: pushw $-1 # encoding: [0x6a,0xff]
14 //CHECK16: pushw $30 # encoding: [0x6a,0x1e]
15 //CHECK16: pushw $257 # encoding: [0x68,0x01,0x01]
16 //CHECK16: pushl $65536 # encoding: [0x66,0x68,0x00,0x00,0x01,0x00]
17
18 //CHECK: pushl $0 # encoding: [0x6a,0x00]
19 //CHECK: pushl $-1 # encoding: [0x6a,0xff]
20 //CHECK: pushl $30 # encoding: [0x6a,0x1e]
21 //CHECK: pushl $257 # encoding: [0x68,0x01,0x01,0x00,0x00]
22 //CHECK: pushl $65536 # encoding: [0x68,0x00,0x00,0x01,0x00]