aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorBarinzaya <barinzaya@gmail.com>2025-05-24 12:41:28 -0400
committerBarinzaya <barinzaya@gmail.com>2025-05-24 12:41:28 -0400
commit717b9f157889cdcdd60253eb656648e9251d3be7 (patch)
tree28eefc025fb677879a3c8781253c16d80e40bbc5 /src/types.cpp
parent0a6dced9daf6baa1b2e81b7d5542899ca6022c7e (diff)
Change union tag size to account for `#align`.
The prior behavior was adjusting the tag size based on the alignment of the types in the union, even when the union has a custom alignment specified with `#align`. This changes the behavior so that a custom alignment, if specified, takes precedence over the alignment of the types.
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/types.cpp b/src/types.cpp
index ce921796d..57e277035 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -3059,11 +3059,15 @@ gb_internal i64 union_tag_size(Type *u) {
compiler_error("how many variants do you have?! %lld", cast(long long)u->Union.variants.count);
}
- for_array(i, u->Union.variants) {
- Type *variant_type = u->Union.variants[i];
- i64 align = type_align_of(variant_type);
- if (max_align < align) {
- max_align = align;
+ if (u->Union.custom_align > 0) {
+ max_align = gb_max(max_align, u->Union.custom_align);
+ } else {
+ for_array(i, u->Union.variants) {
+ Type *variant_type = u->Union.variants[i];
+ i64 align = type_align_of(variant_type);
+ if (max_align < align) {
+ max_align = align;
+ }
}
}