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;