From 9d3363fee9314815b9afc55c20cfde92f38e2575 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 26 Jul 2023 18:02:26 -0700 Subject: [PATCH] add behavior test for bitcast packed struct twice closes #9914 --- test/behavior/packed-struct.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index e2970c3603..d3d761c3db 100644 --- 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); +}