aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-03 15:57:35 +0100
committergingerBill <bill@gingerbill.org>2021-05-03 15:57:35 +0100
commite4286d0ff9d383d03b220ac8fc52934853b35c34 (patch)
treedf49c45a57dc1b2e02a3067cc2dfb0a08e603bd2 /src/types.cpp
parent3a556eb3046f3f7ff1183981b261ac38e38c0c87 (diff)
Force `zero_init` in `lb_add_local` in certain cases
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp
index 3fafa00d5..ffdb90c03 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -2779,7 +2779,36 @@ void type_path_pop(TypePath *tp) {
i64 type_size_of_internal (Type *t, TypePath *path);
i64 type_align_of_internal(Type *t, TypePath *path);
+i64 type_size_of(Type *t);
+i64 type_align_of(Type *t);
+i64 type_size_of_struct_pretend_is_packed(Type *ot) {
+ if (ot == nullptr) {
+ return 0;
+ }
+ Type *t = core_type(ot);
+ if (t->kind != Type_Struct) {
+ return type_size_of(ot);
+ }
+
+ if (t->Struct.is_packed) {
+ return type_size_of(ot);
+ }
+
+ i64 count = 0, size = 0, align = 1;
+
+ auto const &fields = t->Struct.fields;
+ count = fields.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ for_array(i, fields) {
+ size += type_size_of(fields[i]->type);
+ }
+
+ return align_formula(size, align);
+}
i64 type_size_of(Type *t) {