| author | |
| committer | |
| log | 55ccf4c7a8451edca47d8d6d82bddd9fe192744a |
| tree | 9fd1bb8ed2c124c3162ba6f400b3af834d9b0892 |
| parent | 6ffa44554ef70dea9e4e58e0c8a4733be7c939b3 |
By the time zirElemVal is reached for a many pointer, a load has already
happened, making sure the operand is already dereferenced.
This makes `mem.sliceTo` now work.3 files changed, 17 insertions(+), 7 deletions(-)
src/Sema.zig+2-4| ... | @@ -15629,15 +15629,13 @@ fn elemVal( | ... | @@ -15629,15 +15629,13 @@ fn elemVal( |
| 15629 | return block.addBinOp(.slice_elem_val, array, elem_index); | 15629 | return block.addBinOp(.slice_elem_val, array, elem_index); |
| 15630 | }, | 15630 | }, |
| 15631 | .Many, .C => { | 15631 | .Many, .C => { |
| 15632 | const maybe_ptr_val = try sema.resolveDefinedValue(block, array_src, array); | 15632 | const maybe_array_val = try sema.resolveDefinedValue(block, array_src, array); |
| 15633 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | 15633 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| 15634 | 15634 | ||
| 15635 | const runtime_src = rs: { | 15635 | const runtime_src = rs: { |
| 15636 | const ptr_val = maybe_ptr_val orelse break :rs array_src; | 15636 | const array_val = maybe_array_val orelse break :rs array_src; |
| 15637 | const index_val = maybe_index_val orelse break :rs elem_index_src; | 15637 | const index_val = maybe_index_val orelse break :rs elem_index_src; |
| 15638 | const index = @intCast(usize, index_val.toUnsignedInt()); | 15638 | const index = @intCast(usize, index_val.toUnsignedInt()); |
| 15639 | const maybe_array_val = try sema.pointerDeref(block, array_src, ptr_val, array_ty); | ||
| 15640 | const array_val = maybe_array_val orelse break :rs array_src; | ||
| 15641 | const elem_val = try array_val.elemValue(sema.arena, index); | 15639 | const elem_val = try array_val.elemValue(sema.arena, index); |
| 15642 | return sema.addConstant(array_ty.elemType2(), elem_val); | 15640 | return sema.addConstant(array_ty.elemType2(), elem_val); |
| 15643 | }; | 15641 | }; |
test/behavior/cast.zig+5-1| ... | @@ -521,7 +521,11 @@ fn testCastPtrOfArrayToSliceAndPtr() !void { | ... | @@ -521,7 +521,11 @@ fn testCastPtrOfArrayToSliceAndPtr() !void { |
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { | 523 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 524 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | 524 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 525 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 526 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 527 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 528 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 525 | 529 | ||
| 526 | const window_name = [1][*]const u8{"window name"}; | 530 | const window_name = [1][*]const u8{"window name"}; |
| 527 | const x: [*]const ?[*]const u8 = &window_name; | 531 | const x: [*]const ?[*]const u8 = &window_name; |
test/behavior/pointers.zig+10-2| ... | @@ -279,7 +279,11 @@ test "array initialization types" { | ... | @@ -279,7 +279,11 @@ test "array initialization types" { |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | test "null terminated pointer" { | 281 | test "null terminated pointer" { |
| 282 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | 282 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 283 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 284 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 285 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 286 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 283 | 287 | ||
| 284 | const S = struct { | 288 | const S = struct { |
| 285 | fn doTheTest() !void { | 289 | fn doTheTest() !void { |
| ... | @@ -295,7 +299,11 @@ test "null terminated pointer" { | ... | @@ -295,7 +299,11 @@ test "null terminated pointer" { |
| 295 | } | 299 | } |
| 296 | 300 | ||
| 297 | test "allow any sentinel" { | 301 | test "allow any sentinel" { |
| 298 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | 302 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 303 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 304 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 305 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 306 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 299 | 307 | ||
| 300 | const S = struct { | 308 | const S = struct { |
| 301 | fn doTheTest() !void { | 309 | fn doTheTest() !void { |