authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-09-23 13:04:18-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-09-23 13:22:22-04:00
log4e9f5f25c8226144eff8d9c1df79cfcffbae5492
treefd324fee01465213bf1d3ec913bb671b5cf9656b
parentf2a24b48e1221a8954ddf16e9070e1470ee13e8d

type: resolve packed union type layouts in bitSizeAdvanced

Before this change, packed structs containing packed unions could make it to codegen without having their layout resolved.

3 files changed, 8 insertions(+), 4 deletions(-)

src/Sema.zig+1-1
......@@ -4000,7 +4000,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
40004000 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
40014001 const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
40024002 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
4003 const payload_ty = union_ty.unionFieldType(tag_val, mod);
4003 const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
40044004 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
40054005 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
40064006 const store_val = try mod.unionValue(union_ty, tag_val, payload_val);
src/TypedValue.zig+1-1
......@@ -417,7 +417,7 @@ pub fn print(
417417 try print(.{
418418 .ty = field_ty,
419419 .val = un.val.toValue(),
420 }, writer, level - 1, mod);
420 }, writer, level - 1, mod);
421421 } else {
422422 try writer.writeAll("(no tag)");
423423 }
src/type.zig+6-2
......@@ -1646,8 +1646,12 @@ pub const Type = struct {
16461646 },
16471647
16481648 .union_type => |union_type| {
1649 if (opt_sema) |sema| try sema.resolveTypeFields(ty);
1650 if (ty.containerLayout(mod) != .Packed) {
1649 const is_packed = ty.containerLayout(mod) == .Packed;
1650 if (opt_sema) |sema| {
1651 try sema.resolveTypeFields(ty);
1652 if (is_packed) try sema.resolveTypeLayout(ty);
1653 }
1654 if (!is_packed) {
16511655 return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;
16521656 }
16531657 const union_obj = ip.loadUnionType(union_type);