commit 9050a07540b7387dade8184d3a3daf957e805e4f (tree)
parent 8ed88280a62f2a400d00b5ac20618539693dad36
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 18 Jun 2019 11:31:05 -0400
when resolving slice types, might need to...
...resolve alignment if custom alignment is provided
fixes #2689
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -16794,7 +16794,9 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
case ZigTypeIdPromise:
case ZigTypeIdVector:
{
- if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown)))
+ ResolveStatus needed_status = (align_bytes == 0) ?
+ ResolveStatusZeroBitsKnown : ResolveStatusAlignmentKnown;
+ if ((err = type_resolve(ira->codegen, child_type, needed_status)))
return ira->codegen->invalid_instruction;
ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero);
diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig
@@ -54,3 +54,14 @@ test "comptime slices are disambiguated" {
expect(sliceSum([_]u8{ 1, 2 }) == 3);
expect(sliceSum([_]u8{ 3, 4 }) == 7);
}
+
+test "slice type with custom alignment" {
+ const LazilyResolvedType = struct {
+ anything: i32,
+ };
+ var slice: []align(32) LazilyResolvedType = undefined;
+ var array: [10]LazilyResolvedType align(32) = undefined;
+ slice = &array;
+ slice[1].anything = 42;
+ expect(array[1].anything == 42);
+}