From 233c1632714e8699bfc066702d0b0d3cc2754888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E6=99=AF=E6=84=89?= <776459475@qq.com> Date: Mon, 1 Jun 2026 16:00:00 +0800 Subject: [PATCH] Lab6: fix performance test freeze by only zero-initializing local variables with initializers --- scripts/run_all_tests.sh | 4 ++-- src/irgen/IRGenDecl.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 scripts/run_all_tests.sh diff --git a/scripts/run_all_tests.sh b/scripts/run_all_tests.sh old mode 100644 new mode 100755 index 25b7604..9219ca1 --- a/scripts/run_all_tests.sh +++ b/scripts/run_all_tests.sh @@ -2,8 +2,8 @@ # 批量测试所有.sy文件的语法解析 -test_dir="/home/lingli/nudt-compiler-cpp/test/test_case" -compiler="/home/lingli/nudt-compiler-cpp/build/bin/compiler" +test_dir="$(pwd)/test/test_case" +compiler="$(pwd)/build/bin/compiler" if [ ! -f "$compiler" ]; then echo "错误:编译器不存在,请先构建项目" diff --git a/src/irgen/IRGenDecl.cpp b/src/irgen/IRGenDecl.cpp index 0438372..e59f170 100644 --- a/src/irgen/IRGenDecl.cpp +++ b/src/irgen/IRGenDecl.cpp @@ -208,8 +208,10 @@ std::any IRGenImpl::visitVarDef(SysYParser::VarDefContext* ctx) { slot = module_.CreateGlobalValue(name, StorageType(ty), init); } else { slot = builder_.CreateAlloca(StorageType(ty), name); - ZeroInitializeLocal(slot, ty); - if (ctx->initValue()) EmitLocalInitValue(slot, ty, ctx->initValue()); + if (ctx->initValue()) { + ZeroInitializeLocal(slot, ty); + EmitLocalInitValue(slot, ty, ctx->initValue()); + } } storage_map_[ctx] = slot;