authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-15 16:50:20+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-16 01:12:28+02:00
logfb09093d95f2dc9bf454ba0d1d489316311adffc
treed033652857b160b2862c935fbd498a9f5aa7dfec
parent2cfa7165e715321dffea21380d4fde0dd5079925

Module: call `ensureDeclAnalyzed` on `builtin.test_functions`

Previously the compiler would crash on branching on undefined values if you tried using `zig test` with a freestanding target since there was no start code referencing `builtin.test_functions`. Closes #12554

2 files changed, 16 insertions(+), 2 deletions(-)

src/Compilation.zig+1-1
......@@ -2361,7 +2361,7 @@ pub fn update(comp: *Compilation) !void {
23612361 // The `test_functions` decl has been intentionally postponed until now,
23622362 // at which point we must populate it with the list of test functions that
23632363 // have been discovered and not filtered out.
2364 try module.populateTestFunctions();
2364 try module.populateTestFunctions(main_progress_node);
23652365 }
23662366
23672367 // Process the deletion set. We use a while loop here because the
src/Module.zig+15-1
......@@ -6431,13 +6431,27 @@ pub fn processExports(mod: *Module) !void {
64316431 }
64326432}
64336433
6434pub fn populateTestFunctions(mod: *Module) !void {
6434pub fn populateTestFunctions(
6435 mod: *Module,
6436 main_progress_node: *std.Progress.Node,
6437) !void {
64356438 const gpa = mod.gpa;
64366439 const builtin_pkg = mod.main_pkg.table.get("builtin").?;
64376440 const builtin_file = (mod.importPkg(builtin_pkg) catch unreachable).file;
64386441 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
64396442 const builtin_namespace = root_decl.src_namespace;
64406443 const decl_index = builtin_namespace.decls.getKeyAdapted(@as([]const u8, "test_functions"), DeclAdapter{ .mod = mod }).?;
6444 {
6445 // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions`
6446 // was not referenced by start code.
6447 mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
6448 mod.sema_prog_node.activate();
6449 defer {
6450 mod.sema_prog_node.end();
6451 mod.sema_prog_node = undefined;
6452 }
6453 try mod.ensureDeclAnalyzed(decl_index);
6454 }
64416455 const decl = mod.declPtr(decl_index);
64426456 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
64436457 const tmp_test_fn_ty = decl.ty.slicePtrFieldType(&buf).elemType();