| author | |
| committer | |
| log | 4eb7b28700b23d8465a36e364e60394b2a1da41b |
| tree | cb46cfbbd0a3efc2dc2862cee7a871c593427e9b |
| parent | 7062c8a8865bbd2fb8181b579da552295cd68e6a |
3 files changed, 12 insertions(+), 12 deletions(-)
src/codegen/llvm.zig+3-3| ... | ... | @@ -762,7 +762,7 @@ pub const DeclGen = struct { |
| 762 | 762 | } |
| 763 | 763 | const llvm_addrspace = dg.llvmAddressSpace(t.ptrAddressSpace()); |
| 764 | 764 | const elem_ty = t.childType(); |
| 765 | const llvm_elem_ty = if (elem_ty.hasCodeGenBits()) | |
| 765 | const llvm_elem_ty = if (elem_ty.hasCodeGenBits() or elem_ty.zigTypeTag() == .Array) | |
| 766 | 766 | try dg.llvmType(elem_ty) |
| 767 | 767 | else |
| 768 | 768 | dg.context.intType(8); |
| ... | ... | @@ -1475,7 +1475,7 @@ pub const DeclGen = struct { |
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | const llvm_type = try self.llvmType(tv.ty); |
| 1478 | if (!tv.ty.childType().hasCodeGenBits()) { | |
| 1478 | if (!tv.ty.childType().hasCodeGenBits() or !decl.ty.hasCodeGenBits()) { | |
| 1479 | 1479 | return self.lowerPtrToVoid(tv.ty); |
| 1480 | 1480 | } |
| 1481 | 1481 | |
| ... | ... | @@ -1497,7 +1497,7 @@ pub const DeclGen = struct { |
| 1497 | 1497 | // for non-optional pointers. We also need to respect the alignment, even though |
| 1498 | 1498 | // the address will never be dereferenced. |
| 1499 | 1499 | const llvm_usize = try dg.llvmType(Type.usize); |
| 1500 | const llvm_ptr_ty = dg.context.intType(8).pointerType(0); | |
| 1500 | const llvm_ptr_ty = try dg.llvmType(ptr_ty); | |
| 1501 | 1501 | if (alignment != 0) { |
| 1502 | 1502 | return llvm_usize.constInt(alignment, .False).constIntToPtr(llvm_ptr_ty); |
| 1503 | 1503 | } |
test/behavior/slice.zig+9| ... | ... | @@ -157,3 +157,12 @@ test "comptime pointer cast array and then slice" { |
| 157 | 157 | try expect(sliceA[1] == 2); |
| 158 | 158 | try expect(sliceB[1] == 2); |
| 159 | 159 | } |
| 160 | ||
| 161 | test "slicing zero length array" { | |
| 162 | const s1 = ""[0..]; | |
| 163 | const s2 = ([_]u32{})[0..]; | |
| 164 | try expect(s1.len == 0); | |
| 165 | try expect(s2.len == 0); | |
| 166 | try expect(mem.eql(u8, s1, "")); | |
| 167 | try expect(mem.eql(u32, s2, &[_]u32{})); | |
| 168 | } |
test/behavior/slice_stage1.zig-9| ... | ... | @@ -4,15 +4,6 @@ const expectEqualSlices = std.testing.expectEqualSlices; |
| 4 | 4 | const expectEqual = std.testing.expectEqual; |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | |
| 7 | test "slicing zero length array" { | |
| 8 | const s1 = ""[0..]; | |
| 9 | const s2 = ([_]u32{})[0..]; | |
| 10 | try expect(s1.len == 0); | |
| 11 | try expect(s2.len == 0); | |
| 12 | try expect(mem.eql(u8, s1, "")); | |
| 13 | try expect(mem.eql(u32, s2, &[_]u32{})); | |
| 14 | } | |
| 15 | ||
| 16 | 7 | test "slice string literal has correct type" { |
| 17 | 8 | comptime { |
| 18 | 9 | try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8); |