Skip to content

Commit 3bfb365

Browse files
author
Coby Tayree
committedAug 9, 2017
[AsmParser][AVX512]Enhance OpMask/Zero/Merge syntax check rubostness
Adopt a more strict approach regarding what marks should/can appear after a destination register, when operating upon an AVX512 platform. Differential Revision: https://reviews.llvm.org/D35785 llvm-svn: 310467
1 parent 40d0839 commit 3bfb365

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed
 

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -2089,14 +2089,17 @@ bool X86AsmParser::HandleAVX512Operand(OperandVector &Operands,
20892089
// no errors.
20902090
// Query for the need of further parsing for a {%k<NUM>} mark
20912091
if (!Z || getLexer().is(AsmToken::LCurly)) {
2092-
const SMLoc StartLoc = Z ? consumeToken() : consumedToken;
2092+
SMLoc StartLoc = Z ? consumeToken() : consumedToken;
20932093
// Parse an op-mask register mark ({%k<NUM>}), which is now to be
20942094
// expected
2095-
if (std::unique_ptr<X86Operand> Op = ParseOperand()) {
2095+
unsigned RegNo;
2096+
if (!ParseRegister(RegNo, StartLoc, StartLoc) &&
2097+
X86MCRegisterClasses[X86::VK1RegClassID].contains(RegNo)) {
20962098
if (!getLexer().is(AsmToken::RCurly))
20972099
return Error(getLexer().getLoc(), "Expected } at this point");
20982100
Operands.push_back(X86Operand::CreateToken("{", StartLoc));
2099-
Operands.push_back(std::move(Op));
2101+
Operands.push_back(std::move(X86Operand::CreateReg(RegNo, StartLoc,
2102+
StartLoc)));
21002103
Operands.push_back(X86Operand::CreateToken("}", consumeToken()));
21012104
} else
21022105
return Error(getLexer().getLoc(),
@@ -2106,7 +2109,8 @@ bool X86AsmParser::HandleAVX512Operand(OperandVector &Operands,
21062109
// Have we've found a parsing error, or found no (expected) {z} mark
21072110
// - report an error
21082111
if (ParseZ(Z, consumeToken()) || !Z)
2109-
return true;
2112+
return Error(getLexer().getLoc(),
2113+
"Expected a {z} mark at this point");
21102114

21112115
}
21122116
// '{z}' on its own is meaningless, hence should be ignored.

‎llvm/test/MC/X86/avx512-err.s

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// RUN: not llvm-mc -triple x86_64-unknown-unknown -mcpu=knl -mattr=+avx512dq --show-encoding %s 2> %t.err
1+
// RUN: not llvm-mc -triple x86_64-unknown-unknown -mcpu=knl -mattr=+avx512dq -mattr=+avx512f --show-encoding %s 2> %t.err
22
// RUN: FileCheck --check-prefix=ERR < %t.err %s
33

44
// ERR: invalid operand for instruction
55
vpcmpd $1, %zmm24, %zmm7, %k5{%k0}
66

7+
// ERR: Expected a {z} mark at this point
8+
vfmsub213ps %zmm8, %zmm8, %zmm8{%k2} {rn-sae}
9+
10+
// ERR: Expected an op-mask register at this point
11+
vfmsub213ps %zmm8, %zmm8, %zmm8 {rn-sae}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not llvm-mc %s -triple x86_64-unknown-unknown -mcpu=knl -mattr=+avx512f -x86-asm-syntax=intel -output-asm-variant=1 -o /dev/null 2>&1 | FileCheck %s
2+
3+
// Validate that only OpMask/Zero mark may immediately follow destination
4+
vfmsub213ps zmm8{rn-sae} {k2}, zmm8, zmm8
5+
// CHECK: error: Expected an op-mask register at this point
6+
vfmsub213ps zmm8{k2} {rn-sae}, zmm8, zmm8
7+
// CHECK: error: Expected a {z} mark at this point
8+
vfmsub213ps zmm8{rn-sae}, zmm8, zmm8
9+
// CHECK: error: Expected an op-mask register at this point

0 commit comments

Comments
 (0)
Please sign in to comment.