authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2023-01-31 00:59:18+01:00
committergravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2023-01-31 00:59:18+01:00
log1f64432196e51785fe1dba442a0878c1b10f8b06
tree57612888269602d917a9d6a4b7e0ba2f97d30728
parent885d6968958e1cad4862ed1b6f1ea0b2d84c3845

wasm: correctly handle optional slices


1 files changed, 9 insertions(+), 4 deletions(-)

src/arch/wasm/CodeGen.zig+9-4
......@@ -1706,9 +1706,11 @@ fn isByRef(ty: Type, target: std.Target) bool {
17061706 return true;
17071707 },
17081708 .Optional => {
1709 if (ty.optionalReprIsPayload()) return false;
1709 if (ty.isPtrLikeOptional()) return false;
17101710 var buf: Type.Payload.ElemType = undefined;
1711 return ty.optionalChild(&buf).hasRuntimeBitsIgnoreComptime();
1711 const pl_type = ty.optionalChild(&buf);
1712 if (pl_type.zigTypeTag() == .ErrorSet) return false;
1713 return pl_type.hasRuntimeBitsIgnoreComptime();
17121714 },
17131715 .Pointer => {
17141716 // Slices act like struct and will be passed by reference
......@@ -3869,14 +3871,17 @@ fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind:
38693871/// NOTE: Leaves the result on the stack
38703872fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcode) InnerError!WValue {
38713873 try func.emitWValue(operand);
3874 var buf: Type.Payload.ElemType = undefined;
3875 const payload_ty = optional_ty.optionalChild(&buf);
38723876 if (!optional_ty.optionalReprIsPayload()) {
3873 var buf: Type.Payload.ElemType = undefined;
3874 const payload_ty = optional_ty.optionalChild(&buf);
38753877 // When payload is zero-bits, we can treat operand as a value, rather than
38763878 // a pointer to the stack value
38773879 if (payload_ty.hasRuntimeBitsIgnoreComptime()) {
38783880 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset(), .alignment = 1 });
38793881 }
3882 } else if (payload_ty.isSlice()) {
3883 // move the ptr on top of the stack
3884 _ = try func.load(operand, Type.usize, 0);
38803885 }
38813886
38823887 // Compare the null value with '0'