@@ -74,6 +74,7 @@ type Generator struct {
7474 const build_file.Info* build_info;
7575 const target_info.Info* targetInfo;
7676 bool enable_asserts;
77+ bool force_initializers;
7778 bool fast_build;
7879 bool asan;
7980 bool msan;
@@ -612,13 +613,16 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl
612613 // generate definition to c file
613614 if (!d.isExported() && !emit_header) out.add("static ");
614615 gen.emitGlobalVarDeclCommon(out, d);
615- out.add(" = ");
616616 Expr* ie = vd.getInit();
617617 if (ie) {
618+ out.add(" = ");
618619 gen.emitConstExpr(out, ie, Assignment);
619620 } else {
620621 // auto-initialize (only required for embedded targets)
621- gen.emitAutoInit(out, d.getType());
622+ if (gen.force_initializers) {
623+ out.add(" = ");
624+ gen.emitAutoInit(out, d.getType());
625+ }
622626 }
623627 out.add(";\n");
624628 }
@@ -1284,6 +1288,7 @@ public fn void generate(string_pool.Pool* astPool,
12841288 Decl* mainFunc,
12851289 string_list.List* asm_files,
12861290 bool enable_asserts,
1291+ bool force_initializers,
12871292 bool fast_build, bool asan, bool msan, bool ubsan,
12881293 bool test_mode, bool trace_calls)
12891294{
@@ -1298,6 +1303,7 @@ public fn void generate(string_pool.Pool* astPool,
12981303 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
12991304 gen.auxPool = auxPool;
13001305 gen.enable_asserts = enable_asserts;
1306+ gen.force_initializers = force_initializers;
13011307 gen.fast_build = fast_build;
13021308 gen.asan = asan;
13031309 gen.msan = msan;
0 commit comments