fix bitcast packed struct to integer and back

This commit is contained in:
Andrew Kelley 2019-06-13 20:24:10 -04:00
parent 57347aacd7
commit eaf74f4f96
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 18 additions and 20 deletions

View File

@ -23254,9 +23254,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
return result;
}
IrInstruction *result = ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
ir_assert(!(handle_is_ptr(dest_type) && !handle_is_ptr(src_type)), source_instr);
return result;
return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
}
static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,

View File

@ -95,20 +95,20 @@ test "@bitCast extern structs at runtime and comptime" {
comptime S.doTheTest();
}
//test "bitcast packed struct to integer and back" {
// const LevelUpMove = packed struct {
// move_id: u9,
// level: u7,
// };
// const S = struct {
// fn doTheTest() void {
// var move = LevelUpMove{ .move_id = 1, .level = 2 };
// var v = @bitCast(u16, move);
// var back_to_a_move = @bitCast(LevelUpMove, v);
// expect(back_to_a_move.move_id == 1);
// expect(back_to_a_move.level == 2);
// }
// };
// S.doTheTest();
// comptime S.doTheTest();
//}
test "bitcast packed struct to integer and back" {
const LevelUpMove = packed struct {
move_id: u9,
level: u7,
};
const S = struct {
fn doTheTest() void {
var move = LevelUpMove{ .move_id = 1, .level = 2 };
var v = @bitCast(u16, move);
var back_to_a_move = @bitCast(LevelUpMove, v);
expect(back_to_a_move.move_id == 1);
expect(back_to_a_move.level == 2);
}
};
S.doTheTest();
comptime S.doTheTest();
}