From 11f192cd102f43e770db45ff8d2c30b89fbb9f3c Mon Sep 17 00:00:00 2001 From: jing <3030349106@qq.com> Date: Wed, 11 Mar 2026 00:38:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(ir):=20=E8=A7=84=E8=8C=83ir=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/irgen/IRGenFunc.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/irgen/IRGenFunc.cpp b/src/irgen/IRGenFunc.cpp index 36bd16c..4ad30b5 100644 --- a/src/irgen/IRGenFunc.cpp +++ b/src/irgen/IRGenFunc.cpp @@ -5,6 +5,19 @@ #include "SysYParser.h" #include "ir/IR.h" +namespace { + +void VerifyFunctionStructure(const ir::Function& func) { + for (const auto& bb : func.blocks()) { + if (!bb || !bb->HasTerminator()) { + throw std::runtime_error("[irgen] 基本块未正确终结: " + + (bb ? bb->name() : std::string(""))); + } + } +} + +} // namespace + IRGenImpl::IRGenImpl(ir::Module& module) : module_(module), func_(nullptr), builder_(nullptr) {} @@ -28,4 +41,5 @@ void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) { locals_.clear(); GenBlock(*func.block()); + VerifyFunctionStructure(*func_); }