mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 05:48:31 +00:00
Sema: add error for too big packed struct
This commit is contained in:
parent
9dcfc829e6
commit
d9fe5ba7f8
27
src/Sema.zig
27
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),
|
||||
|
||||
13
test/cases/compile_errors/too_big_packed_struct.zig
Normal file
13
test/cases/compile_errors/too_big_packed_struct.zig
Normal file
@ -0,0 +1,13 @@
|
||||
pub export fn entry() void {
|
||||
const T = packed struct {
|
||||
a: u65535,
|
||||
b: u65535,
|
||||
};
|
||||
@compileLog(@sizeOf(T));
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:22: error: size of packed struct '131070' exceeds maximum bit width of 65535
|
||||
Loading…
x
Reference in New Issue
Block a user