authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2025-02-28 01:14:40+01:00
committergravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2025-03-24 15:00:00+01:00
log58b38238f51b6a268559144e8bbe7c0646170488
tree2e2cc3e774c54ea3b9ee5ca53579653bf9d36410
parent07f14bd43b983de4467095b37613325b49022835

stage2-wasm: enable undef test + ignore undef store/memset with safety off


2 files changed, 8 insertions(+), 11 deletions(-)

src/arch/wasm/CodeGen.zig+8-10
......@@ -2302,11 +2302,6 @@ fn airAlloc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
23022302fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
23032303 const pt = cg.pt;
23042304 const zcu = pt.zcu;
2305 if (safety) {
2306 // TODO if the value is undef, write 0xaa bytes to dest
2307 } else {
2308 // TODO if the value is undef, don't lower this instruction
2309 }
23102305 const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
23112306
23122307 const lhs = try cg.resolveInst(bin_op.lhs);
......@@ -2315,6 +2310,10 @@ fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
23152310 const ptr_info = ptr_ty.ptrInfo(zcu);
23162311 const ty = ptr_ty.childType(zcu);
23172312
2313 if (!safety and bin_op.rhs == .undef) {
2314 return cg.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
2315 }
2316
23182317 if (ptr_info.packed_offset.host_size == 0) {
23192318 try cg.store(lhs, rhs, ty, 0);
23202319 } else {
......@@ -4756,11 +4755,6 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
47564755
47574756fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
47584757 const zcu = cg.pt.zcu;
4759 if (safety) {
4760 // TODO if the value is undef, write 0xaa bytes to dest
4761 } else {
4762 // TODO if the value is undef, don't lower this instruction
4763 }
47644758 const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
47654759
47664760 const ptr = try cg.resolveInst(bin_op.lhs);
......@@ -4777,6 +4771,10 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
47774771 else
47784772 ptr_ty.childType(zcu);
47794773
4774 if (!safety and bin_op.rhs == .undef) {
4775 return cg.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
4776 }
4777
47804778 const dst_ptr = try cg.sliceOrArrayPtr(ptr, ptr_ty);
47814779 try cg.memset(elem_ty, dst_ptr, len, value);
47824780
test/behavior/undefined.zig-1
......@@ -103,7 +103,6 @@ test "reslice of undefined global var slice" {
103103test "returned undef is 0xaa bytes when runtime safety is enabled" {
104104 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
105105 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
106 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
107106 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
108107 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
109108