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...@@ -4000,7 +4000,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
4000 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;4000 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
4001 const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;4001 const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
4002 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);4002 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).?;
4004 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {4004 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
4005 const new_ptr = ptr_mapping.get(air_ptr_inst).?;4005 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
4006 const store_val = try mod.unionValue(union_ty, tag_val, payload_val);4006 const store_val = try mod.unionValue(union_ty, tag_val, payload_val);
src/TypedValue.zig+1-1
...@@ -417,7 +417,7 @@ pub fn print(...@@ -417,7 +417,7 @@ pub fn print(
417 try print(.{417 try print(.{
418 .ty = field_ty,418 .ty = field_ty,
419 .val = un.val.toValue(),419 .val = un.val.toValue(),
420 }, writer, level - 1, mod);420 }, writer, level - 1, mod);
421 } else {421 } else {
422 try writer.writeAll("(no tag)");422 try writer.writeAll("(no tag)");
423 }423 }
src/type.zig+6-2
...@@ -1646,8 +1646,12 @@ pub const Type = struct {...@@ -1646,8 +1646,12 @@ pub const Type = struct {
1646 },1646 },
16471647
1648 .union_type => |union_type| {1648 .union_type => |union_type| {
1649 if (opt_sema) |sema| try sema.resolveTypeFields(ty);1649 const is_packed = ty.containerLayout(mod) == .Packed;
1650 if (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) {
1651 return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;1655 return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;
1652 }1656 }
1653 const union_obj = ip.loadUnionType(union_type);1657 const union_obj = ip.loadUnionType(union_type);