zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9d3363fee9314815b9afc55c20cfde92f38e2575 (tree)
parent 508294e9be2173b47c2e4d2fb1c52c41fcfcbc1c
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 26 Jul 2023 18:02:26 -0700

add behavior test for bitcast packed struct twice

closes #9914

Diffstat:
Mtest/behavior/packed-struct.zig | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig @@ -640,3 +640,13 @@ test "store undefined to packed result location" { var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; try expectEqual(x, s.x); } + +test "bitcast back and forth" { + // Originally reported at https://github.com/ziglang/zig/issues/9914 + const S = packed struct { one: u6, two: u1 }; + const s = S{ .one = 0b110101, .two = 0b1 }; + const u: u7 = @bitCast(s); + const s2: S = @bitCast(u); + try expect(s.one == s2.one); + try expect(s.two == s2.two); +}