@@ -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 }
@@ -1285,6 +1289,7 @@ public fn void generate(string_pool.Pool* astPool,
12851289 Decl* mainFunc,
12861290 string_list.List* asm_files,
12871291 bool enable_asserts,
1292+ bool force_initializers,
12881293 bool fast_build, bool asan, bool msan, bool ubsan,
12891294 bool test_mode, bool trace_calls)
12901295{
@@ -1299,6 +1304,7 @@ public fn void generate(string_pool.Pool* astPool,
12991304 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
13001305 gen.auxPool = auxPool;
13011306 gen.enable_asserts = enable_asserts;
1307+ gen.force_initializers = force_initializers;
13021308 gen.fast_build = fast_build;
13031309 gen.asan = asan;
13041310 gen.msan = msan;
0 commit comments