authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-26 18:02:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-26 19:02:02-07:00
log9d3363fee9314815b9afc55c20cfde92f38e2575
treed3ae6697031508d12b5b9ead0ce79f7b176adfaa
parent508294e9be2173b47c2e4d2fb1c52c41fcfcbc1c

add behavior test for bitcast packed struct twice

closes #9914

1 files changed, 10 insertions(+), 0 deletions(-)

test/behavior/packed-struct.zig+10
......@@ -640,3 +640,13 @@ test "store undefined to packed result location" {
640640 var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined };
641641 try expectEqual(x, s.x);
642642}
643
644test "bitcast back and forth" {
645 // Originally reported at https://github.com/ziglang/zig/issues/9914
646 const S = packed struct { one: u6, two: u1 };
647 const s = S{ .one = 0b110101, .two = 0b1 };
648 const u: u7 = @bitCast(s);
649 const s2: S = @bitCast(u);
650 try expect(s.one == s2.one);
651 try expect(s.two == s2.two);
652}