Skip to content

Commit 73dd12e

Browse files
Zero initialize var declarations for structs/arrays.
1 parent d13b240 commit 73dd12e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

bootstrap/stage0.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,7 +3280,7 @@ std_map_Map__7 *std_map_Map__7_new(void) {
32803280
}
32813281

32823282
std_span_Location std_span_Location_default(void) {
3283-
std_span_Location loc;
3283+
std_span_Location loc = {0};
32843284
loc.filename="<default>";
32853285
loc.line=((u32)0);
32863286
loc.col=((u32)0);
@@ -3297,7 +3297,7 @@ bool std_span_Location_is_valid(std_span_Location *this) {
32973297
}
32983298

32993299
std_span_Span std_span_Span_default(void) {
3300-
std_span_Span span;
3300+
std_span_Span span = {0};
33013301
span.start=(std_span_Location){.filename="<default>", .line=((u32)0), .col=((u32)0), .index=((u32)0)};
33023302
span.end=(std_span_Location){.filename="<default>", .line=((u32)0), .col=((u32)0), .index=((u32)0)};
33033303
return span;
@@ -3308,7 +3308,7 @@ bool std_span_Span_is_valid(std_span_Span this) {
33083308
}
33093309

33103310
std_span_Span std_span_Span_join(std_span_Span this, std_span_Span other) {
3311-
std_span_Span span;
3311+
std_span_Span span = {0};
33123312
span.start=this.start;
33133313
span.end=other.end;
33143314
return span;
@@ -7598,6 +7598,15 @@ void passes_code_generator_CodeGenerator_gen_var_declaration(passes_code_generat
75987598
if (((bool)node->u.var_decl.init)) {
75997599
std_buffer_Buffer_puts(&this->out, " = ");
76007600
passes_code_generator_CodeGenerator_gen_expression(this, node->u.var_decl.init);
7601+
} else {
7602+
switch (var->type->base) {
7603+
case types_BaseType_Array:
7604+
case types_BaseType_Structure: {
7605+
std_buffer_Buffer_puts(&this->out, " = {0}");
7606+
} break;
7607+
default: {
7608+
} break;
7609+
}
76017610
}
76027611
}
76037612

@@ -7971,7 +7980,7 @@ char *passes_code_generator_CodeGenerator_helper_gen_type(passes_code_generator_
79717980
}
79727981

79737982
char *passes_code_generator_CodeGenerator_get_type_name_string(passes_code_generator_CodeGenerator *this, types_Type *type, char *name, bool is_func_def) {
7974-
ae_assert((type != NULL), "compiler/passes/code_generator.oc:898:12: Assertion failed: `type != null`", NULL); char *final = passes_code_generator_CodeGenerator_helper_gen_type(this, type, type, strdup(name), is_func_def);
7983+
ae_assert((type != NULL), "compiler/passes/code_generator.oc:903:12: Assertion failed: `type != null`", NULL); char *final = passes_code_generator_CodeGenerator_helper_gen_type(this, type, type, strdup(name), is_func_def);
79757984
str_strip_trailing_whitespace(final);
79767985
return final;
79777986
}
@@ -8024,7 +8033,7 @@ void passes_code_generator_CodeGenerator_gen_functions(passes_code_generator_Cod
80248033
ast_scopes_TemplateInstance *instance = std_vector_Iterator__9_cur(&__iter);
80258034
{
80268035
ast_scopes_Symbol *sym = instance->resolved;
8027-
ae_assert(sym->type==ast_scopes_SymbolType_Function, "compiler/passes/code_generator.oc:943:24: Assertion failed: `sym.type == Function`", NULL); ast_nodes_Function *func = sym->u.func;
8036+
ae_assert(sym->type==ast_scopes_SymbolType_Function, "compiler/passes/code_generator.oc:948:24: Assertion failed: `sym.type == Function`", NULL); ast_nodes_Function *func = sym->u.func;
80288037
passes_code_generator_CodeGenerator_gen_function(this, func);
80298038
}
80308039
}
@@ -8060,7 +8069,7 @@ void passes_code_generator_CodeGenerator_gen_function_decls(passes_code_generato
80608069
ast_scopes_TemplateInstance *instance = std_vector_Iterator__9_cur(&__iter);
80618070
{
80628071
ast_scopes_Symbol *sym = instance->resolved;
8063-
ae_assert(sym->type==ast_scopes_SymbolType_Function, "compiler/passes/code_generator.oc:970:24: Assertion failed: `sym.type == Function`", NULL); ast_nodes_Function *func = sym->u.func;
8072+
ae_assert(sym->type==ast_scopes_SymbolType_Function, "compiler/passes/code_generator.oc:975:24: Assertion failed: `sym.type == Function`", NULL); ast_nodes_Function *func = sym->u.func;
80648073
if (func->is_dead)
80658074
continue;
80668075

compiler/passes/code_generator.oc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ def CodeGenerator::gen_var_declaration(&this, node: &AST) {
530530
if node.u.var_decl.init? {
531531
.out.puts(" = ")
532532
.gen_expression(node.u.var_decl.init)
533+
} else {
534+
match var.type.base {
535+
Array | Structure => .out.puts(" = {0}")
536+
else => {}
537+
}
533538
}
534539
}
535540

0 commit comments

Comments
 (0)