aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Verigo <paul.verigo@gmail.com>2025-02-28 01:14:40 +0100
committerPavel Verigo <paul.verigo@gmail.com>2025-03-24 15:00:00 +0100
commit58b38238f51b6a268559144e8bbe7c0646170488 (patch)
tree2e2cc3e774c54ea3b9ee5ca53579653bf9d36410
parent07f14bd43b983de4467095b37613325b49022835 (diff)
downloadzig-58b38238f51b6a268559144e8bbe7c0646170488.tar.gz
zig-58b38238f51b6a268559144e8bbe7c0646170488.zip
stage2-wasm: enable undef test + ignore undef store/memset with safety off
-rw-r--r--src/arch/wasm/CodeGen.zig18
-rw-r--r--test/behavior/undefined.zig1
2 files changed, 8 insertions, 11 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index d198cd7eb2..29a264f973 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -2302,11 +2302,6 @@ fn airAlloc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
const pt = cg.pt;
const zcu = pt.zcu;
- if (safety) {
- // TODO if the value is undef, write 0xaa bytes to dest
- } else {
- // TODO if the value is undef, don't lower this instruction
- }
const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
const lhs = try cg.resolveInst(bin_op.lhs);
@@ -2315,6 +2310,10 @@ fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
const ptr_info = ptr_ty.ptrInfo(zcu);
const ty = ptr_ty.childType(zcu);
+ if (!safety and bin_op.rhs == .undef) {
+ return cg.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
+ }
+
if (ptr_info.packed_offset.host_size == 0) {
try cg.store(lhs, rhs, ty, 0);
} else {
@@ -4756,11 +4755,6 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
const zcu = cg.pt.zcu;
- if (safety) {
- // TODO if the value is undef, write 0xaa bytes to dest
- } else {
- // TODO if the value is undef, don't lower this instruction
- }
const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
const ptr = try cg.resolveInst(bin_op.lhs);
@@ -4777,6 +4771,10 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
else
ptr_ty.childType(zcu);
+ if (!safety and bin_op.rhs == .undef) {
+ return cg.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
+ }
+
const dst_ptr = try cg.sliceOrArrayPtr(ptr, ptr_ty);
try cg.memset(elem_ty, dst_ptr, len, value);
diff --git a/test/behavior/undefined.zig b/test/behavior/undefined.zig
index d4f74fb78c..307deb84bf 100644
--- a/test/behavior/undefined.zig
+++ b/test/behavior/undefined.zig
@@ -103,7 +103,6 @@ test "reslice of undefined global var slice" {
test "returned undef is 0xaa bytes when runtime safety is enabled" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;