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 {...@@ -4926,6 +4926,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4926 const result = try func.allocStack(result_ty);4926 const result = try func.allocStack(result_ty);
4927 const elem_ty = result_ty.childType();4927 const elem_ty = result_ty.childType();
4928 const elem_size = @intCast(u32, elem_ty.abiSize(func.target));4928 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
4930 // When the element type is by reference, we must copy the entire4933 // When the element type is by reference, we must copy the entire
4931 // value. It is therefore safer to move the offset pointer and store4934 // 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 {...@@ -4938,10 +4941,13 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4938 const elem_val = try func.resolveInst(elem);4941 const elem_val = try func.resolveInst(elem);
4939 try func.store(offset, elem_val, elem_ty, 0);4942 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) {
4942 _ = try func.buildPointerOffset(offset, elem_size, .modify);4945 _ = try func.buildPointerOffset(offset, elem_size, .modify);
4943 }4946 }
4944 }4947 }
4948 if (sentinel) |sent| {
4949 try func.store(offset, sent, elem_ty, 0);
4950 }
4945 } else {4951 } else {
4946 var offset: u32 = 0;4952 var offset: u32 = 0;
4947 for (elements) |elem| {4953 for (elements) |elem| {
...@@ -4949,6 +4955,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4949,6 +4955,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4949 try func.store(result, elem_val, elem_ty, offset);4955 try func.store(result, elem_val, elem_ty, offset);
4950 offset += elem_size;4956 offset += elem_size;
4951 }4957 }
4958 if (sentinel) |sent| {
4959 try func.store(result, sent, elem_ty, offset);
4960 }
4952 }4961 }
4953 break :result_value result;4962 break :result_value result;
4954 },4963 },