authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-27 15:14:18+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-31 18:04:32+02:00
log128814f9bf89460232569ae3e47c52f90cdf4ffd
tree4a8d8a259c07d326eb09238e456ff3ed56c36016
parent969f9211622b3f2d296a6f51449605d65b66bb31
signaturelock-open Commit is signed but in an unrecognized format.

wasm: `aggregate_init` store sentinel for arrays


1 files changed, 10 insertions(+), 1 deletions(-)

src/arch/wasm/CodeGen.zig+10-1
......@@ -4926,6 +4926,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49264926 const result = try func.allocStack(result_ty);
49274927 const elem_ty = result_ty.childType();
49284928 const elem_size = @intCast(u32, elem_ty.abiSize(func.target));
4929 const sentinel = if (result_ty.sentinel()) |sent| blk: {
4930 break :blk try func.lowerConstant(sent, elem_ty);
4931 } else null;
49294932
49304933 // When the element type is by reference, we must copy the entire
49314934 // value. It is therefore safer to move the offset pointer and store
......@@ -4938,10 +4941,13 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49384941 const elem_val = try func.resolveInst(elem);
49394942 try func.store(offset, elem_val, elem_ty, 0);
49404943
4941 if (elem_index < elements.len - 1) {
4944 if (elem_index < elements.len - 1 and sentinel == null) {
49424945 _ = try func.buildPointerOffset(offset, elem_size, .modify);
49434946 }
49444947 }
4948 if (sentinel) |sent| {
4949 try func.store(offset, sent, elem_ty, 0);
4950 }
49454951 } else {
49464952 var offset: u32 = 0;
49474953 for (elements) |elem| {
......@@ -4949,6 +4955,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49494955 try func.store(result, elem_val, elem_ty, offset);
49504956 offset += elem_size;
49514957 }
4958 if (sentinel) |sent| {
4959 try func.store(result, sent, elem_ty, offset);
4960 }
49524961 }
49534962 break :result_value result;
49544963 },