mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
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
This commit is contained in:
commit
44e99edd7a
3 changed files with 13 additions and 2 deletions
|
|
@ -175,9 +175,11 @@ const ComptimeAlloc = struct {
|
||||||
|
|
||||||
/// `src` may be `null` if `is_const` will be set.
|
/// `src` may be `null` if `is_const` will be set.
|
||||||
fn newComptimeAlloc(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
|
fn newComptimeAlloc(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
|
||||||
|
const pt = sema.pt;
|
||||||
|
const init_val = try sema.typeHasOnePossibleValue(ty) orelse try pt.undefValue(ty);
|
||||||
const idx = sema.comptime_allocs.items.len;
|
const idx = sema.comptime_allocs.items.len;
|
||||||
try sema.comptime_allocs.append(sema.gpa, .{
|
try sema.comptime_allocs.append(sema.gpa, .{
|
||||||
.val = .{ .interned = try sema.pt.intern(.{ .undef = ty.toIntern() }) },
|
.val = .{ .interned = init_val.toIntern() },
|
||||||
.is_const = false,
|
.is_const = false,
|
||||||
.src = src,
|
.src = src,
|
||||||
.alignment = alignment,
|
.alignment = alignment,
|
||||||
|
|
|
||||||
|
|
@ -595,7 +595,7 @@ const Writer = struct {
|
||||||
},
|
},
|
||||||
|
|
||||||
.reify_slice_arg_ty => {
|
.reify_slice_arg_ty => {
|
||||||
const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.operand);
|
const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.small);
|
||||||
const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
|
const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
|
||||||
try stream.print("{t}, ", .{reify_slice_arg_info});
|
try stream.print("{t}, ", .{reify_slice_arg_info});
|
||||||
try self.writeInstRef(stream, extra.operand);
|
try self.writeInstRef(stream, extra.operand);
|
||||||
|
|
|
||||||
|
|
@ -427,3 +427,12 @@ test "undefined type value" {
|
||||||
};
|
};
|
||||||
comptime assert(@TypeOf(S.undef_type) == type);
|
comptime assert(@TypeOf(S.undef_type) == type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "reify struct with zero fields through const arrays" {
|
||||||
|
const names: [0][]const u8 = .{};
|
||||||
|
const types: [0]type = .{};
|
||||||
|
const attrs: [0]std.builtin.Type.StructField.Attributes = .{};
|
||||||
|
const S = @Struct(.auto, null, &names, &types, &attrs);
|
||||||
|
comptime assert(@typeInfo(S) == .@"struct");
|
||||||
|
comptime assert(@typeInfo(S).@"struct".fields.len == 0);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue