mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 01:44:36 +00:00
Correct global constant procedure initialization
This commit is contained in:
@@ -758,6 +758,10 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
e->code_gen_module = entity_module;
|
||||
|
||||
if (e->token.string == "XXH3_init_custom_secret") {
|
||||
gb_printf_err("HERE1\n");
|
||||
}
|
||||
|
||||
Ast *init_expr = var->decl->init_expr;
|
||||
if (init_expr != nullptr) {
|
||||
lbValue init = lb_build_expr(p, init_expr);
|
||||
@@ -780,6 +784,10 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start
|
||||
var->init = init;
|
||||
} else if (lb_is_const_or_global(init)) {
|
||||
if (!var->is_initialized) {
|
||||
if (is_type_proc(init.type)) {
|
||||
LLVMTypeRef global_type = llvm_addr_type(p->module, var->var);
|
||||
init.value = LLVMConstPointerCast(init.value, global_type);
|
||||
}
|
||||
LLVMSetInitializer(var->var.value, init.value);
|
||||
var->is_initialized = true;
|
||||
continue;
|
||||
@@ -1649,6 +1657,10 @@ void lb_generate_code(lbGenerator *gen) {
|
||||
if (tav.value.kind != ExactValue_Invalid) {
|
||||
ExactValue v = tav.value;
|
||||
lbValue init = lb_const_value(m, tav.type, v);
|
||||
if (is_type_proc(init.type)) {
|
||||
LLVMTypeRef global_type = llvm_addr_type(m, var.var);
|
||||
init.value = LLVMConstPointerCast(init.value, global_type);
|
||||
}
|
||||
LLVMSetInitializer(g.value, init.value);
|
||||
var.is_initialized = true;
|
||||
}
|
||||
|
||||
@@ -854,13 +854,6 @@ void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
|
||||
lb_emit_store(p, addr.addr, value);
|
||||
}
|
||||
|
||||
void lb_const_store(lbValue ptr, lbValue value) {
|
||||
GB_ASSERT(lb_is_const(ptr));
|
||||
GB_ASSERT(lb_is_const(value));
|
||||
GB_ASSERT(is_type_pointer(ptr.type));
|
||||
LLVMSetInitializer(ptr.value, value.value);
|
||||
}
|
||||
|
||||
void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) {
|
||||
GB_ASSERT(value.value != nullptr);
|
||||
Type *a = type_deref(ptr.type);
|
||||
|
||||
@@ -554,7 +554,6 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
|
||||
lbValue index = lb_const_int(m, t_int, i);
|
||||
lbValue type_info = lb_emit_ptr_offset(p, memory_types, index);
|
||||
|
||||
// TODO(bill): Make this constant if possible, 'lb_const_store' does not work
|
||||
lb_emit_store(p, type_info, lb_type_info(m, f->type));
|
||||
if (f->token.string.len > 0) {
|
||||
lbValue name = lb_emit_ptr_offset(p, memory_names, index);
|
||||
|
||||
Reference in New Issue
Block a user