@@ -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;
@@ -613,13 +614,16 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl
613614 // generate definition to c file
614615 if (!d.isExported() && !emit_header) out.add("static ");
615616 gen.emitGlobalVarDeclCommon(out, d);
616- out.add(" = ");
617617 Expr* ie = vd.getInit();
618618 if (ie) {
619+ out.add(" = ");
619620 gen.emitConstExpr(out, ie, Assignment);
620621 } else {
621622 // auto-initialize (only required for embedded targets)
622- gen.emitAutoInit(out, d.getType());
623+ if (gen.force_initializers) {
624+ out.add(" = ");
625+ gen.emitAutoInit(out, d.getType());
626+ }
623627 }
624628 out.add(";\n");
625629 }
@@ -1293,6 +1297,7 @@ public fn void generate(string_pool.Pool* astPool,
12931297 Decl* mainFunc,
12941298 string_list.List* asm_files,
12951299 bool enable_asserts,
1300+ bool force_initializers,
12961301 bool fast_build, bool asan, bool msan, bool ubsan,
12971302 bool test_mode, bool trace_calls)
12981303{
@@ -1307,6 +1312,7 @@ public fn void generate(string_pool.Pool* astPool,
13071312 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
13081313 gen.auxPool = auxPool;
13091314 gen.enable_asserts = enable_asserts;
1315+ gen.force_initializers = force_initializers;
13101316 gen.fast_build = fast_build;
13111317 gen.asan = asan;
13121318 gen.msan = msan;
0 commit comments