From c8f23efcc809a8865c6cdde0ea0111d570d150c2 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Thu, 27 Mar 2014 15:00:44 +0000 Subject: [PATCH] [mips] Attempting to use register $32 should be an error instead of an assertion. Reviewers: matheusalmeida Reviewed By: matheusalmeida Differential Revision: http://llvm-reviews.chandlerc.com/D3201 llvm-svn: 204932 --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 2 +- test/MC/Mips/mips-register-names-invalid.s | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/MC/Mips/mips-register-names-invalid.s diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 602bf04dac3..5bc8f9d4b63 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -1217,7 +1217,7 @@ unsigned MipsAsmParser::getGPR(int RegNo) { int MipsAsmParser::matchRegisterByNumber(unsigned RegNum, unsigned RegClass) { if (RegNum > - getContext().getRegisterInfo()->getRegClass(RegClass).getNumRegs()) + getContext().getRegisterInfo()->getRegClass(RegClass).getNumRegs() - 1) return -1; if (RegClass == Mips::GPR32RegClassID || RegClass == Mips::GPR64RegClassID) diff --git a/test/MC/Mips/mips-register-names-invalid.s b/test/MC/Mips/mips-register-names-invalid.s new file mode 100644 index 00000000000..df1054fed42 --- /dev/null +++ b/test/MC/Mips/mips-register-names-invalid.s @@ -0,0 +1,8 @@ +# RUN: not llvm-mc %s -triple=mips-unknown-freebsd -show-encoding 2>%t0 +# RUN: FileCheck %s < %t0 + +# $32 used to trigger an assertion instead of the usual error message due to +# an off-by-one bug. + +# CHECK: :[[@LINE+1]]:18: error: invalid operand for instruction + add $32, $0, $0