|
@@ -13460,7 +13460,6 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
|
default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break;
|
|
default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break;
|
|
|
|
|
|
case Type_Struct: {
|
|
case Type_Struct: {
|
|
-
|
|
|
|
// TODO(bill): "constant" '#raw_union's are not initialized constantly at the moment.
|
|
// 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
|
|
// 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);
|
|
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);
|
|
GB_ASSERT(e->kind == Entity_Variable);
|
|
e->code_gen_module = entity_module;
|
|
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);
|
|
LLVMValueKind value_kind = LLVMGetValueKind(init.value);
|
|
// gb_printf_err("%s %d\n", LLVMPrintValueToString(init.value));
|
|
// gb_printf_err("%s %d\n", LLVMPrintValueToString(init.value));
|
|
|
|
|