mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
Fix global initialization when non was set
This commit is contained in:
@@ -3255,6 +3255,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
}
|
}
|
||||||
GB_ASSERT(e->kind == Entity_Variable);
|
GB_ASSERT(e->kind == Entity_Variable);
|
||||||
|
|
||||||
|
|
||||||
bool is_foreign = e->Variable.is_foreign;
|
bool is_foreign = e->Variable.is_foreign;
|
||||||
bool is_export = e->Variable.is_export;
|
bool is_export = e->Variable.is_export;
|
||||||
|
|
||||||
@@ -3269,7 +3270,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
g.type = alloc_type_pointer(e->type);
|
g.type = alloc_type_pointer(e->type);
|
||||||
g.value = LLVMAddGlobal(m->mod, lb_type(m, e->type), alloc_cstring(permanent_allocator(), name));
|
g.value = LLVMAddGlobal(m->mod, lb_type(m, e->type), alloc_cstring(permanent_allocator(), name));
|
||||||
|
|
||||||
|
|
||||||
if (decl->init_expr != nullptr) {
|
if (decl->init_expr != nullptr) {
|
||||||
TypeAndValue tav = type_and_value_of_expr(decl->init_expr);
|
TypeAndValue tav = type_and_value_of_expr(decl->init_expr);
|
||||||
if (!is_type_any(e->type) && !is_type_union(e->type)) {
|
if (!is_type_any(e->type) && !is_type_union(e->type)) {
|
||||||
@@ -3313,7 +3313,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
LLVMSetDLLStorageClass(g.value, LLVMDLLImportStorageClass);
|
LLVMSetDLLStorageClass(g.value, LLVMDLLImportStorageClass);
|
||||||
LLVMSetExternallyInitialized(g.value, true);
|
LLVMSetExternallyInitialized(g.value, true);
|
||||||
lb_add_foreign_library_path(m, e->Variable.foreign_library);
|
lb_add_foreign_library_path(m, e->Variable.foreign_library);
|
||||||
} else if (!var.is_initialized) {
|
} else if (LLVMGetInitializer(g.value) == nullptr) {
|
||||||
LLVMSetInitializer(g.value, LLVMConstNull(lb_type(m, e->type)));
|
LLVMSetInitializer(g.value, LLVMConstNull(lb_type(m, e->type)));
|
||||||
}
|
}
|
||||||
if (is_export) {
|
if (is_export) {
|
||||||
|
|||||||
Reference in New Issue
Block a user