Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39bc17f

Browse files
committedMar 12, 2025·
Sema: convert slice sentinel to single pointer correctly
1 parent d091178 commit 39bc17f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎src/Sema.zig

+6
Original file line numberDiff line numberDiff line change
@@ -26336,18 +26336,24 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2633626336
const array_ty = try pt.arrayType(.{
2633726337
.child = dest_elem_ty.toIntern(),
2633826338
.len = len_u64,
26339+
.sentinel = sentinel: {
26340+
const info = dest_ty.ptrInfo(zcu);
26341+
break :sentinel info.sentinel;
26342+
},
2633926343
});
2634026344

2634126345
const dest_array_ptr_ty = try pt.ptrType(info: {
2634226346
var info = dest_ty.ptrInfo(zcu);
2634326347
info.flags.size = .one;
2634426348
info.child = array_ty.toIntern();
26349+
info.sentinel = .none;
2634526350
break :info info;
2634626351
});
2634726352
const src_array_ptr_ty = try pt.ptrType(info: {
2634826353
var info = src_ty.ptrInfo(zcu);
2634926354
info.flags.size = .one;
2635026355
info.child = array_ty.toIntern();
26356+
info.sentinel = .none;
2635126357
break :info info;
2635226358
});
2635326359

‎test/behavior/memcpy.zig

+13
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,16 @@ test "@memcpy zero-bit type with aliasing" {
133133
S.doTheTest();
134134
comptime S.doTheTest();
135135
}
136+
137+
test "@memcpy with sentinel" {
138+
const S = struct {
139+
fn doTheTest() void {
140+
const field = @typeInfo(struct { a: u32 }).@"struct".fields[0];
141+
var buffer: [field.name.len]u8 = undefined;
142+
@memcpy(&buffer, field.name);
143+
}
144+
};
145+
146+
S.doTheTest();
147+
comptime S.doTheTest();
148+
}

0 commit comments

Comments
 (0)
Please sign in to comment.