mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
value: handle lazy_align and lazy_size in writeToPackedMemory
This commit is contained in:
parent
89572c6342
commit
7fbbeae617
@ -803,7 +803,14 @@ pub const Value = struct {
|
||||
switch (ip.indexToKey((try val.intFromEnum(ty, mod)).toIntern()).int.storage) {
|
||||
inline .u64, .i64 => |int| std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian),
|
||||
.big_int => |bigint| bigint.writePackedTwosComplement(buffer, bit_offset, bits, endian),
|
||||
else => unreachable,
|
||||
.lazy_align => |lazy_align| {
|
||||
const num = Type.fromInterned(lazy_align).abiAlignment(mod).toByteUnits(0);
|
||||
std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
|
||||
},
|
||||
.lazy_size => |lazy_size| {
|
||||
const num = Type.fromInterned(lazy_size).abiSize(mod);
|
||||
std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
|
||||
},
|
||||
}
|
||||
},
|
||||
.Float => switch (ty.floatBits(target)) {
|
||||
|
||||
@ -1225,3 +1225,13 @@ test "auto-numbered enum with signed tag type" {
|
||||
try std.testing.expectEqualStrings("a", @tagName(E.a));
|
||||
try std.testing.expectEqualStrings("b", @tagName(E.b));
|
||||
}
|
||||
|
||||
test "lazy initialized field" {
|
||||
try std.testing.expectEqual(@as(u8, @alignOf(struct {})), getLazyInitialized(.a));
|
||||
}
|
||||
|
||||
fn getLazyInitialized(param: enum(u8) {
|
||||
a = @bitCast(packed struct(u8) { a: u8 }{ .a = @alignOf(struct {}) }),
|
||||
}) u8 {
|
||||
return @intFromEnum(param);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user