diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-09-09 15:23:36 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-15 00:48:47 +0300 |
| commit | 930f904aaa7d591d86a8c3216526711be95fcc17 (patch) | |
| tree | 6f5577f11861cd70793f1731f3e7bdccbc972161 | |
| parent | de24cea2cff33654ee41369517144bb94f6d139d (diff) | |
| download | zig-930f904aaa7d591d86a8c3216526711be95fcc17.tar.gz zig-930f904aaa7d591d86a8c3216526711be95fcc17.zip | |
Sema: resolve lazy align in reifyStruct
Closes #12786
| -rw-r--r-- | src/Sema.zig | 2 | ||||
| -rw-r--r-- | test/behavior.zig | 1 | ||||
| -rw-r--r-- | test/behavior/bugs/12786.zig | 28 |
3 files changed, 30 insertions, 1 deletions
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 {}, + }, + }); +} |
