| author | |
| committer | |
| log | aca8ed9deccda88c79daf31b9a427df8871ec3b3 |
| tree | af82854b31127f074acab85d780eac7ce081c936 |
| parent | 6ac462b08827a70a6bc2c1c695372a2f34075234 |
| signature |
2 files changed, 33 insertions(+), 0 deletions(-)
src/Sema.zig+2| ... | @@ -26350,12 +26350,14 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -26350,12 +26350,14 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 26350 | var info = dest_ty.ptrInfo(zcu); | 26350 | var info = dest_ty.ptrInfo(zcu); |
| 26351 | info.flags.size = .one; | 26351 | info.flags.size = .one; |
| 26352 | info.child = array_ty.toIntern(); | 26352 | info.child = array_ty.toIntern(); |
| 26353 | info.sentinel = .none; | ||
| 26353 | break :info info; | 26354 | break :info info; |
| 26354 | }); | 26355 | }); |
| 26355 | const src_array_ptr_ty = try pt.ptrType(info: { | 26356 | const src_array_ptr_ty = try pt.ptrType(info: { |
| 26356 | var info = src_ty.ptrInfo(zcu); | 26357 | var info = src_ty.ptrInfo(zcu); |
| 26357 | info.flags.size = .one; | 26358 | info.flags.size = .one; |
| 26358 | info.child = array_ty.toIntern(); | 26359 | info.child = array_ty.toIntern(); |
| 26360 | info.sentinel = .none; | ||
| 26359 | break :info info; | 26361 | break :info info; |
| 26360 | }); | 26362 | }); |
| 26361 | 26363 |
test/behavior/memcpy.zig+31| ... | @@ -133,3 +133,34 @@ test "@memcpy zero-bit type with aliasing" { | ... | @@ -133,3 +133,34 @@ test "@memcpy zero-bit type with aliasing" { |
| 133 | S.doTheTest(); | 133 | S.doTheTest(); |
| 134 | comptime S.doTheTest(); | 134 | comptime S.doTheTest(); |
| 135 | } | 135 | } |
| 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 | } |