authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-25 01:08:35-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-25 13:42:10-04:00
loga1fcb516928d1ba1106ea715acd1f6feba95e977
tree6449fdb37a56b6ceda045b91babffa41bc6f0bd2
parentf1782c07a9c1c66da843e6c7f345e9f004bc3b45

cbe: fix mutability issues with builtin test_functions


4 files changed, 21 insertions(+), 24 deletions(-)

src/Compilation.zig+1-1
......@@ -5265,7 +5265,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
52655265
52665266 if (comp.bin_file.options.is_test) {
52675267 try buffer.appendSlice(
5268 \\pub var test_functions: []std.builtin.TestFn = undefined; // overwritten later
5268 \\pub var test_functions: []const std.builtin.TestFn = undefined; // overwritten later
52695269 \\
52705270 );
52715271 if (comp.test_evented_io) {
src/Module.zig+18-12
......@@ -6439,19 +6439,25 @@ pub fn populateTestFunctions(
64396439 errdefer new_decl_arena.deinit();
64406440 const arena = new_decl_arena.allocator();
64416441
6442 // This copy accesses the old Decl Type/Value so it must be done before `clearValues`.
6443 const new_ty = try Type.Tag.const_slice.create(arena, try tmp_test_fn_ty.copy(arena));
6444 const new_val = try Value.Tag.slice.create(arena, .{
6445 .ptr = try Value.Tag.decl_ref.create(arena, array_decl_index),
6446 .len = try Value.Tag.int_u64.create(arena, mod.test_functions.count()),
6447 });
6442 {
6443 // This copy accesses the old Decl Type/Value so it must be done before `clearValues`.
6444 const new_ty = try Type.Tag.const_slice.create(arena, try tmp_test_fn_ty.copy(arena));
6445 const new_var = try gpa.create(Var);
6446 errdefer gpa.destroy(new_var);
6447 new_var.* = decl.val.castTag(.variable).?.data.*;
6448 new_var.init = try Value.Tag.slice.create(arena, .{
6449 .ptr = try Value.Tag.decl_ref.create(arena, array_decl_index),
6450 .len = try Value.Tag.int_u64.create(arena, mod.test_functions.count()),
6451 });
6452 const new_val = try Value.Tag.variable.create(arena, new_var);
64486453
6449 // Since we are replacing the Decl's value we must perform cleanup on the
6450 // previous value.
6451 decl.clearValues(mod);
6452 decl.ty = new_ty;
6453 decl.val = new_val;
6454 decl.has_tv = true;
6454 // Since we are replacing the Decl's value we must perform cleanup on the
6455 // previous value.
6456 decl.clearValues(mod);
6457 decl.ty = new_ty;
6458 decl.val = new_val;
6459 decl.has_tv = true;
6460 }
64556461
64566462 try decl.finalizeNewArena(&new_decl_arena);
64576463 }
src/codegen/c/type.zig+1-11
......@@ -1720,17 +1720,7 @@ pub const CType = extern union {
17201720 } else self.init(.anon_struct);
17211721 },
17221722
1723 .Opaque => switch (ty.tag()) {
1724 .anyopaque => self.init(.void),
1725 .@"opaque" => {
1726 self.storage = .{ .fwd = .{
1727 .base = .{ .tag = .fwd_struct },
1728 .data = ty.getOwnerDecl(),
1729 } };
1730 self.value = .{ .cty = initPayload(&self.storage.fwd) };
1731 },
1732 else => unreachable,
1733 },
1723 .Opaque => self.init(.void),
17341724
17351725 .Fn => {
17361726 const info = ty.fnInfo();
test/behavior/basic.zig+1
......@@ -774,6 +774,7 @@ test "extern variable with non-pointer opaque type" {
774774 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
775775 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
776776 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
777 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
777778
778779 @export(var_to_export, .{ .name = "opaque_extern_var" });
779780 try expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);