[llvm] r199948 - Update the X86 assembler for .intel_syntax to produce an error for invalid base
Kevin Enderby
enderby at apple.com
Thu Jan 23 14:34:43 PST 2014
Author: enderby
Date: Thu Jan 23 16:34:42 2014
New Revision: 199948
URL: http://llvm.org/viewvc/llvm-project?rev=199948&view=rev
Log:
Update the X86 assembler for .intel_syntax to produce an error for invalid base
registers in memory addresses that do not match the index register. As it does
for .att_syntax.
rdar://15887380
Added:
llvm/trunk/test/MC/X86/intel-syntax-invalid-basereg.s
Modified:
llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=199948&r1=199947&r2=199948&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Thu Jan 23 16:34:42 2014
@@ -1152,6 +1152,44 @@ struct X86Operand : public MCParsedAsmOp
} // end anonymous namespace.
+static bool CheckBaseRegAndIndexReg(unsigned BaseReg, unsigned IndexReg,
+ StringRef &ErrMsg) {
+ // If we have both a base register and an index register make sure they are
+ // both 64-bit or 32-bit registers.
+ // To support VSIB, IndexReg can be 128-bit or 256-bit registers.
+ if (BaseReg != 0 && IndexReg != 0) {
+ if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
+ (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
+ X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg)) &&
+ IndexReg != X86::RIZ) {
+ ErrMsg = "base register is 64-bit, but index register is not";
+ return true;
+ }
+ if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
+ (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
+ X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) &&
+ IndexReg != X86::EIZ){
+ ErrMsg = "base register is 32-bit, but index register is not";
+ return true;
+ }
+ if (X86MCRegisterClasses[X86::GR16RegClassID].contains(BaseReg)) {
+ if (X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg) ||
+ X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) {
+ ErrMsg = "base register is 16-bit, but index register is not";
+ return true;
+ }
+ if (((BaseReg == X86::BX || BaseReg == X86::BP) &&
+ IndexReg != X86::SI && IndexReg != X86::DI) ||
+ ((BaseReg == X86::SI || BaseReg == X86::DI) &&
+ IndexReg != X86::BX && IndexReg != X86::BP)) {
+ ErrMsg = "invalid 16-bit base/index register combination";
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
bool X86AsmParser::doSrcDstMatch(X86Operand &Op1, X86Operand &Op2)
{
// Return true and let a normal complaint about bogus operands happen.
@@ -1575,6 +1613,11 @@ X86Operand *X86AsmParser::ParseIntelBrac
else
return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, Start, End, Size);
}
+ StringRef ErrMsg;
+ if (CheckBaseRegAndIndexReg(BaseReg, IndexReg, ErrMsg)) {
+ Error(StartInBrac, ErrMsg);
+ return 0;
+ }
return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
End, Size);
}
@@ -2080,38 +2123,11 @@ X86Operand *X86AsmParser::ParseMemOperan
Error(IndexLoc, "16-bit memory operand may not include only index register");
return 0;
}
- // If we have both a base register and an index register make sure they are
- // both 64-bit or 32-bit registers.
- // To support VSIB, IndexReg can be 128-bit or 256-bit registers.
- if (BaseReg != 0 && IndexReg != 0) {
- if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
- (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
- X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg)) &&
- IndexReg != X86::RIZ) {
- Error(BaseLoc, "base register is 64-bit, but index register is not");
- return 0;
- }
- if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
- (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
- X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) &&
- IndexReg != X86::EIZ){
- Error(BaseLoc, "base register is 32-bit, but index register is not");
- return 0;
- }
- if (X86MCRegisterClasses[X86::GR16RegClassID].contains(BaseReg)) {
- if (X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg) ||
- X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) {
- Error(BaseLoc, "base register is 16-bit, but index register is not");
- return 0;
- }
- if (((BaseReg == X86::BX || BaseReg == X86::BP) &&
- IndexReg != X86::SI && IndexReg != X86::DI) ||
- ((BaseReg == X86::SI || BaseReg == X86::DI) &&
- IndexReg != X86::BX && IndexReg != X86::BP)) {
- Error(BaseLoc, "invalid 16-bit base/index register combination");
- return 0;
- }
- }
+
+ StringRef ErrMsg;
+ if (CheckBaseRegAndIndexReg(BaseReg, IndexReg, ErrMsg)) {
+ Error(BaseLoc, ErrMsg);
+ return 0;
}
return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
Added: llvm/trunk/test/MC/X86/intel-syntax-invalid-basereg.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/intel-syntax-invalid-basereg.s?rev=199948&view=auto
==============================================================================
--- llvm/trunk/test/MC/X86/intel-syntax-invalid-basereg.s (added)
+++ llvm/trunk/test/MC/X86/intel-syntax-invalid-basereg.s Thu Jan 23 16:34:42 2014
@@ -0,0 +1,7 @@
+// RUN: not llvm-mc -triple x86_64-unknown-unknown %s 2> %t.err
+// RUN: FileCheck < %t.err %s
+
+.intel_syntax
+
+// CHECK: error: base register is 64-bit, but index register is not
+ lea rax, [rdi + edx]
More information about the llvm-commits
mailing list