Begin to support constant array of unions

This commit is contained in:
gingerBill
2025-09-28 20:20:26 +01:00
parent a974c51d57
commit ffdfbfe2c2
7 changed files with 71 additions and 34 deletions

View File

@@ -3253,11 +3253,18 @@ gb_internal lbAddr lb_add_global_generated_with_name(lbModule *m, Type *type, lb
GB_ASSERT(type != nullptr);
type = default_type(type);
LLVMTypeRef actual_type = lb_type(m, type);
if (value.value != nullptr) {
LLVMTypeRef value_type = LLVMTypeOf(value.value);
GB_ASSERT(lb_sizeof(actual_type) == lb_sizeof(value_type));
actual_type = value_type;
}
Scope *scope = nullptr;
Entity *e = alloc_entity_variable(scope, make_token_ident(name), type);
lbValue g = {};
g.type = alloc_type_pointer(type);
g.value = LLVMAddGlobal(m->mod, lb_type(m, type), alloc_cstring(temporary_allocator(), name));
g.value = LLVMAddGlobal(m->mod, actual_type, alloc_cstring(temporary_allocator(), name));
if (value.value != nullptr) {
GB_ASSERT_MSG(LLVMIsConstant(value.value), LLVMPrintValueToString(value.value));
LLVMSetInitializer(g.value, value.value);
@@ -3265,6 +3272,8 @@ gb_internal lbAddr lb_add_global_generated_with_name(lbModule *m, Type *type, lb
LLVMSetInitializer(g.value, LLVMConstNull(lb_type(m, type)));
}
g.value = LLVMConstPointerCast(g.value, lb_type(m, g.type));
lb_add_entity(m, e, g);
lb_add_member(m, name, g);