| author | |
| committer | |
| log | 09ec720dab6331c8be0300f2943f7d757ad0d7c3 |
| tree | c9b2fc59b1efb6148dbf39f1c4b9c476b2a9a512 |
| parent | f7574f44c120dc834ebaf2773dc1ab098a20c232 |
| signature |
2 files changed, 22 insertions(+), 8 deletions(-)
src/ir.cpp+20-5| ... | @@ -18585,12 +18585,27 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -18585,12 +18585,27 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18585 | case ConstPtrSpecialDiscard: | 18585 | case ConstPtrSpecialDiscard: |
| 18586 | zig_unreachable(); | 18586 | zig_unreachable(); |
| 18587 | case ConstPtrSpecialRef: | 18587 | case ConstPtrSpecialRef: |
| 18588 | mem_size = 1; | 18588 | if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) { |
| 18589 | old_size = 1; | 18589 | ConstExprValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee; |
| 18590 | new_index = index; | 18590 | new_index = index; |
| 18591 | ZigType *array_type = array_val->type; | ||
| 18592 | mem_size = array_type->data.array.len; | ||
| 18593 | if (array_type->data.array.sentinel != nullptr) { | ||
| 18594 | mem_size += 1; | ||
| 18595 | } | ||
| 18596 | old_size = mem_size; | ||
| 18591 | 18597 | ||
| 18592 | out_val->data.x_ptr.special = ConstPtrSpecialRef; | 18598 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 18593 | out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee; | 18599 | out_val->data.x_ptr.data.base_array.array_val = array_val; |
| 18600 | out_val->data.x_ptr.data.base_array.elem_index = new_index; | ||
| 18601 | } else { | ||
| 18602 | mem_size = 1; | ||
| 18603 | old_size = 1; | ||
| 18604 | new_index = index; | ||
| 18605 | |||
| 18606 | out_val->data.x_ptr.special = ConstPtrSpecialRef; | ||
| 18607 | out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee; | ||
| 18608 | } | ||
| 18594 | break; | 18609 | break; |
| 18595 | case ConstPtrSpecialBaseArray: | 18610 | case ConstPtrSpecialBaseArray: |
| 18596 | { | 18611 | { |
test/stage1/behavior/pointers.zig+2-3| ... | @@ -204,13 +204,12 @@ test "assign null directly to C pointer and test null equality" { | ... | @@ -204,13 +204,12 @@ test "assign null directly to C pointer and test null equality" { |
| 204 | test "null terminated pointer" { | 204 | test "null terminated pointer" { |
| 205 | const S = struct { | 205 | const S = struct { |
| 206 | fn doTheTest() void { | 206 | fn doTheTest() void { |
| 207 | var array_with_zero = [_]u8{'h', 'e', 'l', 'l', 'o', 0}; | 207 | var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'}; |
| 208 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); | 208 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 209 | var no_zero_ptr: [*]const u8 = zero_ptr; | 209 | var no_zero_ptr: [*]const u8 = zero_ptr; |
| 210 | expect(std.mem.eql(u8, std.mem.toSliceConst(u8, no_zero_ptr), "hello")); | 210 | expect(std.mem.eql(u8, std.mem.toSliceConst(u8, no_zero_ptr), "hello")); |
| 211 | } | 211 | } |
| 212 | }; | 212 | }; |
| 213 | S.doTheTest(); | 213 | S.doTheTest(); |
| 214 | // TODO test fails at comptime | 214 | comptime S.doTheTest(); |
| 215 | //comptime S.doTheTest(); | ||
| 216 | } | 215 | } |