From 4f00d05c86127ad0f295ff6cffb6c6520e7ad528 Mon Sep 17 00:00:00 2001 From: mxr <> Date: Fri, 10 Apr 2026 11:02:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(mir)=E4=BF=AE=E5=A4=8DRet=E8=BF=94=E5=9B=9E?= =?UTF-8?q?void=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir/AsmPrinter.cpp | 1 - src/mir/FrameLowering.cpp | 2 +- src/mir/Lowering.cpp | 11 ++++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mir/AsmPrinter.cpp b/src/mir/AsmPrinter.cpp index 6d8ca3c..4550730 100644 --- a/src/mir/AsmPrinter.cpp +++ b/src/mir/AsmPrinter.cpp @@ -314,7 +314,6 @@ void PrintAsm(const MachineFunction& function, std::ostream& os) { void PrintAsm(const MachineModule& module, std::ostream& os) { // 输出文件头 os << ".arch armv8-a\n"; - os << ".text\n"; DEBUG_MSG("module"); // 遍历所有函数,输出汇编 diff --git a/src/mir/FrameLowering.cpp b/src/mir/FrameLowering.cpp index b9fa84e..6758105 100644 --- a/src/mir/FrameLowering.cpp +++ b/src/mir/FrameLowering.cpp @@ -5,7 +5,7 @@ #include "utils/Log.h" -#define DEBUG_Frame +//#define DEBUG_Frame #ifdef DEBUG_Frame #include diff --git a/src/mir/Lowering.cpp b/src/mir/Lowering.cpp index 3365385..013aa26 100644 --- a/src/mir/Lowering.cpp +++ b/src/mir/Lowering.cpp @@ -7,7 +7,7 @@ #include "ir/IR.h" #include "utils/Log.h" -#define DEBUG_Lower +//#define DEBUG_Lower #ifdef DEBUG_Lower #include @@ -125,6 +125,9 @@ void EmitValueToReg(const ir::Value* value, PhysReg target, const ValueSlotMap& slots, MachineBasicBlock& block, MachineFunction& function) { // 处理整数常量 + if (value == nullptr) { + DEBUG_MSG( "EmitValueToReg called with null value\n"); + } if (auto* constant = dynamic_cast(value)) { block.Append(Opcode::MovImm, {Operand::Reg(target), Operand::Imm(constant->GetValue())}); @@ -219,7 +222,6 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function, //auto& block = function.GetEntry(); DEBUG_MSG("Processing instruction: " << inst.GetName() << " (opcode: " << static_cast(inst.GetOpcode()) << ")"); - switch (inst.GetOpcode()) { case ir::Opcode::Alloca: { slots.emplace(&inst, function.CreateFrameIndex(GetTypeSize(inst.GetType().get()))); @@ -326,7 +328,10 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function, } case ir::Opcode::Ret: { auto& ret = static_cast(inst); - EmitValueToReg(ret.GetValue(), PhysReg::W0, slots, block, function); + const ir::Value* retVal = ret.GetValue(); + if (retVal != nullptr) { + EmitValueToReg(retVal, PhysReg::W0, slots, block, function); + } block.Append(Opcode::Ret); return; }