aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-10-24 22:19:24 +0300
committerVeikka Tuominen <git@vexu.eu>2022-10-27 01:31:18 +0300
commitd9fe5ba7f805c82f14c162945ac851ebb570ec89 (patch)
treefb353da646ba9fc9c25e74b60076f7f2b08fc638 /src
parent9dcfc829e650bc9c0a89e9f7778744c774120c09 (diff)
downloadzig-d9fe5ba7f805c82f14c162945ac851ebb570ec89.tar.gz
zig-d9fe5ba7f805c82f14c162945ac851ebb570ec89.zip
Sema: add error for too big packed struct
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 9c52fd91a3..d1a558d15b 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -29075,6 +29075,33 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
struct_obj.backing_int_ty = try backing_int_ty.copy(decl_arena_allocator);
try wip_captures.finalize();
} else {
+ if (fields_bit_sum > std.math.maxInt(u16)) {
+ var sema: Sema = .{
+ .mod = mod,
+ .gpa = gpa,
+ .arena = undefined,
+ .perm_arena = decl_arena_allocator,
+ .code = zir,
+ .owner_decl = decl,
+ .owner_decl_index = decl_index,
+ .func = null,
+ .fn_ret_ty = Type.void,
+ .owner_func = null,
+ };
+ defer sema.deinit();
+
+ var block: Block = .{
+ .parent = null,
+ .sema = &sema,
+ .src_decl = decl_index,
+ .namespace = &struct_obj.namespace,
+ .wip_capture_scope = undefined,
+ .instructions = .{},
+ .inlining = null,
+ .is_comptime = true,
+ };
+ return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
+ }
var buf: Type.Payload.Bits = .{
.base = .{ .tag = .int_unsigned },
.data = @intCast(u16, fields_bit_sum),