Index: lib/Target/X86/AsmParser/X86AsmParser.cpp =================================================================== --- lib/Target/X86/AsmParser/X86AsmParser.cpp +++ lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1865,6 +1865,11 @@ SMRange(Start, End)); return nullptr; } + if (RegNo == X86::RIP) { + Error(Start, "%rip can only be used as a base register", + SMRange(Start, End)); + 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. @@ -2045,6 +2050,14 @@ if (getLexer().is(AsmToken::Percent)) { SMLoc L; if (ParseRegister(IndexReg, L, L)) return nullptr; + if (BaseReg == X86::RIP) { + Error(IndexLoc, "%rip as base register can not have an index register"); + return nullptr; + } + if (IndexReg == X86::RIP) { + Error(IndexLoc, "%rip is not allowed as an index register"); + return nullptr; + } if (getLexer().isNot(AsmToken::RParen)) { // Parse the scale amount: Index: test/MC/X86/x86_errors.s =================================================================== --- test/MC/X86/x86_errors.s +++ test/MC/X86/x86_errors.s @@ -74,3 +74,11 @@ // 32: error: register %dr8 is only available in 64-bit mode movl %edx, %dr8 + +// 32: error: register %rip is only available in 64-bit mode +// 64: error: %rip can only be used as a base register +mov %rip, %rax + +// 32: error: register %rax is only available in 64-bit mode +// 64: error: %rip is not allowed as an index register +mov (%rax,%rip), %rbx