diff options
| author | gingerBill <bill@gingerbill.org> | 2022-02-22 23:01:28 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-02-22 23:01:28 +0000 |
| commit | ad2f1ac24ebdb4937c5a469c3d3f48b8f53f6218 (patch) | |
| tree | 7bb48d6f4fad4c28eb4ef68c93252f51a20755bc /src/types.cpp | |
| parent | 62d232d798fff25597b6e3591c6a178c32fa440e (diff) | |
Improve `union_tag_size`
Diffstat (limited to 'src/types.cpp')
| -rw-r--r-- | src/types.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp index 2c1e6162f..74080334a 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2623,6 +2623,17 @@ i64 union_tag_size(Type *u) { // TODO(bill): Is this an okay approach? i64 max_align = 1; + + if (u->Union.variants.count < 1ull<<8) { + max_align = 1; + } else if (u->Union.variants.count < 1ull<<16) { + max_align = 2; + } else if (u->Union.variants.count < 1ull<<32) { + max_align = 4; + } else { + GB_PANIC("how many variants do you have?!"); + } + for_array(i, u->Union.variants) { Type *variant_type = u->Union.variants[i]; i64 align = type_align_of(variant_type); |