@@ -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;
@@ -615,13 +616,16 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl
615616 // generate definition to c file
616617 if (!d.isExported() && !emit_header) out.add("static ");
617618 gen.emitGlobalVarDeclCommon(out, d);
618- out.add(" = ");
619619 Expr* ie = vd.getInit();
620620 if (ie) {
621+ out.add(" = ");
621622 gen.emitConstExpr(out, ie, Assignment);
622623 } else {
623624 // auto-initialize (only required for embedded targets)
624- gen.emitAutoInit(out, d.getType());
625+ if (gen.force_initializers) {
626+ out.add(" = ");
627+ gen.emitAutoInit(out, d.getType());
628+ }
625629 }
626630 out.add(";\n");
627631 }
@@ -1287,6 +1291,7 @@ public fn void generate(string_pool.Pool* astPool,
12871291 Decl* mainFunc,
12881292 string_list.List* asm_files,
12891293 bool enable_asserts,
1294+ bool force_initializers,
12901295 bool fast_build, bool asan, bool msan, bool ubsan,
12911296 bool test_mode, bool trace_calls)
12921297{
@@ -1301,6 +1306,7 @@ public fn void generate(string_pool.Pool* astPool,
13011306 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
13021307 gen.auxPool = auxPool;
13031308 gen.enable_asserts = enable_asserts;
1309+ gen.force_initializers = force_initializers;
13041310 gen.fast_build = fast_build;
13051311 gen.asan = asan;
13061312 gen.msan = msan;
0 commit comments