@@ -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;
@@ -604,13 +605,16 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl
604605 // generate definition to c file
605606 if (!d.isExported() && !emit_header) out.add("static ");
606607 gen.emitGlobalVarDeclCommon(out, d);
607- out.add(" = ");
608608 Expr* ie = vd.getInit();
609609 if (ie) {
610+ out.add(" = ");
610611 gen.emitConstExpr(out, ie);
611612 } else {
612613 // auto-initialize (only required for embedded targets)
613- gen.emitAutoInit(out, d.getType());
614+ if (gen.force_initializers) {
615+ out.add(" = ");
616+ gen.emitAutoInit(out, d.getType());
617+ }
614618 }
615619 out.add(";\n\n");
616620 }
@@ -1263,6 +1267,7 @@ public fn void generate(string_pool.Pool* astPool,
12631267 Decl* mainFunc,
12641268 string_list.List* asm_files,
12651269 bool enable_asserts,
1270+ bool force_initializers,
12661271 bool fast_build, bool asan, bool msan, bool ubsan,
12671272 bool test_mode, bool trace_calls)
12681273{
@@ -1277,6 +1282,7 @@ public fn void generate(string_pool.Pool* astPool,
12771282 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
12781283 gen.auxPool = auxPool;
12791284 gen.enable_asserts = enable_asserts;
1285+ gen.force_initializers = force_initializers;
12801286 gen.fast_build = fast_build;
12811287 gen.asan = asan;
12821288 gen.msan = msan;
0 commit comments