| author | |
| committer | |
| log | 9050a07540b7387dade8184d3a3daf957e805e4f |
| tree | 61b0e83b961a8e5f7f13a0d4ec92f5b3730101fd |
| parent | 8ed88280a62f2a400d00b5ac20618539693dad36 |
| signature |
...resolve alignment if custom alignment is provided
fixes #26892 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 | 16794 | case ZigTypeIdPromise: |
| 16795 | 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 | 16800 | return ira->codegen->invalid_instruction; |
| 16799 | 16801 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 16800 | 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 | 54 | expect(sliceSum([_]u8{ 1, 2 }) == 3); |
| 55 | 55 | expect(sliceSum([_]u8{ 3, 4 }) == 7); |
| 56 | 56 | } |
| 57 | ||
| 58 | test "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 | } |