Skip to content

Commit acfdad8

Browse files
Rexicon226mlugg
authored andcommitted
Sema: convert slice sentinel to single pointer correctly
1 parent f296eec commit acfdad8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Sema.zig

+2
Original file line numberDiff line numberDiff line change
@@ -25726,12 +25726,14 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2572625726
var info = dest_ty.ptrInfo(zcu);
2572725727
info.flags.size = .one;
2572825728
info.child = array_ty.toIntern();
25729+
info.sentinel = .none;
2572925730
break :info info;
2573025731
});
2573125732
const src_array_ptr_ty = try pt.ptrType(info: {
2573225733
var info = src_ty.ptrInfo(zcu);
2573325734
info.flags.size = .one;
2573425735
info.child = array_ty.toIntern();
25736+
info.sentinel = .none;
2573525737
break :info info;
2573625738
});
2573725739

test/behavior/memcpy.zig

+31
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,34 @@ test "@memcpy zero-bit type with aliasing" {
133133
S.doTheTest();
134134
comptime S.doTheTest();
135135
}
136+
137+
test "@memcpy with sentinel" {
138+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
139+
140+
const S = struct {
141+
fn doTheTest() void {
142+
const field = @typeInfo(struct { a: u32 }).@"struct".fields[0];
143+
var buffer: [field.name.len]u8 = undefined;
144+
@memcpy(&buffer, field.name);
145+
}
146+
};
147+
148+
S.doTheTest();
149+
comptime S.doTheTest();
150+
}
151+
152+
test "@memcpy no sentinel source into sentinel destination" {
153+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
154+
155+
const S = struct {
156+
fn doTheTest() void {
157+
const src: []const u8 = &.{ 1, 2, 3 };
158+
comptime var dest_buf: [3:0]u8 = @splat(0);
159+
const dest: [:0]u8 = &dest_buf;
160+
@memcpy(dest, src);
161+
}
162+
};
163+
164+
S.doTheTest();
165+
comptime S.doTheTest();
166+
}

0 commit comments

Comments
 (0)