From 2687b8f7f4825c9018af6998e1de140e6185f9cd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 26 Feb 2022 20:59:36 -0700 Subject: stage2: implement `@unionInit` The ZIR instruction `union_init_ptr` is renamed to `union_init`. I made it always use by-value semantics for now, not taking the time to invest in result location semantics, in case we decide to change the rules for unions. This way is much simpler. There is a new AIR instruction: union_init. This is for a comptime known tag, runtime-known field value. vector_init is renamed to aggregate_init, which solves a TODO comment. --- src/Module.zig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 91386405be..048895e5bf 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1123,6 +1123,15 @@ pub const Union = struct { /// undefined until `status` is `have_field_types` or `have_layout`. ty: Type, abi_align: Value, + + /// Returns the field alignment, assuming the union is not packed. + pub fn normalAlignment(field: Field, target: Target) u32 { + if (field.abi_align.tag() == .abi_align_default) { + return field.ty.abiAlignment(target); + } else { + return @intCast(u32, field.abi_align.toUnsignedInt()); + } + } }; pub const Fields = std.StringArrayHashMapUnmanaged(Field); -- cgit v1.2.3