aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2023-05-27 15:14:18 +0200
committerLuuk de Gram <luuk@degram.dev>2023-05-31 18:04:32 +0200
commit128814f9bf89460232569ae3e47c52f90cdf4ffd (patch)
tree4a8d8a259c07d326eb09238e456ff3ed56c36016 /src
parent969f9211622b3f2d296a6f51449605d65b66bb31 (diff)
downloadzig-128814f9bf89460232569ae3e47c52f90cdf4ffd.tar.gz
zig-128814f9bf89460232569ae3e47c52f90cdf4ffd.zip
wasm: `aggregate_init` store sentinel for arrays
Diffstat (limited to 'src')
-rw-r--r--src/arch/wasm/CodeGen.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index 2a8e1668e8..57f6beb035 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -4926,6 +4926,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const result = try func.allocStack(result_ty);
const elem_ty = result_ty.childType();
const elem_size = @intCast(u32, elem_ty.abiSize(func.target));
+ const sentinel = if (result_ty.sentinel()) |sent| blk: {
+ break :blk try func.lowerConstant(sent, elem_ty);
+ } else null;
// When the element type is by reference, we must copy the entire
// 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 {
const elem_val = try func.resolveInst(elem);
try func.store(offset, elem_val, elem_ty, 0);
- if (elem_index < elements.len - 1) {
+ if (elem_index < elements.len - 1 and sentinel == null) {
_ = try func.buildPointerOffset(offset, elem_size, .modify);
}
}
+ if (sentinel) |sent| {
+ try func.store(offset, sent, elem_ty, 0);
+ }
} else {
var offset: u32 = 0;
for (elements) |elem| {
@@ -4949,6 +4955,9 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
try func.store(result, elem_val, elem_ty, offset);
offset += elem_size;
}
+ if (sentinel) |sent| {
+ try func.store(result, sent, elem_ty, offset);
+ }
}
break :result_value result;
},