aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-09-30 13:05:28 +0100
committergingerBill <bill@gingerbill.org>2024-09-30 13:05:28 +0100
commita7d7c92a5302a9d0db503af37fe96c737a536544 (patch)
tree3ce9711f163b5c7cee64d85e21466f730b9f24f1 /src/check_type.cpp
parent4b6410e2253fb7c305c20ba1a55263cab4ec2c5a (diff)
`#min_field_align` & `#max_field_align`; deprecate `#field_align` in favour of `#min_field_align`
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index f0e0acb9b..bbeff9ca7 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -673,7 +673,7 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *
#define ST_ALIGN(_name) if (st->_name != nullptr) { \
if (st->is_packed) { \
- syntax_error(st->_name, "'#%s' cannot be applied with '#packed'", #_name); \
+ error(st->_name, "'#%s' cannot be applied with '#packed'", #_name); \
return; \
} \
i64 align = 1; \
@@ -682,12 +682,31 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *
} \
}
- ST_ALIGN(field_align);
+ ST_ALIGN(min_field_align);
+ ST_ALIGN(max_field_align);
ST_ALIGN(align);
- if (struct_type->Struct.custom_align < struct_type->Struct.custom_field_align) {
- warning(st->align, "#align(%lld) is defined to be less than #field_name(%lld)",
- cast(long long)struct_type->Struct.custom_align,
- cast(long long)struct_type->Struct.custom_field_align);
+ if (struct_type->Struct.custom_align < struct_type->Struct.custom_min_field_align) {
+ error(st->align, "#align(%lld) is defined to be less than #min_field_align(%lld)",
+ cast(long long)struct_type->Struct.custom_align,
+ cast(long long)struct_type->Struct.custom_min_field_align);
+ }
+ if (struct_type->Struct.custom_max_field_align != 0 &&
+ struct_type->Struct.custom_align > struct_type->Struct.custom_max_field_align) {
+ error(st->align, "#align(%lld) is defined to be greater than #max_field_align(%lld)",
+ cast(long long)struct_type->Struct.custom_align,
+ cast(long long)struct_type->Struct.custom_max_field_align);
+ }
+ if (struct_type->Struct.custom_max_field_align != 0 &&
+ struct_type->Struct.custom_min_field_align > struct_type->Struct.custom_max_field_align) {
+ error(st->align, "#min_field_align(%lld) is defined to be greater than #max_field_align(%lld)",
+ cast(long long)struct_type->Struct.custom_min_field_align,
+ cast(long long)struct_type->Struct.custom_max_field_align);
+
+ i64 a = gb_min(struct_type->Struct.custom_min_field_align, struct_type->Struct.custom_max_field_align);
+ i64 b = gb_max(struct_type->Struct.custom_min_field_align, struct_type->Struct.custom_max_field_align);
+ // NOTE(bill): sort them to keep code consistent
+ struct_type->Struct.custom_min_field_align = a;
+ struct_type->Struct.custom_max_field_align = b;
}
#undef ST_ALIGN