mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
test: add behavior coverage for global setter in function liveness
This commit is contained in:
parent
20abf1394a
commit
8a0429e885
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user