authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-26 17:30:51+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-31 18:04:32+02:00
logffa89d3b8370377b56be594650c0ea73f225c926
tree611a23c6a865e1bb28b50c72b15e18d3e2b82aa1
parent3c72b4d25eb14bbdc03503c368a750b1ca1b7c28
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 7 insertions(+), 2 deletions(-)

src/arch/wasm/CodeGen.zig+7-2
...@@ -3161,7 +3161,7 @@ fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {...@@ -3161,7 +3161,7 @@ fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {
3161fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {3161fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3162 switch (ty.zigTypeTag()) {3162 switch (ty.zigTypeTag()) {
3163 .Bool, .ErrorSet => return WValue{ .imm32 = 0xaaaaaaaa },3163 .Bool, .ErrorSet => return WValue{ .imm32 = 0xaaaaaaaa },
3164 .Int => switch (ty.intInfo(func.target).bits) {3164 .Int, .Enum => switch (ty.intInfo(func.target).bits) {
3165 0...32 => return WValue{ .imm32 = 0xaaaaaaaa },3165 0...32 => return WValue{ .imm32 = 0xaaaaaaaa },
3166 33...64 => return WValue{ .imm64 = 0xaaaaaaaaaaaaaaaa },3166 33...64 => return WValue{ .imm64 = 0xaaaaaaaaaaaaaaaa },
3167 else => unreachable,3167 else => unreachable,
...@@ -3958,7 +3958,12 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo...@@ -3958,7 +3958,12 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
3958 const payload_ty = err_ty.errorUnionPayload();3958 const payload_ty = err_ty.errorUnionPayload();
39593959
3960 const result = result: {3960 const result = result: {
3961 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) break :result WValue{ .none = {} };3961 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
3962 if (op_is_ptr) {
3963 break :result WValue{ .imm32 = 0 };
3964 }
3965 break :result WValue{ .none = {} };
3966 }
39623967
3963 const pl_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, func.target));3968 const pl_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, func.target));
3964 if (op_is_ptr or isByRef(payload_ty, func.target)) {3969 if (op_is_ptr or isByRef(payload_ty, func.target)) {