Skip to content

Commit

Permalink
Added a missing error check for X86 assembly with mismatched base and…
Browse files Browse the repository at this point in the history
… index

registers not both being 64-bit or both being 32-bit registers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152580 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
enderby committed Mar 12, 2012
1 parent a185362 commit 84faf65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {
// If we reached here, then we just ate the ( of the memory operand. Process
// the rest of the memory operand.
unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
SMLoc IndexLoc;

if (getLexer().is(AsmToken::Percent)) {
SMLoc StartLoc, EndLoc;
Expand All @@ -851,6 +852,7 @@ X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {

if (getLexer().is(AsmToken::Comma)) {
Parser.Lex(); // Eat the comma.
IndexLoc = Parser.getTok().getLoc();

// Following the comma we should have either an index register, or a scale
// value. We don't support the later form, but we want to parse it
Expand Down Expand Up @@ -912,6 +914,23 @@ X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {
SMLoc MemEnd = Parser.getTok().getLoc();
Parser.Lex(); // Eat the ')'.

// If we have both a base register and an index register make sure they are
// both 64-bit or 32-bit registers.
if (BaseReg != 0 && IndexReg != 0) {
if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
!X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg) &&
IndexReg != X86::RIZ) {
Error(IndexLoc, "index register is 32-bit, but base register is 64-bit");
return 0;
}
if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
!X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg) &&
IndexReg != X86::EIZ){
Error(IndexLoc, "index register is 64-bit, but base register is 32-bit");
return 0;
}
}

return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
MemStart, MemEnd);
}
Expand Down
4 changes: 4 additions & 0 deletions test/MC/X86/x86_errors.s
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ sysexitq
// rdar://10710167
// 64: error: expected scale expression
lea (%rsp, %rbp, $4), %rax

// rdar://10423777
// 64: error: index register is 32-bit, but base register is 64-bit
movq (%rsi,%ecx),%xmm0

0 comments on commit 84faf65

Please sign in to comment.