mirror of
https://github.com/ziglang/zig.git
synced 2025-12-28 17:13:19 +00:00
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.
This commit is contained in:
parent
f2a24b48e1
commit
4e9f5f25c8
@ -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);
|
||||
|
||||
@ -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)");
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user