diff options
| author | gingerBill <bill@gingerbill.org> | 2021-06-26 23:31:04 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-06-26 23:31:04 +0100 |
| commit | a779cb2798c374caa54a350ef3091787894329c1 (patch) | |
| tree | e4186802a7f6eebf36b7aa804110d165fc578b89 /src/llvm_backend.cpp | |
| parent | 5e42675b425e0deb3f6bb99911c6655b28438a50 (diff) | |
Fix #1044
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index a9a9ad0ac..129263ecd 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -13460,7 +13460,6 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break; case Type_Struct: { - // TODO(bill): "constant" '#raw_union's are not initialized constantly at the moment. // NOTE(bill): This is due to the layout of the unions when printed to LLVM-IR bool is_raw_union = is_type_raw_union(bt); @@ -15048,9 +15047,23 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start GB_ASSERT(e->kind == Entity_Variable); e->code_gen_module = entity_module; - if (var->decl->init_expr != nullptr) { - // gb_printf_err("%s\n", expr_to_string(var->decl->init_expr)); - lbValue init = lb_build_expr(p, var->decl->init_expr); + Ast *init_expr = var->decl->init_expr; + if (init_expr != nullptr) { + lbValue init = lb_build_expr(p, init_expr); + if (init.value == nullptr) { + LLVMTypeRef global_type = LLVMGetElementType(LLVMTypeOf(var->var.value)); + if (is_type_untyped_undef(init.type)) { + LLVMSetInitializer(var->var.value, LLVMGetUndef(global_type)); + var->is_initialized = true; + continue; + } else if (is_type_untyped_nil(init.type)) { + LLVMSetInitializer(var->var.value, LLVMConstNull(global_type)); + var->is_initialized = true; + continue; + } + GB_PANIC("Invalid init value, got %s", expr_to_string(init_expr)); + } + LLVMValueKind value_kind = LLVMGetValueKind(init.value); // gb_printf_err("%s %d\n", LLVMPrintValueToString(init.value)); |