range check bitfield fields for untyped constants

This commit is contained in:
kalsprite
2026-08-19 10:52:58 -07:00
parent 0be39571f6
commit 8c239a8f43
2 changed files with 182 additions and 0 deletions

View File

@@ -100,6 +100,7 @@ gb_internal Type * check_init_variable (CheckerContext *c, Entity *
gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type, i64 max_bit_size=0);
gb_internal bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type);
gb_internal void add_map_key_type_dependencies(CheckerContext *ctx, Type *key);
gb_internal Type *make_soa_struct_fixed(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type);
@@ -1182,6 +1183,14 @@ gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *typ
return;
}
// a bit_field field's width is on its entity, not its type
if (c->bit_field_bit_size != 0 && operand->mode == Addressing_Constant && is_type_typed(operand->type)) {
check_is_expressible(c, operand, type);
if (operand->mode == Addressing_Invalid) {
return;
}
}
if (operand->mode == Addressing_ProcGroup) {
bool good = false;
if (type != nullptr && is_type_proc(type)) {