@@ -75,6 +75,7 @@ type Generator struct {
7575 const build_file.Info* build_info;
7676 const target_info.Info* targetInfo;
7777 bool enable_asserts;
78+ bool force_initializers;
7879 bool fast_build;
7980 bool asan;
8081 bool msan;
@@ -605,13 +606,16 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl
605606 // generate definition to c file
606607 if (!d.isExported() && !emit_header) out.add("static ");
607608 gen.emitGlobalVarDeclCommon(out, d);
608- out.add(" = ");
609609 Expr* ie = vd.getInit();
610610 if (ie) {
611+ out.add(" = ");
611612 gen.emitConstExpr(out, ie, Assignment);
612613 } else {
613614 // auto-initialize (only required for embedded targets)
614- gen.emitAutoInit(out, d.getType());
615+ if (gen.force_initializers) {
616+ out.add(" = ");
617+ gen.emitAutoInit(out, d.getType());
618+ }
615619 }
616620 out.add(";\n");
617621 }
@@ -1264,6 +1268,7 @@ public fn void generate(string_pool.Pool* astPool,
12641268 Decl* mainFunc,
12651269 string_list.List* asm_files,
12661270 bool enable_asserts,
1271+ bool force_initializers,
12671272 bool fast_build, bool asan, bool msan, bool ubsan,
12681273 bool test_mode, bool trace_calls)
12691274{
@@ -1278,6 +1283,7 @@ public fn void generate(string_pool.Pool* astPool,
12781283 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
12791284 gen.auxPool = auxPool;
12801285 gen.enable_asserts = enable_asserts;
1286+ gen.force_initializers = force_initializers;
12811287 gen.fast_build = fast_build;
12821288 gen.asan = asan;
12831289 gen.msan = msan;
0 commit comments