Commit ea54c9a375

Micah Switzer <micah.switzer.dev@outlook.com>
2022-11-04 00:56:23
Sema: resolve lazy align in zirReify for union fields
Closes #13435
1 parent cbed6bb
Changed files (3)
src
test
behavior
src/Sema.zig
@@ -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))).?),
                 };
             }
 
test/behavior/bugs/13435.zig
@@ -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 {});
+}
test/behavior.zig
@@ -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");