Skip to content

Commit a1fcb51

Browse files
committed
cbe: fix mutability issues with builtin test_functions
1 parent f1782c0 commit a1fcb51

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

src/Compilation.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)