authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-29 20:21:30+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-29 20:21:30+01:00
log44e99edd7a12ea7e04fbfe53746c3af4b531f687
treed1e18165c95c127a53655828c6778fc3fa55bf00
parenta0289d0cce370729099a1ec0228e7f49bcdabc80
parent8f5db19791dde73e8e969c6ebf821767f1c3e50b

Merge pull request 'Sema: initialize OPV comptime allocs correctly' (#30043) from reify-empty-struct into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30043

3 files changed, 13 insertions(+), 2 deletions(-)

src/Sema.zig+3-1
...@@ -175,9 +175,11 @@ const ComptimeAlloc = struct {...@@ -175,9 +175,11 @@ const ComptimeAlloc = struct {
175175
176/// `src` may be `null` if `is_const` will be set.176/// `src` may be `null` if `is_const` will be set.
177fn newComptimeAlloc(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, alignment: Alignment) !ComptimeAllocIndex {177fn newComptimeAlloc(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
178 const pt = sema.pt;
179 const init_val = try sema.typeHasOnePossibleValue(ty) orelse try pt.undefValue(ty);
178 const idx = sema.comptime_allocs.items.len;180 const idx = sema.comptime_allocs.items.len;
179 try sema.comptime_allocs.append(sema.gpa, .{181 try sema.comptime_allocs.append(sema.gpa, .{
180 .val = .{ .interned = try sema.pt.intern(.{ .undef = ty.toIntern() }) },182 .val = .{ .interned = init_val.toIntern() },
181 .is_const = false,183 .is_const = false,
182 .src = src,184 .src = src,
183 .alignment = alignment,185 .alignment = alignment,
src/print_zir.zig+1-1
...@@ -595,7 +595,7 @@ const Writer = struct {...@@ -595,7 +595,7 @@ const Writer = struct {
595 },595 },
596596
597 .reify_slice_arg_ty => {597 .reify_slice_arg_ty => {
598 const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.operand);598 const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.small);
599 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;599 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
600 try stream.print("{t}, ", .{reify_slice_arg_info});600 try stream.print("{t}, ", .{reify_slice_arg_info});
601 try self.writeInstRef(stream, extra.operand);601 try self.writeInstRef(stream, extra.operand);
test/behavior/type.zig+9
...@@ -427,3 +427,12 @@ test "undefined type value" {...@@ -427,3 +427,12 @@ test "undefined type value" {
427 };427 };
428 comptime assert(@TypeOf(S.undef_type) == type);428 comptime assert(@TypeOf(S.undef_type) == type);
429}429}
430
431test "reify struct with zero fields through const arrays" {
432 const names: [0][]const u8 = .{};
433 const types: [0]type = .{};
434 const attrs: [0]std.builtin.Type.StructField.Attributes = .{};
435 const S = @Struct(.auto, null, &names, &types, &attrs);
436 comptime assert(@typeInfo(S) == .@"struct");
437 comptime assert(@typeInfo(S).@"struct".fields.len == 0);
438}