Sema: @memcpy convert src slice to many ptr

Closes #15838
This commit is contained in:
Veikka Tuominen 2023-05-24 13:14:16 +03:00
parent 16dbb960fc
commit b2a514b3d2
2 changed files with 6 additions and 1 deletions

View File

@ -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);

View File

@ -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');