From ffa89d3b8370377b56be594650c0ea73f225c926 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Fri, 26 May 2023 17:30:51 +0200 Subject: [PATCH] wasm: `UnwrapErrUnionPayloadPtr` ensure ptr ret When the paylaod is zero-sized we must ensure a valid pointer is still returned for the ptr variation of the instruction. This, because it's valid to have a pointer to a zero-sized value. In such a case, we simply return the operand. --- src/arch/wasm/CodeGen.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 74eb075eab..1cd282f5f7 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -3161,7 +3161,7 @@ fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue { fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue { switch (ty.zigTypeTag()) { .Bool, .ErrorSet => return WValue{ .imm32 = 0xaaaaaaaa }, - .Int => switch (ty.intInfo(func.target).bits) { + .Int, .Enum => switch (ty.intInfo(func.target).bits) { 0...32 => return WValue{ .imm32 = 0xaaaaaaaa }, 33...64 => return WValue{ .imm64 = 0xaaaaaaaaaaaaaaaa }, else => unreachable, @@ -3958,7 +3958,12 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo const payload_ty = err_ty.errorUnionPayload(); const result = result: { - if (!payload_ty.hasRuntimeBitsIgnoreComptime()) break :result WValue{ .none = {} }; + if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { + if (op_is_ptr) { + break :result WValue{ .imm32 = 0 }; + } + break :result WValue{ .none = {} }; + } const pl_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, func.target)); if (op_is_ptr or isByRef(payload_ty, func.target)) {