diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-05-24 13:14:16 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-05-24 14:29:15 +0300 |
| commit | b2a514b3d2d2d880a41a26e798fb3c9ee014c229 (patch) | |
| tree | 9aa31eaef54e46d112b426dbedc0de286885fe48 | |
| parent | 16dbb960fc8dada79cd42dd2ba1ebf0f66ccaaec (diff) | |
| download | zig-b2a514b3d2d2d880a41a26e798fb3c9ee014c229.tar.gz zig-b2a514b3d2d2d880a41a26e798fb3c9ee014c229.zip | |
Sema: `@memcpy` convert src slice to many ptr
Closes #15838
| -rw-r--r-- | src/Sema.zig | 4 | ||||
| -rw-r--r-- | test/behavior/memcpy.zig | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 76c9891467..1ee19515aa 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -22235,6 +22235,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void // Change the dest to a slice, since its type must have the length. const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr); new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false); + const new_src_ptr_ty = sema.typeOf(new_src_ptr); + if (new_src_ptr_ty.isSlice()) { + new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty); + } } try sema.requireRuntimeBlock(block, src, runtime_src); diff --git a/test/behavior/memcpy.zig b/test/behavior/memcpy.zig index b7c5eb29d9..3a87b66fb1 100644 --- a/test/behavior/memcpy.zig +++ b/test/behavior/memcpy.zig @@ -58,7 +58,8 @@ test "@memcpy dest many pointer" { fn testMemcpyDestManyPtr() !void { var str = "hello".*; var buf: [5]u8 = undefined; - @memcpy(@ptrCast([*]u8, &buf), @ptrCast([*]const u8, &str)[0..5]); + var len: usize = 5; + @memcpy(@ptrCast([*]u8, &buf), @ptrCast([*]const u8, &str)[0..len]); try expect(buf[0] == 'h'); try expect(buf[1] == 'e'); try expect(buf[2] == 'l'); |
