| author | |
| committer | |
| log | 4e9f5f25c8226144eff8d9c1df79cfcffbae5492 |
| tree | fd324fee01465213bf1d3ec913bb671b5cf9656b |
| parent | f2a24b48e1221a8954ddf16e9070e1470ee13e8d |
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 | 4000 | const air_ptr_inst = Air.refToIndex(bin_op.lhs).?; |
| 4001 | 4001 | const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?; |
| 4002 | 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 | 4004 | if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| { |
| 4005 | 4005 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; |
| 4006 | 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 | 417 | try print(.{ |
| 418 | 418 | .ty = field_ty, |
| 419 | 419 | .val = un.val.toValue(), |
| 420 | }, writer, level - 1, mod); | |
| 420 | }, writer, level - 1, mod); | |
| 421 | 421 | } else { |
| 422 | 422 | try writer.writeAll("(no tag)"); |
| 423 | 423 | } |
src/type.zig+6-2| ... | ... | @@ -1646,8 +1646,12 @@ pub const Type = struct { |
| 1646 | 1646 | }, |
| 1647 | 1647 | |
| 1648 | 1648 | .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) { | |
| 1651 | 1655 | return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8; |
| 1652 | 1656 | } |
| 1653 | 1657 | const union_obj = ip.loadUnionType(union_type); |