diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-26 20:59:36 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-26 20:59:36 -0700 |
| commit | 2687b8f7f4825c9018af6998e1de140e6185f9cd (patch) | |
| tree | 4bbd5f609153618e883ad4cce09c7a8c920a22b0 /src/Module.zig | |
| parent | 32e89a98d82c0f4505a3f3d4cd72e7db2eadfbb9 (diff) | |
| download | zig-2687b8f7f4825c9018af6998e1de140e6185f9cd.tar.gz zig-2687b8f7f4825c9018af6998e1de140e6185f9cd.zip | |
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.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 9 |
1 files changed, 9 insertions, 0 deletions
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); |
