mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
wasm: aggregate_init store sentinel for arrays
This commit is contained in:
parent
969f921162
commit
128814f9bf
@ -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;
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user