diff --git a/src/Compilation.zig b/src/Compilation.zig index 00b691f780c472d068e88a2e62abc3d648196a0a..f11f158e1b9697499ff4b169b8bfba9365946d51 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -5265,7 +5265,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca if (comp.bin_file.options.is_test) { try buffer.appendSlice( - \\pub var test_functions: []std.builtin.TestFn = undefined; // overwritten later + \\pub var test_functions: []const std.builtin.TestFn = undefined; // overwritten later \\ ); if (comp.test_evented_io) { diff --git a/src/Module.zig b/src/Module.zig index 27f7b24e7a06af5f5233c5df9944e2c763e85d7c..8460c243d707ec7768d5264a694790aaa06e6538 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -6439,19 +6439,25 @@ pub fn populateTestFunctions( errdefer new_decl_arena.deinit(); const arena = new_decl_arena.allocator(); - // This copy accesses the old Decl Type/Value so it must be done before `clearValues`. - const new_ty = try Type.Tag.const_slice.create(arena, try tmp_test_fn_ty.copy(arena)); - const new_val = try Value.Tag.slice.create(arena, .{ - .ptr = try Value.Tag.decl_ref.create(arena, array_decl_index), - .len = try Value.Tag.int_u64.create(arena, mod.test_functions.count()), - }); + { + // This copy accesses the old Decl Type/Value so it must be done before `clearValues`. + const new_ty = try Type.Tag.const_slice.create(arena, try tmp_test_fn_ty.copy(arena)); + const new_var = try gpa.create(Var); + errdefer gpa.destroy(new_var); + new_var.* = decl.val.castTag(.variable).?.data.*; + new_var.init = try Value.Tag.slice.create(arena, .{ + .ptr = try Value.Tag.decl_ref.create(arena, array_decl_index), + .len = try Value.Tag.int_u64.create(arena, mod.test_functions.count()), + }); + const new_val = try Value.Tag.variable.create(arena, new_var); - // Since we are replacing the Decl's value we must perform cleanup on the - // previous value. - decl.clearValues(mod); - decl.ty = new_ty; - decl.val = new_val; - decl.has_tv = true; + // Since we are replacing the Decl's value we must perform cleanup on the + // previous value. + decl.clearValues(mod); + decl.ty = new_ty; + decl.val = new_val; + decl.has_tv = true; + } try decl.finalizeNewArena(&new_decl_arena); } diff --git a/src/codegen/c/type.zig b/src/codegen/c/type.zig index 72ee89df7d43604896c68e79c8f07ab179c45f7b..892914ea3d1aa1c3dd91bfb8b4a006462e8f42d4 100644 --- a/src/codegen/c/type.zig +++ b/src/codegen/c/type.zig @@ -1720,17 +1720,7 @@ pub const CType = extern union { } else self.init(.anon_struct); }, - .Opaque => switch (ty.tag()) { - .anyopaque => self.init(.void), - .@"opaque" => { - self.storage = .{ .fwd = .{ - .base = .{ .tag = .fwd_struct }, - .data = ty.getOwnerDecl(), - } }; - self.value = .{ .cty = initPayload(&self.storage.fwd) }; - }, - else => unreachable, - }, + .Opaque => self.init(.void), .Fn => { const info = ty.fnInfo(); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index d3cd6918f57f66a55e4fe20cbbb4e4e3486fdf18..c2e47d7334441c91531df1302e69d784b97aad16 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -774,6 +774,7 @@ test "extern variable with non-pointer opaque type" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO @export(var_to_export, .{ .name = "opaque_extern_var" }); try expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);