[llvm] c31fca1 - [M68k] Fix printing of immediate in `M68kOperand::print`

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 16 15:45:15 PDT 2023


Author: Ian Douglas Scott
Date: 2023-04-16T15:44:18-07:00
New Revision: c31fca105bb75812ffc70a41a4c9ecdf4983a3f4

URL: https://github.com/llvm/llvm-project/commit/c31fca105bb75812ffc70a41a4c9ecdf4983a3f4
DIFF: https://github.com/llvm/llvm-project/commit/c31fca105bb75812ffc70a41a4c9ecdf4983a3f4.diff

LOG: [M68k] Fix printing of immediate in `M68kOperand::print`

The `Imm` union variant wasn't initialized anywhere. This fixes what is
printed by `llvm-mc -arch m68k --show-inst-operands`.

Differential Revision: https://reviews.llvm.org/D148302

Added: 
    llvm/test/MC/M68k/operand.s

Modified: 
    llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp b/llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
index c606eaa9af13e..8d6abe8341c94 100644
--- a/llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
+++ b/llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
@@ -133,7 +133,6 @@ class M68kOperand : public MCParsedAsmOperand {
   SMLoc Start, End;
   union {
     StringRef Token;
-    int64_t Imm;
     const MCExpr *Expr;
     M68kMemOp MemOp;
   };
@@ -1069,9 +1068,12 @@ void M68kOperand::print(raw_ostream &OS) const {
     OS << "token '" << Token << "'";
     break;
 
-  case KindTy::Imm:
-    OS << "immediate " << Imm;
+  case KindTy::Imm: {
+    int64_t Value;
+    Expr->evaluateAsAbsolute(Value);
+    OS << "immediate " << Value;
     break;
+  }
 
   case KindTy::MemOp:
     MemOp.print(OS);

diff  --git a/llvm/test/MC/M68k/operand.s b/llvm/test/MC/M68k/operand.s
new file mode 100644
index 0000000000000..b8946bd891020
--- /dev/null
+++ b/llvm/test/MC/M68k/operand.s
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple=m68k -show-inst-operands %s 2> %t0
+# RUN: FileCheck %s < %t0
+
+; CHECK:	parsed instruction: [token 'move.l', immediate 123, %24]
+move.l	#123, %d0


        


More information about the llvm-commits mailing list