| author | |
| committer | |
| log | 9c5852aa8674320d2912627708f32fea37d7cd08 |
| tree | 1c8d9657be238579002ab35e019b5d37f7fd285d |
| parent | e3b275fa47e44d0a77e513d03a3b37b0f9ea0c0d |
| signature |
closes #20023 files changed, 15 insertions(+), 3 deletions(-)
src/codegen.cpp+1-1| ... | ... | @@ -4570,7 +4570,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst |
| 4570 | 4570 | |
| 4571 | 4571 | return tmp_struct_ptr; |
| 4572 | 4572 | } else if (array_type->id == ZigTypeIdPointer) { |
| 4573 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); | |
| 4573 | assert(array_type->data.pointer.ptr_len != PtrLenSingle); | |
| 4574 | 4574 | LLVMValueRef start_val = ir_llvm_value(g, instruction->start); |
| 4575 | 4575 | LLVMValueRef end_val = ir_llvm_value(g, instruction->end); |
| 4576 | 4576 |
src/ir.cpp+3| ... | ... | @@ -19757,6 +19757,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 19757 | 19757 | return ira->codegen->invalid_instruction; |
| 19758 | 19758 | } |
| 19759 | 19759 | } else { |
| 19760 | if (array_type->data.pointer.ptr_len == PtrLenC) { | |
| 19761 | array_type = adjust_ptr_len(ira->codegen, array_type, PtrLenUnknown); | |
| 19762 | } | |
| 19760 | 19763 | return_type = get_slice_type(ira->codegen, array_type); |
| 19761 | 19764 | if (!end) { |
| 19762 | 19765 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); |
test/stage1/behavior/slice.zig+11-2| ... | ... | @@ -1,5 +1,7 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | const mem = @import("std").mem; | |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | const expectEqualSlices = std.testing.expectEqualSlices; | |
| 4 | const mem = std.mem; | |
| 3 | 5 | |
| 4 | 6 | const x = @intToPtr([*]i32, 0x1000)[0..0x500]; |
| 5 | 7 | const y = x[0x100..]; |
| ... | ... | @@ -38,3 +40,10 @@ test "implicitly cast array of size 0 to slice" { |
| 38 | 40 | fn assertLenIsZero(msg: []const u8) void { |
| 39 | 41 | expect(msg.len == 0); |
| 40 | 42 | } |
| 43 | ||
| 44 | test "C pointer" { | |
| 45 | var buf: [*c]const u8 = c"kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; | |
| 46 | var len: u32 = 10; | |
| 47 | var slice = buf[0..len]; | |
| 48 | expectEqualSlices(u8, "kjdhfkjdhf", slice); | |
| 49 | } |