From feab5508a8158e86e3bbc1209b59781d29e0bdae Mon Sep 17 00:00:00 2001 From: lzkk <956449176@qq.com> Date: Thu, 28 May 2026 11:42:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(irgen):=20starttime/stoptime=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E6=81=A2=E5=A4=8D=E4=B8=BA=20=5Fsysy=5Fstart?= =?UTF-8?q?time/=5Fsysy=5Fstoptime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 平台运行时库期望 _sysy_starttime(int) 和 _sysy_stoptime(int) 签名, 之前错误地生成 starttime(void) / stoptime(void), 导致所有程序链接到错误函数而崩溃返回 1。 恢复队友原版:下划线前缀 + 行号参数。 --- src/irgen/IRGenExp.cpp | 11 +++++++++-- src/irgen/IRGenFunc.cpp | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/irgen/IRGenExp.cpp b/src/irgen/IRGenExp.cpp index 7ff3ba50..76136c75 100644 --- a/src/irgen/IRGenExp.cpp +++ b/src/irgen/IRGenExp.cpp @@ -656,9 +656,16 @@ std::any IRGenImpl::visitUnaryExp(SysYParser::UnaryExpContext* ctx) { } } + if (callee_name == "starttime" || callee_name == "stoptime") { + int lineno = ctx->getStart()->getLine(); + args.push_back(static_cast(builder_.CreateConstInt(lineno))); + } + if (args.size() != func_it->second->GetParams().size()) { - throw std::runtime_error( - FormatError("irgen", "函数参数个数不匹配: " + callee_name)); + if (callee_name != "starttime" && callee_name != "stoptime") { + throw std::runtime_error( + FormatError("irgen", "函数参数个数不匹配: " + callee_name)); + } } for (size_t i = 0; i < args.size(); ++i) { args[i] = CastValueTo(args[i], func_it->second->GetParams()[i]->GetType()); diff --git a/src/irgen/IRGenFunc.cpp b/src/irgen/IRGenFunc.cpp index 21ca2631..9c6c1342 100644 --- a/src/irgen/IRGenFunc.cpp +++ b/src/irgen/IRGenFunc.cpp @@ -119,9 +119,11 @@ std::any IRGenImpl::visitCompUnit(SysYParser::CompUnitContext* ctx) { auto* putch = module_.CreateFunction("putch", ir::Type::GetVoidType(), true); putch->AddParam("%arg.x", ir::Type::GetInt32Type()); function_map_["putch"] = putch; - auto* sysy_starttime = module_.CreateFunction("starttime", ir::Type::GetVoidType(), true); + auto* sysy_starttime = module_.CreateFunction("_sysy_starttime", ir::Type::GetVoidType(), true); + sysy_starttime->AddParam("%arg.lineno", ir::Type::GetInt32Type()); function_map_["starttime"] = sysy_starttime; - auto* sysy_stoptime = module_.CreateFunction("stoptime", ir::Type::GetVoidType(), true); + auto* sysy_stoptime = module_.CreateFunction("_sysy_stoptime", ir::Type::GetVoidType(), true); + sysy_stoptime->AddParam("%arg.lineno", ir::Type::GetInt32Type()); function_map_["stoptime"] = sysy_stoptime; SysYParser::FuncDefContext* main_func = nullptr;