From aea28d5189848746725707d595155726b6b94ea0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 11 May 2024 13:47:33 +0100 Subject: Allow edge-case where backing type of a `bit_field` is (array of) `u8`, to allow any endian type --- src/check_type.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index 11e332757..6fe87c2c7 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1133,12 +1133,13 @@ gb_internal void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, return Endian_Native; }; - EndianKind backing_type_endian_kind = determine_endian_kind(core_array_type(backing_type)); + Type *backing_type_elem = core_array_type(backing_type); + EndianKind backing_type_endian_kind = determine_endian_kind(backing_type_elem); EndianKind endian_kind = Endian_Unknown; for (Entity *f : fields) { EndianKind field_kind = determine_endian_kind(f->type); - if (field_kind && backing_type_endian_kind != field_kind) { + if (field_kind && backing_type_endian_kind != field_kind && backing_type_elem != t_u8) { error(f->token, "All 'bit_field' field types must match the same endian kind as the backing type, i.e. all native, all little, or all big"); } -- cgit v1.2.3 From 811d53b305643607f25718437336c74dffdccb6b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 11 May 2024 13:48:19 +0100 Subject: Generalize to any 1-byte element in `bit_field` --- src/check_type.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index 6fe87c2c7..88aa4ca1e 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1134,12 +1134,13 @@ gb_internal void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, }; Type *backing_type_elem = core_array_type(backing_type); + i64 backing_type_elem_size = type_size_of(backing_type_elem); EndianKind backing_type_endian_kind = determine_endian_kind(backing_type_elem); EndianKind endian_kind = Endian_Unknown; for (Entity *f : fields) { EndianKind field_kind = determine_endian_kind(f->type); - if (field_kind && backing_type_endian_kind != field_kind && backing_type_elem != t_u8) { + if (field_kind && backing_type_endian_kind != field_kind && backing_type_elem_size > 1) { error(f->token, "All 'bit_field' field types must match the same endian kind as the backing type, i.e. all native, all little, or all big"); } -- cgit v1.2.3 From 6bfaf4a093fc566c38e97c5c7b80b9586ddf41e9 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 11 May 2024 22:36:17 +0100 Subject: Fix another oversight for `bit_field` endian with 1-byte types --- src/check_type.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index 88aa4ca1e..4df0c5d19 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1139,14 +1139,15 @@ gb_internal void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, EndianKind endian_kind = Endian_Unknown; for (Entity *f : fields) { EndianKind field_kind = determine_endian_kind(f->type); + i64 field_size = type_size_of(f->type); - if (field_kind && backing_type_endian_kind != field_kind && backing_type_elem_size > 1) { + if (field_kind && backing_type_endian_kind != field_kind && field_size > 1 && backing_type_elem_size > 1) { error(f->token, "All 'bit_field' field types must match the same endian kind as the backing type, i.e. all native, all little, or all big"); } if (endian_kind == Endian_Unknown) { endian_kind = field_kind; - } else if (field_kind && endian_kind != field_kind) { + } else if (field_kind && endian_kind != field_kind && field_size > 1) { error(f->token, "All 'bit_field' field types must be of the same endian variety, i.e. all native, all little, or all big"); } } -- cgit v1.2.3