authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-19 17:50:37-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-19 17:50:37-04:00
log3dbed54294bc6769f64fc8bd23b98605d009677c
tree526bd9f01b83185dad4bbf91b5a238c43d6aa7a9
parent07c5e906010e85d7e6560dc3ed398d7e4b284ec0
signaturelock-open Commit is signed but in an unrecognized format.

fix @bitCast of packed struct literal

closes #3042

2 files changed, 11 insertions(+), 0 deletions(-)

src/ir.cpp+3
......@@ -14802,6 +14802,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1480214802 return ira->codegen->invalid_instruction;
1480314803 }
1480414804 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
14805 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
14806 return ira->codegen->invalid_instruction;
14807 }
1480514808 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
1480614809 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
1480714810 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
test/stage1/behavior/bitcast.zig+8
......@@ -131,3 +131,11 @@ test "bitcast literal [4]u8 param to u32" {
131131 const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });
132132 expect(ip == maxInt(u32));
133133}
134
135test "bitcast packed struct literal to byte" {
136 const Foo = packed struct {
137 value: u8,
138 };
139 const casted = @bitCast(u8, Foo{ .value = 0xF });
140 expect(casted == 0xf);
141}