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.
This commit is contained in:
Luuk de Gram 2023-05-26 17:30:51 +02:00
parent 3c72b4d25e
commit ffa89d3b83
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664

View File

@ -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)) {