Merge pull request #7293 from kalsprite/bitfield_offset_not_found

bit_field: diagnose a missing field name in type_field_bit_offset / type_field_bit_size
This commit is contained in:
gingerBill
2026-08-12 13:09:16 +02:00
committed by GitHub

View File

@@ -7313,6 +7313,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
i64 bit_offset = 0;
i64 bit_size = 0;
bool found = false;
for_array(i, type->BitField.fields) {
Entity *f = type->BitField.fields[i];
if (f->kind != Entity_Variable || (f->flags & EntityFlag_Field) == 0) {
@@ -7322,9 +7323,18 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
if (field_name == str) {
bit_offset = type->BitField.bit_offsets[i];
bit_size = type->BitField.bit_sizes[i];
found = true;
break;
}
}
// A missing field would otherwise return 0, which is also the correct offset of the
// first declared field, so the caller has nothing to test for.
if (!found) {
gbString t = type_to_string(type);
error(ce->args[1], "'%s' is not a field of type %s", field_name.cstring(), t);
gb_string_free(t);
return false;
}
i64 value = 0;
switch (id) {