Sema: resolve lazy align in zirReify for union fields

Closes #13435
This commit is contained in:
Micah Switzer
2022-11-03 19:56:23 -04:00
committed by Andrew Kelley
parent 6165de9a61
commit 8d95b713c5
3 changed files with 24 additions and 1 deletions

View File

@@ -18232,7 +18232,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
var buffer: Value.ToTypeBuffer = undefined;
gop.value_ptr.* = .{
.ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator),
.abi_align = @intCast(u32, alignment_val.toUnsignedInt(target)),
.abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?),
};
}

View File

@@ -111,6 +111,7 @@ test {
_ = @import("behavior/bugs/13159.zig");
_ = @import("behavior/bugs/13171.zig");
_ = @import("behavior/bugs/13285.zig");
_ = @import("behavior/bugs/13435.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@@ -0,0 +1,22 @@
const std = @import("std");
fn CreateUnion(comptime T: type) type {
return @Type(.{
.Union = .{
.layout = .Auto,
.tag_type = null,
.fields = &[_]std.builtin.Type.UnionField{
.{
.name = "field",
.field_type = T,
.alignment = @alignOf(T),
},
},
.decls = &[_]std.builtin.Type.Declaration{},
},
});
}
test {
_ = CreateUnion(struct {});
}