diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-16 11:47:57 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-16 11:52:22 -0700 |
| commit | 1f313b3d7c757a8cdc5a52a1986f0f694b7ffc5f (patch) | |
| tree | 3a39c4523a700af4d2264e2eb3483f51bd010a25 /test/behavior/struct.zig | |
| parent | dd55b7294946cf1982815518422a007b19438d71 (diff) | |
| download | zig-1f313b3d7c757a8cdc5a52a1986f0f694b7ffc5f.tar.gz zig-1f313b3d7c757a8cdc5a52a1986f0f694b7ffc5f.zip | |
LLVM: make the load function copy isByRef=true types
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 8383b81cd5..1d52900796 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1290,3 +1290,29 @@ test "initialize struct with empty literal" { var s: S = .{}; try expect(s.x == 1234); } + +test "loading a struct pointer perfoms a copy" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const S = struct { + a: i32, + b: i32, + c: i32, + + fn swap(a: *@This(), b: *@This()) void { + const tmp = a.*; + a.* = b.*; + b.* = tmp; + } + }; + var s1: S = .{ .a = 1, .b = 2, .c = 3 }; + var s2: S = .{ .a = 4, .b = 5, .c = 6 }; + S.swap(&s1, &s2); + try expect(s1.a == 4); + try expect(s1.b == 5); + try expect(s1.c == 6); + try expect(s2.a == 1); + try expect(s2.b == 2); + try expect(s2.c == 3); +} |
