| ... | @@ -46,3 +46,29 @@ test "slices pointing at the same address as global array." { | ... | @@ -46,3 +46,29 @@ test "slices pointing at the same address as global array." { |
| 46 | try S.checkAddress(&S.a); | 46 | try S.checkAddress(&S.a); |
| 47 | try comptime S.checkAddress(&S.a); | 47 | try comptime S.checkAddress(&S.a); |
| 48 | } | 48 | } |
| | 49 | |
| | 50 | test "global loads can affect liveness" { |
| | 51 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; |
| | 52 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| | 53 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| | 54 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| | 55 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 56 | |
| | 57 | const S = struct { |
| | 58 | const ByRef = struct { |
| | 59 | a: u32, |
| | 60 | }; |
| | 61 | |
| | 62 | var global_ptr: *ByRef = undefined; |
| | 63 | |
| | 64 | fn f() void { |
| | 65 | global_ptr.* = .{ .a = 42 }; |
| | 66 | } |
| | 67 | }; |
| | 68 | |
| | 69 | var x: S.ByRef = .{ .a = 1 }; |
| | 70 | S.global_ptr = &x; |
| | 71 | const y = x; |
| | 72 | S.f(); |
| | 73 | try std.testing.expect(y.a == 1); |
| | 74 | } |