diff options
author | Marina Yatsina <marina.yatsina@intel.com> | 2015-12-03 12:17:03 +0000 |
---|---|---|
committer | Marina Yatsina <marina.yatsina@intel.com> | 2015-12-03 12:17:03 +0000 |
commit | 4b1aea0802c233a2dbfd9c3657b0225017b3edb4 (patch) | |
tree | f62e76ff8a93b9cdf2c417635fbad5320664f9a4 | |
parent | fceb4e7cb4e538f329464a2d2b50263b61bbb784 (diff) | |
download | bcm5719-llvm-4b1aea0802c233a2dbfd9c3657b0225017b3edb4.tar.gz bcm5719-llvm-4b1aea0802c233a2dbfd9c3657b0225017b3edb4.zip |
[X86] MS inline asm: produce error when encountering "<type> ptr <reg name>"
Currently "<type> ptr <reg name>" treated as <reg name> in MS inline asm, ignoring the "<type> ptr" completely and possibly ignoring the intention of the user.
Fixed llvm to produce an error when encountering "<type> ptr <reg name>" operands.
For example: andpd xmm1,xmmword ptr xmm1 --> andpd xmm1, xmm1
though andpd has 2 possible matching formats - andpd xmm, xmm/m128
Patch by: ziv.izhar@intel.com
Differential Revision: http://reviews.llvm.org/D14607
llvm-svn: 254607
-rw-r--r-- | llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 13 | ||||
-rw-r--r-- | llvm/test/MC/X86/intel-syntax-ambiguous.s | 12 |
2 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 7089c1f7592..d53ab71f3d5 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1693,12 +1693,14 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseIntelOperand() { return ParseIntelOperator(IOK_TYPE); } + bool PtrInOperand = false; unsigned Size = getIntelMemOperandSize(Tok.getString()); if (Size) { Parser.Lex(); // Eat operand size (e.g., byte, word). if (Tok.getString() != "PTR" && Tok.getString() != "ptr") return ErrorOperand(Tok.getLoc(), "Expected 'PTR' or 'ptr' token!"); Parser.Lex(); // Eat ptr. + PtrInOperand = true; } Start = Tok.getLoc(); @@ -1754,9 +1756,16 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseIntelOperand() { if (!ParseRegister(RegNo, Start, End)) { // If this is a segment register followed by a ':', then this is the start // of a segment override, otherwise this is a normal register reference. - if (getLexer().isNot(AsmToken::Colon)) + // In case it is a normal register and there is ptr in the operand this + // is an error + if (getLexer().isNot(AsmToken::Colon)){ + if (PtrInOperand){ + return ErrorOperand(Start, "expected memory operand after " + "'ptr', found register operand instead"); + } return X86Operand::CreateReg(RegNo, Start, End); - + } + return ParseIntelSegmentOverride(/*SegReg=*/RegNo, Start, Size); } diff --git a/llvm/test/MC/X86/intel-syntax-ambiguous.s b/llvm/test/MC/X86/intel-syntax-ambiguous.s index fe1fe502390..e90cca82004 100644 --- a/llvm/test/MC/X86/intel-syntax-ambiguous.s +++ b/llvm/test/MC/X86/intel-syntax-ambiguous.s @@ -45,3 +45,15 @@ add rax, 3 fadd "?half@?0??bar@@YAXXZ@4NA" // CHECK: error: ambiguous operand size for instruction 'fadd' + +// Instruction line with PTR inside check that they don't accept register as memory. + +// CHECK: error: expected memory operand after 'ptr', found register operand instead +// CHECK: andps xmm1, xmmword ptr xmm1 +andps xmm1, xmmword ptr xmm1 +// CHECK: error: expected memory operand after 'ptr', found register operand instead +// CHECK: andps xmmword ptr xmm1, xmm1 +andps xmmword ptr xmm1, xmm1 +// CHECK: error: expected memory operand after 'ptr', found register operand instead +// CHECK: mov dword ptr eax, ebx +mov dword ptr eax, ebx |