motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 3dbed54294bc6769f64fc8bd23b98605d009677c (tree)
parent 07c5e906010e85d7e6560dc3ed398d7e4b284ec0
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 19 Aug 2019 17:50:37 -0400

fix @bitCast of packed struct literal

closes #3042

Diffstat:
Msrc/ir.cpp | 3+++
Mtest/stage1/behavior/bitcast.zig | 8++++++++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/ir.cpp b/src/ir.cpp @@ -14802,6 +14802,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe return ira->codegen->invalid_instruction; } uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); + if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { + return ira->codegen->invalid_instruction; + } ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type, parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); diff --git a/test/stage1/behavior/bitcast.zig b/test/stage1/behavior/bitcast.zig @@ -131,3 +131,11 @@ test "bitcast literal [4]u8 param to u32" { const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 }); expect(ip == maxInt(u32)); } + +test "bitcast packed struct literal to byte" { + const Foo = packed struct { + value: u8, + }; + const casted = @bitCast(u8, Foo{ .value = 0xF }); + expect(casted == 0xf); +}