| author | |
| committer | |
| log | 08ea9a9ff6962c40eb87ab4951bc07a05b3831c9 |
| tree | 26185fbbba4dd23e961b2524163db8b322c8385a |
| parent | a7c3d5e4ec551e48166919ab55f618afe7c23b2a |
| signature | Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4 |
2 files changed, 20 insertions(+), 3 deletions(-)
src/codegen/spirv.zig+19-1| ... | ... | @@ -789,7 +789,25 @@ pub const DeclGen = struct { |
| 789 | 789 | const size_ty_ref = try self.sizeType(); |
| 790 | 790 | const index_id = try self.constInt(size_ty_ref, elem_ptr.index); |
| 791 | 791 | |
| 792 | return try self.ptrElemPtr(parent_ptr_ty, parent_ptr_id, index_id); | |
| 792 | const elem_ptr_id = try self.ptrElemPtr(parent_ptr_ty, parent_ptr_id, index_id); | |
| 793 | ||
| 794 | // TODO: Can we consolidate this in ptrElemPtr? | |
| 795 | const elem_ty = parent_ptr_ty.elemType2(mod); // use elemType() so that we get T for *[N]T. | |
| 796 | const elem_ty_ref = try self.resolveType(elem_ty, .direct); | |
| 797 | const elem_ptr_ty_ref = try self.spv.ptrType(elem_ty_ref, spvStorageClass(parent_ptr_ty.ptrAddressSpace(mod))); | |
| 798 | ||
| 799 | if (elem_ptr_ty_ref == result_ty_ref) { | |
| 800 | return elem_ptr_id; | |
| 801 | } | |
| 802 | // This may happen when we have pointer-to-array and the result is | |
| 803 | // another pointer-to-array instead of a pointer-to-element. | |
| 804 | const result_id = self.spv.allocId(); | |
| 805 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ | |
| 806 | .id_result_type = self.typeId(result_ty_ref), | |
| 807 | .id_result = result_id, | |
| 808 | .operand = elem_ptr_id, | |
| 809 | }); | |
| 810 | return result_id; | |
| 793 | 811 | }, |
| 794 | 812 | .field => unreachable, // TODO |
| 795 | 813 | } |
test/behavior/slice.zig+1-2| ... | ... | @@ -183,8 +183,6 @@ test "slicing zero length array" { |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "slicing pointer by length" { |
| 186 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 187 | ||
| 188 | 186 | const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 189 | 187 | const ptr: [*]const u8 = @as([*]const u8, @ptrCast(&array)); |
| 190 | 188 | const slice = ptr[1..][0..5]; |
| ... | ... | @@ -620,6 +618,7 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { |
| 620 | 618 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 621 | 619 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 622 | 620 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 621 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 623 | 622 | |
| 624 | 623 | const S = struct { |
| 625 | 624 | const U = union { |