@@ -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;
@@ -610,13 +611,16 @@ fn bool Generator.emitGlobalVarDecl(Generator* gen, string_buffer.Buf* out, Decl
610611 // generate definition to c file
611612 if (!d.isExported() && !emit_header) out.add("static ");
612613 gen.emitGlobalVarDeclCommon(out, d);
613- out.add(" = ");
614614 Expr* ie = vd.getInit();
615615 if (ie) {
616+ out.add(" = ");
616617 gen.emitConstExpr(out, ie, Assignment);
617618 } else {
618619 // auto-initialize (only required for embedded targets)
619- gen.emitAutoInit(out, d.getType());
620+ if (gen.force_initializers) {
621+ out.add(" = ");
622+ gen.emitAutoInit(out, d.getType());
623+ }
620624 }
621625 out.add(";\n");
622626 }
@@ -1272,6 +1276,7 @@ public fn void generate(string_pool.Pool* astPool,
12721276 Decl* mainFunc,
12731277 string_list.List* asm_files,
12741278 bool enable_asserts,
1279+ bool force_initializers,
12751280 bool fast_build, bool asan, bool msan, bool ubsan,
12761281 bool test_mode, bool trace_calls)
12771282{
@@ -1286,6 +1291,7 @@ public fn void generate(string_pool.Pool* astPool,
12861291 gen.init(astPool, target, kind, output_dir, dir, diags, sm, build_info, mainFunc);
12871292 gen.auxPool = auxPool;
12881293 gen.enable_asserts = enable_asserts;
1294+ gen.force_initializers = force_initializers;
12891295 gen.fast_build = fast_build;
12901296 gen.asan = asan;
12911297 gen.msan = msan;
0 commit comments