mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Sema: convert slice sentinel to single pointer correctly
This commit is contained in:
parent
6ac462b088
commit
aca8ed9dec
2 changed files with 33 additions and 0 deletions
|
|
@ -26350,12 +26350,14 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
|
|||
var info = dest_ty.ptrInfo(zcu);
|
||||
info.flags.size = .one;
|
||||
info.child = array_ty.toIntern();
|
||||
info.sentinel = .none;
|
||||
break :info info;
|
||||
});
|
||||
const src_array_ptr_ty = try pt.ptrType(info: {
|
||||
var info = src_ty.ptrInfo(zcu);
|
||||
info.flags.size = .one;
|
||||
info.child = array_ty.toIntern();
|
||||
info.sentinel = .none;
|
||||
break :info info;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -133,3 +133,34 @@ test "@memcpy zero-bit type with aliasing" {
|
|||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "@memcpy with sentinel" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
const S = struct {
|
||||
fn doTheTest() void {
|
||||
const field = @typeInfo(struct { a: u32 }).@"struct".fields[0];
|
||||
var buffer: [field.name.len]u8 = undefined;
|
||||
@memcpy(&buffer, field.name);
|
||||
}
|
||||
};
|
||||
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "@memcpy no sentinel source into sentinel destination" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
const S = struct {
|
||||
fn doTheTest() void {
|
||||
const src: []const u8 = &.{ 1, 2, 3 };
|
||||
comptime var dest_buf: [3:0]u8 = @splat(0);
|
||||
const dest: [:0]u8 = &dest_buf;
|
||||
@memcpy(dest, src);
|
||||
}
|
||||
};
|
||||
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue