@@ -840,6 +840,11 @@ static bool CheckBaseRegAndIndexReg(unsigned BaseReg, unsigned IndexReg,
840
840
// If we have both a base register and an index register make sure they are
841
841
// both 64-bit or 32-bit registers.
842
842
// To support VSIB, IndexReg can be 128-bit or 256-bit registers.
843
+
844
+ if ((BaseReg == X86::RIP && IndexReg != 0 ) || (IndexReg == X86::RIP)) {
845
+ ErrMsg = " invalid base+index expression" ;
846
+ return true ;
847
+ }
843
848
if (BaseReg != 0 && IndexReg != 0 ) {
844
849
if (X86MCRegisterClasses[X86::GR64RegClassID].contains (BaseReg) &&
845
850
(X86MCRegisterClasses[X86::GR16RegClassID].contains (IndexReg) ||
@@ -1781,10 +1786,12 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseIntelOperand() {
1781
1786
!ParseRegister (RegNo, Start, End)) {
1782
1787
// If this is a segment register followed by a ':', then this is the start
1783
1788
// of a segment override, otherwise this is a normal register reference.
1784
- // In case it is a normal register and there is ptr in the operand this
1789
+ // In case it is a normal register and there is ptr in the operand this
1785
1790
// is an error
1786
- if (getLexer ().isNot (AsmToken::Colon)){
1787
- if (PtrInOperand){
1791
+ if (RegNo == X86::RIP)
1792
+ return ErrorOperand (Start, " rip can only be used as a base register" );
1793
+ if (getLexer ().isNot (AsmToken::Colon)) {
1794
+ if (PtrInOperand) {
1788
1795
return ErrorOperand (Start, " expected memory operand after "
1789
1796
" 'ptr', found register operand instead" );
1790
1797
}
@@ -1865,6 +1872,11 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseATTOperand() {
1865
1872
SMRange (Start, End));
1866
1873
return nullptr ;
1867
1874
}
1875
+ if (RegNo == X86::RIP) {
1876
+ Error (Start, " %rip can only be used as a base register" ,
1877
+ SMRange (Start, End));
1878
+ return nullptr ;
1879
+ }
1868
1880
1869
1881
// If this is a segment register followed by a ':', then this is the start
1870
1882
// of a memory reference, otherwise this is a normal register reference.
@@ -2044,7 +2056,16 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
2044
2056
// like "1(%eax,,1)", the assembler doesn't. Use "eiz" or "riz" for this.
2045
2057
if (getLexer ().is (AsmToken::Percent)) {
2046
2058
SMLoc L;
2047
- if (ParseRegister (IndexReg, L, L)) return nullptr ;
2059
+ if (ParseRegister (IndexReg, L, L))
2060
+ return nullptr ;
2061
+ if (BaseReg == X86::RIP) {
2062
+ Error (IndexLoc, " %rip as base register can not have an index register" );
2063
+ return nullptr ;
2064
+ }
2065
+ if (IndexReg == X86::RIP) {
2066
+ Error (IndexLoc, " %rip is not allowed as an index register" );
2067
+ return nullptr ;
2068
+ }
2048
2069
2049
2070
if (getLexer ().isNot (AsmToken::RParen)) {
2050
2071
// Parse the scale amount:
0 commit comments