commit 8a0429e885489eac497aa97fdfcaaa1befb2b6d4 (tree) parent 20abf1394aef44eb1882e801f1d729fcff452db3 Author: Meghan Denny <hello@nektro.net> Date: Fri, 26 Jan 2024 05:26:37 -0800 test: add behavior coverage for global setter in function liveness Diffstat:
| M | test/behavior/globals.zig | | | 26 | ++++++++++++++++++++++++++ |
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/test/behavior/globals.zig b/test/behavior/globals.zig @@ -46,3 +46,29 @@ test "slices pointing at the same address as global array." { try S.checkAddress(&S.a); try comptime S.checkAddress(&S.a); } + +test "global loads can affect liveness" { + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const S = struct { + const ByRef = struct { + a: u32, + }; + + var global_ptr: *ByRef = undefined; + + fn f() void { + global_ptr.* = .{ .a = 42 }; + } + }; + + var x: S.ByRef = .{ .a = 1 }; + S.global_ptr = &x; + const y = x; + S.f(); + try std.testing.expect(y.a == 1); +}