| author | |
| committer | |
| log | acfdad858138de029abcb1c9bf20df0e58738eb3 |
| tree | 845f2f5e2e8298598b2206a22ac8204dbdf9a72b |
| parent | f296eec294f7263c9e809c1d825a13a395e5234b |
2 files changed, 33 insertions(+), 0 deletions(-)
src/Sema.zig+2| ... | @@ -25726,12 +25726,14 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25726,12 +25726,14 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25726 | var info = dest_ty.ptrInfo(zcu); | 25726 | var info = dest_ty.ptrInfo(zcu); |
| 25727 | info.flags.size = .one; | 25727 | info.flags.size = .one; |
| 25728 | info.child = array_ty.toIntern(); | 25728 | info.child = array_ty.toIntern(); |
| 25729 | info.sentinel = .none; | ||
| 25729 | break :info info; | 25730 | break :info info; |
| 25730 | }); | 25731 | }); |
| 25731 | const src_array_ptr_ty = try pt.ptrType(info: { | 25732 | const src_array_ptr_ty = try pt.ptrType(info: { |
| 25732 | var info = src_ty.ptrInfo(zcu); | 25733 | var info = src_ty.ptrInfo(zcu); |
| 25733 | info.flags.size = .one; | 25734 | info.flags.size = .one; |
| 25734 | info.child = array_ty.toIntern(); | 25735 | info.child = array_ty.toIntern(); |
| 25736 | info.sentinel = .none; | ||
| 25735 | break :info info; | 25737 | break :info info; |
| 25736 | }); | 25738 | }); |
| 25737 | 25739 |
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 | } |