diff options
| author | gingerBill <bill@gingerbill.org> | 2022-08-12 12:29:11 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-08-12 12:29:11 +0100 |
| commit | 697c839c84b36b4e0c12ac9ea264e28f564ef5d5 (patch) | |
| tree | d937f261c4d354b61c3e3874f429eae67338b8e9 /src/llvm_backend.cpp | |
| parent | de8bd88d2a6f0e99af6fe76442bcccd159724872 (diff) | |
Correct global constant procedure initialization
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
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; } |