From d2f9646d98615d85589d2c46237559d1249f2765 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 28 Oct 2021 15:59:14 -0700 Subject: C backend: fix enough that zig test works * test_functions: properly add dependencies of the array on test functions and test names so that the order comes out correctly. * fix lowering of struct literals to add parentheses around the type name. * omit const qualifier in slices because otherwise slices cannot be reassigned even when they are local variables. * special case pointer to functions and double pointer to functions in renderTypeAndName. This code will need to be cleaned up but for now it helps us make progress on other C backend stuff. * fix slice element access to lower to `.ptr[` instead of `[`. * airSliceElemVal: respect volatile slices --- src/Module.zig | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index f0b3701e6e..1f394a0833 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4734,6 +4734,10 @@ pub fn populateTestFunctions(mod: *Module) !void { }), .val = try Value.Tag.array.create(arena, test_fn_vals), }); + + // Add a dependency on each test name and function pointer. + try array_decl.dependencies.ensureUnusedCapacity(gpa, test_fn_vals.len * 2); + for (mod.test_functions.keys()) |test_decl, i| { const test_name_slice = mem.sliceTo(test_decl.name, 0); const test_name_decl = n: { @@ -4747,6 +4751,8 @@ pub fn populateTestFunctions(mod: *Module) !void { try test_name_decl.finalizeNewArena(&name_decl_arena); break :n test_name_decl; }; + array_decl.dependencies.putAssumeCapacityNoClobber(test_decl, {}); + array_decl.dependencies.putAssumeCapacityNoClobber(test_name_decl, {}); try mod.linkerUpdateDecl(test_name_decl); const field_vals = try arena.create([3]Value); -- cgit v1.2.3