diff options
| author | Meghan Denny <hello@nektro.net> | 2024-01-26 05:26:37 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-26 15:26:37 +0200 |
| commit | 8a0429e885489eac497aa97fdfcaaa1befb2b6d4 (patch) | |
| tree | 92dcb672fba5cd8971675917cd12449ab031fcd0 /test/behavior | |
| parent | 20abf1394aef44eb1882e801f1d729fcff452db3 (diff) | |
| download | zig-8a0429e885489eac497aa97fdfcaaa1befb2b6d4.tar.gz zig-8a0429e885489eac497aa97fdfcaaa1befb2b6d4.zip | |
test: add behavior coverage for global setter in function liveness
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/globals.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/behavior/globals.zig b/test/behavior/globals.zig index 46d9610ed6..25968ba424 100644 --- 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); +} |
