authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-18 11:31:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-18 11:31:05-04:00
log9050a07540b7387dade8184d3a3daf957e805e4f
tree61b0e83b961a8e5f7f13a0d4ec92f5b3730101fd
parent8ed88280a62f2a400d00b5ac20618539693dad36
signaturelock-open Commit is signed but in an unrecognized format.

when resolving slice types, might need to...

...resolve alignment if custom alignment is provided fixes #2689

2 files changed, 14 insertions(+), 1 deletions(-)

src/ir.cpp+3-1
...@@ -16794,7 +16794,9 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -16794,7 +16794,9 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
16794 case ZigTypeIdPromise:16794 case ZigTypeIdPromise:
16795 case ZigTypeIdVector:16795 case ZigTypeIdVector:
16796 {16796 {
16797 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown)))16797 ResolveStatus needed_status = (align_bytes == 0) ?
16798 ResolveStatusZeroBitsKnown : ResolveStatusAlignmentKnown;
16799 if ((err = type_resolve(ira->codegen, child_type, needed_status)))
16798 return ira->codegen->invalid_instruction;16800 return ira->codegen->invalid_instruction;
16799 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,16801 ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
16800 is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero);16802 is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero);
test/stage1/behavior/slice.zig+11
...@@ -54,3 +54,14 @@ test "comptime slices are disambiguated" {...@@ -54,3 +54,14 @@ test "comptime slices are disambiguated" {
54 expect(sliceSum([_]u8{ 1, 2 }) == 3);54 expect(sliceSum([_]u8{ 1, 2 }) == 3);
55 expect(sliceSum([_]u8{ 3, 4 }) == 7);55 expect(sliceSum([_]u8{ 3, 4 }) == 7);
56}56}
57
58test "slice type with custom alignment" {
59 const LazilyResolvedType = struct {
60 anything: i32,
61 };
62 var slice: []align(32) LazilyResolvedType = undefined;
63 var array: [10]LazilyResolvedType align(32) = undefined;
64 slice = &array;
65 slice[1].anything = 42;
66 expect(array[1].anything == 42);
67}