authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-20 00:21:56-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-20 11:56:52-07:00
log6e053dbf04a224d5aa73dd976c994ec68dd5a7cf
treeca207f5bbbd28d85f411d827573183191b44bce9
parentc8bb44618a9c3c7bfff4a9f672a451fdeda1bb02

Sema: include sentinel in the allocated result of array concatenation


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

src/Sema.zig+17-4
...@@ -13560,13 +13560,23 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13560,13 +13560,23 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1356013560
13561 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);13561 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);
13562 const rhs_len = try sema.usizeCast(block, rhs_src, rhs_info.len);13562 const rhs_len = try sema.usizeCast(block, rhs_src, rhs_info.len);
13563 const result_len = std.math.add(usize, lhs_len, rhs_len) catch |err| switch (err) {13563 const result_len, const result_len_with_sent = blk: {
13564 error.Overflow => return sema.fail(13564 if (std.math.add(usize, lhs_len, rhs_len)) |result_len| {
13565 const sent_len = @intFromBool(res_sent_val != null);
13566 if (std.math.add(usize, result_len, sent_len)) |with_sent| {
13567 break :blk .{ result_len, with_sent };
13568 } else |err| switch (err) {
13569 error.Overflow => {},
13570 }
13571 } else |err| switch (err) {
13572 error.Overflow => {},
13573 }
13574 return sema.fail(
13565 block,13575 block,
13566 src,13576 src,
13567 "concatenating arrays of length {d} and {d} produces an array too large for this compiler implementation to handle",13577 "concatenating arrays of length {d} and {d} produces an array too large for this compiler implementation to handle",
13568 .{ lhs_len, rhs_len },13578 .{ lhs_len, rhs_len },
13569 ),13579 );
13570 };13580 };
1357113581
13572 const result_ty = try pt.arrayType(.{13582 const result_ty = try pt.arrayType(.{
...@@ -13604,7 +13614,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13604,7 +13614,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13604 else13614 else
13605 rhs_val;13615 rhs_val;
1360613616
13607 const element_vals = try sema.arena.alloc(InternPool.Index, result_len);13617 const element_vals = try sema.arena.alloc(InternPool.Index, result_len_with_sent);
13608 var elem_i: u32 = 0;13618 var elem_i: u32 = 0;
13609 while (elem_i < lhs_len) : (elem_i += 1) {13619 while (elem_i < lhs_len) : (elem_i += 1) {
13610 const lhs_elem_i = elem_i;13620 const lhs_elem_i = elem_i;
...@@ -13632,6 +13642,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13632,6 +13642,9 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13632 const coerced_elem_val = sema.resolveValue(coerced_elem_val_inst).?;13642 const coerced_elem_val = sema.resolveValue(coerced_elem_val_inst).?;
13633 element_vals[elem_i] = coerced_elem_val.toIntern();13643 element_vals[elem_i] = coerced_elem_val.toIntern();
13634 }13644 }
13645 if (res_sent_val) |v| {
13646 element_vals[result_len] = v.toIntern();
13647 }
13635 return sema.addConstantMaybeRef(13648 return sema.addConstantMaybeRef(
13636 try pt.aggregateValue(result_ty, element_vals),13649 try pt.aggregateValue(result_ty, element_vals),
13637 ptr_addrspace != null,13650 ptr_addrspace != null,