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_); }