Value: handle more legacy tags when writing extern struct to memory

Closes #16130
This commit is contained in:
Jacob Young
2023-06-21 21:42:30 -04:00
committed by Andrew Kelley
parent 93e54f2354
commit c60896743d
2 changed files with 16 additions and 1 deletions

View File

@@ -745,7 +745,15 @@ pub const Value = struct {
.Extern => for (ty.structFields(mod).values(), 0..) |field, i| {
const off = @intCast(usize, ty.structFieldOffset(i, mod));
const field_val = switch (val.ip_index) {
.none => val.castTag(.aggregate).?.data[i],
.none => switch (val.tag()) {
.bytes => {
buffer[off] = val.castTag(.bytes).?.data[i];
continue;
},
.aggregate => val.castTag(.aggregate).?.data[i],
.repeated => val.castTag(.repeated).?.data,
else => unreachable,
},
else => switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
.bytes => |bytes| {
buffer[off] = bytes[i];

View File

@@ -431,3 +431,10 @@ test "dereference undefined pointer to zero-bit type" {
const p1: *[0]u32 = undefined;
try testing.expect(p1.*.len == 0);
}
test "type pun extern struct" {
const S = extern struct { f: u8 };
comptime var s = S{ .f = 123 };
@ptrCast(*u8, &s).* = 72;
try testing.expectEqual(@as(u8, 72), s.f);
}