From 930f904aaa7d591d86a8c3216526711be95fcc17 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 9 Sep 2022 15:23:36 +0300 Subject: [PATCH] Sema: resolve lazy align in reifyStruct Closes #12786 --- src/Sema.zig | 2 +- test/behavior.zig | 1 + test/behavior/bugs/12786.zig | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/behavior/bugs/12786.zig diff --git a/src/Sema.zig b/src/Sema.zig index d96363b160..79946fcd1b 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17406,7 +17406,7 @@ fn reifyStruct( if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) { return sema.fail(block, src, "alignment must fit in 'u32'", .{}); } - const abi_align = @intCast(u29, alignment_val.toUnsignedInt(target)); + const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?); const field_name = try name_val.toAllocatedBytes( Type.initTag(.const_slice_u8), diff --git a/test/behavior.zig b/test/behavior.zig index e11cda3b27..e8a13d7034 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -87,6 +87,7 @@ test { _ = @import("behavior/bugs/12486.zig"); _ = @import("behavior/bugs/12680.zig"); _ = @import("behavior/bugs/12776.zig"); + _ = @import("behavior/bugs/12786.zig"); _ = @import("behavior/bugs/12794.zig"); _ = @import("behavior/byteswap.zig"); _ = @import("behavior/byval_arg_var.zig"); diff --git a/test/behavior/bugs/12786.zig b/test/behavior/bugs/12786.zig new file mode 100644 index 0000000000..e8c1a2333f --- /dev/null +++ b/test/behavior/bugs/12786.zig @@ -0,0 +1,28 @@ +const std = @import("std"); + +fn NamespacedGlobals(comptime modules: anytype) type { + return @Type(.{ + .Struct = .{ + .layout = .Auto, + .is_tuple = false, + .fields = &.{ + .{ + .name = "globals", + .field_type = modules.mach.globals, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(modules.mach.globals), + }, + }, + .decls = &[_]std.builtin.Type.Declaration{}, + }, + }); +} + +test { + _ = NamespacedGlobals(.{ + .mach = .{ + .globals = struct {}, + }, + }); +}