authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-24 22:19:24+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-27 01:31:18+03:00
logd9fe5ba7f805c82f14c162945ac851ebb570ec89
treefb353da646ba9fc9c25e74b60076f7f2b08fc638
parent9dcfc829e650bc9c0a89e9f7778744c774120c09

Sema: add error for too big packed struct


2 files changed, 40 insertions(+), 0 deletions(-)

src/Sema.zig+27
......@@ -29075,6 +29075,33 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
2907529075 struct_obj.backing_int_ty = try backing_int_ty.copy(decl_arena_allocator);
2907629076 try wip_captures.finalize();
2907729077 } else {
29078 if (fields_bit_sum > std.math.maxInt(u16)) {
29079 var sema: Sema = .{
29080 .mod = mod,
29081 .gpa = gpa,
29082 .arena = undefined,
29083 .perm_arena = decl_arena_allocator,
29084 .code = zir,
29085 .owner_decl = decl,
29086 .owner_decl_index = decl_index,
29087 .func = null,
29088 .fn_ret_ty = Type.void,
29089 .owner_func = null,
29090 };
29091 defer sema.deinit();
29092
29093 var block: Block = .{
29094 .parent = null,
29095 .sema = &sema,
29096 .src_decl = decl_index,
29097 .namespace = &struct_obj.namespace,
29098 .wip_capture_scope = undefined,
29099 .instructions = .{},
29100 .inlining = null,
29101 .is_comptime = true,
29102 };
29103 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
29104 }
2907829105 var buf: Type.Payload.Bits = .{
2907929106 .base = .{ .tag = .int_unsigned },
2908029107 .data = @intCast(u16, fields_bit_sum),
test/cases/compile_errors/too_big_packed_struct.zig created+13
......@@ -0,0 +1,13 @@
1pub export fn entry() void {
2 const T = packed struct {
3 a: u65535,
4 b: u65535,
5 };
6 @compileLog(@sizeOf(T));
7}
8
9// error
10// backend=stage2
11// target=native
12//
13// :2:22: error: size of packed struct '131070' exceeds maximum bit width of 65535