diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-11-06 07:27:55 -0500 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-11-06 14:11:31 -0500 |
| commit | 9ced27dace99da1f2bc704b4d5a7fabe9a62eca4 (patch) | |
| tree | acaf279fce16c96e3efdd1fd2d648516264a9893 /test | |
| parent | 62e67a2b565e20f684319f5e59e1bddd79c988d3 (diff) | |
| download | zig-9ced27dace99da1f2bc704b4d5a7fabe9a62eca4.tar.gz zig-9ced27dace99da1f2bc704b4d5a7fabe9a62eca4.zip | |
x86_64: fix passing register-sized payload as non-reigster-sized union
Closes #17885
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/union.zig | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/behavior/union.zig b/test/behavior/union.zig index da36a34d1d..26e213fb16 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -1881,3 +1881,24 @@ test "union field is a pointer to an aligned version of itself" { try expect(&e == e.next); } + +test "pass register-sized field as non-register-sized union" { + const S = struct { + fn taggedUnion(u: union(enum) { x: usize, y: [2]usize }) !void { + try expectEqual(@as(usize, 42), u.x); + } + + fn untaggedUnion(u: union { x: usize, y: [2]usize }) !void { + try expectEqual(@as(usize, 42), u.x); + } + + fn externUnion(u: extern union { x: usize, y: [2]usize }) !void { + try expectEqual(@as(usize, 42), u.x); + } + }; + + var x: usize = 42; + try S.taggedUnion(.{ .x = x }); + try S.untaggedUnion(.{ .x = x }); + try S.externUnion(.{ .x = x }); +} |
