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 {...@@ -2302,11 +2302,6 @@ fn airAlloc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2302fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {2302fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
2303 const pt = cg.pt;2303 const pt = cg.pt;
2304 const zcu = pt.zcu;2304 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 }
2310 const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2305 const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
23112306
2312 const lhs = try cg.resolveInst(bin_op.lhs);2307 const lhs = try cg.resolveInst(bin_op.lhs);
...@@ -2315,6 +2310,10 @@ fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {...@@ -2315,6 +2310,10 @@ fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
2315 const ptr_info = ptr_ty.ptrInfo(zcu);2310 const ptr_info = ptr_ty.ptrInfo(zcu);
2316 const ty = ptr_ty.childType(zcu);2311 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
2318 if (ptr_info.packed_offset.host_size == 0) {2317 if (ptr_info.packed_offset.host_size == 0) {
2319 try cg.store(lhs, rhs, ty, 0);2318 try cg.store(lhs, rhs, ty, 0);
2320 } else {2319 } else {
...@@ -4756,11 +4755,6 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -4756,11 +4755,6 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
47564755
4757fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {4756fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
4758 const zcu = cg.pt.zcu;4757 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 }
4764 const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4758 const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
47654759
4766 const ptr = try cg.resolveInst(bin_op.lhs);4760 const ptr = try cg.resolveInst(bin_op.lhs);
...@@ -4777,6 +4771,10 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {...@@ -4777,6 +4771,10 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
4777 else4771 else
4778 ptr_ty.childType(zcu);4772 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
4780 const dst_ptr = try cg.sliceOrArrayPtr(ptr, ptr_ty);4778 const dst_ptr = try cg.sliceOrArrayPtr(ptr, ptr_ty);
4781 try cg.memset(elem_ty, dst_ptr, len, value);4779 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" {...@@ -103,7 +103,6 @@ test "reslice of undefined global var slice" {
103test "returned undef is 0xaa bytes when runtime safety is enabled" {103test "returned undef is 0xaa bytes when runtime safety is enabled" {
104 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO104 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
105 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO105 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
106 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
107 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;106 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
108 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;107 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
109108