diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 6eec9103b..7a8f57fdd 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -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; } diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 65cc8c41d..8458d8687 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -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); diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp index d424fa5b2..c29713881 100644 --- a/src/llvm_backend_type.cpp +++ b/src/llvm_backend_type.cpp @@ -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);