aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-11-29 23:00:16 +0000
committergingerBill <bill@gingerbill.org>2018-11-29 23:00:16 +0000
commit784c48c9e36c11595b23fb0df002c063dd42a2bf (patch)
tree4c5c2c91e63031fb83601089eae2264c6e655e60 /src/types.cpp
parent008d8f25c824d45096dfc23d1c741dba7babdff4 (diff)
Redefine how union tag size is calculated to match alignment of the union0.9.1
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp
index a85a9fdd1..6024ecfd1 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1632,11 +1632,26 @@ i64 union_tag_size(Type *u) {
return 0;
}
+#if 1
+ // TODO(bill): Is this an okay approach?
+ i64 max_align = 1;
+ 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;
+ }
+ }
+
+ u->Union.tag_size = gb_min(max_align, build_context.max_align);
+ return max_align;
+#else
i64 bytes = next_pow2(cast(i64)(floor_log2(n)/8 + 1));
i64 tag_size = gb_max(bytes, 1);
u->Union.tag_size = tag_size;
return tag_size;
+#endif
}
Type *union_tag_type(Type *u) {