mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
parent
16dbb960fc
commit
b2a514b3d2
@ -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.
|
// 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);
|
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);
|
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);
|
try sema.requireRuntimeBlock(block, src, runtime_src);
|
||||||
|
|||||||
@ -58,7 +58,8 @@ test "@memcpy dest many pointer" {
|
|||||||
fn testMemcpyDestManyPtr() !void {
|
fn testMemcpyDestManyPtr() !void {
|
||||||
var str = "hello".*;
|
var str = "hello".*;
|
||||||
var buf: [5]u8 = undefined;
|
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[0] == 'h');
|
||||||
try expect(buf[1] == 'e');
|
try expect(buf[1] == 'e');
|
||||||
try expect(buf[2] == 'l');
|
try expect(buf[2] == 'l');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user