test: add behavior coverage for global setter in function liveness

This commit is contained in:
Meghan Denny 2024-01-26 05:26:37 -08:00 committed by GitHub
parent 20abf1394a
commit 8a0429e885
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}