diff --git a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp index 96eb8b1b0528ac..efc8b77f8d8fab 100644 --- a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp +++ b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp @@ -669,13 +669,33 @@ static bool matchRegisterNameHelper(MCRegister &RegNo, StringRef Name) { bool LoongArchAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) { - return Error(getLoc(), "invalid register number"); + if (!tryParseRegister(Reg, StartLoc, EndLoc).isSuccess()) + return Error(getLoc(), "invalid register name"); + + if (!LoongArchMCRegisterClasses[LoongArch::GPRRegClassID].contains(Reg) && + !LoongArchMCRegisterClasses[LoongArch::FPR32RegClassID].contains(Reg)) + return Error(getLoc(), "invalid register name"); + + return false; } ParseStatus LoongArchAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) { - llvm_unreachable("Unimplemented function."); + const AsmToken &Tok = getParser().getTok(); + StartLoc = Tok.getLoc(); + EndLoc = Tok.getEndLoc(); + + parseOptionalToken(AsmToken::Dollar); + if (getLexer().getKind() != AsmToken::Identifier) + return ParseStatus::NoMatch; + + StringRef Name = Tok.getIdentifier(); + if (matchRegisterNameHelper(Reg, Name)) + return ParseStatus::NoMatch; + + getParser().Lex(); // Eat identifier token. + return ParseStatus::Success; } bool LoongArchAsmParser::classifySymbolRef(const MCExpr *Expr, diff --git a/llvm/test/MC/LoongArch/Directives/cfi.s b/llvm/test/MC/LoongArch/Directives/cfi.s index 7101fc90729067..978028dfd66e6d 100644 --- a/llvm/test/MC/LoongArch/Directives/cfi.s +++ b/llvm/test/MC/LoongArch/Directives/cfi.s @@ -1,10 +1,10 @@ ## Test cfi directives. -# RUN: llvm-mc %s --triple=loongarch32 | FileCheck %s -# RUN: llvm-mc %s --triple=loongarch64 | FileCheck %s -# RUN: not llvm-mc --triple=loongarch32 --defsym=ERR=1 < %s 2>&1 \ +# RUN: llvm-mc %s --triple=loongarch32 --mattr=+lasx | FileCheck %s +# RUN: llvm-mc %s --triple=loongarch64 --mattr=+lasx | FileCheck %s +# RUN: not llvm-mc --triple=loongarch32 --mattr=+lasx --defsym=ERR=1 < %s 2>&1 \ # RUN: | FileCheck %s --check-prefix=CHECK-ERR -# RUN: not llvm-mc --triple=loongarch64 --defsym=ERR=1 < %s 2>&1 \ +# RUN: not llvm-mc --triple=loongarch64 --mattr=+lasx --defsym=ERR=1 < %s 2>&1 \ # RUN: | FileCheck %s --check-prefix=CHECK-ERR # CHECK: .cfi_startproc @@ -15,20 +15,36 @@ .cfi_offset 9, 8 # CHECK-NEXT: .cfi_offset 31, 16 .cfi_offset 31, 16 +# CHECK-NEXT: .cfi_offset 22, -8 +.cfi_offset r22, -8 +# CHECK-NEXT: .cfi_offset 22, -8 +.cfi_offset $r22, -8 +# CHECK-NEXT: .cfi_offset 22, -8 +.cfi_offset fp, -8 +# CHECK-NEXT: .cfi_offset 22, -8 +.cfi_offset $fp, -8 +# CHECK-NEXT: .cfi_offset 42, 8 +.cfi_offset f10, 8 +# CHECK-NEXT: .cfi_offset 56, 8 +.cfi_offset fs0, 8 # CHECK-NEXT: .cfi_endproc .cfi_endproc .ifdef ERR .cfi_startproc -# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number +# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name .cfi_offset -22, -8 -# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number -.cfi_offset fp, -8 -# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number +# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name +.cfi_offset lr, -8 +# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name +.cfi_offset r32, -8 +# CHECK-ERR: :[[#@LINE+1]]:14: error: invalid register name +.cfi_offset $r32, -8 +# CHECK-ERR: :[[#@LINE+1]]:14: error: invalid register name .cfi_offset $22, -8 -# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number -.cfi_offset $r22, -8 -# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number -.cfi_offset $fp, -8 +# CHECK-ERR: :[[#@LINE+1]]:16: error: invalid register name +.cfi_offset vr0, 8 +# CHECK-ERR: :[[#@LINE+1]]:16: error: invalid register name +.cfi_offset xr0, 8 .cfi_endproc .endif