mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
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.
This commit is contained in:
@@ -3059,6 +3059,9 @@ gb_internal i64 union_tag_size(Type *u) {
|
|||||||
compiler_error("how many variants do you have?! %lld", cast(long long)u->Union.variants.count);
|
compiler_error("how many variants do you have?! %lld", cast(long long)u->Union.variants.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (u->Union.custom_align > 0) {
|
||||||
|
max_align = gb_max(max_align, u->Union.custom_align);
|
||||||
|
} else {
|
||||||
for_array(i, u->Union.variants) {
|
for_array(i, u->Union.variants) {
|
||||||
Type *variant_type = u->Union.variants[i];
|
Type *variant_type = u->Union.variants[i];
|
||||||
i64 align = type_align_of(variant_type);
|
i64 align = type_align_of(variant_type);
|
||||||
@@ -3066,6 +3069,7 @@ gb_internal i64 union_tag_size(Type *u) {
|
|||||||
max_align = align;
|
max_align = align;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
u->Union.tag_size = cast(i16)gb_min3(max_align, build_context.max_align, 8);
|
u->Union.tag_size = cast(i16)gb_min3(max_align, build_context.max_align, 8);
|
||||||
return u->Union.tag_size;
|
return u->Union.tag_size;
|
||||||
|
|||||||
Reference in New Issue
Block a user