Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This fixes #504.
  • Loading branch information
saagarjha authored Jul 20, 2021
1 parent 6bfc23f commit 1475885
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@ static bool CheckBaseRegAndIndexReg(unsigned BaseReg, unsigned IndexReg,
// 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 == X86::RIP && IndexReg != 0) || (IndexReg == X86::RIP)) {
ErrMsg = "invalid base+index expression";
return true;
}
if (BaseReg != 0 && IndexReg != 0) {
if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
(X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
Expand Down Expand Up @@ -2057,10 +2062,12 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseIntelOperand(std::string Mnem, un
if (!ParseRegister(RegNo, Start, End, ErrorCode)) {
// 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.
// In case it is a normal register and there is ptr in the operand this
// 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){
if (RegNo == X86::RIP)
return ErrorOperand(Start, "rip can only be used as a base register");
if (getLexer().isNot(AsmToken::Colon)) {
if (PtrInOperand) {
return ErrorOperand(Start, "expected memory operand after "
"'ptr', found register operand instead");
}
Expand Down Expand Up @@ -2093,6 +2100,12 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseATTOperand(unsigned int &KsError)
KsError = KS_ERR_ASM_INVALIDOPERAND;
return nullptr;
}
if (RegNo == X86::RIP) {
// Error(Start, "%rip can only be used as a base register",
// SMRange(Start, End));
KsError = KS_ERR_ASM_INVALIDOPERAND;
return nullptr;
}

// If this is a segment register followed by a ':', then this is the start
// of a memory reference, otherwise this is a normal register reference.
Expand Down Expand Up @@ -2312,6 +2325,21 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
return nullptr;
}

if (ParseRegister(IndexReg, L, L, ErrorCode)) {
KsError = KS_ERR_ASM_X86_INVALIDOPERAND;
return nullptr;
}
if (BaseReg == X86::RIP) {
// Error(IndexLoc, "%rip as base register can not have an index register");
KsError = KS_ERR_ASM_INVALIDOPERAND;
return nullptr;
}
if (IndexReg == X86::RIP) {
// Error(IndexLoc, "%rip is not allowed as an index register");
KsError = KS_ERR_ASM_INVALIDOPERAND;
return nullptr;
}

if (getLexer().isNot(AsmToken::RParen)) {
// Parse the scale amount:
// ::= ',' [scale-expression]
Expand Down

0 comments on commit 1475885

Please sign in to comment.