[PATCH] D101733: [M68k][AsmParser] Fix invalid register name parsing logics

Min-Yih Hsu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 2 15:01:26 PDT 2021


myhsu created this revision.
myhsu added a reviewer: ricky26.
Herald added a subscriber: hiraditya.
myhsu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Adjust sanity check in register parsing function to allow register name with more than 2 characters (e.g. ccr).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101733

Files:
  llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
  llvm/test/MC/M68k/Data/Classes/MxMoveCCR.s


Index: llvm/test/MC/M68k/Data/Classes/MxMoveCCR.s
===================================================================
--- /dev/null
+++ llvm/test/MC/M68k/Data/Classes/MxMoveCCR.s
@@ -0,0 +1,16 @@
+; RUN: llvm-mc -triple=m68k -show-encoding %s | FileCheck %s
+	.text
+	.globl	MxMoveToCCR
+; CHECK-LABEL: MxMoveToCCR:
+MxMoveToCCR:
+	; CHECK:      move.w  %d1, %ccr
+	; CHECK-SAME: encoding: [0x44,0xc1]
+	move.w	%d1, %ccr
+
+	.globl	MxMoveFromCCR
+; CHECK-LABEL: MxMoveFromCCR:
+MxMoveFromCCR:
+	; CHECK:      move.w  %ccr, %d1
+	; CHECK-SAME: encoding: [0x42,0xc1]
+	move.w	%ccr, %d1
+
Index: llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
===================================================================
--- llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
+++ llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
@@ -480,7 +480,7 @@
   auto RegisterNameLower = RegisterName.lower();
 
   // Parse simple general-purpose registers.
-  if (RegisterNameLower.size() == 2) {
+  if (RegisterNameLower.size() >= 2) {
     static unsigned RegistersByIndex[] = {
         M68k::D0, M68k::D1, M68k::D2, M68k::D3, M68k::D4, M68k::D5,
         M68k::D6, M68k::D7, M68k::A0, M68k::A1, M68k::A2, M68k::A3,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101733.342282.patch
Type: text/x-patch
Size: 1196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210502/b15fa7e2/attachment.bin>


More information about the llvm-commits mailing list