commit 4e9f5f25c8226144eff8d9c1df79cfcffbae5492 (tree)
parent f2a24b48e1221a8954ddf16e9070e1470ee13e8d
Author: kcbanner <kcbanner@gmail.com>
Date: Sat, 23 Sep 2023 13:04:18 -0400
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.
Diffstat:
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/Sema.zig b/src/Sema.zig
@@ -4000,7 +4000,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
- const payload_ty = union_ty.unionFieldType(tag_val, mod);
+ const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
const new_ptr = ptr_mapping.get(air_ptr_inst).?;
const store_val = try mod.unionValue(union_ty, tag_val, payload_val);
diff --git a/src/TypedValue.zig b/src/TypedValue.zig
@@ -417,7 +417,7 @@ pub fn print(
try print(.{
.ty = field_ty,
.val = un.val.toValue(),
- }, writer, level - 1, mod);
+ }, writer, level - 1, mod);
} else {
try writer.writeAll("(no tag)");
}
diff --git a/src/type.zig b/src/type.zig
@@ -1646,8 +1646,12 @@ pub const Type = struct {
},
.union_type => |union_type| {
- if (opt_sema) |sema| try sema.resolveTypeFields(ty);
- if (ty.containerLayout(mod) != .Packed) {
+ const is_packed = ty.containerLayout(mod) == .Packed;
+ if (opt_sema) |sema| {
+ try sema.resolveTypeFields(ty);
+ if (is_packed) try sema.resolveTypeLayout(ty);
+ }
+ if (!is_packed) {
return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;
}
const union_obj = ip.loadUnionType(union_type);