authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-13 20:24:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-13 20:24:10-04:00
logeaf74f4f96f5a6c864dec9ada47eba067b699881
tree481c15c37632398a8b552c25ddefa4906012d9c6
parent57347aacd72dba0f5843e582f414f71f434a4d6f
signaturelock-open Commit is signed but in an unrecognized format.

fix bitcast packed struct to integer and back


2 files changed, 18 insertions(+), 20 deletions(-)

src/ir.cpp+1-3
......@@ -23254,9 +23254,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2325423254 return result;
2325523255 }
2325623256
23257 IrInstruction *result = ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
23258 ir_assert(!(handle_is_ptr(dest_type) && !handle_is_ptr(src_type)), source_instr);
23259 return result;
23257 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
2326023258}
2326123259
2326223260static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
test/stage1/behavior/bitcast.zig+17-17
......@@ -95,20 +95,20 @@ test "@bitCast extern structs at runtime and comptime" {
9595 comptime S.doTheTest();
9696}
9797
98//test "bitcast packed struct to integer and back" {
99// const LevelUpMove = packed struct {
100// move_id: u9,
101// level: u7,
102// };
103// const S = struct {
104// fn doTheTest() void {
105// var move = LevelUpMove{ .move_id = 1, .level = 2 };
106// var v = @bitCast(u16, move);
107// var back_to_a_move = @bitCast(LevelUpMove, v);
108// expect(back_to_a_move.move_id == 1);
109// expect(back_to_a_move.level == 2);
110// }
111// };
112// S.doTheTest();
113// comptime S.doTheTest();
114//}
98test "bitcast packed struct to integer and back" {
99 const LevelUpMove = packed struct {
100 move_id: u9,
101 level: u7,
102 };
103 const S = struct {
104 fn doTheTest() void {
105 var move = LevelUpMove{ .move_id = 1, .level = 2 };
106 var v = @bitCast(u16, move);
107 var back_to_a_move = @bitCast(LevelUpMove, v);
108 expect(back_to_a_move.move_id == 1);
109 expect(back_to_a_move.level == 2);
110 }
111 };
112 S.doTheTest();
113 comptime S.doTheTest();
114}