authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-29 00:19:55-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-04-29 00:19:55-07:00
logd65b42e07caa00dfe2f2fbf221c593ce57882784
tree7926cbea1499e0affe930bf6d7455dc24adf014e
parentfd6200eda6d4fe19c34a59430a88a9ce38d6d7a4
parentfa200ca0cad2705bad40eb723dedf4e3bf11f2ff
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #15481 from ziglang/use-mem-intrinsics

actually use the new memory intrinsics

155 files changed, 1188 insertions(+), 882 deletions(-)

lib/compiler_rt/udivmodei4.zig+3-3
......@@ -29,8 +29,8 @@ inline fn limb_set(x: []u32, i: usize, v: u32) void {
2929
3030// Uses Knuth's Algorithm D, 4.3.1, p. 272.
3131fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
32 if (q) |q_| std.mem.set(u32, q_[0..], 0);
33 if (r) |r_| std.mem.set(u32, r_[0..], 0);
32 if (q) |q_| @memset(q_[0..], 0);
33 if (r) |r_| @memset(r_[0..], 0);
3434
3535 if (u.len == 0 or v.len == 0) return error.DivisionByZero;
3636
......@@ -44,7 +44,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
4444 }
4545
4646 if (n > m) {
47 if (r) |r_| std.mem.copy(u32, r_[0..], u[0..]);
47 if (r) |r_| @memcpy(r_[0..u.len], u);
4848 return;
4949 }
5050
lib/std/Build.zig+2-2
......@@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u
16931693 u8,
16941694 name.len + if (value) |value_slice| value_slice.len + 1 else 0,
16951695 ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable;
1696 mem.copy(u8, macro, name);
1696 @memcpy(macro[0..name.len], name);
16971697 if (value) |value_slice| {
16981698 macro[name.len] = '=';
1699 mem.copy(u8, macro[name.len + 1 ..], value_slice);
1699 @memcpy(macro[name.len + 1 ..][0..value_slice.len], value_slice);
17001700 }
17011701 return macro;
17021702}
lib/std/Build/Cache.zig+1-1
......@@ -388,7 +388,7 @@ pub const Manifest = struct {
388388 self.hash.hasher = hasher_init;
389389 self.hash.hasher.update(&bin_digest);
390390
391 mem.copy(u8, &manifest_file_path, &self.hex_digest);
391 @memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest);
392392 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
393393
394394 if (self.files.items.len == 0) {
lib/std/Build/CompileStep.zig+1-1
......@@ -1139,7 +1139,7 @@ fn appendModuleArgs(
11391139 // We'll use this buffer to store the name we decide on
11401140 var buf = try b.allocator.alloc(u8, dep.name.len + 32);
11411141 // First, try just the exposed dependency name
1142 std.mem.copy(u8, buf, dep.name);
1142 @memcpy(buf[0..dep.name.len], dep.name);
11431143 var name = buf[0..dep.name.len];
11441144 var n: usize = 0;
11451145 while (names.contains(name)) {
lib/std/Build/RunStep.zig+16-3
......@@ -822,9 +822,19 @@ fn runCommand(
822822 },
823823 },
824824 .zig_test => {
825 const prefix: []const u8 = p: {
826 if (result.stdio.test_metadata) |tm| {
827 if (tm.next_index <= tm.names.len) {
828 const name = tm.testName(tm.next_index - 1);
829 break :p b.fmt("while executing test '{s}', ", .{name});
830 }
831 }
832 break :p "";
833 };
825834 const expected_term: std.process.Child.Term = .{ .Exited = 0 };
826835 if (!termMatches(expected_term, result.term)) {
827 return step.fail("the following command {} (expected {}):\n{s}", .{
836 return step.fail("{s}the following command {} (expected {}):\n{s}", .{
837 prefix,
828838 fmtTerm(result.term),
829839 fmtTerm(expected_term),
830840 try Step.allocPrintCmd(arena, self.cwd, final_argv),
......@@ -832,8 +842,8 @@ fn runCommand(
832842 }
833843 if (!result.stdio.test_results.isSuccess()) {
834844 return step.fail(
835 "the following test command failed:\n{s}",
836 .{try Step.allocPrintCmd(arena, self.cwd, final_argv)},
845 "{s}the following test command failed:\n{s}",
846 .{ prefix, try Step.allocPrintCmd(arena, self.cwd, final_argv) },
837847 );
838848 }
839849 },
......@@ -922,6 +932,7 @@ const StdIoResult = struct {
922932 stdout_null: bool,
923933 stderr_null: bool,
924934 test_results: Step.TestResults,
935 test_metadata: ?TestMetadata,
925936};
926937
927938fn evalZigTest(
......@@ -1057,6 +1068,7 @@ fn evalZigTest(
10571068 .skip_count = skip_count,
10581069 .leak_count = leak_count,
10591070 },
1071 .test_metadata = metadata,
10601072 };
10611073}
10621074
......@@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
11721184 .stdout_null = stdout_null,
11731185 .stderr_null = stderr_null,
11741186 .test_results = .{},
1187 .test_metadata = null,
11751188 };
11761189}
11771190
lib/std/Progress.zig+1-1
......@@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
374374 self.columns_written += self.output_buffer.len - end.*;
375375 end.* = self.output_buffer.len;
376376 const suffix = "... ";
377 std.mem.copy(u8, self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
377 @memcpy(self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
378378 },
379379 }
380380}
lib/std/Thread.zig+1-1
......@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
5656
5757 const name_with_terminator = blk: {
5858 var name_buf: [max_name_len:0]u8 = undefined;
59 std.mem.copy(u8, &name_buf, name);
59 @memcpy(name_buf[0..name.len], name);
6060 name_buf[name.len] = 0;
6161 break :blk name_buf[0..name.len :0];
6262 };
lib/std/array_hash_map.zig+3-3
......@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(
578578 self.entries.len = 0;
579579 if (self.index_header) |header| {
580580 switch (header.capacityIndexType()) {
581 .u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),
582 .u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),
583 .u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),
581 .u8 => @memset(header.indexes(u8), Index(u8).empty),
582 .u16 => @memset(header.indexes(u16), Index(u16).empty),
583 .u32 => @memset(header.indexes(u32), Index(u32).empty),
584584 }
585585 }
586586 }
lib/std/array_list.zig+28-20
......@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
120120 }
121121
122122 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
123 mem.copy(T, new_memory, self.items);
123 @memcpy(new_memory, self.items);
124124 @memset(self.items, undefined);
125125 self.clearAndFree();
126126 return new_memory;
......@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
170170 self.items.len += items.len;
171171
172172 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
173 mem.copy(T, self.items[i .. i + items.len], items);
173 @memcpy(self.items[i..][0..items.len], items);
174174 }
175175
176176 /// Replace range of elements `list[start..start+len]` with `new_items`.
......@@ -182,15 +182,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
182182 const range = self.items[start..after_range];
183183
184184 if (range.len == new_items.len)
185 mem.copy(T, range, new_items)
185 @memcpy(range[0..new_items.len], new_items)
186186 else if (range.len < new_items.len) {
187187 const first = new_items[0..range.len];
188188 const rest = new_items[range.len..];
189189
190 mem.copy(T, range, first);
190 @memcpy(range[0..first.len], first);
191191 try self.insertSlice(after_range, rest);
192192 } else {
193 mem.copy(T, range, new_items);
193 @memcpy(range[0..new_items.len], new_items);
194194 const after_subrange = start + new_items.len;
195195
196196 for (self.items[after_range..], 0..) |item, i| {
......@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
260260 const new_len = old_len + items.len;
261261 assert(new_len <= self.capacity);
262262 self.items.len = new_len;
263 mem.copy(T, self.items[old_len..], items);
263 @memcpy(self.items[old_len..][0..items.len], items);
264264 }
265265
266266 /// Append an unaligned slice of items to the list. Allocates more
......@@ -306,18 +306,22 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
306306 /// Append a value to the list `n` times.
307307 /// Allocates more memory as necessary.
308308 /// Invalidates pointers if additional memory is needed.
309 pub fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void {
309 /// The function is inline so that a comptime-known `value` parameter will
310 /// have a more optimal memset codegen in case it has a repeated byte pattern.
311 pub inline fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void {
310312 const old_len = self.items.len;
311313 try self.resize(self.items.len + n);
312 mem.set(T, self.items[old_len..self.items.len], value);
314 @memset(self.items[old_len..self.items.len], value);
313315 }
314316
315317 /// Append a value to the list `n` times.
316318 /// Asserts the capacity is enough. **Does not** invalidate pointers.
317 pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
319 /// The function is inline so that a comptime-known `value` parameter will
320 /// have a more optimal memset codegen in case it has a repeated byte pattern.
321 pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
318322 const new_len = self.items.len + n;
319323 assert(new_len <= self.capacity);
320 mem.set(T, self.items.ptr[self.items.len..new_len], value);
324 @memset(self.items.ptr[self.items.len..new_len], value);
321325 self.items.len = new_len;
322326 }
323327
......@@ -397,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
397401 self.capacity = new_capacity;
398402 } else {
399403 const new_memory = try self.allocator.alignedAlloc(T, alignment, new_capacity);
400 mem.copy(T, new_memory, self.items);
404 @memcpy(new_memory[0..self.items.len], self.items);
401405 self.allocator.free(old_memory);
402406 self.items.ptr = new_memory.ptr;
403407 self.capacity = new_memory.len;
......@@ -596,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
596600 }
597601
598602 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
599 mem.copy(T, new_memory, self.items);
603 @memcpy(new_memory, self.items);
600604 @memset(self.items, undefined);
601605 self.clearAndFree(allocator);
602606 return new_memory;
......@@ -647,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
647651 self.items.len += items.len;
648652
649653 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
650 mem.copy(T, self.items[i .. i + items.len], items);
654 @memcpy(self.items[i..][0..items.len], items);
651655 }
652656
653657 /// Replace range of elements `list[start..start+len]` with `new_items`
......@@ -716,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
716720 const new_len = old_len + items.len;
717721 assert(new_len <= self.capacity);
718722 self.items.len = new_len;
719 mem.copy(T, self.items[old_len..], items);
723 @memcpy(self.items[old_len..][0..items.len], items);
720724 }
721725
722726 /// Append the slice of items to the list. Allocates more
......@@ -766,19 +770,23 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
766770 /// Append a value to the list `n` times.
767771 /// Allocates more memory as necessary.
768772 /// Invalidates pointers if additional memory is needed.
769 pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void {
773 /// The function is inline so that a comptime-known `value` parameter will
774 /// have a more optimal memset codegen in case it has a repeated byte pattern.
775 pub inline fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void {
770776 const old_len = self.items.len;
771777 try self.resize(allocator, self.items.len + n);
772 mem.set(T, self.items[old_len..self.items.len], value);
778 @memset(self.items[old_len..self.items.len], value);
773779 }
774780
775781 /// Append a value to the list `n` times.
776782 /// **Does not** invalidate pointers.
777783 /// Asserts the capacity is enough.
778 pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
784 /// The function is inline so that a comptime-known `value` parameter will
785 /// have a more optimal memset codegen in case it has a repeated byte pattern.
786 pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
779787 const new_len = self.items.len + n;
780788 assert(new_len <= self.capacity);
781 mem.set(T, self.items.ptr[self.items.len..new_len], value);
789 @memset(self.items.ptr[self.items.len..new_len], value);
782790 self.items.len = new_len;
783791 }
784792
......@@ -815,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
815823 },
816824 };
817825
818 mem.copy(T, new_memory, self.items[0..new_len]);
826 @memcpy(new_memory, self.items[0..new_len]);
819827 allocator.free(old_memory);
820828 self.items = new_memory;
821829 self.capacity = new_memory.len;
......@@ -877,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
877885 self.capacity = new_capacity;
878886 } else {
879887 const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity);
880 mem.copy(T, new_memory, self.items);
888 @memcpy(new_memory[0..self.items.len], self.items);
881889 allocator.free(old_memory);
882890 self.items.ptr = new_memory.ptr;
883891 self.capacity = new_memory.len;
lib/std/base64.zig+2-2
......@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {
309309 const input = "foo";
310310
311311 var expect: [128]u8 = undefined;
312 std.mem.set(u8, &expect, 0);
312 @memset(&expect, 0);
313313 _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);
314314
315315 var got: [128]u8 = undefined;
316 std.mem.set(u8, &got, 0);
316 @memset(&got, 0);
317317 _ = url_safe.Encoder.encode(&got, input);
318318
319319 try std.testing.expectEqualSlices(u8, &expect, &got);
lib/std/bit_set.zig+2-2
......@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {
738738 // fill in any new masks
739739 if (new_masks > old_masks) {
740740 const fill_value = std.math.boolMask(MaskInt, fill);
741 std.mem.set(MaskInt, self.masks[old_masks..new_masks], fill_value);
741 @memset(self.masks[old_masks..new_masks], fill_value);
742742 }
743743 }
744744
......@@ -765,7 +765,7 @@ pub const DynamicBitSetUnmanaged = struct {
765765 const num_masks = numMasks(self.bit_length);
766766 var copy = Self{};
767767 try copy.resize(new_allocator, self.bit_length, false);
768 std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]);
768 @memcpy(copy.masks[0..num_masks], self.masks[0..num_masks]);
769769 return copy;
770770 }
771771
lib/std/bounded_array.zig+10-10
......@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(
7373 /// Copy the content of an existing slice.
7474 pub fn fromSlice(m: []const T) error{Overflow}!Self {
7575 var list = try init(m.len);
76 std.mem.copy(T, list.slice(), m);
76 @memcpy(list.slice(), m);
7777 return list;
7878 }
7979
......@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(
165165 try self.ensureUnusedCapacity(items.len);
166166 self.len += items.len;
167167 mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);
168 mem.copy(T, self.slice()[i .. i + items.len], items);
168 @memcpy(self.slice()[i..][0..items.len], items);
169169 }
170170
171171 /// Replace range of elements `slice[start..start+len]` with `new_items`.
......@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(
181181 var range = self.slice()[start..after_range];
182182
183183 if (range.len == new_items.len) {
184 mem.copy(T, range, new_items);
184 @memcpy(range[0..new_items.len], new_items);
185185 } else if (range.len < new_items.len) {
186186 const first = new_items[0..range.len];
187187 const rest = new_items[range.len..];
188 mem.copy(T, range, first);
188 @memcpy(range[0..first.len], first);
189189 try self.insertSlice(after_range, rest);
190190 } else {
191 mem.copy(T, range, new_items);
191 @memcpy(range[0..new_items.len], new_items);
192192 const after_subrange = start + new_items.len;
193193 for (self.constSlice()[after_range..], 0..) |item, i| {
194194 self.slice()[after_subrange..][i] = item;
......@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(
243243 /// Append the slice of items to the slice, asserting the capacity is already
244244 /// enough to store the new items.
245245 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
246 const oldlen = self.len;
246 const old_len = self.len;
247247 self.len += items.len;
248 mem.copy(T, self.slice()[oldlen..], items);
248 @memcpy(self.slice()[old_len..][0..items.len], items);
249249 }
250250
251251 /// Append a value to the slice `n` times.
......@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(
253253 pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {
254254 const old_len = self.len;
255255 try self.resize(old_len + n);
256 mem.set(T, self.slice()[old_len..self.len], value);
256 @memset(self.slice()[old_len..self.len], value);
257257 }
258258
259259 /// Append a value to the slice `n` times.
......@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(
262262 const old_len = self.len;
263263 self.len += n;
264264 assert(self.len <= buffer_capacity);
265 mem.set(T, self.slice()[old_len..self.len], value);
265 @memset(self.slice()[old_len..self.len], value);
266266 }
267267
268268 pub const Writer = if (T != u8)
......@@ -329,7 +329,7 @@ test "BoundedArray" {
329329 try testing.expectEqual(a.popOrNull(), 0);
330330 try testing.expectEqual(a.popOrNull(), null);
331331 var unused = a.unusedCapacitySlice();
332 mem.set(u8, unused[0..8], 2);
332 @memset(unused[0..8], 2);
333333 unused[8] = 3;
334334 unused[9] = 4;
335335 try testing.expectEqual(unused.len, a.capacity());
lib/std/buf_set.zig+1-1
......@@ -97,7 +97,7 @@ pub const BufSet = struct {
9797
9898 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
9999 const result = try self.hash_map.allocator.alloc(u8, value.len);
100 mem.copy(u8, result, value);
100 @memcpy(result, value);
101101 return result;
102102 }
103103};
lib/std/child_process.zig+3-3
......@@ -259,7 +259,7 @@ pub const ChildProcess = struct {
259259
260260 fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {
261261 if (fifo.head > 0) {
262 std.mem.copy(u8, fifo.buf[0..fifo.count], fifo.buf[fifo.head .. fifo.head + fifo.count]);
262 @memcpy(fifo.buf[0..fifo.count], fifo.buf[fifo.head..][0..fifo.count]);
263263 }
264264 const result = std.ArrayList(u8){
265265 .items = fifo.buf[0..fifo.count],
......@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
14361436 var i: usize = 0;
14371437 while (it.next()) |pair| : (i += 1) {
14381438 const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);
1439 mem.copy(u8, env_buf, pair.key_ptr.*);
1439 @memcpy(env_buf[0..pair.key_ptr.len], pair.key_ptr.*);
14401440 env_buf[pair.key_ptr.len] = '=';
1441 mem.copy(u8, env_buf[pair.key_ptr.len + 1 ..], pair.value_ptr.*);
1441 @memcpy(env_buf[pair.key_ptr.len + 1 ..][0..pair.value_ptr.len], pair.value_ptr.*);
14421442 envp_buf[i] = env_buf.ptr;
14431443 }
14441444 assert(i == envp_count);
lib/std/compress/deflate.zig+14
......@@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;
1212pub const compressor = deflate.compressor;
1313pub const decompressor = inflate.decompressor;
1414
15/// Copies elements from a source `src` slice into a destination `dst` slice.
16/// The copy never returns an error but might not be complete if the destination is too small.
17/// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
18/// TODO: remove this smelly function
19pub fn copy(dst: []u8, src: []const u8) usize {
20 if (dst.len <= src.len) {
21 @memcpy(dst, src[0..dst.len]);
22 return dst.len;
23 } else {
24 @memcpy(dst[0..src.len], src);
25 return src.len;
26 }
27}
28
1529test {
1630 _ = @import("deflate/token.zig");
1731 _ = @import("deflate/bits_utils.zig");
lib/std/compress/deflate/compressor.zig+12-13
......@@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;
1010const deflate_const = @import("deflate_const.zig");
1111const fast = @import("deflate_fast.zig");
1212const hm_bw = @import("huffman_bit_writer.zig");
13const mu = @import("mem_utils.zig");
1413const token = @import("token.zig");
1514
1615pub const Compression = enum(i5) {
......@@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
296295 fn fillDeflate(self: *Self, b: []const u8) u32 {
297296 if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {
298297 // shift the window by window_size
299 mem.copy(u8, self.window, self.window[window_size .. 2 * window_size]);
298 mem.copyForwards(u8, self.window, self.window[window_size .. 2 * window_size]);
300299 self.index -= window_size;
301300 self.window_end -= window_size;
302301 if (self.block_start >= window_size) {
......@@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
328327 }
329328 }
330329 }
331 var n = mu.copy(self.window[self.window_end..], b);
330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
332331 self.window_end += n;
333332 return @intCast(u32, n);
334333 }
......@@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
369368 b = b[b.len - window_size ..];
370369 }
371370 // Add all to window.
372 mem.copy(u8, self.window, b);
371 @memcpy(self.window[0..b.len], b);
373372 var n = b.len;
374373
375374 // Calculate 256 hashes at the time (more L1 cache hits)
......@@ -543,7 +542,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
543542 self.hash_offset = 1;
544543 self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);
545544 self.tokens_count = 0;
546 mem.set(token.Token, self.tokens, 0);
545 @memset(self.tokens, 0);
547546 self.length = min_match_length - 1;
548547 self.offset = 0;
549548 self.byte_available = false;
......@@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
706705 }
707706
708707 fn fillStore(self: *Self, b: []const u8) u32 {
709 var n = mu.copy(self.window[self.window_end..], b);
708 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
710709 self.window_end += n;
711710 return @intCast(u32, n);
712711 }
......@@ -841,9 +840,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
841840 s.hash_head = try allocator.alloc(u32, hash_size);
842841 s.hash_prev = try allocator.alloc(u32, window_size);
843842 s.hash_match = try allocator.alloc(u32, max_match_length - 1);
844 mem.set(u32, s.hash_head, 0);
845 mem.set(u32, s.hash_prev, 0);
846 mem.set(u32, s.hash_match, 0);
843 @memset(s.hash_head, 0);
844 @memset(s.hash_prev, 0);
845 @memset(s.hash_match, 0);
847846
848847 switch (options.level) {
849848 .no_compression => {
......@@ -936,8 +935,8 @@ pub fn Compressor(comptime WriterType: anytype) type {
936935 .best_compression,
937936 => {
938937 self.chain_head = 0;
939 mem.set(u32, self.hash_head, 0);
940 mem.set(u32, self.hash_prev, 0);
938 @memset(self.hash_head, 0);
939 @memset(self.hash_prev, 0);
941940 self.hash_offset = 1;
942941 self.index = 0;
943942 self.window_end = 0;
......@@ -1091,8 +1090,8 @@ test "bulkHash4" {
10911090 // double the test data
10921091 var out = try testing.allocator.alloc(u8, x.out.len * 2);
10931092 defer testing.allocator.free(out);
1094 mem.copy(u8, out[0..x.out.len], x.out);
1095 mem.copy(u8, out[x.out.len..], x.out);
1093 @memcpy(out[0..x.out.len], x.out);
1094 @memcpy(out[x.out.len..], x.out);
10961095
10971096 var j: usize = 4;
10981097 while (j < out.len) : (j += 1) {
lib/std/compress/deflate/decompressor.zig+2-3
......@@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;
99const bu = @import("bits_utils.zig");
1010const ddec = @import("dict_decoder.zig");
1111const deflate_const = @import("deflate_const.zig");
12const mu = @import("mem_utils.zig");
1312
1413const max_match_offset = deflate_const.max_match_offset;
1514const end_block_marker = deflate_const.end_block_marker;
......@@ -159,7 +158,7 @@ const HuffmanDecoder = struct {
159158 if (sanity) {
160159 // initialize to a known invalid chunk code (0) to see if we overwrite
161160 // this value later on
162 mem.set(u16, self.links[off], 0);
161 @memset(self.links[off], 0);
163162 }
164163 try self.sub_chunks.append(off);
165164 }
......@@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
451450 pub fn read(self: *Self, output: []u8) Error!usize {
452451 while (true) {
453452 if (self.to_read.len > 0) {
454 var n = mu.copy(output, self.to_read);
453 const n = std.compress.deflate.copy(output, self.to_read);
455454 self.to_read = self.to_read[n..];
456455 if (self.to_read.len == 0 and
457456 self.err != null)
lib/std/compress/deflate/deflate_fast.zig+3-3
......@@ -237,7 +237,7 @@ pub const DeflateFast = struct {
237237 }
238238 self.cur += @intCast(i32, src.len);
239239 self.prev_len = @intCast(u32, src.len);
240 mem.copy(u8, self.prev[0..self.prev_len], src);
240 @memcpy(self.prev[0..self.prev_len], src);
241241 return;
242242 }
243243
......@@ -566,11 +566,11 @@ test "best speed match 2/2" {
566566 for (cases) |c| {
567567 var previous = try testing.allocator.alloc(u8, c.previous);
568568 defer testing.allocator.free(previous);
569 mem.set(u8, previous, 0);
569 @memset(previous, 0);
570570
571571 var current = try testing.allocator.alloc(u8, c.current);
572572 defer testing.allocator.free(current);
573 mem.set(u8, current, 0);
573 @memset(current, 0);
574574
575575 var e = DeflateFast{
576576 .prev = previous,
lib/std/compress/deflate/deflate_fast_test.zig+5-5
......@@ -123,13 +123,13 @@ test "best speed max match offset" {
123123 var src = try testing.allocator.alloc(u8, src_len);
124124 defer testing.allocator.free(src);
125125
126 mem.copy(u8, src, abc);
126 @memcpy(src[0..abc.len], abc);
127127 if (!do_match_before) {
128 var src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
129 mem.copy(u8, src[src_offset..], xyz);
128 const src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
129 @memcpy(src[src_offset..][0..xyz.len], xyz);
130130 }
131 var src_offset: usize = @intCast(usize, offset);
132 mem.copy(u8, src[src_offset..], abc);
131 const src_offset: usize = @intCast(usize, offset);
132 @memcpy(src[src_offset..][0..abc.len], abc);
133133
134134 var compressed = ArrayList(u8).init(testing.allocator);
135135 defer compressed.deinit();
lib/std/compress/deflate/dict_decoder.zig+7-3
......@@ -47,7 +47,8 @@ pub const DictDecoder = struct {
4747 self.wr_pos = 0;
4848
4949 if (dict != null) {
50 mem.copy(u8, self.hist, dict.?[dict.?.len -| self.hist.len..]);
50 const src = dict.?[dict.?.len -| self.hist.len..];
51 @memcpy(self.hist[0..src.len], src);
5152 self.wr_pos = @intCast(u32, dict.?.len);
5253 }
5354
......@@ -103,12 +104,15 @@ pub const DictDecoder = struct {
103104 self.wr_pos += 1;
104105 }
105106
107 /// TODO: eliminate this function because the callsites should care about whether
108 /// or not their arguments alias and then they should directly call `@memcpy` or
109 /// `mem.copyForwards`.
106110 fn copy(dst: []u8, src: []const u8) u32 {
107111 if (src.len > dst.len) {
108 mem.copy(u8, dst, src[0..dst.len]);
112 mem.copyForwards(u8, dst, src[0..dst.len]);
109113 return @intCast(u32, dst.len);
110114 }
111 mem.copy(u8, dst, src);
115 mem.copyForwards(u8, dst[0..src.len], src);
112116 return @intCast(u32, src.len);
113117 }
114118
lib/std/compress/deflate/huffman_code.zig+1-1
......@@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {
202202 // more values in the level below
203203 l.last_freq = l.next_pair_freq;
204204 // Take leaf counts from the lower level, except counts[level] remains the same.
205 mem.copy(u32, leaf_counts[level][0..level], leaf_counts[level - 1][0..level]);
205 @memcpy(leaf_counts[level][0..level], leaf_counts[level - 1][0..level]);
206206 levels[l.level - 1].needed = 2;
207207 }
208208
lib/std/compress/deflate/mem_utils.zig deleted-15
......@@ -1,15 +0,0 @@
1const std = @import("std");
2const math = std.math;
3const mem = std.mem;
4
5// Copies elements from a source `src` slice into a destination `dst` slice.
6// The copy never returns an error but might not be complete if the destination is too small.
7// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
8pub fn copy(dst: []u8, src: []const u8) usize {
9 if (dst.len <= src.len) {
10 mem.copy(u8, dst[0..], src[0..dst.len]);
11 } else {
12 mem.copy(u8, dst[0..src.len], src[0..]);
13 }
14 return math.min(dst.len, src.len);
15}
lib/std/compress/lzma.zig+3-3
......@@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {
7575 }
7676 }
7777 const input = self.to_read.items;
78 const n = math.min(input.len, output.len);
79 mem.copy(u8, output[0..n], input[0..n]);
80 mem.copy(u8, input, input[n..]);
78 const n = @min(input.len, output.len);
79 @memcpy(output[0..n], input[0..n]);
80 @memcpy(input[0 .. input.len - n], input[n..]);
8181 self.to_read.shrinkRetainingCapacity(input.len - n);
8282 return n;
8383 }
lib/std/compress/lzma/decode/rangecoder.zig+1-1
......@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {
143143 }
144144
145145 pub fn reset(self: *Self) void {
146 mem.set(u16, &self.probs, 0x400);
146 @memset(&self.probs, 0x400);
147147 }
148148 };
149149}
lib/std/compress/lzma/vec2d.zig+2-2
......@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {
1313 pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {
1414 const len = try math.mul(usize, size[0], size[1]);
1515 const data = try allocator.alloc(T, len);
16 mem.set(T, data, value);
16 @memset(data, value);
1717 return Self{
1818 .data = data,
1919 .cols = size[1],
......@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {
2626 }
2727
2828 pub fn fill(self: *Self, value: T) void {
29 mem.set(T, self.data, value);
29 @memset(self.data, value);
3030 }
3131
3232 inline fn _get(self: Self, row: usize) ![]T {
lib/std/compress/xz/block.zig+3-3
......@@ -59,9 +59,9 @@ pub fn Decoder(comptime ReaderType: type) type {
5959 while (true) {
6060 if (self.to_read.items.len > 0) {
6161 const input = self.to_read.items;
62 const n = std.math.min(input.len, output.len);
63 std.mem.copy(u8, output[0..n], input[0..n]);
64 std.mem.copy(u8, input, input[n..]);
62 const n = @min(input.len, output.len);
63 @memcpy(output[0..n], input[0..n]);
64 std.mem.copyForwards(u8, input, input[n..]);
6565 self.to_read.shrinkRetainingCapacity(input.len - n);
6666 if (self.to_read.items.len == 0 and self.err != null) {
6767 if (self.err.? == DecodeError.EndOfStreamWithNoError) {
lib/std/compress/zstandard/decode/block.zig+7-10
......@@ -293,10 +293,10 @@ pub const DecodeState = struct {
293293
294294 try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);
295295 const copy_start = write_pos + sequence.literal_length - sequence.offset;
296 const copy_end = copy_start + sequence.match_length;
297 // NOTE: we ignore the usage message for std.mem.copy and copy with dest.ptr >= src.ptr
298 // to allow repeats
299 std.mem.copy(u8, dest[write_pos + sequence.literal_length ..], dest[copy_start..copy_end]);
296 for (
297 dest[write_pos + sequence.literal_length ..][0..sequence.match_length],
298 dest[copy_start..][0..sequence.match_length],
299 ) |*d, s| d.* = s;
300300 self.written_count += sequence.match_length;
301301 }
302302
......@@ -311,7 +311,6 @@ pub const DecodeState = struct {
311311 try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);
312312 const copy_start = dest.write_index + dest.data.len - sequence.offset;
313313 const copy_slice = dest.sliceAt(copy_start, sequence.match_length);
314 // TODO: would std.mem.copy and figuring out dest slice be better/faster?
315314 for (copy_slice.first) |b| dest.writeAssumeCapacity(b);
316315 for (copy_slice.second) |b| dest.writeAssumeCapacity(b);
317316 self.written_count += sequence.match_length;
......@@ -444,9 +443,8 @@ pub const DecodeState = struct {
444443
445444 switch (self.literal_header.block_type) {
446445 .raw => {
447 const literals_end = self.literal_written_count + len;
448 const literal_data = self.literal_streams.one[self.literal_written_count..literals_end];
449 std.mem.copy(u8, dest, literal_data);
446 const literal_data = self.literal_streams.one[self.literal_written_count..][0..len];
447 @memcpy(dest[0..len], literal_data);
450448 self.literal_written_count += len;
451449 self.written_count += len;
452450 },
......@@ -615,8 +613,7 @@ pub fn decodeBlock(
615613 .raw => {
616614 if (src.len < block_size) return error.MalformedBlockSize;
617615 if (dest[written_count..].len < block_size) return error.DestTooSmall;
618 const data = src[0..block_size];
619 std.mem.copy(u8, dest[written_count..], data);
616 @memcpy(dest[written_count..][0..block_size], src[0..block_size]);
620617 consumed_count.* += block_size;
621618 decode_state.written_count += block_size;
622619 return block_size;
lib/std/crypto/25519/ed25519.zig+9-9
......@@ -79,8 +79,8 @@ pub const Ed25519 = struct {
7979 const r_bytes = r.toBytes();
8080
8181 var t: [64]u8 = undefined;
82 mem.copy(u8, t[0..32], &r_bytes);
83 mem.copy(u8, t[32..], &public_key.bytes);
82 t[0..32].* = r_bytes;
83 t[32..].* = public_key.bytes;
8484 var h = Sha512.init(.{});
8585 h.update(&t);
8686
......@@ -200,8 +200,8 @@ pub const Ed25519 = struct {
200200 /// Return the raw signature (r, s) in little-endian format.
201201 pub fn toBytes(self: Signature) [encoded_length]u8 {
202202 var bytes: [encoded_length]u8 = undefined;
203 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
204 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
203 bytes[0 .. encoded_length / 2].* = self.r;
204 bytes[encoded_length / 2 ..].* = self.s;
205205 return bytes;
206206 }
207207
......@@ -260,8 +260,8 @@ pub const Ed25519 = struct {
260260 const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;
261261 const pk_bytes = pk_p.toBytes();
262262 var sk_bytes: [SecretKey.encoded_length]u8 = undefined;
263 mem.copy(u8, &sk_bytes, &ss);
264 mem.copy(u8, sk_bytes[seed_length..], &pk_bytes);
263 sk_bytes[0..ss.len].* = ss;
264 sk_bytes[seed_length..].* = pk_bytes;
265265 return KeyPair{
266266 .public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,
267267 .secret_key = try SecretKey.fromBytes(sk_bytes),
......@@ -373,7 +373,7 @@ pub const Ed25519 = struct {
373373 var z_batch: [count]Curve.scalar.CompressedScalar = undefined;
374374 for (&z_batch) |*z| {
375375 crypto.random.bytes(z[0..16]);
376 mem.set(u8, z[16..], 0);
376 @memset(z[16..], 0);
377377 }
378378
379379 var zs_sum = Curve.scalar.zero;
......@@ -444,8 +444,8 @@ pub const Ed25519 = struct {
444444 };
445445
446446 var prefix: [64]u8 = undefined;
447 mem.copy(u8, prefix[0..32], h[32..64]);
448 mem.copy(u8, prefix[32..64], blind_h[32..64]);
447 prefix[0..32].* = h[32..64].*;
448 prefix[32..64].* = blind_h[32..64].*;
449449
450450 const blind_secret_key = BlindSecretKey{
451451 .prefix = prefix,
lib/std/crypto/25519/edwards25519.zig+4-4
......@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {
306306 var pcs: [count][9]Edwards25519 = undefined;
307307
308308 var bpc: [9]Edwards25519 = undefined;
309 mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]);
309 @memcpy(&bpc, basePointPc[0..bpc.len]);
310310
311311 for (ps, 0..) |p, i| {
312312 if (p.is_base) {
......@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {
439439 var u: [n * H.digest_length]u8 = undefined;
440440 var i: usize = 0;
441441 while (i < n * H.digest_length) : (i += H.digest_length) {
442 mem.copy(u8, u[i..][0..H.digest_length], u_0[0..]);
442 u[i..][0..H.digest_length].* = u_0;
443443 var j: usize = 0;
444444 while (i > 0 and j < H.digest_length) : (j += 1) {
445445 u[i + j] ^= u[i + j - H.digest_length];
......@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {
455455 var px: [n]Edwards25519 = undefined;
456456 i = 0;
457457 while (i < n) : (i += 1) {
458 mem.set(u8, u_0[0 .. H.digest_length - h_l], 0);
459 mem.copy(u8, u_0[H.digest_length - h_l ..][0..h_l], u[i * h_l ..][0..h_l]);
458 @memset(u_0[0 .. H.digest_length - h_l], 0);
459 u_0[H.digest_length - h_l ..][0..h_l].* = u[i * h_l ..][0..h_l].*;
460460 px[i] = fromHash(u_0);
461461 }
462462 return px;
lib/std/crypto/25519/scalar.zig+3-3
......@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
8383pub fn neg(s: CompressedScalar) CompressedScalar {
8484 const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;
8585 var sx: [64]u8 = undefined;
86 mem.copy(u8, sx[0..32], s[0..]);
87 mem.set(u8, sx[32..], 0);
86 sx[0..32].* = s;
87 @memset(sx[32..], 0);
8888 var carry: u32 = 0;
8989 var i: usize = 0;
9090 while (i < 64) : (i += 1) {
......@@ -593,7 +593,7 @@ const ScalarDouble = struct {
593593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
594594 }
595595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
596 mem.set(u64, limbs[5..], 0);
596 @memset(limbs[5..], 0);
597597 return ScalarDouble{ .limbs = limbs };
598598 }
599599
lib/std/crypto/25519/x25519.zig+7-7
......@@ -37,7 +37,7 @@ pub const X25519 = struct {
3737 break :sk random_seed;
3838 };
3939 var kp: KeyPair = undefined;
40 mem.copy(u8, &kp.secret_key, sk[0..]);
40 kp.secret_key = sk;
4141 kp.public_key = try X25519.recoverPublicKey(sk);
4242 return kp;
4343 }
......@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {
120120 var i: usize = 0;
121121 while (i < 1) : (i += 1) {
122122 const output = try X25519.scalarmult(k, u);
123 mem.copy(u8, u[0..], k[0..]);
124 mem.copy(u8, k[0..], output[0..]);
123 u = k;
124 k = output;
125125 }
126126
127127 try std.testing.expectEqual(k, expected_output);
......@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {
142142 var i: usize = 0;
143143 while (i < 1000) : (i += 1) {
144144 const output = try X25519.scalarmult(&k, &u);
145 mem.copy(u8, u[0..], k[0..]);
146 mem.copy(u8, k[0..], output[0..]);
145 u = k;
146 k = output;
147147 }
148148
149149 try std.testing.expectEqual(k, expected_output);
......@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
163163 var i: usize = 0;
164164 while (i < 1000000) : (i += 1) {
165165 const output = try X25519.scalarmult(&k, &u);
166 mem.copy(u8, u[0..], k[0..]);
167 mem.copy(u8, k[0..], output[0..]);
166 u = k;
167 k = output;
168168 }
169169
170170 try std.testing.expectEqual(k[0..], expected_output);
lib/std/crypto/Certificate.zig+7-7
......@@ -928,7 +928,7 @@ pub const rsa = struct {
928928 pub const PSSSignature = struct {
929929 pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {
930930 var result = [1]u8{0} ** modulus_len;
931 std.mem.copy(u8, &result, msg);
931 std.mem.copyForwards(u8, &result, msg);
932932 return result;
933933 }
934934
......@@ -1025,9 +1025,9 @@ pub const rsa = struct {
10251025 // initial zero octets.
10261026 var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);
10271027 defer allocator.free(m_p);
1028 std.mem.copy(u8, m_p, &([_]u8{0} ** 8));
1029 std.mem.copy(u8, m_p[8..], &mHash);
1030 std.mem.copy(u8, m_p[(8 + Hash.digest_length)..], salt);
1028 std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8));
1029 std.mem.copyForwards(u8, m_p[8..], &mHash);
1030 std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
10311031
10321032 // 13. Let H' = Hash(M'), an octet string of length hLen.
10331033 var h_p: [Hash.digest_length]u8 = undefined;
......@@ -1047,7 +1047,7 @@ pub const rsa = struct {
10471047
10481048 var hash = try allocator.alloc(u8, seed.len + c.len);
10491049 defer allocator.free(hash);
1050 std.mem.copy(u8, hash, seed);
1050 std.mem.copyForwards(u8, hash, seed);
10511051 var hashed: [Hash.digest_length]u8 = undefined;
10521052
10531053 while (idx < len) {
......@@ -1056,10 +1056,10 @@ pub const rsa = struct {
10561056 c[2] = @intCast(u8, (counter >> 8) & 0xFF);
10571057 c[3] = @intCast(u8, counter & 0xFF);
10581058
1059 std.mem.copy(u8, hash[seed.len..], &c);
1059 std.mem.copyForwards(u8, hash[seed.len..], &c);
10601060 Hash.hash(hash, &hashed, .{});
10611061
1062 std.mem.copy(u8, out[idx..], &hashed);
1062 std.mem.copyForwards(u8, out[idx..], &hashed);
10631063 idx += hashed.len;
10641064
10651065 counter += 1;
lib/std/crypto/aegis.zig+25-25
......@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
152152 state.absorb(ad[i..][0..32]);
153153 }
154154 if (ad.len % 32 != 0) {
155 mem.set(u8, src[0..], 0);
156 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
155 @memset(src[0..], 0);
156 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
157157 state.absorb(&src);
158158 }
159159 i = 0;
......@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
161161 state.enc(c[i..][0..32], m[i..][0..32]);
162162 }
163163 if (m.len % 32 != 0) {
164 mem.set(u8, src[0..], 0);
165 mem.copy(u8, src[0 .. m.len % 32], m[i .. i + m.len % 32]);
164 @memset(src[0..], 0);
165 @memcpy(src[0 .. m.len % 32], m[i..][0 .. m.len % 32]);
166166 state.enc(&dst, &src);
167 mem.copy(u8, c[i .. i + m.len % 32], dst[0 .. m.len % 32]);
167 @memcpy(c[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
168168 }
169169 tag.* = state.mac(tag_bits, ad.len, m.len);
170170 }
......@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
185185 state.absorb(ad[i..][0..32]);
186186 }
187187 if (ad.len % 32 != 0) {
188 mem.set(u8, src[0..], 0);
189 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
188 @memset(src[0..], 0);
189 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
190190 state.absorb(&src);
191191 }
192192 i = 0;
......@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
194194 state.dec(m[i..][0..32], c[i..][0..32]);
195195 }
196196 if (m.len % 32 != 0) {
197 mem.set(u8, src[0..], 0);
198 mem.copy(u8, src[0 .. m.len % 32], c[i .. i + m.len % 32]);
197 @memset(src[0..], 0);
198 @memcpy(src[0 .. m.len % 32], c[i..][0 .. m.len % 32]);
199199 state.dec(&dst, &src);
200 mem.copy(u8, m[i .. i + m.len % 32], dst[0 .. m.len % 32]);
201 mem.set(u8, dst[0 .. m.len % 32], 0);
200 @memcpy(m[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
201 @memset(dst[0 .. m.len % 32], 0);
202202 const blocks = &state.blocks;
203203 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));
204204 blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));
......@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
334334 state.enc(&dst, ad[i..][0..16]);
335335 }
336336 if (ad.len % 16 != 0) {
337 mem.set(u8, src[0..], 0);
338 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
337 @memset(src[0..], 0);
338 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
339339 state.enc(&dst, &src);
340340 }
341341 i = 0;
......@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
343343 state.enc(c[i..][0..16], m[i..][0..16]);
344344 }
345345 if (m.len % 16 != 0) {
346 mem.set(u8, src[0..], 0);
347 mem.copy(u8, src[0 .. m.len % 16], m[i .. i + m.len % 16]);
346 @memset(src[0..], 0);
347 @memcpy(src[0 .. m.len % 16], m[i..][0 .. m.len % 16]);
348348 state.enc(&dst, &src);
349 mem.copy(u8, c[i .. i + m.len % 16], dst[0 .. m.len % 16]);
349 @memcpy(c[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
350350 }
351351 tag.* = state.mac(tag_bits, ad.len, m.len);
352352 }
......@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
367367 state.enc(&dst, ad[i..][0..16]);
368368 }
369369 if (ad.len % 16 != 0) {
370 mem.set(u8, src[0..], 0);
371 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
370 @memset(src[0..], 0);
371 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
372372 state.enc(&dst, &src);
373373 }
374374 i = 0;
......@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
376376 state.dec(m[i..][0..16], c[i..][0..16]);
377377 }
378378 if (m.len % 16 != 0) {
379 mem.set(u8, src[0..], 0);
380 mem.copy(u8, src[0 .. m.len % 16], c[i .. i + m.len % 16]);
379 @memset(src[0..], 0);
380 @memcpy(src[0 .. m.len % 16], c[i..][0 .. m.len % 16]);
381381 state.dec(&dst, &src);
382 mem.copy(u8, m[i .. i + m.len % 16], dst[0 .. m.len % 16]);
383 mem.set(u8, dst[0 .. m.len % 16], 0);
382 @memcpy(m[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
383 @memset(dst[0 .. m.len % 16], 0);
384384 const blocks = &state.blocks;
385385 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));
386386 }
......@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {
457457 self.msg_len += b.len;
458458
459459 const len_partial = @min(b.len, block_length - self.off);
460 mem.copy(u8, self.buf[self.off..][0..len_partial], b[0..len_partial]);
460 @memcpy(self.buf[self.off..][0..len_partial], b[0..len_partial]);
461461 self.off += len_partial;
462462 if (self.off < block_length) {
463463 return;
......@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {
470470 self.state.absorb(b[i..][0..block_length]);
471471 }
472472 if (i != b.len) {
473 mem.copy(u8, self.buf[0..], b[i..]);
473 @memcpy(self.buf[0..], b[i..]);
474474 self.off = b.len - i;
475475 }
476476 }
......@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {
479479 pub fn final(self: *Self, out: *[mac_length]u8) void {
480480 if (self.off > 0) {
481481 var pad = [_]u8{0} ** block_length;
482 mem.copy(u8, pad[0..], self.buf[0..self.off]);
482 @memcpy(pad[0..self.off], self.buf[0..self.off]);
483483 self.state.absorb(&pad);
484484 }
485485 out.* = self.state.mac(T.tag_length * 8, self.msg_len, 0);
lib/std/crypto/aes_gcm.zig+2-2
......@@ -31,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
3131
3232 var t: [16]u8 = undefined;
3333 var j: [16]u8 = undefined;
34 mem.copy(u8, j[0..nonce_length], npub[0..]);
34 j[0..nonce_length].* = npub;
3535 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
3636 aes.encrypt(&t, &j);
3737
......@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {
6464
6565 var t: [16]u8 = undefined;
6666 var j: [16]u8 = undefined;
67 mem.copy(u8, j[0..nonce_length], npub[0..]);
67 j[0..nonce_length].* = npub;
6868 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
6969 aes.encrypt(&t, &j);
7070
lib/std/crypto/aes_ocb.zig+10-10
......@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {
7575 if (leftover > 0) {
7676 xorWith(&offset, lx.star);
7777 var padded = [_]u8{0} ** 16;
78 mem.copy(u8, padded[0..leftover], a[i * 16 ..][0..leftover]);
78 @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]);
7979 padded[leftover] = 1;
8080 var e = xorBlocks(offset, padded);
8181 aes_enc_ctx.encrypt(&e, &e);
......@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {
8888 var nx = [_]u8{0} ** 16;
8989 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);
9090 nx[16 - nonce_length - 1] = 1;
91 mem.copy(u8, nx[16 - nonce_length ..], &npub);
91 nx[nx.len - nonce_length ..].* = npub;
9292
9393 const bottom = @truncate(u6, nx[15]);
9494 nx[15] &= 0xc0;
......@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {
132132 xorWith(&offset, lt[@ctz(i + 1 + j)]);
133133 offsets[j] = offset;
134134 const p = m[(i + j) * 16 ..][0..16].*;
135 mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j]));
135 es[j * 16 ..][0..16].* = xorBlocks(p, offsets[j]);
136136 xorWith(&sum, p);
137137 }
138138 aes_enc_ctx.encryptWide(wb, &es, &es);
139139 j = 0;
140140 while (j < wb) : (j += 1) {
141141 const e = es[j * 16 ..][0..16].*;
142 mem.copy(u8, c[(i + j) * 16 ..][0..16], &xorBlocks(e, offsets[j]));
142 c[(i + j) * 16 ..][0..16].* = xorBlocks(e, offsets[j]);
143143 }
144144 }
145145 while (i < full_blocks) : (i += 1) {
......@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {
147147 const p = m[i * 16 ..][0..16].*;
148148 var e = xorBlocks(p, offset);
149149 aes_enc_ctx.encrypt(&e, &e);
150 mem.copy(u8, c[i * 16 ..][0..16], &xorBlocks(e, offset));
150 c[i * 16 ..][0..16].* = xorBlocks(e, offset);
151151 xorWith(&sum, p);
152152 }
153153 const leftover = m.len % 16;
......@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {
159159 c[i * 16 + j] = pad[j] ^ x;
160160 }
161161 var e = [_]u8{0} ** 16;
162 mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);
162 @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
163163 e[leftover] = 0x80;
164164 xorWith(&sum, e);
165165 }
......@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {
196196 xorWith(&offset, lt[@ctz(i + 1 + j)]);
197197 offsets[j] = offset;
198198 const q = c[(i + j) * 16 ..][0..16].*;
199 mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j]));
199 es[j * 16 ..][0..16].* = xorBlocks(q, offsets[j]);
200200 }
201201 aes_dec_ctx.decryptWide(wb, &es, &es);
202202 j = 0;
203203 while (j < wb) : (j += 1) {
204204 const p = xorBlocks(es[j * 16 ..][0..16].*, offsets[j]);
205 mem.copy(u8, m[(i + j) * 16 ..][0..16], &p);
205 m[(i + j) * 16 ..][0..16].* = p;
206206 xorWith(&sum, p);
207207 }
208208 }
......@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {
212212 var e = xorBlocks(q, offset);
213213 aes_dec_ctx.decrypt(&e, &e);
214214 const p = xorBlocks(e, offset);
215 mem.copy(u8, m[i * 16 ..][0..16], &p);
215 m[i * 16 ..][0..16].* = p;
216216 xorWith(&sum, p);
217217 }
218218 const leftover = m.len % 16;
......@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {
224224 m[i * 16 + j] = pad[j] ^ x;
225225 }
226226 var e = [_]u8{0} ** 16;
227 mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);
227 @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
228228 e[leftover] = 0x80;
229229 xorWith(&sum, e);
230230 }
lib/std/crypto/argon2.zig+8-8
......@@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {
149149 h.update(&outlen_bytes);
150150 h.update(in);
151151 h.final(&out_buf);
152 mem.copy(u8, out, out_buf[0..out.len]);
152 @memcpy(out, out_buf[0..out.len]);
153153 return;
154154 }
155155
......@@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {
158158 h.update(in);
159159 h.final(&out_buf);
160160 var out_slice = out;
161 mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]);
161 out_slice[0 .. H.digest_length / 2].* = out_buf[0 .. H.digest_length / 2].*;
162162 out_slice = out_slice[H.digest_length / 2 ..];
163163
164164 var in_buf: [H.digest_length]u8 = undefined;
165165 while (out_slice.len > H.digest_length) {
166 mem.copy(u8, &in_buf, &out_buf);
166 in_buf = out_buf;
167167 H.hash(&in_buf, &out_buf, .{});
168 mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]);
168 out_slice[0 .. H.digest_length / 2].* = out_buf[0 .. H.digest_length / 2].*;
169169 out_slice = out_slice[H.digest_length / 2 ..];
170170 }
171 mem.copy(u8, &in_buf, &out_buf);
171 in_buf = out_buf;
172172 H.hash(&in_buf, &out_buf, .{ .expected_out_bits = out_slice.len * 8 });
173 mem.copy(u8, out_slice, out_buf[0..out_slice.len]);
173 @memcpy(out_slice, out_buf[0..out_slice.len]);
174174}
175175
176176fn initBlocks(
......@@ -494,7 +494,7 @@ pub fn kdf(
494494 if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
495495
496496 var h0 = initHash(password, salt, params, derived_key.len, mode);
497 const memory = math.max(
497 const memory = @max(
498498 params.m / (sync_points * params.p) * (sync_points * params.p),
499499 2 * sync_points * params.p,
500500 );
......@@ -877,7 +877,7 @@ test "kdf" {
877877 .hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",
878878 },
879879 };
880 inline for (test_vectors) |v| {
880 for (test_vectors) |v| {
881881 var want: [24]u8 = undefined;
882882 _ = try std.fmt.hexToBytes(&want, v.hash);
883883
lib/std/crypto/ascon.zig+7-7
......@@ -34,7 +34,7 @@ pub fn State(comptime endian: builtin.Endian) type {
3434 /// Initialize the state from a slice of bytes.
3535 pub fn init(initial_state: [block_bytes]u8) Self {
3636 var state = Self{ .st = undefined };
37 mem.copy(u8, state.asBytes(), &initial_state);
37 @memcpy(state.asBytes(), &initial_state);
3838 state.endianSwap();
3939 return state;
4040 }
......@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {
8787 }
8888 if (i < bytes.len) {
8989 var padded = [_]u8{0} ** 8;
90 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
90 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
9191 self.st[i / 8] = mem.readInt(u64, padded[0..], endian);
9292 }
9393 }
......@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {
109109 }
110110 if (i < bytes.len) {
111111 var padded = [_]u8{0} ** 8;
112 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
112 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
113113 self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);
114114 }
115115 }
......@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {
123123 if (i < out.len) {
124124 var padded = [_]u8{0} ** 8;
125125 mem.writeInt(u64, padded[0..], self.st[i / 8], endian);
126 mem.copy(u8, out[i..], padded[0 .. out.len - i]);
126 @memcpy(out[i..], padded[0 .. out.len - i]);
127127 }
128128 }
129129
......@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {
138138 }
139139 if (i < in.len) {
140140 var padded = [_]u8{0} ** 8;
141 mem.copy(u8, padded[0 .. in.len - i], in[i..]);
141 @memcpy(padded[0 .. in.len - i], in[i..]);
142142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
143143 mem.writeIntNative(u64, &padded, x);
144 mem.copy(u8, out[i..], padded[0 .. in.len - i]);
144 @memcpy(out[i..], padded[0 .. in.len - i]);
145145 }
146146 }
147147
148148 /// Set the words storing the bytes of a given range to zero.
149149 pub fn clear(self: *Self, from: usize, to: usize) void {
150 mem.set(u64, self.st[from / 8 .. (to + 7) / 8], 0);
150 @memset(self.st[from / 8 .. (to + 7) / 8], 0);
151151 }
152152
153153 /// Clear the entire state, disabling compiler optimizations.
lib/std/crypto/bcrypt.zig+3-3
......@@ -416,8 +416,8 @@ pub fn bcrypt(
416416) [dk_length]u8 {
417417 var state = State{};
418418 var password_buf: [73]u8 = undefined;
419 const trimmed_len = math.min(password.len, password_buf.len - 1);
420 mem.copy(u8, password_buf[0..], password[0..trimmed_len]);
419 const trimmed_len = @min(password.len, password_buf.len - 1);
420 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
421421 password_buf[trimmed_len] = 0;
422422 var passwordZ = password_buf[0 .. trimmed_len + 1];
423423 state.expand(salt[0..], passwordZ);
......@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {
626626 crypto.random.bytes(&salt);
627627
628628 const hash = crypt_format.strHashInternal(password, salt, params);
629 mem.copy(u8, buf, &hash);
629 @memcpy(buf[0..hash.len], &hash);
630630
631631 return buf[0..pwhash_str_length];
632632 }
lib/std/crypto/benchmark.zig+2-2
......@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
113113 var i: usize = 0;
114114 while (i < exchange_count) : (i += 1) {
115115 const out = try DhKeyExchange.scalarmult(secret, public);
116 mem.copy(u8, secret[0..16], out[0..16]);
117 mem.copy(u8, public[0..16], out[16..32]);
116 secret[0..16].* = out[0..16].*;
117 public[0..16].* = out[16..32].*;
118118 mem.doNotOptimizeAway(&out);
119119 }
120120 }
lib/std/crypto/blake2.zig+16-14
......@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
7676 comptime debug.assert(8 <= out_bits and out_bits <= 256);
7777
7878 var d: Self = undefined;
79 mem.copy(u32, d.h[0..], iv[0..]);
79 d.h = iv;
8080
8181 const key_len = if (options.key) |key| key.len else 0;
8282 // default parameters
......@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
9393 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
9494 }
9595 if (key_len > 0) {
96 mem.set(u8, d.buf[key_len..], 0);
96 @memset(d.buf[key_len..], 0);
9797 d.update(options.key.?);
9898 d.buf_len = 64;
9999 }
......@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
112112 // Partial buffer exists from previous update. Copy into buffer then hash.
113113 if (d.buf_len != 0 and d.buf_len + b.len > 64) {
114114 off += 64 - d.buf_len;
115 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
115 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
116116 d.t += 64;
117117 d.round(d.buf[0..], false);
118118 d.buf_len = 0;
......@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {
125125 }
126126
127127 // Copy any remainder for next pass.
128 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
129 d.buf_len += @intCast(u8, b[off..].len);
128 const b_slice = b[off..];
129 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
130 d.buf_len += @intCast(u8, b_slice.len);
130131 }
131132
132133 pub fn final(d: *Self, out: *[digest_length]u8) void {
133 mem.set(u8, d.buf[d.buf_len..], 0);
134 @memset(d.buf[d.buf_len..], 0);
134135 d.t += d.buf_len;
135136 d.round(d.buf[0..], true);
136137 for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
137 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
138 out.* = @ptrCast(*[digest_length]u8, &d.h).*;
138139 }
139140
140141 fn round(d: *Self, b: *const [64]u8, last: bool) void {
......@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
511512 comptime debug.assert(8 <= out_bits and out_bits <= 512);
512513
513514 var d: Self = undefined;
514 mem.copy(u64, d.h[0..], iv[0..]);
515 d.h = iv;
515516
516517 const key_len = if (options.key) |key| key.len else 0;
517518 // default parameters
......@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
528529 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
529530 }
530531 if (key_len > 0) {
531 mem.set(u8, d.buf[key_len..], 0);
532 @memset(d.buf[key_len..], 0);
532533 d.update(options.key.?);
533534 d.buf_len = 128;
534535 }
......@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
547548 // Partial buffer exists from previous update. Copy into buffer then hash.
548549 if (d.buf_len != 0 and d.buf_len + b.len > 128) {
549550 off += 128 - d.buf_len;
550 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
551 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
551552 d.t += 128;
552553 d.round(d.buf[0..], false);
553554 d.buf_len = 0;
......@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {
560561 }
561562
562563 // Copy any remainder for next pass.
563 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
564 d.buf_len += @intCast(u8, b[off..].len);
564 const b_slice = b[off..];
565 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
566 d.buf_len += @intCast(u8, b_slice.len);
565567 }
566568
567569 pub fn final(d: *Self, out: *[digest_length]u8) void {
568 mem.set(u8, d.buf[d.buf_len..], 0);
570 @memset(d.buf[d.buf_len..], 0);
569571 d.t += d.buf_len;
570572 d.round(d.buf[0..], true);
571573 for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
572 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
574 out.* = @ptrCast(*[digest_length]u8, &d.h).*;
573575 }
574576
575577 fn round(d: *Self, b: *const [128]u8, last: bool) void {
lib/std/crypto/blake3.zig+4-4
......@@ -253,7 +253,7 @@ const Output = struct {
253253 while (out_word_it.next()) |out_word| {
254254 var word_bytes: [4]u8 = undefined;
255255 mem.writeIntLittle(u32, &word_bytes, words[word_counter]);
256 mem.copy(u8, out_word, word_bytes[0..out_word.len]);
256 @memcpy(out_word, word_bytes[0..out_word.len]);
257257 word_counter += 1;
258258 }
259259 output_block_counter += 1;
......@@ -284,7 +284,7 @@ const ChunkState = struct {
284284 fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {
285285 const want = BLOCK_LEN - self.block_len;
286286 const take = math.min(want, input.len);
287 mem.copy(u8, self.block[self.block_len..][0..take], input[0..take]);
287 @memcpy(self.block[self.block_len..][0..take], input[0..take]);
288288 self.block_len += @truncate(u8, take);
289289 return input[take..];
290290 }
......@@ -336,8 +336,8 @@ fn parentOutput(
336336 flags: u8,
337337) Output {
338338 var block_words: [16]u32 align(16) = undefined;
339 mem.copy(u32, block_words[0..8], left_child_cv[0..]);
340 mem.copy(u32, block_words[8..], right_child_cv[0..]);
339 block_words[0..8].* = left_child_cv;
340 block_words[8..].* = right_child_cv;
341341 return Output{
342342 .input_chaining_value = key,
343343 .block_words = block_words,
lib/std/crypto/chacha20.zig+4-4
......@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {
211211
212212 var buf: [64]u8 = undefined;
213213 hashToBytes(buf[0..], x);
214 mem.copy(u8, out[i..], buf[0 .. out.len - i]);
214 @memcpy(out[i..], buf[0 .. out.len - i]);
215215 }
216216 }
217217
......@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
372372
373373 var buf: [64]u8 = undefined;
374374 hashToBytes(buf[0..], x);
375 mem.copy(u8, out[i..], buf[0 .. out.len - i]);
375 @memcpy(out[i..], buf[0 .. out.len - i]);
376376 }
377377 }
378378
......@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {
413413
414414fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {
415415 var subnonce: [12]u8 = undefined;
416 mem.set(u8, subnonce[0..4], 0);
417 mem.copy(u8, subnonce[4..], nonce[16..24]);
416 @memset(subnonce[0..4], 0);
417 subnonce[4..].* = nonce[16..24].*;
418418 return .{
419419 .key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),
420420 .nonce = subnonce,
lib/std/crypto/ecdsa.zig+9-11
......@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
102102 /// Return the raw signature (r, s) in big-endian format.
103103 pub fn toBytes(self: Signature) [encoded_length]u8 {
104104 var bytes: [encoded_length]u8 = undefined;
105 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
106 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
105 @memcpy(bytes[0 .. encoded_length / 2], &self.r);
106 @memcpy(bytes[encoded_length / 2 ..], &self.s);
107107 return bytes;
108108 }
109109
......@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
325325 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
326326 if (unreduced_len >= 48) {
327327 var xs = [_]u8{0} ** 64;
328 mem.copy(u8, xs[xs.len - s.len ..], s[0..]);
328 @memcpy(xs[xs.len - s.len ..], s[0..]);
329329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);
330330 }
331331 var xs = [_]u8{0} ** 48;
332 mem.copy(u8, xs[xs.len - s.len ..], s[0..]);
332 @memcpy(xs[xs.len - s.len ..], s[0..]);
333333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);
334334 }
335335
......@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
345345 const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];
346346 const m_h = m[m.len - h.len ..];
347347
348 mem.set(u8, m_v, 0x01);
348 @memset(m_v, 0x01);
349349 m_i.* = 0x00;
350 if (noise) |n| mem.copy(u8, m_z, &n);
351 mem.copy(u8, m_x, &secret_key);
352 mem.copy(u8, m_h, &h);
350 if (noise) |n| @memcpy(m_z, &n);
351 @memcpy(m_x, &secret_key);
352 @memcpy(m_h, &h);
353353 Hmac.create(&k, &m, &k);
354354 Hmac.create(m_v, m_v, &k);
355 mem.copy(u8, m_v, m_v);
356355 m_i.* = 0x01;
357356 Hmac.create(&k, &m, &k);
358357 Hmac.create(m_v, m_v, &k);
......@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
361360 while (t_off < t.len) : (t_off += m_v.len) {
362361 const t_end = @min(t_off + m_v.len, t.len);
363362 Hmac.create(m_v, m_v, &k);
364 std.mem.copy(u8, t[t_off..t_end], m_v[0 .. t_end - t_off]);
363 @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]);
365364 }
366365 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
367 mem.copy(u8, m_v, m_v);
368366 m_i.* = 0x00;
369367 Hmac.create(&k, m[0 .. m_v.len + 1], &k);
370368 Hmac.create(m_v, m_v, &k);
lib/std/crypto/hkdf.zig+1-1
......@@ -63,7 +63,7 @@ pub fn Hkdf(comptime Hmac: type) type {
6363 st.update(&counter);
6464 var tmp: [prk_length]u8 = undefined;
6565 st.final(tmp[0..prk_length]);
66 mem.copy(u8, out[i..][0..left], tmp[0..left]);
66 @memcpy(out[i..][0..left], tmp[0..left]);
6767 }
6868 }
6969 };
lib/std/crypto/hmac.zig+4-4
......@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {
3838 // Normalize key length to block size of hash
3939 if (key.len > Hash.block_length) {
4040 Hash.hash(key, scratch[0..mac_length], .{});
41 mem.set(u8, scratch[mac_length..Hash.block_length], 0);
41 @memset(scratch[mac_length..Hash.block_length], 0);
4242 } else if (key.len < Hash.block_length) {
43 mem.copy(u8, scratch[0..key.len], key);
44 mem.set(u8, scratch[key.len..Hash.block_length], 0);
43 @memcpy(scratch[0..key.len], key);
44 @memset(scratch[key.len..Hash.block_length], 0);
4545 } else {
46 mem.copy(u8, scratch[0..], key);
46 @memcpy(&scratch, key);
4747 }
4848
4949 for (&ctx.o_key_pad, 0..) |*b, i| {
lib/std/crypto/isap.zig+1-1
......@@ -43,7 +43,7 @@ pub const IsapA128A = struct {
4343 }
4444 } else {
4545 var padded = [_]u8{0} ** 8;
46 mem.copy(u8, padded[0..left], m[i..]);
46 @memcpy(padded[0..left], m[i..]);
4747 padded[left] = 0x80;
4848 isap.st.addBytes(&padded);
4949 isap.st.permute();
lib/std/crypto/keccak_p.zig+8-8
......@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {
6868 }
6969 if (i < bytes.len) {
7070 var padded = [_]u8{0} ** @sizeOf(T);
71 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
71 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
7272 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
7373 }
7474 }
......@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {
8787 }
8888 if (i < bytes.len) {
8989 var padded = [_]u8{0} ** @sizeOf(T);
90 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
90 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
9191 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
9292 }
9393 }
......@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {
101101 if (i < out.len) {
102102 var padded = [_]u8{0} ** @sizeOf(T);
103103 mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);
104 mem.copy(u8, out[i..], padded[0 .. out.len - i]);
104 @memcpy(out[i..], padded[0 .. out.len - i]);
105105 }
106106 }
107107
......@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {
116116 }
117117 if (i < in.len) {
118118 var padded = [_]u8{0} ** @sizeOf(T);
119 mem.copy(u8, padded[0 .. in.len - i], in[i..]);
119 @memcpy(padded[0 .. in.len - i], in[i..]);
120120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
121121 mem.writeIntNative(T, &padded, x);
122 mem.copy(u8, out[i..], padded[0 .. in.len - i]);
122 @memcpy(out[i..], padded[0 .. in.len - i]);
123123 }
124124 }
125125
126126 /// Set the words storing the bytes of a given range to zero.
127127 pub fn clear(self: *Self, from: usize, to: usize) void {
128 mem.set(T, self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
128 @memset(self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
129129 }
130130
131131 /// Clear the entire state, disabling compiler optimizations.
......@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
215215 var bytes = bytes_;
216216 if (self.offset > 0) {
217217 const left = math.min(rate - self.offset, bytes.len);
218 mem.copy(u8, self.buf[self.offset..], bytes[0..left]);
218 @memcpy(self.buf[self.offset..][0..left], bytes[0..left]);
219219 self.offset += left;
220220 if (self.offset == rate) {
221221 self.offset = 0;
......@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
231231 bytes = bytes[rate..];
232232 }
233233 if (bytes.len > 0) {
234 mem.copy(u8, &self.buf, bytes);
234 @memcpy(self.buf[0..bytes.len], bytes);
235235 self.offset = bytes.len;
236236 }
237237 }
lib/std/crypto/kyber_d00.zig+14-18
......@@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {
323323 s += InnerSk.bytes_length;
324324 ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);
325325 s += InnerPk.bytes_length;
326 mem.copy(u8, &ret.hpk, buf[s .. s + h_length]);
326 ret.hpk = buf[s..][0..h_length].*;
327327 s += h_length;
328 mem.copy(u8, &ret.z, buf[s .. s + shared_length]);
328 ret.z = buf[s..][0..shared_length].*;
329329 return ret;
330330 }
331331 };
......@@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {
345345 break :sk random_seed;
346346 };
347347 var ret: KeyPair = undefined;
348 mem.copy(u8, &ret.secret_key.z, seed[inner_seed_length..seed_length]);
348 ret.secret_key.z = seed[inner_seed_length..seed_length].*;
349349
350350 // Generate inner key
351351 innerKeyFromSeed(
......@@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {
356356 ret.secret_key.pk = ret.public_key.pk;
357357
358358 // Copy over z from seed.
359 mem.copy(u8, &ret.secret_key.z, seed[inner_seed_length..seed_length]);
359 ret.secret_key.z = seed[inner_seed_length..seed_length].*;
360360
361361 // Compute H(pk)
362362 var h = sha3.Sha3_256.init(.{});
......@@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {
418418 fn fromBytes(buf: *const [bytes_length]u8) InnerPk {
419419 var ret: InnerPk = undefined;
420420 ret.th = V.fromBytes(buf[0..V.bytes_length]).normalize();
421 mem.copy(u8, &ret.rho, buf[V.bytes_length..bytes_length]);
421 ret.rho = buf[V.bytes_length..bytes_length].*;
422422 ret.aT = M.uniform(ret.rho, true);
423423 return ret;
424424 }
......@@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {
459459 var h = sha3.Sha3_512.init(.{});
460460 h.update(&seed);
461461 h.final(&expanded_seed);
462 mem.copy(u8, &pk.rho, expanded_seed[0..32]);
462 pk.rho = expanded_seed[0..32].*;
463463 const sigma = expanded_seed[32..64];
464464 pk.aT = M.uniform(pk.rho, false); // Expand ρ to A; we'll transpose later on
465465
......@@ -1381,7 +1381,7 @@ fn Vec(comptime K: u8) type {
13811381 const cs = comptime Poly.compressedSize(d);
13821382 var ret: [compressedSize(d)]u8 = undefined;
13831383 inline for (0..K) |i| {
1384 mem.copy(u8, ret[i * cs .. (i + 1) * cs], &v.ps[i].compress(d));
1384 ret[i * cs .. (i + 1) * cs].* = v.ps[i].compress(d);
13851385 }
13861386 return ret;
13871387 }
......@@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {
13991399 fn toBytes(v: Self) [bytes_length]u8 {
14001400 var ret: [bytes_length]u8 = undefined;
14011401 inline for (0..K) |i| {
1402 mem.copy(
1403 u8,
1404 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length],
1405 &v.ps[i].toBytes(),
1406 );
1402 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length].* = v.ps[i].toBytes();
14071403 }
14081404 return ret;
14091405 }
......@@ -1479,7 +1475,7 @@ test "MulHat" {
14791475 const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();
14801476 var p: Poly = undefined;
14811477
1482 mem.set(i16, &p.cs, 0);
1478 @memset(&p.cs, 0);
14831479
14841480 for (0..N) |i| {
14851481 for (0..N) |j| {
......@@ -1742,15 +1738,15 @@ const NistDRBG = struct {
17421738 g.incV();
17431739 var block: [16]u8 = undefined;
17441740 ctx.encrypt(&block, &g.v);
1745 mem.copy(u8, buf[i * 16 .. (i + 1) * 16], &block);
1741 buf[i * 16 ..][0..16].* = block;
17461742 }
17471743 if (pd) |p| {
17481744 for (&buf, p) |*b, x| {
17491745 b.* ^= x;
17501746 }
17511747 }
1752 mem.copy(u8, &g.key, buf[0..32]);
1753 mem.copy(u8, &g.v, buf[32..48]);
1748 g.key = buf[0..32].*;
1749 g.v = buf[32..48].*;
17541750 }
17551751
17561752 // randombytes.
......@@ -1763,10 +1759,10 @@ const NistDRBG = struct {
17631759 g.incV();
17641760 ctx.encrypt(&block, &g.v);
17651761 if (dst.len < 16) {
1766 mem.copy(u8, dst, block[0..dst.len]);
1762 @memcpy(dst, block[0..dst.len]);
17671763 break;
17681764 }
1769 mem.copy(u8, dst, &block);
1765 dst[0..block.len].* = block;
17701766 dst = dst[16..dst.len];
17711767 }
17721768 g.update(null);
lib/std/crypto/md5.zig+6-5
......@@ -66,7 +66,7 @@ pub const Md5 = struct {
6666 // Partial buffer exists from previous update. Copy into buffer then hash.
6767 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
6868 off += 64 - d.buf_len;
69 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
69 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
7070
7171 d.round(&d.buf);
7272 d.buf_len = 0;
......@@ -78,8 +78,9 @@ pub const Md5 = struct {
7878 }
7979
8080 // Copy any remainder for next pass.
81 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
82 d.buf_len += @intCast(u8, b[off..].len);
81 const b_slice = b[off..];
82 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
83 d.buf_len += @intCast(u8, b_slice.len);
8384
8485 // Md5 uses the bottom 64-bits for length padding
8586 d.total_len +%= b.len;
......@@ -87,7 +88,7 @@ pub const Md5 = struct {
8788
8889 pub fn final(d: *Self, out: *[digest_length]u8) void {
8990 // The buffer here will never be completely full.
90 mem.set(u8, d.buf[d.buf_len..], 0);
91 @memset(d.buf[d.buf_len..], 0);
9192
9293 // Append padding bits.
9394 d.buf[d.buf_len] = 0x80;
......@@ -96,7 +97,7 @@ pub const Md5 = struct {
9697 // > 448 mod 512 so need to add an extra round to wrap around.
9798 if (64 - d.buf_len < 8) {
9899 d.round(d.buf[0..]);
99 mem.set(u8, d.buf[0..], 0);
100 @memset(d.buf[0..], 0);
100101 }
101102
102103 // Append message length.
lib/std/crypto/modes.zig+4-2
......@@ -38,8 +38,10 @@ pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8,
3838 if (i < src.len) {
3939 mem.writeInt(u128, &counter, counterInt, endian);
4040 var pad = [_]u8{0} ** block_length;
41 mem.copy(u8, &pad, src[i..]);
41 const src_slice = src[i..];
42 @memcpy(pad[0..src_slice.len], src_slice);
4243 block_cipher.xor(&pad, &pad, counter);
43 mem.copy(u8, dst[i..], pad[0 .. src.len - i]);
44 const pad_slice = pad[0 .. src.len - i];
45 @memcpy(dst[i..][0..pad_slice.len], pad_slice);
4446 }
4547}
lib/std/crypto/pbkdf2.zig+2-2
......@@ -129,13 +129,13 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
129129 const offset = block * h_len;
130130 const block_len = if (block != blocks_count - 1) h_len else r;
131131 const dk_block: []u8 = dk[offset..][0..block_len];
132 mem.copy(u8, dk_block, prev_block[0..dk_block.len]);
132 @memcpy(dk_block, prev_block[0..dk_block.len]);
133133
134134 var i: u32 = 1;
135135 while (i < rounds) : (i += 1) {
136136 // U_c = PRF (P, U_{c-1})
137137 Prf.create(&new_block, prev_block[0..], password);
138 mem.copy(u8, prev_block[0..], new_block[0..]);
138 prev_block = new_block;
139139
140140 // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
141141 for (dk_block, 0..) |_, j| {
lib/std/crypto/pcurves/common.zig+2-2
......@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {
228228 }
229229 if (iterations % 2 != 0) {
230230 fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);
231 mem.copy(Word, &v, &out4);
232 mem.copy(Word, &f, &out2);
231 v = out4;
232 f = out2;
233233 }
234234 var v_opp: Limbs = undefined;
235235 fiat.opp(&v_opp, v);
lib/std/crypto/pcurves/p256.zig+3-3
......@@ -105,7 +105,7 @@ pub const P256 = struct {
105105 var out: [33]u8 = undefined;
106106 const xy = p.affineCoordinates();
107107 out[0] = if (xy.y.isOdd()) 3 else 2;
108 mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
108 out[1..].* = xy.x.toBytes(.Big);
109109 return out;
110110 }
111111
......@@ -114,8 +114,8 @@ pub const P256 = struct {
114114 var out: [65]u8 = undefined;
115115 out[0] = 4;
116116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
118 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
117 out[1..33].* = xy.x.toBytes(.Big);
118 out[33..65].* = xy.y.toBytes(.Big);
119119 return out;
120120 }
121121
lib/std/crypto/pcurves/p256/scalar.zig+5-5
......@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193193 {
194194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);
195 const len = @min(s.len, 24);
196 b[0..len].* = s[0..len].*;
197197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198198 }
199199 if (s_.len >= 24) {
200200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);
201 const len = @min(s.len - 24, 24);
202 b[0..len].* = s[24..][0..len].*;
203203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204204 }
205205 if (s_.len >= 48) {
206206 var b = [_]u8{0} ** encoded_length;
207207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);
208 b[0..len].* = s[48..][0..len].*;
209209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210210 }
211211 return t;
lib/std/crypto/pcurves/p384.zig+3-3
......@@ -105,7 +105,7 @@ pub const P384 = struct {
105105 var out: [49]u8 = undefined;
106106 const xy = p.affineCoordinates();
107107 out[0] = if (xy.y.isOdd()) 3 else 2;
108 mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
108 out[1..].* = xy.x.toBytes(.Big);
109109 return out;
110110 }
111111
......@@ -114,8 +114,8 @@ pub const P384 = struct {
114114 var out: [97]u8 = undefined;
115115 out[0] = 4;
116116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..49], &xy.x.toBytes(.Big));
118 mem.copy(u8, out[49..97], &xy.y.toBytes(.Big));
117 out[1..49].* = xy.x.toBytes(.Big);
118 out[49..97].* = xy.y.toBytes(.Big);
119119 return out;
120120 }
121121
lib/std/crypto/pcurves/p384/scalar.zig+4-4
......@@ -180,14 +180,14 @@ const ScalarDouble = struct {
180180 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
181181 {
182182 var b = [_]u8{0} ** encoded_length;
183 const len = math.min(s.len, 32);
184 mem.copy(u8, b[0..len], s[0..len]);
183 const len = @min(s.len, 32);
184 b[0..len].* = s[0..len].*;
185185 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
186186 }
187187 if (s_.len >= 32) {
188188 var b = [_]u8{0} ** encoded_length;
189 const len = math.min(s.len - 32, 32);
190 mem.copy(u8, b[0..len], s[32..][0..len]);
189 const len = @min(s.len - 32, 32);
190 b[0..len].* = s[32..][0..len].*;
191191 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
192192 }
193193 return t;
lib/std/crypto/pcurves/secp256k1.zig+3-3
......@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {
158158 var out: [33]u8 = undefined;
159159 const xy = p.affineCoordinates();
160160 out[0] = if (xy.y.isOdd()) 3 else 2;
161 mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
161 out[1..].* = xy.x.toBytes(.Big);
162162 return out;
163163 }
164164
......@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {
167167 var out: [65]u8 = undefined;
168168 out[0] = 4;
169169 const xy = p.affineCoordinates();
170 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
171 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
170 out[1..33].* = xy.x.toBytes(.Big);
171 out[33..65].* = xy.y.toBytes(.Big);
172172 return out;
173173 }
174174
lib/std/crypto/pcurves/secp256k1/scalar.zig+5-5
......@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193193 {
194194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);
195 const len = @min(s.len, 24);
196 b[0..len].* = s[0..len].*;
197197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198198 }
199199 if (s_.len >= 24) {
200200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);
201 const len = @min(s.len - 24, 24);
202 b[0..len].* = s[24..][0..len].*;
203203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204204 }
205205 if (s_.len >= 48) {
206206 var b = [_]u8{0} ** encoded_length;
207207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);
208 b[0..len].* = s[48..][0..len].*;
209209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210210 }
211211 return t;
lib/std/crypto/phc_encoding.zig+1-1
......@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {
3535 pub fn fromSlice(slice: []const u8) Error!Self {
3636 if (slice.len > capacity) return Error.NoSpaceLeft;
3737 var bin_value: Self = undefined;
38 mem.copy(u8, &bin_value.buf, slice);
38 @memcpy(bin_value.buf[0..slice.len], slice);
3939 bin_value.len = slice.len;
4040 return bin_value;
4141 }
lib/std/crypto/salsa20.zig+6-6
......@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {
383383 debug.assert(c.len == m.len);
384384 const extended = extend(rounds, k, npub);
385385 var block0 = [_]u8{0} ** 64;
386 const mlen0 = math.min(32, m.len);
387 mem.copy(u8, block0[32..][0..mlen0], m[0..mlen0]);
386 const mlen0 = @min(32, m.len);
387 @memcpy(block0[32..][0..mlen0], m[0..mlen0]);
388388 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
389 mem.copy(u8, c[0..mlen0], block0[32..][0..mlen0]);
389 @memcpy(c[0..mlen0], block0[32..][0..mlen0]);
390390 Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);
391391 var mac = Poly1305.init(block0[0..32]);
392392 mac.update(ad);
......@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {
405405 const extended = extend(rounds, k, npub);
406406 var block0 = [_]u8{0} ** 64;
407407 const mlen0 = math.min(32, c.len);
408 mem.copy(u8, block0[32..][0..mlen0], c[0..mlen0]);
408 @memcpy(block0[32..][0..mlen0], c[0..mlen0]);
409409 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
410410 var mac = Poly1305.init(block0[0..32]);
411411 mac.update(ad);
......@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {
420420 utils.secureZero(u8, &computedTag);
421421 return error.AuthenticationFailed;
422422 }
423 mem.copy(u8, m[0..mlen0], block0[32..][0..mlen0]);
423 @memcpy(m[0..mlen0], block0[32..][0..mlen0]);
424424 Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);
425425 }
426426};
......@@ -533,7 +533,7 @@ pub const SealedBox = struct {
533533 debug.assert(c.len == m.len + seal_length);
534534 var ekp = try KeyPair.create(null);
535535 const nonce = createNonce(ekp.public_key, public_key);
536 mem.copy(u8, c[0..public_length], ekp.public_key[0..]);
536 c[0..public_length].* = ekp.public_key;
537537 try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);
538538 utils.secureZero(u8, ekp.secret_key[0..]);
539539 }
lib/std/crypto/scrypt.zig+3-3
......@@ -27,7 +27,7 @@ const max_salt_len = 64;
2727const max_hash_len = 64;
2828
2929fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
30 mem.copy(u32, dst, src[0 .. n * 16]);
30 @memcpy(dst[0 .. n * 16], src[0 .. n * 16]);
3131}
3232
3333fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
......@@ -242,7 +242,7 @@ const crypt_format = struct {
242242 pub fn fromSlice(slice: []const u8) EncodingError!Self {
243243 if (slice.len > capacity) return EncodingError.NoSpaceLeft;
244244 var bin_value: Self = undefined;
245 mem.copy(u8, &bin_value.buf, slice);
245 @memcpy(bin_value.buf[0..slice.len], slice);
246246 bin_value.len = slice.len;
247247 return bin_value;
248248 }
......@@ -314,7 +314,7 @@ const crypt_format = struct {
314314
315315 fn serializeTo(params: anytype, out: anytype) !void {
316316 var header: [14]u8 = undefined;
317 mem.copy(u8, header[0..3], prefix);
317 header[0..3].* = prefix.*;
318318 Codec.intEncode(header[3..4], params.ln);
319319 Codec.intEncode(header[4..9], params.r);
320320 Codec.intEncode(header[9..14], params.p);
lib/std/crypto/sha1.zig+4-4
......@@ -62,7 +62,7 @@ pub const Sha1 = struct {
6262 // Partial buffer exists from previous update. Copy into buffer then hash.
6363 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
6464 off += 64 - d.buf_len;
65 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
65 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
6666
6767 d.round(d.buf[0..]);
6868 d.buf_len = 0;
......@@ -74,7 +74,7 @@ pub const Sha1 = struct {
7474 }
7575
7676 // Copy any remainder for next pass.
77 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
77 @memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);
7878 d.buf_len += @intCast(u8, b[off..].len);
7979
8080 d.total_len += b.len;
......@@ -82,7 +82,7 @@ pub const Sha1 = struct {
8282
8383 pub fn final(d: *Self, out: *[digest_length]u8) void {
8484 // The buffer here will never be completely full.
85 mem.set(u8, d.buf[d.buf_len..], 0);
85 @memset(d.buf[d.buf_len..], 0);
8686
8787 // Append padding bits.
8888 d.buf[d.buf_len] = 0x80;
......@@ -91,7 +91,7 @@ pub const Sha1 = struct {
9191 // > 448 mod 512 so need to add an extra round to wrap around.
9292 if (64 - d.buf_len < 8) {
9393 d.round(d.buf[0..]);
94 mem.set(u8, d.buf[0..], 0);
94 @memset(d.buf[0..], 0);
9595 }
9696
9797 // Append message length.
lib/std/crypto/sha2.zig+10-8
......@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
118118 // Partial buffer exists from previous update. Copy into buffer then hash.
119119 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
120120 off += 64 - d.buf_len;
121 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
121 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
122122
123123 d.round(&d.buf);
124124 d.buf_len = 0;
......@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {
130130 }
131131
132132 // Copy any remainder for next pass.
133 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
133 const b_slice = b[off..];
134 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
134135 d.buf_len += @intCast(u8, b[off..].len);
135136
136137 d.total_len += b.len;
......@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
143144
144145 pub fn final(d: *Self, out: *[digest_length]u8) void {
145146 // The buffer here will never be completely full.
146 mem.set(u8, d.buf[d.buf_len..], 0);
147 @memset(d.buf[d.buf_len..], 0);
147148
148149 // Append padding bits.
149150 d.buf[d.buf_len] = 0x80;
......@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
152153 // > 448 mod 512 so need to add an extra round to wrap around.
153154 if (64 - d.buf_len < 8) {
154155 d.round(&d.buf);
155 mem.set(u8, d.buf[0..], 0);
156 @memset(d.buf[0..], 0);
156157 }
157158
158159 // Append message length.
......@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
609610 // Partial buffer exists from previous update. Copy into buffer then hash.
610611 if (d.buf_len != 0 and d.buf_len + b.len >= 128) {
611612 off += 128 - d.buf_len;
612 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
613 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
613614
614615 d.round(&d.buf);
615616 d.buf_len = 0;
......@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {
621622 }
622623
623624 // Copy any remainder for next pass.
624 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
625 const b_slice = b[off..];
626 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
625627 d.buf_len += @intCast(u8, b[off..].len);
626628
627629 d.total_len += b.len;
......@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
634636
635637 pub fn final(d: *Self, out: *[digest_length]u8) void {
636638 // The buffer here will never be completely full.
637 mem.set(u8, d.buf[d.buf_len..], 0);
639 @memset(d.buf[d.buf_len..], 0);
638640
639641 // Append padding bits.
640642 d.buf[d.buf_len] = 0x80;
......@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
643645 // > 896 mod 1024 so need to add an extra round to wrap around.
644646 if (128 - d.buf_len < 16) {
645647 d.round(d.buf[0..]);
646 mem.set(u8, d.buf[0..], 0);
648 @memset(d.buf[0..], 0);
647649 }
648650
649651 // Append message length.
lib/std/crypto/sha3.zig+2-2
......@@ -149,7 +149,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
149149 const left = self.buf.len - self.offset;
150150 if (left > 0) {
151151 const n = math.min(left, out.len);
152 mem.copy(u8, out[0..n], self.buf[self.offset..][0..n]);
152 @memcpy(out[0..n], self.buf[self.offset..][0..n]);
153153 out = out[n..];
154154 self.offset += n;
155155 if (out.len == 0) {
......@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
164164 }
165165 if (out.len > 0) {
166166 self.st.squeeze(self.buf[0..]);
167 mem.copy(u8, out[0..], self.buf[0..out.len]);
167 @memcpy(out[0..], self.buf[0..out.len]);
168168 self.offset = out.len;
169169 }
170170 }
lib/std/crypto/siphash.zig+5-4
......@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
9898 self.msg_len +%= @truncate(u8, b.len);
9999
100100 var buf = [_]u8{0} ** 8;
101 mem.copy(u8, buf[0..], b[0..]);
101 @memcpy(buf[0..b.len], b);
102102 buf[7] = self.msg_len;
103103 self.round(buf);
104104
......@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
203203
204204 if (self.buf_len != 0 and self.buf_len + b.len >= 8) {
205205 off += 8 - self.buf_len;
206 mem.copy(u8, self.buf[self.buf_len..], b[0..off]);
206 @memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
207207 self.state.update(self.buf[0..]);
208208 self.buf_len = 0;
209209 }
......@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
212212 const aligned_len = remain_len - (remain_len % 8);
213213 self.state.update(b[off .. off + aligned_len]);
214214
215 mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
216 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
215 const b_slice = b[off + aligned_len ..];
216 @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
217 self.buf_len += @intCast(u8, b_slice.len);
217218 }
218219
219220 pub fn peek(self: Self) [mac_length]u8 {
lib/std/crypto/tls.zig+2-2
......@@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(
312312 buf[2] = @intCast(u8, tls13.len + label.len);
313313 buf[3..][0..tls13.len].* = tls13.*;
314314 var i: usize = 3 + tls13.len;
315 mem.copy(u8, buf[i..], label);
315 @memcpy(buf[i..][0..label.len], label);
316316 i += label.len;
317317 buf[i] = @intCast(u8, context.len);
318318 i += 1;
319 mem.copy(u8, buf[i..], context);
319 @memcpy(buf[i..][0..context.len], context);
320320 i += context.len;
321321
322322 var result: [len]u8 = undefined;
lib/std/crypto/tls/Client.zig+15-15
......@@ -685,7 +685,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
685685 .application_cipher = app_cipher,
686686 .partially_read_buffer = undefined,
687687 };
688 mem.copy(u8, &client.partially_read_buffer, leftover);
688 @memcpy(client.partially_read_buffer[0..leftover.len], leftover);
689689 return client;
690690 },
691691 else => {
......@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(
809809 .overhead_len = overhead_len,
810810 };
811811
812 mem.copy(u8, &cleartext_buf, bytes[bytes_i..][0..encrypted_content_len]);
812 @memcpy(cleartext_buf[0..encrypted_content_len], bytes[bytes_i..][0..encrypted_content_len]);
813813 cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);
814814 bytes_i += encrypted_content_len;
815815 const ciphertext_len = encrypted_content_len + 1;
......@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10291029 if (frag1.len < second_len)
10301030 return finishRead2(c, first, frag1, vp.total);
10311031
1032 mem.copy(u8, frag[0..in], first);
1033 mem.copy(u8, frag[first.len..], frag1[0..second_len]);
1032 @memcpy(frag[0..in], first);
1033 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
10341034 frag = frag[0..full_record_len];
10351035 frag1 = frag1[second_len..];
10361036 in = 0;
......@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10591059 if (frag1.len < second_len)
10601060 return finishRead2(c, first, frag1, vp.total);
10611061
1062 mem.copy(u8, frag[0..in], first);
1063 mem.copy(u8, frag[first.len..], frag1[0..second_len]);
1062 @memcpy(frag[0..in], first);
1063 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
10641064 frag = frag[0..full_record_len];
10651065 frag1 = frag1[second_len..];
10661066 in = 0;
......@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11771177 // We have already run out of room in iovecs. Continue
11781178 // appending to `partially_read_buffer`.
11791179 const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];
1180 mem.copy(u8, dest, msg);
1180 @memcpy(dest[0..msg.len], msg);
11811181 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);
11821182 } else {
11831183 const amt = vp.put(msg);
......@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11851185 const rest = msg[amt..];
11861186 c.partial_cleartext_idx = 0;
11871187 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);
1188 mem.copy(u8, &c.partially_read_buffer, rest);
1188 @memcpy(c.partially_read_buffer[0..rest.len], rest);
11891189 }
11901190 }
11911191 } else {
......@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
12131213 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
12141214 // There is cleartext at the beginning already which we need to preserve.
12151215 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);
1216 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], saved_buf);
1216 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);
12171217 } else {
12181218 c.partial_cleartext_idx = 0;
12191219 c.partial_ciphertext_idx = 0;
12201220 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);
1221 mem.copy(u8, &c.partially_read_buffer, saved_buf);
1221 @memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);
12221222 }
12231223 return out;
12241224}
......@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi
12271227 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
12281228 // There is cleartext at the beginning already which we need to preserve.
12291229 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);
1230 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], first);
1231 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..], frag1);
1230 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
1231 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
12321232 } else {
12331233 c.partial_cleartext_idx = 0;
12341234 c.partial_ciphertext_idx = 0;
12351235 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);
1236 mem.copy(u8, &c.partially_read_buffer, first);
1237 mem.copy(u8, c.partially_read_buffer[first.len..], frag1);
1236 @memcpy(c.partially_read_buffer[0..first.len], first);
1237 @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
12381238 }
12391239 return out;
12401240}
......@@ -1282,7 +1282,7 @@ const VecPut = struct {
12821282 const v = vp.iovecs[vp.idx];
12831283 const dest = v.iov_base[vp.off..v.iov_len];
12841284 const src = bytes[bytes_i..][0..@min(dest.len, bytes.len - bytes_i)];
1285 mem.copy(u8, dest, src);
1285 @memcpy(dest[0..src.len], src);
12861286 bytes_i += src.len;
12871287 vp.off += src.len;
12881288 if (vp.off >= v.iov_len) {
lib/std/crypto/utils.zig+4-8
......@@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
134134
135135/// Sets a slice to zeroes.
136136/// Prevents the store from being optimized out.
137pub fn secureZero(comptime T: type, s: []T) void {
138 // TODO: implement `@memset` for non-byte-sized element type in the llvm backend
139 //@memset(@as([]volatile T, s), 0);
140 const ptr = @ptrCast([*]volatile u8, s.ptr);
141 const length = s.len * @sizeOf(T);
142 @memset(ptr[0..length], 0);
137pub inline fn secureZero(comptime T: type, s: []T) void {
138 @memset(@as([]volatile T, s), 0);
143139}
144140
145141test "crypto.utils.timingSafeEql" {
......@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
148144 random.bytes(a[0..]);
149145 random.bytes(b[0..]);
150146 try testing.expect(!timingSafeEql([100]u8, a, b));
151 mem.copy(u8, a[0..], b[0..]);
147 a = b;
152148 try testing.expect(timingSafeEql([100]u8, a, b));
153149}
154150
......@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
201197 var a = [_]u8{0xfe} ** 8;
202198 var b = [_]u8{0xfe} ** 8;
203199
204 mem.set(u8, a[0..], 0);
200 @memset(a[0..], 0);
205201 secureZero(u8, b[0..]);
206202
207203 try testing.expectEqualSlices(u8, a[0..], b[0..]);
lib/std/cstr.zig+2-2
......@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {
3434/// Caller owns the returned memory.
3535pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {
3636 const result = try allocator.alloc(u8, slice.len + 1);
37 mem.copy(u8, result, slice);
37 @memcpy(result[0..slice.len], slice);
3838 result[slice.len] = 0;
3939 return result[0..slice.len :0];
4040}
......@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {
7878 for (slice) |inner| {
7979 index_buf[i] = buf.ptr + write_index;
8080 i += 1;
81 mem.copy(u8, buf[write_index..], inner);
81 @memcpy(buf[write_index..][0..inner.len], inner);
8282 write_index += inner.len;
8383 buf[write_index] = 0;
8484 write_index += 1;
lib/std/debug.zig+2-2
......@@ -309,8 +309,8 @@ pub fn panicExtra(
309309 // error being part of the @panic stack trace (but that error should
310310 // only happen rarely)
311311 const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {
312 std.fmt.BufPrintError.NoSpaceLeft => blk: {
313 std.mem.copy(u8, buf[size..], trunc_msg);
312 error.NoSpaceLeft => blk: {
313 @memcpy(buf[size..], trunc_msg);
314314 break :blk &buf;
315315 },
316316 };
lib/std/dynamic_library.zig+1-1
......@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {
210210 -1,
211211 0,
212212 );
213 mem.copy(u8, sect_mem, file_bytes[0..ph.p_filesz]);
213 @memcpy(sect_mem[0..ph.p_filesz], file_bytes[0..ph.p_filesz]);
214214 }
215215 },
216216 else => {},
lib/std/enums.zig+2-2
......@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
275275 .bits = Self.BitSet.initFull(),
276276 .values = undefined,
277277 };
278 std.mem.set(V, &result.values, value);
278 @memset(&result.values, value);
279279 return result;
280280 }
281281 /// Initializes a full mapping with supplied values.
......@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)
11751175
11761176 pub fn initFill(v: Value) Self {
11771177 var self: Self = undefined;
1178 std.mem.set(Value, &self.values, v);
1178 @memset(&self.values, v);
11791179 return self;
11801180 }
11811181
lib/std/fifo.zig+12-14
......@@ -86,19 +86,17 @@ pub fn LinearFifo(
8686
8787 pub fn realign(self: *Self) void {
8888 if (self.buf.len - self.head >= self.count) {
89 // this copy overlaps
90 mem.copy(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
89 mem.copyForwards(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
9190 self.head = 0;
9291 } else {
9392 var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;
9493
9594 while (self.head != 0) {
96 const n = math.min(self.head, tmp.len);
95 const n = @min(self.head, tmp.len);
9796 const m = self.buf.len - n;
98 mem.copy(T, tmp[0..n], self.buf[0..n]);
99 // this middle copy overlaps; the others here don't
100 mem.copy(T, self.buf[0..m], self.buf[n..][0..m]);
101 mem.copy(T, self.buf[m..], tmp[0..n]);
97 @memcpy(tmp[0..n], self.buf[0..n]);
98 mem.copyForwards(T, self.buf[0..m], self.buf[n..][0..m]);
99 @memcpy(self.buf[m..][0..n], tmp[0..n]);
102100 self.head -= n;
103101 }
104102 }
......@@ -223,8 +221,8 @@ pub fn LinearFifo(
223221 while (dst_left.len > 0) {
224222 const slice = self.readableSlice(0);
225223 if (slice.len == 0) break;
226 const n = math.min(slice.len, dst_left.len);
227 mem.copy(T, dst_left, slice[0..n]);
224 const n = @min(slice.len, dst_left.len);
225 @memcpy(dst_left[0..n], slice[0..n]);
228226 self.discard(n);
229227 dst_left = dst_left[n..];
230228 }
......@@ -289,8 +287,8 @@ pub fn LinearFifo(
289287 while (src_left.len > 0) {
290288 const writable_slice = self.writableSlice(0);
291289 assert(writable_slice.len != 0);
292 const n = math.min(writable_slice.len, src_left.len);
293 mem.copy(T, writable_slice, src_left[0..n]);
290 const n = @min(writable_slice.len, src_left.len);
291 @memcpy(writable_slice[0..n], src_left[0..n]);
294292 self.update(n);
295293 src_left = src_left[n..];
296294 }
......@@ -354,11 +352,11 @@ pub fn LinearFifo(
354352
355353 const slice = self.readableSliceMut(0);
356354 if (src.len < slice.len) {
357 mem.copy(T, slice, src);
355 @memcpy(slice[0..src.len], src);
358356 } else {
359 mem.copy(T, slice, src[0..slice.len]);
357 @memcpy(slice, src[0..slice.len]);
360358 const slice2 = self.readableSliceMut(slice.len);
361 mem.copy(T, slice2, src[slice.len..]);
359 @memcpy(slice2[0 .. src.len - slice.len], src[slice.len..]);
362360 }
363361 }
364362
lib/std/fmt/errol.zig+2-2
......@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
8484 const i = tableLowerBound(bits);
8585 if (i < enum3.len and enum3[i] == bits) {
8686 const data = enum3_data[i];
87 const digits = buffer[1 .. data.str.len + 1];
88 mem.copy(u8, digits, data.str);
87 const digits = buffer[1..][0..data.str.len];
88 @memcpy(digits, data.str);
8989 return FloatDecimal{
9090 .digits = digits,
9191 .exp = data.exp,
lib/std/fs.zig+19-15
......@@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:
106106 var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;
107107 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));
108108 defer allocator.free(tmp_path);
109 mem.copy(u8, tmp_path[0..], dirname);
109 @memcpy(tmp_path[0..dirname.len], dirname);
110110 tmp_path[dirname.len] = path.sep;
111111 while (true) {
112112 crypto.random.bytes(rand_buf[0..]);
......@@ -1541,9 +1541,9 @@ pub const Dir = struct {
15411541 return error.NameTooLong;
15421542 }
15431543
1544 mem.copy(u8, out_buffer, out_path);
1545
1546 return out_buffer[0..out_path.len];
1544 const result = out_buffer[0..out_path.len];
1545 @memcpy(result, out_path);
1546 return result;
15471547 }
15481548
15491549 /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.
......@@ -1593,9 +1593,9 @@ pub const Dir = struct {
15931593 return error.NameTooLong;
15941594 }
15951595
1596 mem.copy(u8, out_buffer, out_path);
1597
1598 return out_buffer[0..out_path.len];
1596 const result = out_buffer[0..out_path.len];
1597 @memcpy(result, out_path);
1598 return result;
15991599 }
16001600
16011601 /// Same as `Dir.realpath` except caller must free the returned memory.
......@@ -2346,8 +2346,9 @@ pub const Dir = struct {
23462346 if (cleanup_dir_parent) |*d| d.close();
23472347 cleanup_dir_parent = iterable_dir;
23482348 iterable_dir = new_dir;
2349 mem.copy(u8, &dir_name_buf, entry.name);
2350 dir_name = dir_name_buf[0..entry.name.len];
2349 const result = dir_name_buf[0..entry.name.len];
2350 @memcpy(result, entry.name);
2351 dir_name = result;
23512352 continue :scan_dir;
23522353 } else {
23532354 if (iterable_dir.dir.deleteFile(entry.name)) {
......@@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
29742975 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
29752976 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);
29762977 if (real_path.len > out_buffer.len) return error.NameTooLong;
2977 std.mem.copy(u8, out_buffer, real_path);
2978 return out_buffer[0..real_path.len];
2978 const result = out_buffer[0..real_path.len];
2979 @memcpy(result, real_path);
2980 return result;
29792981 }
29802982 switch (builtin.os.tag) {
29812983 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),
......@@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
30143016 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);
30153017 if (real_path.len > out_buffer.len)
30163018 return error.NameTooLong;
3017 mem.copy(u8, out_buffer, real_path);
3018 return out_buffer[0..real_path.len];
3019 const result = out_buffer[0..real_path.len];
3020 @memcpy(result, real_path);
3021 return result;
30193022 } else if (argv0.len != 0) {
30203023 // argv[0] is not empty (and not a path): search it inside PATH
30213024 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;
......@@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
30323035 // found a file, and hope it is the right file
30333036 if (real_path.len > out_buffer.len)
30343037 return error.NameTooLong;
3035 mem.copy(u8, out_buffer, real_path);
3036 return out_buffer[0..real_path.len];
3038 const result = out_buffer[0..real_path.len];
3039 @memcpy(result, real_path);
3040 return result;
30373041 } else |_| continue;
30383042 }
30393043 }
lib/std/fs/path.zig+6-6
......@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
7979 const buf = try allocator.alloc(u8, total_len);
8080 errdefer allocator.free(buf);
8181
82 mem.copy(u8, buf, paths[first_path_index]);
82 @memcpy(buf[0..paths[first_path_index].len], paths[first_path_index]);
8383 var buf_index: usize = paths[first_path_index].len;
8484 var prev_path = paths[first_path_index];
8585 assert(prev_path.len > 0);
......@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
9494 buf_index += 1;
9595 }
9696 const adjusted_path = if (prev_sep and this_sep) this_path[1..] else this_path;
97 mem.copy(u8, buf[buf_index..], adjusted_path);
97 @memcpy(buf[buf_index..][0..adjusted_path.len], adjusted_path);
9898 buf_index += adjusted_path.len;
9999 prev_path = this_path;
100100 }
......@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
631631 real_result[i..][0..3].* = "..\\".*;
632632 i += 3;
633633 }
634 mem.copy(u8, real_result[i..], result.items);
634 @memcpy(real_result[i..][0..result.items.len], result.items);
635635 return real_result;
636636 }
637637}
......@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
710710 real_result[i..][0..3].* = "../".*;
711711 i += 3;
712712 }
713 mem.copy(u8, real_result[i..], result.items);
713 @memcpy(real_result[i..][0..result.items.len], result.items);
714714 return real_result;
715715 }
716716}
......@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
11061106 while (rest_it.next()) |to_component| {
11071107 result[result_index] = '\\';
11081108 result_index += 1;
1109 mem.copy(u8, result[result_index..], to_component);
1109 @memcpy(result[result_index..][0..to_component.len], to_component);
11101110 result_index += to_component.len;
11111111 }
11121112
......@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
11511151 return allocator.realloc(result, result_index - 1);
11521152 }
11531153
1154 mem.copy(u8, result[result_index..], to_rest);
1154 @memcpy(result[result_index..][0..to_rest.len], to_rest);
11551155 return result;
11561156 }
11571157
lib/std/hash/cityhash.zig+2-2
......@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
348348 var key: [256]u8 = undefined;
349349 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
350350
351 std.mem.set(u8, &key, 0);
352 std.mem.set(u8, &hashes_bytes, 0);
351 @memset(&key, 0);
352 @memset(&hashes_bytes, 0);
353353
354354 var i: u32 = 0;
355355 while (i < 256) : (i += 1) {
lib/std/hash/wyhash.zig+3-2
......@@ -147,7 +147,7 @@ pub const Wyhash = struct {
147147
148148 if (self.buf_len != 0 and self.buf_len + b.len >= 32) {
149149 off += 32 - self.buf_len;
150 mem.copy(u8, self.buf[self.buf_len..], b[0..off]);
150 @memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
151151 self.state.update(self.buf[0..]);
152152 self.buf_len = 0;
153153 }
......@@ -156,7 +156,8 @@ pub const Wyhash = struct {
156156 const aligned_len = remain_len - (remain_len % 32);
157157 self.state.update(b[off .. off + aligned_len]);
158158
159 mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
159 const src = b[off + aligned_len ..];
160 @memcpy(self.buf[self.buf_len..][0..src.len], src);
160161 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
161162 }
162163
lib/std/hash/xxhash.zig+6-6
......@@ -36,7 +36,7 @@ pub const XxHash64 = struct {
3636
3737 pub fn update(self: *XxHash64, input: []const u8) void {
3838 if (input.len < 32 - self.buf_len) {
39 mem.copy(u8, self.buf[self.buf_len..], input);
39 @memcpy(self.buf[self.buf_len..][0..input.len], input);
4040 self.buf_len += input.len;
4141 return;
4242 }
......@@ -45,7 +45,7 @@ pub const XxHash64 = struct {
4545
4646 if (self.buf_len > 0) {
4747 i = 32 - self.buf_len;
48 mem.copy(u8, self.buf[self.buf_len..], input[0..i]);
48 @memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
4949 self.processStripe(&self.buf);
5050 self.buf_len = 0;
5151 }
......@@ -55,7 +55,7 @@ pub const XxHash64 = struct {
5555 }
5656
5757 const remaining_bytes = input[i..];
58 mem.copy(u8, &self.buf, remaining_bytes);
58 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
5959 self.buf_len = remaining_bytes.len;
6060 }
6161
......@@ -165,7 +165,7 @@ pub const XxHash32 = struct {
165165
166166 pub fn update(self: *XxHash32, input: []const u8) void {
167167 if (input.len < 16 - self.buf_len) {
168 mem.copy(u8, self.buf[self.buf_len..], input);
168 @memcpy(self.buf[self.buf_len..][0..input.len], input);
169169 self.buf_len += input.len;
170170 return;
171171 }
......@@ -174,7 +174,7 @@ pub const XxHash32 = struct {
174174
175175 if (self.buf_len > 0) {
176176 i = 16 - self.buf_len;
177 mem.copy(u8, self.buf[self.buf_len..], input[0..i]);
177 @memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
178178 self.processStripe(&self.buf);
179179 self.buf_len = 0;
180180 }
......@@ -184,7 +184,7 @@ pub const XxHash32 = struct {
184184 }
185185
186186 const remaining_bytes = input[i..];
187 mem.copy(u8, &self.buf, remaining_bytes);
187 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
188188 self.buf_len = remaining_bytes.len;
189189 }
190190
lib/std/heap/WasmAllocator.zig+1-1
......@@ -230,7 +230,7 @@ test "shrink" {
230230 var slice = try test_ally.alloc(u8, 20);
231231 defer test_ally.free(slice);
232232
233 mem.set(u8, slice, 0x11);
233 @memset(slice, 0x11);
234234
235235 try std.testing.expect(test_ally.resize(slice, 17));
236236 slice = slice[0..17];
lib/std/heap/WasmPageAllocator.zig+1-1
......@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {
153153
154154 extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];
155155 // Since this is the first page being freed and we consume it, assume *nothing* is free.
156 mem.set(u128, extended.data, PageStatus.none_free);
156 @memset(extended.data, PageStatus.none_free);
157157 }
158158 const clamped_start = @max(extendedOffset(), start);
159159 extended.recycle(clamped_start - extendedOffset(), new_end - clamped_start);
lib/std/heap/general_purpose_allocator.zig+2-2
......@@ -448,7 +448,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
448448
449449 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
450450 if (stack_n == 0) return;
451 mem.set(usize, addresses, 0);
451 @memset(addresses, 0);
452452 var stack_trace = StackTrace{
453453 .instruction_addresses = addresses,
454454 .index = 0,
......@@ -1113,7 +1113,7 @@ test "shrink" {
11131113 var slice = try allocator.alloc(u8, 20);
11141114 defer allocator.free(slice);
11151115
1116 mem.set(u8, slice, 0x11);
1116 @memset(slice, 0x11);
11171117
11181118 try std.testing.expect(allocator.resize(slice, 17));
11191119 slice = slice[0..17];
lib/std/http/Client.zig+1-1
......@@ -284,7 +284,7 @@ pub const BufferedConnection = struct {
284284 if (available > 0) {
285285 const can_read = @truncate(u16, @min(available, left));
286286
287 std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);
287 @memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
288288 out_index += can_read;
289289 bconn.start += can_read;
290290
lib/std/http/Headers.zig+2-1
......@@ -38,7 +38,8 @@ pub const Field = struct {
3838
3939 pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {
4040 if (entry.value.len <= new_value.len) {
41 std.mem.copy(u8, @constCast(entry.value), new_value);
41 // TODO: eliminate this use of `@constCast`.
42 @memcpy(@constCast(entry.value)[0..new_value.len], new_value);
4243 } else {
4344 allocator.free(entry.value);
4445
lib/std/http/Server.zig+1-1
......@@ -128,7 +128,7 @@ pub const BufferedConnection = struct {
128128 if (available > 0) {
129129 const can_read = @truncate(u16, @min(available, left));
130130
131 std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);
131 @memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
132132 out_index += can_read;
133133 bconn.start += can_read;
134134
lib/std/http/protocol.zig+1-1
......@@ -654,7 +654,7 @@ const MockBufferedConnection = struct {
654654 if (available > 0) {
655655 const can_read = @truncate(u16, @min(available, left));
656656
657 std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);
657 @memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
658658 out_index += can_read;
659659 bconn.start += can_read;
660660
lib/std/io/buffered_reader.zig+4-7
......@@ -20,8 +20,8 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
2020 var dest_index: usize = 0;
2121
2222 while (dest_index < dest.len) {
23 const written = std.math.min(dest.len - dest_index, self.end - self.start);
24 std.mem.copy(u8, dest[dest_index..], self.buf[self.start .. self.start + written]);
23 const written = @min(dest.len - dest_index, self.end - self.start);
24 @memcpy(dest[dest_index..][0..written], self.buf[self.start..][0..written]);
2525 if (written == 0) {
2626 // buf empty, fill it
2727 const n = try self.unbuffered_reader.read(self.buf[0..]);
......@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {
115115 }
116116
117117 fn read(self: *Self, dest: []u8) Error!usize {
118 if (self.curr_read >= self.reads_allowed) {
119 return 0;
120 }
121 std.debug.assert(dest.len >= self.block.len);
122 std.mem.copy(u8, dest, self.block);
118 if (self.curr_read >= self.reads_allowed) return 0;
119 @memcpy(dest[0..self.block.len], self.block);
123120
124121 self.curr_read += 1;
125122 return self.block.len;
lib/std/io/buffered_writer.zig+3-2
......@@ -30,8 +30,9 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty
3030 return self.unbuffered_writer.write(bytes);
3131 }
3232
33 mem.copy(u8, self.buf[self.end..], bytes);
34 self.end += bytes.len;
33 const new_end = self.end + bytes.len;
34 @memcpy(self.buf[self.end..new_end], bytes);
35 self.end = new_end;
3536 return bytes.len;
3637 }
3738 };
lib/std/io/fixed_buffer_stream.zig+3-3
......@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
4545 }
4646
4747 pub fn read(self: *Self, dest: []u8) ReadError!usize {
48 const size = std.math.min(dest.len, self.buffer.len - self.pos);
48 const size = @min(dest.len, self.buffer.len - self.pos);
4949 const end = self.pos + size;
5050
51 mem.copy(u8, dest[0..size], self.buffer[self.pos..end]);
51 @memcpy(dest[0..size], self.buffer[self.pos..end]);
5252 self.pos = end;
5353
5454 return size;
......@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
6767 else
6868 self.buffer.len - self.pos;
6969
70 mem.copy(u8, self.buffer[self.pos .. self.pos + n], bytes[0..n]);
70 @memcpy(self.buffer[self.pos..][0..n], bytes[0..n]);
7171 self.pos += n;
7272
7373 if (n == 0) return error.NoSpaceLeft;
lib/std/io/writer.zig+1-1
......@@ -35,7 +35,7 @@ pub fn Writer(
3535
3636 pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {
3737 var bytes: [256]u8 = undefined;
38 mem.set(u8, bytes[0..], byte);
38 @memset(bytes[0..], byte);
3939
4040 var remaining: usize = n;
4141 while (remaining > 0) {
lib/std/json.zig+2-2
......@@ -1667,7 +1667,7 @@ fn parseInternal(
16671667 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
16681668 if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
16691669 switch (stringToken.escapes) {
1670 .None => mem.copy(u8, &r, source_slice),
1670 .None => @memcpy(r[0..source_slice.len], source_slice),
16711671 .Some => try unescapeValidString(&r, source_slice),
16721672 }
16731673 return r;
......@@ -1733,7 +1733,7 @@ fn parseInternal(
17331733 try allocator.alloc(u8, len);
17341734 errdefer allocator.free(output);
17351735 switch (stringToken.escapes) {
1736 .None => mem.copy(u8, output, source_slice),
1736 .None => @memcpy(output[0..source_slice.len], source_slice),
17371737 .Some => try unescapeValidString(output, source_slice),
17381738 }
17391739
lib/std/json/test.zig+1-1
......@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {
28112811 // StreamingParser has multiple internal fields set to undefined. This causes issues when using
28122812 // expectEqual so these are zeroed. We are testing for equality here only because this is a
28132813 // known small test reproduction which hits the relevant LLVM issue.
2814 std.mem.set(u8, @ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
2814 @memset(@ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
28152815 try std.testing.expectEqual(parser, parser);
28162816}
28172817
lib/std/math/big/int.zig+32-32
......@@ -176,7 +176,7 @@ pub const Mutable = struct {
176176 /// Asserts the value fits in the limbs buffer.
177177 pub fn copy(self: *Mutable, other: Const) void {
178178 if (self.limbs.ptr != other.limbs.ptr) {
179 mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);
179 @memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
180180 }
181181 self.positive = other.positive;
182182 self.len = other.limbs.len;
......@@ -199,7 +199,7 @@ pub const Mutable = struct {
199199 /// can be modified separately from the original.
200200 /// Asserts that limbs is big enough to store the value.
201201 pub fn clone(other: Mutable, limbs: []Limb) Mutable {
202 mem.copy(Limb, limbs, other.limbs[0..other.len]);
202 @memcpy(limbs[0..other.len], other.limbs[0..other.len]);
203203 return .{
204204 .limbs = limbs,
205205 .len = other.len,
......@@ -344,7 +344,7 @@ pub const Mutable = struct {
344344 .min => {
345345 // Negative bound, signed = -0x80.
346346 r.len = req_limbs;
347 mem.set(Limb, r.limbs[0 .. r.len - 1], 0);
347 @memset(r.limbs[0 .. r.len - 1], 0);
348348 r.limbs[r.len - 1] = signmask;
349349 r.positive = false;
350350 },
......@@ -363,7 +363,7 @@ pub const Mutable = struct {
363363 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
364364
365365 r.len = new_req_limbs;
366 std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
366 @memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
367367 r.limbs[r.len - 1] = new_mask;
368368 }
369369 },
......@@ -376,7 +376,7 @@ pub const Mutable = struct {
376376 .max => {
377377 // Max bound, unsigned = 0xFF
378378 r.len = req_limbs;
379 std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
379 @memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
380380 r.limbs[r.len - 1] = mask;
381381 },
382382 },
......@@ -489,7 +489,7 @@ pub const Mutable = struct {
489489 if (msl < req_limbs) {
490490 r.limbs[msl] = 1;
491491 r.len = req_limbs;
492 mem.set(Limb, r.limbs[msl + 1 .. req_limbs], 0);
492 @memset(r.limbs[msl + 1 .. req_limbs], 0);
493493 } else {
494494 carry_truncated = true;
495495 }
......@@ -637,14 +637,14 @@ pub const Mutable = struct {
637637
638638 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
639639 const start = buf_index;
640 mem.copy(Limb, limbs_buffer[buf_index..], a.limbs);
640 @memcpy(limbs_buffer[buf_index..][0..a.limbs.len], a.limbs);
641641 buf_index += a.limbs.len;
642642 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
643643 } else a;
644644
645645 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
646646 const start = buf_index;
647 mem.copy(Limb, limbs_buffer[buf_index..], b.limbs);
647 @memcpy(limbs_buffer[buf_index..][0..b.limbs.len], b.limbs);
648648 buf_index += b.limbs.len;
649649 break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();
650650 } else b;
......@@ -676,7 +676,7 @@ pub const Mutable = struct {
676676 }
677677 }
678678
679 mem.set(Limb, rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
679 @memset(rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
680680
681681 llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);
682682
......@@ -708,7 +708,7 @@ pub const Mutable = struct {
708708 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
709709 const start = buf_index;
710710 const a_len = math.min(req_limbs, a.limbs.len);
711 mem.copy(Limb, limbs_buffer[buf_index..], a.limbs[0..a_len]);
711 @memcpy(limbs_buffer[buf_index..][0..a_len], a.limbs[0..a_len]);
712712 buf_index += a_len;
713713 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
714714 } else a;
......@@ -716,7 +716,7 @@ pub const Mutable = struct {
716716 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
717717 const start = buf_index;
718718 const b_len = math.min(req_limbs, b.limbs.len);
719 mem.copy(Limb, limbs_buffer[buf_index..], b.limbs[0..b_len]);
719 @memcpy(limbs_buffer[buf_index..][0..b_len], b.limbs[0..b_len]);
720720 buf_index += b_len;
721721 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
722722 } else b;
......@@ -751,7 +751,7 @@ pub const Mutable = struct {
751751 const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];
752752 const b_limbs = b.limbs[0..math.min(req_limbs, b.limbs.len)];
753753
754 mem.set(Limb, rma.limbs[0..req_limbs], 0);
754 @memset(rma.limbs[0..req_limbs], 0);
755755
756756 llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);
757757 rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));
......@@ -919,7 +919,7 @@ pub const Mutable = struct {
919919 _ = opt_allocator;
920920 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
921921
922 mem.set(Limb, rma.limbs, 0);
922 @memset(rma.limbs, 0);
923923
924924 llsquareBasecase(rma.limbs, a.limbs);
925925
......@@ -1522,7 +1522,7 @@ pub const Mutable = struct {
15221522 if (xy_trailing != 0) {
15231523 // Manually shift here since we know its limb aligned.
15241524 mem.copyBackwards(Limb, r.limbs[xy_trailing..], r.limbs[0..r.len]);
1525 mem.set(Limb, r.limbs[0..xy_trailing], 0);
1525 @memset(r.limbs[0..xy_trailing], 0);
15261526 r.len += xy_trailing;
15271527 }
15281528 }
......@@ -1556,7 +1556,7 @@ pub const Mutable = struct {
15561556 // for 0 <= j <= n - t, set q[j] to 0
15571557 q.len = shift + 1;
15581558 q.positive = true;
1559 mem.set(Limb, q.limbs[0..q.len], 0);
1559 @memset(q.limbs[0..q.len], 0);
15601560
15611561 // 2.
15621562 // while x >= y * b^(n - t):
......@@ -1691,7 +1691,7 @@ pub const Mutable = struct {
16911691
16921692 r.addScalar(a.abs(), -1);
16931693 if (req_limbs > r.len) {
1694 mem.set(Limb, r.limbs[r.len..req_limbs], 0);
1694 @memset(r.limbs[r.len..req_limbs], 0);
16951695 }
16961696
16971697 assert(r.limbs.len >= req_limbs);
......@@ -1730,7 +1730,7 @@ pub const Mutable = struct {
17301730
17311731 // Zero-extend the result
17321732 if (req_limbs > r.len) {
1733 mem.set(Limb, r.limbs[r.len..req_limbs], 0);
1733 @memset(r.limbs[r.len..req_limbs], 0);
17341734 }
17351735
17361736 // Truncate to required number of limbs.
......@@ -1921,8 +1921,8 @@ pub const Const = struct {
19211921
19221922 /// The result is an independent resource which is managed by the caller.
19231923 pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {
1924 const limbs = try allocator.alloc(Limb, math.max(Managed.default_capacity, self.limbs.len));
1925 mem.copy(Limb, limbs, self.limbs);
1924 const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
1925 @memcpy(limbs[0..self.limbs.len], self.limbs);
19261926 return Managed{
19271927 .allocator = allocator,
19281928 .limbs = limbs,
......@@ -1935,7 +1935,7 @@ pub const Const = struct {
19351935
19361936 /// Asserts `limbs` is big enough to store the value.
19371937 pub fn toMutable(self: Const, limbs: []Limb) Mutable {
1938 mem.copy(Limb, limbs, self.limbs[0..self.limbs.len]);
1938 @memcpy(limbs[0..self.limbs.len], self.limbs[0..self.limbs.len]);
19391939 return .{
19401940 .limbs = limbs,
19411941 .positive = self.positive,
......@@ -2253,7 +2253,7 @@ pub const Const = struct {
22532253 .positive = true, // Make absolute by ignoring self.positive.
22542254 .len = self.limbs.len,
22552255 };
2256 mem.copy(Limb, q.limbs, self.limbs);
2256 @memcpy(q.limbs[0..self.limbs.len], self.limbs);
22572257
22582258 var r: Mutable = .{
22592259 .limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],
......@@ -2587,8 +2587,8 @@ pub const Managed = struct {
25872587 .allocator = allocator,
25882588 .metadata = other.metadata,
25892589 .limbs = block: {
2590 var limbs = try allocator.alloc(Limb, other.len());
2591 mem.copy(Limb, limbs[0..], other.limbs[0..other.len()]);
2590 const limbs = try allocator.alloc(Limb, other.len());
2591 @memcpy(limbs, other.limbs[0..other.len()]);
25922592 break :block limbs;
25932593 },
25942594 };
......@@ -2600,7 +2600,7 @@ pub const Managed = struct {
26002600 if (self.limbs.ptr == other.limbs.ptr) return;
26012601
26022602 try self.ensureCapacity(other.limbs.len);
2603 mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);
2603 @memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
26042604 self.setMetadata(other.positive, other.limbs.len);
26052605 }
26062606
......@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(
33023302 // Note, we don't need to compute all of p2, just enough limbs to satisfy r.
33033303 const p2_limbs = math.min(limbs_after_split, a1.len + b1.len);
33043304
3305 mem.set(Limb, tmp[0..p2_limbs], 0);
3305 @memset(tmp[0..p2_limbs], 0);
33063306 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
33073307 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
33083308
......@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(
33173317 // Compute p0.
33183318 // Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.
33193319 const p0_limbs = a0.len + b0.len;
3320 mem.set(Limb, tmp[0..p0_limbs], 0);
3320 @memset(tmp[0..p0_limbs], 0);
33213321 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
33223322 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
33233323
......@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(
33413341 return;
33423342 }
33433343
3344 mem.set(Limb, tmp, 0);
3344 @memset(tmp, 0);
33453345
33463346 // p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.
33473347 // Note that in this case, we again need some storage for intermediary results
......@@ -3666,7 +3666,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
36663666 }
36673667
36683668 r[limb_shift - 1] = carry;
3669 mem.set(Limb, r[0 .. limb_shift - 1], 0);
3669 @memset(r[0 .. limb_shift - 1], 0);
36703670}
36713671
36723672fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
......@@ -4061,8 +4061,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
40614061 tmp2 = tmp_limbs;
40624062 }
40634063
4064 mem.copy(Limb, tmp1, a);
4065 mem.set(Limb, tmp1[a.len..], 0);
4064 @memcpy(tmp1[0..a.len], a);
4065 @memset(tmp1[a.len..], 0);
40664066
40674067 // Scan the exponent as a binary number, from left to right, dropping the
40684068 // most significant bit set.
......@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
40744074 var i: usize = 0;
40754075 while (i < exp_bits) : (i += 1) {
40764076 // Square
4077 mem.set(Limb, tmp2, 0);
4077 @memset(tmp2, 0);
40784078 llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);
40794079 mem.swap([]Limb, &tmp1, &tmp2);
40804080 // Multiply by a
40814081 const ov = @shlWithOverflow(exp, 1);
40824082 exp = ov[0];
40834083 if (ov[1] != 0) {
4084 mem.set(Limb, tmp2, 0);
4084 @memset(tmp2, 0);
40854085 llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);
40864086 mem.swap([]Limb, &tmp1, &tmp2);
40874087 }
lib/std/mem.zig+14-15
......@@ -192,12 +192,15 @@ test "Allocator.resize" {
192192 }
193193}
194194
195/// Deprecated: use `@memcpy` if the arguments do not overlap, or
196/// `copyForwards` if they do.
197pub const copy = copyForwards;
198
195199/// Copy all of source into dest at position 0.
196200/// dest.len must be >= source.len.
197201/// If the slices overlap, dest.ptr must be <= src.ptr.
198pub fn copy(comptime T: type, dest: []T, source: []const T) void {
199 for (dest[0..source.len], source) |*d, s|
200 d.* = s;
202pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void {
203 for (dest[0..source.len], source) |*d, s| d.* = s;
201204}
202205
203206/// Copy all of source into dest at position 0.
......@@ -216,11 +219,7 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
216219 }
217220}
218221
219/// Sets all elements of `dest` to `value`.
220pub fn set(comptime T: type, dest: []T, value: T) void {
221 for (dest) |*d|
222 d.* = value;
223}
222pub const set = @compileError("deprecated; use @memset instead");
224223
225224/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
226225/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when
......@@ -249,7 +248,7 @@ pub fn zeroes(comptime T: type) T {
249248 if (@sizeOf(T) == 0) return undefined;
250249 if (struct_info.layout == .Extern) {
251250 var item: T = undefined;
252 set(u8, asBytes(&item), 0);
251 @memset(asBytes(&item), 0);
253252 return item;
254253 } else {
255254 var structure: T = undefined;
......@@ -1667,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
16671666 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16681667
16691668 if (@typeInfo(T).Int.bits == 0) {
1670 return set(u8, buffer, 0);
1669 return @memset(buffer, 0);
16711670 } else if (@typeInfo(T).Int.bits == 8) {
1672 set(u8, buffer, 0);
1671 @memset(buffer, 0);
16731672 buffer[0] = @bitCast(u8, value);
16741673 return;
16751674 }
......@@ -1691,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
16911690 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16921691
16931692 if (@typeInfo(T).Int.bits == 0) {
1694 return set(u8, buffer, 0);
1693 return @memset(buffer, 0);
16951694 } else if (@typeInfo(T).Int.bits == 8) {
1696 set(u8, buffer, 0);
1695 @memset(buffer, 0);
16971696 buffer[buffer.len - 1] = @bitCast(u8, value);
16981697 return;
16991698 }
......@@ -2706,7 +2705,7 @@ fn testReadIntImpl() !void {
27062705 }
27072706}
27082707
2709test "writeIntSlice" {
2708test writeIntSlice {
27102709 try testWriteIntImpl();
27112710 comptime try testWriteIntImpl();
27122711}
......@@ -3124,7 +3123,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen
31243123 var replacements: usize = 0;
31253124 while (slide < input.len) {
31263125 if (mem.startsWith(T, input[slide..], needle)) {
3127 mem.copy(T, output[i .. i + replacement.len], replacement);
3126 @memcpy(output[i..][0..replacement.len], replacement);
31283127 i += replacement.len;
31293128 slide += needle.len;
31303129 replacements += 1;
lib/std/mem/Allocator.zig+2-2
......@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {
307307/// Copies `m` to newly allocated memory. Caller owns the memory.
308308pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {
309309 const new_buf = try allocator.alloc(T, m.len);
310 mem.copy(T, new_buf, m);
310 @memcpy(new_buf, m);
311311 return new_buf;
312312}
313313
314314/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
315315pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {
316316 const new_buf = try allocator.alloc(T, m.len + 1);
317 mem.copy(T, new_buf, m);
317 @memcpy(new_buf[0..m.len], m);
318318 new_buf[m.len] = 0;
319319 return new_buf[0..m.len :0];
320320}
lib/std/multi_array_list.zig+3-3
......@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {
380380 inline for (fields, 0..) |field_info, i| {
381381 if (@sizeOf(field_info.type) != 0) {
382382 const field = @intToEnum(Field, i);
383 mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
383 @memcpy(other_slice.items(field), self_slice.items(field));
384384 }
385385 }
386386 gpa.free(self.allocatedBytes());
......@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {
441441 inline for (fields, 0..) |field_info, i| {
442442 if (@sizeOf(field_info.type) != 0) {
443443 const field = @intToEnum(Field, i);
444 mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
444 @memcpy(other_slice.items(field), self_slice.items(field));
445445 }
446446 }
447447 gpa.free(self.allocatedBytes());
......@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {
460460 inline for (fields, 0..) |field_info, i| {
461461 if (@sizeOf(field_info.type) != 0) {
462462 const field = @intToEnum(Field, i);
463 mem.copy(field_info.type, result_slice.items(field), self_slice.items(field));
463 @memcpy(result_slice.items(field), self_slice.items(field));
464464 }
465465 }
466466 return result;
lib/std/net.zig+14-14
......@@ -106,8 +106,8 @@ pub const Address = extern union {
106106 // Add 1 to ensure a terminating 0 is present in the path array for maximum portability.
107107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
108108
109 mem.set(u8, &sock_addr.path, 0);
110 mem.copy(u8, &sock_addr.path, path);
109 @memset(&sock_addr.path, 0);
110 @memcpy(sock_addr.path[0..path.len], path);
111111
112112 return Address{ .un = sock_addr };
113113 }
......@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {
346346 if (!saw_any_digits) {
347347 if (abbrv) return error.InvalidCharacter; // ':::'
348348 if (i != 0) abbrv = true;
349 mem.set(u8, ip_slice[index..], 0);
349 @memset(ip_slice[index..], 0);
350350 ip_slice = tail[0..];
351351 index = 0;
352352 continue;
......@@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {
416416 index += 1;
417417 ip_slice[index] = @truncate(u8, x);
418418 index += 1;
419 mem.copy(u8, result.sa.addr[16 - index ..], ip_slice[0..index]);
419 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
420420 return result;
421421 }
422422 }
......@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {
465465 if (!saw_any_digits) {
466466 if (abbrv) return error.InvalidCharacter; // ':::'
467467 if (i != 0) abbrv = true;
468 mem.set(u8, ip_slice[index..], 0);
468 @memset(ip_slice[index..], 0);
469469 ip_slice = tail[0..];
470470 index = 0;
471471 continue;
......@@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {
550550 index += 1;
551551 ip_slice[index] = @truncate(u8, x);
552552 index += 1;
553 mem.copy(u8, result.sa.addr[16 - index ..], ip_slice[0..index]);
553 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
554554 return result;
555555 }
556556 }
......@@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {
662662 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
663663 defer os.closeSocket(sockfd);
664664
665 std.mem.copy(u8, &ifr.ifrn.name, name);
665 @memcpy(ifr.ifrn.name[0..name.len], name);
666666 ifr.ifrn.name[name.len] = 0;
667667
668668 // TODO investigate if this needs to be integrated with evented I/O.
......@@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {
676676 return error.NameTooLong;
677677
678678 var if_name: [os.IFNAMESIZE:0]u8 = undefined;
679 std.mem.copy(u8, &if_name, name);
679 @memcpy(if_name[0..name.len], name);
680680 if_name[name.len] = 0;
681681 const if_slice = if_name[0..name.len :0];
682682 const index = os.system.if_nametoindex(if_slice);
......@@ -1041,14 +1041,14 @@ fn linuxLookupName(
10411041 var salen: os.socklen_t = undefined;
10421042 var dalen: os.socklen_t = undefined;
10431043 if (addr.addr.any.family == os.AF.INET6) {
1044 mem.copy(u8, &da6.addr, &addr.addr.in6.sa.addr);
1044 da6.addr = addr.addr.in6.sa.addr;
10451045 da = @ptrCast(*os.sockaddr, &da6);
10461046 dalen = @sizeOf(os.sockaddr.in6);
10471047 sa = @ptrCast(*os.sockaddr, &sa6);
10481048 salen = @sizeOf(os.sockaddr.in6);
10491049 } else {
1050 mem.copy(u8, &sa6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
1051 mem.copy(u8, &da6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
1050 sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1051 da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
10521052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
10531053 da4.addr = addr.addr.in.sa.addr;
10541054 da = @ptrCast(*os.sockaddr, &da4);
......@@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(
13431343 // name is not a CNAME record) and serves as a buffer for passing
13441344 // the full requested name to name_from_dns.
13451345 try canon.resize(canon_name.len);
1346 mem.copy(u8, canon.items, canon_name);
1346 @memcpy(canon.items, canon_name);
13471347 try canon.append('.');
13481348
13491349 var tok_it = mem.tokenize(u8, search, " \t");
......@@ -1567,7 +1567,7 @@ fn resMSendRc(
15671567 for (0..ns.len) |i| {
15681568 if (ns[i].any.family != os.AF.INET) continue;
15691569 mem.writeIntNative(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr);
1570 mem.copy(u8, ns[i].in6.sa.addr[0..12], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
1570 ns[i].in6.sa.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
15711571 ns[i].any.family = os.AF.INET6;
15721572 ns[i].in6.sa.flowinfo = 0;
15731573 ns[i].in6.sa.scope_id = 0;
......@@ -1665,7 +1665,7 @@ fn resMSendRc(
16651665 if (i == next) {
16661666 while (next < queries.len and answers[next].len != 0) : (next += 1) {}
16671667 } else {
1668 mem.copy(u8, answer_bufs[i], answer_bufs[next][0..rlen]);
1668 @memcpy(answer_bufs[i][0..rlen], answer_bufs[next][0..rlen]);
16691669 }
16701670
16711671 if (next == queries.len) break :outer;
lib/std/os.zig+19-15
......@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(
18811881 while (it.next()) |search_path| {
18821882 const path_len = search_path.len + file_slice.len + 1;
18831883 if (path_buf.len < path_len + 1) return error.NameTooLong;
1884 mem.copy(u8, &path_buf, search_path);
1884 @memcpy(path_buf[0..search_path.len], search_path);
18851885 path_buf[search_path.len] = '/';
1886 mem.copy(u8, path_buf[search_path.len + 1 ..], file_slice);
1886 @memcpy(path_buf[search_path.len + 1 ..][0..file_slice.len], file_slice);
18871887 path_buf[path_len] = 0;
18881888 const full_path = path_buf[0..path_len :0].ptr;
18891889 switch (arg0_expand) {
......@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
19171917 if (builtin.link_libc) {
19181918 var small_key_buf: [64]u8 = undefined;
19191919 if (key.len < small_key_buf.len) {
1920 mem.copy(u8, &small_key_buf, key);
1920 @memcpy(small_key_buf[0..key.len], key);
19211921 small_key_buf[key.len] = 0;
19221922 const key0 = small_key_buf[0..key.len :0];
19231923 return getenvZ(key0);
......@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
20222022 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
20232023 const path = ".";
20242024 if (out_buffer.len < path.len) return error.NameTooLong;
2025 std.mem.copy(u8, out_buffer, path);
2026 return out_buffer[0..path.len];
2025 const result = out_buffer[0..path.len];
2026 @memcpy(result, path);
2027 return result;
20272028 }
20282029
20292030 const err = if (builtin.link_libc) blk: {
......@@ -2673,7 +2674,7 @@ pub fn renameatW(
26732674 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong
26742675 .FileName = undefined,
26752676 };
2676 std.mem.copy(u16, @as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
2677 @memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
26772678
26782679 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
26792680
......@@ -5264,8 +5265,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
52645265 }
52655266 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;
52665267 if (len == 0) return error.NameTooLong;
5267 mem.copy(u8, out_buffer, kfile.path[0..len]);
5268 return out_buffer[0..len];
5268 const result = out_buffer[0..len];
5269 @memcpy(result, kfile.path[0..len]);
5270 return result;
52695271 } else {
52705272 // This fallback implementation reimplements libutil's `kinfo_getfile()`.
52715273 // The motivation is to avoid linking -lutil when building zig or general
......@@ -5296,8 +5298,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
52965298 if (kf.fd == fd) {
52975299 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
52985300 if (len == 0) return error.NameTooLong;
5299 mem.copy(u8, out_buffer, kf.path[0..len]);
5300 return out_buffer[0..len];
5301 const result = out_buffer[0..len];
5302 @memcpy(result, kf.path[0..len]);
5303 return result;
53015304 }
53025305 i += @intCast(usize, kf.structsize);
53035306 }
......@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
56865689 if (builtin.os.tag == .linux) {
56875690 const uts = uname();
56885691 const hostname = mem.sliceTo(&uts.nodename, 0);
5689 mem.copy(u8, name_buffer, hostname);
5690 return name_buffer[0..hostname.len];
5692 const result = name_buffer[0..hostname.len];
5693 @memcpy(result, hostname);
5694 return result;
56915695 }
56925696
56935697 @compileError("TODO implement gethostname for this OS");
......@@ -5725,7 +5729,7 @@ pub fn res_mkquery(
57255729 @memset(q[0..n], 0);
57265730 q[2] = @as(u8, op) * 8 + 1;
57275731 q[5] = 1;
5728 mem.copy(u8, q[13..], name);
5732 @memcpy(q[13..][0..name.len], name);
57295733 var i: usize = 13;
57305734 var j: usize = undefined;
57315735 while (q[i] != 0) : (i = j + 1) {
......@@ -5748,7 +5752,7 @@ pub fn res_mkquery(
57485752 q[0] = @truncate(u8, id / 256);
57495753 q[1] = @truncate(u8, id);
57505754
5751 mem.copy(u8, buf, q[0..n]);
5755 @memcpy(buf[0..n], q[0..n]);
57525756 return n;
57535757}
57545758
......@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
67556759 var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;
67566760 // >= rather than > to make room for the null byte
67576761 if (name.len >= MFD_MAX_NAME_LEN) return error.NameTooLong;
6758 mem.copy(u8, &path_with_null, name);
6762 @memcpy(path_with_null[0..name.len], name);
67596763 path_with_null[name.len] = 0;
67606764 return path_with_null;
67616765}
lib/std/os/linux/bpf.zig+1-1
......@@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {
16311631 const status = try map_get_next_key(map, &lookup_key, &next_key);
16321632 try expectEqual(status, true);
16331633 try expectEqual(next_key, key);
1634 std.mem.copy(u8, &lookup_key, &next_key);
1634 lookup_key = next_key;
16351635 const status2 = try map_get_next_key(map, &lookup_key, &next_key);
16361636 try expectEqual(status2, false);
16371637
lib/std/os/linux/io_uring.zig+5-5
......@@ -1855,8 +1855,8 @@ test "write_fixed/read_fixed" {
18551855
18561856 var raw_buffers: [2][11]u8 = undefined;
18571857 // First buffer will be written to the file.
1858 std.mem.set(u8, &raw_buffers[0], 'z');
1859 std.mem.copy(u8, &raw_buffers[0], "foobar");
1858 @memset(&raw_buffers[0], 'z');
1859 raw_buffers[0][0.."foobar".len].* = "foobar".*;
18601860
18611861 var buffers = [2]os.iovec{
18621862 .{ .iov_base = &raw_buffers[0], .iov_len = raw_buffers[0].len },
......@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {
29662966 // Provide 1 buffer again
29672967
29682968 // Deliberately put something we don't expect in the buffers
2969 mem.set(u8, mem.sliceAsBytes(&buffers), 42);
2969 @memset(mem.sliceAsBytes(&buffers), 42);
29702970
29712971 const reprovided_buffer_id = 2;
29722972
......@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {
31553155 // Do 4 recv which should consume all buffers
31563156
31573157 // Deliberately put something we don't expect in the buffers
3158 mem.set(u8, mem.sliceAsBytes(&buffers), 1);
3158 @memset(mem.sliceAsBytes(&buffers), 1);
31593159
31603160 var i: usize = 0;
31613161 while (i < buffers.len) : (i += 1) {
......@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {
32353235 // Final recv which should work
32363236
32373237 // Deliberately put something we don't expect in the buffers
3238 mem.set(u8, mem.sliceAsBytes(&buffers), 1);
3238 @memset(mem.sliceAsBytes(&buffers), 1);
32393239
32403240 {
32413241 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
lib/std/os/linux/tls.zig+2-2
......@@ -275,7 +275,7 @@ inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {
275275/// architecture-specific value of the thread-pointer register
276276pub fn prepareTLS(area: []u8) usize {
277277 // Clear the area we're going to use, just to be safe
278 mem.set(u8, area, 0);
278 @memset(area, 0);
279279 // Prepare the DTV
280280 const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);
281281 dtv.entries = 1;
......@@ -287,7 +287,7 @@ pub fn prepareTLS(area: []u8) usize {
287287 .VariantII => area.ptr + tls_image.tcb_offset,
288288 };
289289 // Copy the data
290 mem.copy(u8, area[tls_image.data_offset..], tls_image.init_data);
290 @memcpy(area[tls_image.data_offset..][0..tls_image.init_data.len], tls_image.init_data);
291291
292292 // Return the corrected value (if needed) for the tp register.
293293 // Overflow here is not a problem, the pointer arithmetic involving the tp
lib/std/os/test.zig+1-1
......@@ -587,7 +587,7 @@ test "mmap" {
587587 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
588588
589589 // Make sure the memory is writeable as requested
590 std.mem.set(u8, data, 0x55);
590 @memset(data, 0x55);
591591 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
592592 }
593593
lib/std/os/uefi/protocols/device_path_protocol.zig+1-1
......@@ -48,7 +48,7 @@ pub const DevicePathProtocol = extern struct {
4848 // DevicePathProtocol for the extra node before the end
4949 var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol));
5050
51 mem.copy(u8, buf, @ptrCast([*]const u8, self)[0..path_size]);
51 @memcpy(buf[0..path_size.len], @ptrCast([*]const u8, self)[0..path_size]);
5252
5353 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
5454 // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).
lib/std/os/windows.zig+7-7
......@@ -754,7 +754,7 @@ pub fn CreateSymbolicLink(
754754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,
755755 };
756756
757 std.mem.copy(u8, buffer[0..], std.mem.asBytes(&symlink_data));
757 @memcpy(buffer[0..@sizeOf(SYMLINK_DATA)], std.mem.asBytes(&symlink_data));
758758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
759759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;
760760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
......@@ -1208,8 +1208,8 @@ pub fn GetFinalPathNameByHandle(
12081208
12091209 if (out_buffer.len < drive_letter.len + file_name_u16.len) return error.NameTooLong;
12101210
1211 mem.copy(u16, out_buffer, drive_letter);
1212 mem.copy(u16, out_buffer[drive_letter.len..], file_name_u16);
1211 @memcpy(out_buffer[0..drive_letter.len], drive_letter);
1212 mem.copyForwards(u16, out_buffer[drive_letter.len..][0..file_name_u16.len], file_name_u16);
12131213 const total_len = drive_letter.len + file_name_u16.len;
12141214
12151215 // Validate that DOS does not contain any spurious nul bytes.
......@@ -2012,7 +2012,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
20122012 }
20132013 const prefix_u16 = [_]u16{ '\\', '?', '?', '\\' };
20142014 const start_index = if (prefix_index > 0 or !std.fs.path.isAbsolute(s)) 0 else blk: {
2015 mem.copy(u16, path_space.data[0..], prefix_u16[0..]);
2015 path_space.data[0..prefix_u16.len].* = prefix_u16;
20162016 break :blk prefix_u16.len;
20172017 };
20182018 path_space.len = start_index + try std.unicode.utf8ToUtf16Le(path_space.data[start_index..], s);
......@@ -2025,7 +2025,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
20252025 std.debug.assert(temp_path.len == path_space.len);
20262026 temp_path.data[path_space.len] = 0;
20272027 path_space.len = prefix_u16.len + try getFullPathNameW(&temp_path.data, path_space.data[prefix_u16.len..]);
2028 mem.copy(u16, &path_space.data, &prefix_u16);
2028 path_space.data[0..prefix_u16.len].* = prefix_u16;
20292029 std.debug.assert(path_space.data[path_space.len] == 0);
20302030 return path_space;
20312031 }
......@@ -2053,12 +2053,12 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace {
20532053
20542054 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {
20552055 const prefix = [_]u16{ '\\', '?', '?', '\\' };
2056 mem.copy(u16, path_space.data[0..], &prefix);
2056 path_space.data[0..prefix.len].* = prefix;
20572057 break :blk prefix.len;
20582058 };
20592059 path_space.len = start_index + s.len;
20602060 if (path_space.len > path_space.data.len) return error.NameTooLong;
2061 mem.copy(u16, path_space.data[start_index..], s);
2061 @memcpy(path_space.data[start_index..][0..s.len], s);
20622062 // > File I/O functions in the Windows API convert "/" to "\" as part of
20632063 // > converting the name to an NT-style name, except when using the "\\?\"
20642064 // > prefix as detailed in the following sections.
lib/std/process.zig+1-1
......@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {
855855
856856 const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);
857857 const result_contents = buf[slice_list_bytes..];
858 mem.copy(u8, result_contents, contents_slice);
858 @memcpy(result_contents[0..contents_slice.len], contents_slice);
859859
860860 var contents_index: usize = 0;
861861 for (slice_sizes, 0..) |len, i| {
lib/std/rand/ChaCha.zig+7-6
......@@ -40,7 +40,8 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
4040 }
4141 if (i < bytes.len) {
4242 var k = [_]u8{0} ** Cipher.key_length;
43 mem.copy(u8, k[0..], bytes[i..]);
43 const src = bytes[i..];
44 @memcpy(k[0..src.len], src);
4445 Cipher.xor(
4546 self.state[0..Cipher.key_length],
4647 self.state[0..Cipher.key_length],
......@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {
7273 if (avail > 0) {
7374 // Bytes from the current block
7475 const n = @min(avail, buf.len);
75 mem.copy(u8, buf[0..n], bytes[self.offset..][0..n]);
76 mem.set(u8, bytes[self.offset..][0..n], 0);
76 @memcpy(buf[0..n], bytes[self.offset..][0..n]);
77 @memset(bytes[self.offset..][0..n], 0);
7778 buf = buf[n..];
7879 self.offset += n;
7980 }
......@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {
8384
8485 // Full blocks
8586 while (buf.len >= bytes.len) {
86 mem.copy(u8, buf[0..bytes.len], bytes);
87 @memcpy(buf[0..bytes.len], bytes);
8788 buf = buf[bytes.len..];
8889 self.refill();
8990 }
9091
9192 // Remaining bytes
9293 if (buf.len > 0) {
93 mem.copy(u8, buf, bytes[0..buf.len]);
94 mem.set(u8, bytes[0..buf.len], 0);
94 @memcpy(buf, bytes[0..buf.len]);
95 @memset(bytes[0..buf.len], 0);
9596 self.offset = buf.len;
9697 }
9798}
lib/std/rand/Isaac64.zig+2-2
......@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {
8787fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
8888 // We ignore the multi-pass requirement since we don't currently expose full access to
8989 // seeding the self.m array completely.
90 mem.set(u64, self.m[0..], 0);
90 @memset(self.m[0..], 0);
9191 self.m[0] = init_s;
9292
9393 // prescrambled golden ratio constants
......@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
143143 }
144144 }
145145
146 mem.set(u64, self.r[0..], 0);
146 @memset(self.r[0..], 0);
147147 self.a = 0;
148148 self.b = 0;
149149 self.c = 0;
lib/std/segmented_list.zig+10-13
......@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
230230 allocator.free(new_dynamic_segments);
231231 } else {
232232 // Good thing we allocated that new memory slice.
233 mem.copy([*]T, new_dynamic_segments, self.dynamic_segments[0..new_cap_shelf_count]);
233 @memcpy(new_dynamic_segments, self.dynamic_segments[0..new_cap_shelf_count]);
234234 allocator.free(self.dynamic_segments);
235235 self.dynamic_segments = new_dynamic_segments;
236236 }
......@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
248248
249249 var i = start;
250250 if (end <= prealloc_item_count) {
251 mem.copy(T, dest[i - start ..], self.prealloc_segment[i..end]);
251 const src = self.prealloc_segment[i..end];
252 @memcpy(dest[i - start ..][0..src.len], src);
252253 return;
253254 } else if (i < prealloc_item_count) {
254 mem.copy(T, dest[i - start ..], self.prealloc_segment[i..]);
255 const src = self.prealloc_segment[i..];
256 @memcpy(dest[i - start ..][0..src.len], src);
255257 i = prealloc_item_count;
256258 }
257259
258260 while (i < end) {
259261 const shelf_index = shelfIndex(i);
260262 const copy_start = boxIndex(i, shelf_index);
261 const copy_end = std.math.min(shelfSize(shelf_index), copy_start + end - i);
262
263 mem.copy(
264 T,
265 dest[i - start ..],
266 self.dynamic_segments[shelf_index][copy_start..copy_end],
267 );
268
263 const copy_end = @min(shelfSize(shelf_index), copy_start + end - i);
264 const src = self.dynamic_segments[shelf_index][copy_start..copy_end];
265 @memcpy(dest[i - start ..][0..src.len], src);
269266 i += (copy_end - copy_start);
270267 }
271268 }
......@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {
498495 control[@intCast(usize, i)] = i + 1;
499496 }
500497
501 mem.set(i32, dest[0..], 0);
498 @memset(dest[0..], 0);
502499 list.writeToSlice(dest[0..], 0);
503500 try testing.expect(mem.eql(i32, control[0..], dest[0..]));
504501
505 mem.set(i32, dest[0..], 0);
502 @memset(dest[0..], 0);
506503 list.writeToSlice(dest[50..], 50);
507504 try testing.expect(mem.eql(i32, control[50..], dest[50..]));
508505 }
lib/std/sort.zig+38-21
......@@ -361,8 +361,10 @@ pub fn sort(
361361
362362 if (lessThan(context, items[B1.end - 1], items[A1.start])) {
363363 // the two ranges are in reverse order, so copy them in reverse order into the cache
364 mem.copy(T, cache[B1.length()..], items[A1.start..A1.end]);
365 mem.copy(T, cache[0..], items[B1.start..B1.end]);
364 const a1_items = items[A1.start..A1.end];
365 @memcpy(cache[B1.length()..][0..a1_items.len], a1_items);
366 const b1_items = items[B1.start..B1.end];
367 @memcpy(cache[0..b1_items.len], b1_items);
366368 } else if (lessThan(context, items[B1.start], items[A1.end - 1])) {
367369 // these two ranges weren't already in order, so merge them into the cache
368370 mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);
......@@ -371,23 +373,29 @@ pub fn sort(
371373 if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;
372374
373375 // copy A1 and B1 into the cache in the same order
374 mem.copy(T, cache[0..], items[A1.start..A1.end]);
375 mem.copy(T, cache[A1.length()..], items[B1.start..B1.end]);
376 const a1_items = items[A1.start..A1.end];
377 @memcpy(cache[0..a1_items.len], a1_items);
378 const b1_items = items[B1.start..B1.end];
379 @memcpy(cache[A1.length()..][0..b1_items.len], b1_items);
376380 }
377381 A1 = Range.init(A1.start, B1.end);
378382
379383 // merge A2 and B2 into the cache
380384 if (lessThan(context, items[B2.end - 1], items[A2.start])) {
381385 // the two ranges are in reverse order, so copy them in reverse order into the cache
382 mem.copy(T, cache[A1.length() + B2.length() ..], items[A2.start..A2.end]);
383 mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);
386 const a2_items = items[A2.start..A2.end];
387 @memcpy(cache[A1.length() + B2.length() ..][0..a2_items.len], a2_items);
388 const b2_items = items[B2.start..B2.end];
389 @memcpy(cache[A1.length()..][0..b2_items.len], b2_items);
384390 } else if (lessThan(context, items[B2.start], items[A2.end - 1])) {
385391 // these two ranges weren't already in order, so merge them into the cache
386392 mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);
387393 } else {
388394 // copy A2 and B2 into the cache in the same order
389 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);
390 mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.end]);
395 const a2_items = items[A2.start..A2.end];
396 @memcpy(cache[A1.length()..][0..a2_items.len], a2_items);
397 const b2_items = items[B2.start..B2.end];
398 @memcpy(cache[A1.length() + A2.length() ..][0..b2_items.len], b2_items);
391399 }
392400 A2 = Range.init(A2.start, B2.end);
393401
......@@ -397,15 +405,19 @@ pub fn sort(
397405
398406 if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {
399407 // the two ranges are in reverse order, so copy them in reverse order into the items
400 mem.copy(T, items[A1.start + A2.length() ..], cache[A3.start..A3.end]);
401 mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);
408 const a3_items = cache[A3.start..A3.end];
409 @memcpy(items[A1.start + A2.length() ..][0..a3_items.len], a3_items);
410 const b3_items = cache[B3.start..B3.end];
411 @memcpy(items[A1.start..][0..b3_items.len], b3_items);
402412 } else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {
403413 // these two ranges weren't already in order, so merge them back into the items
404414 mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);
405415 } else {
406416 // copy A3 and B3 into the items in the same order
407 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);
408 mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.end]);
417 const a3_items = cache[A3.start..A3.end];
418 @memcpy(items[A1.start..][0..a3_items.len], a3_items);
419 const b3_items = cache[B3.start..B3.end];
420 @memcpy(items[A1.start + A1.length() ..][0..b3_items.len], b3_items);
409421 }
410422 }
411423
......@@ -423,7 +435,8 @@ pub fn sort(
423435 mem.rotate(T, items[A.start..B.end], A.length());
424436 } else if (lessThan(context, items[B.start], items[A.end - 1])) {
425437 // these two ranges weren't already in order, so we'll need to merge them!
426 mem.copy(T, cache[0..], items[A.start..A.end]);
438 const a_items = items[A.start..A.end];
439 @memcpy(cache[0..a_items.len], a_items);
427440 mergeExternal(T, items, A, B, context, lessThan, cache[0..]);
428441 }
429442 }
......@@ -718,7 +731,8 @@ pub fn sort(
718731 // if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it
719732 // otherwise, if the second buffer is available, block swap the contents into that
720733 if (lastA.length() <= cache.len) {
721 mem.copy(T, cache[0..], items[lastA.start..lastA.end]);
734 const last_a_items = items[lastA.start..lastA.end];
735 @memcpy(cache[0..last_a_items.len], last_a_items);
722736 } else if (buffer2.length() > 0) {
723737 blockSwap(T, items, lastA.start, buffer2.start, lastA.length());
724738 }
......@@ -762,7 +776,7 @@ pub fn sort(
762776 if (buffer2.length() > 0 or block_size <= cache.len) {
763777 // copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway
764778 if (block_size <= cache.len) {
765 mem.copy(T, cache[0..], items[blockA.start .. blockA.start + block_size]);
779 @memcpy(cache[0..block_size], items[blockA.start..][0..block_size]);
766780 } else {
767781 blockSwap(T, items, blockA.start, buffer2.start, block_size);
768782 }
......@@ -1122,7 +1136,8 @@ fn mergeInto(
11221136 insert_index += 1;
11231137 if (A_index == A_last) {
11241138 // copy the remainder of B into the final array
1125 mem.copy(T, into[insert_index..], from[B_index..B_last]);
1139 const from_b = from[B_index..B_last];
1140 @memcpy(into[insert_index..][0..from_b.len], from_b);
11261141 break;
11271142 }
11281143 } else {
......@@ -1131,7 +1146,8 @@ fn mergeInto(
11311146 insert_index += 1;
11321147 if (B_index == B_last) {
11331148 // copy the remainder of A into the final array
1134 mem.copy(T, into[insert_index..], from[A_index..A_last]);
1149 const from_a = from[A_index..A_last];
1150 @memcpy(into[insert_index..][0..from_a.len], from_a);
11351151 break;
11361152 }
11371153 }
......@@ -1171,7 +1187,8 @@ fn mergeExternal(
11711187 }
11721188
11731189 // copy the remainder of A into the final array
1174 mem.copy(T, items[insert_index..], cache[A_index..A_last]);
1190 const cache_a = cache[A_index..A_last];
1191 @memcpy(items[insert_index..][0..cache_a.len], cache_a);
11751192}
11761193
11771194fn swap(
......@@ -1305,7 +1322,7 @@ test "sort" {
13051322 for (u8cases) |case| {
13061323 var buf: [8]u8 = undefined;
13071324 const slice = buf[0..case[0].len];
1308 mem.copy(u8, slice, case[0]);
1325 @memcpy(slice, case[0]);
13091326 sort(u8, slice, {}, asc_u8);
13101327 try testing.expect(mem.eql(u8, slice, case[1]));
13111328 }
......@@ -1340,7 +1357,7 @@ test "sort" {
13401357 for (i32cases) |case| {
13411358 var buf: [8]i32 = undefined;
13421359 const slice = buf[0..case[0].len];
1343 mem.copy(i32, slice, case[0]);
1360 @memcpy(slice, case[0]);
13441361 sort(i32, slice, {}, asc_i32);
13451362 try testing.expect(mem.eql(i32, slice, case[1]));
13461363 }
......@@ -1377,7 +1394,7 @@ test "sort descending" {
13771394 for (rev_cases) |case| {
13781395 var buf: [8]i32 = undefined;
13791396 const slice = buf[0..case[0].len];
1380 mem.copy(i32, slice, case[0]);
1397 @memcpy(slice, case[0]);
13811398 sort(i32, slice, {}, desc_i32);
13821399 try testing.expect(mem.eql(i32, slice, case[1]));
13831400 }
lib/std/tar.zig+8-6
......@@ -55,9 +55,9 @@ pub const Header = struct {
5555 const p = prefix(header);
5656 if (p.len == 0)
5757 return n;
58 std.mem.copy(u8, buffer[0..p.len], p);
58 @memcpy(buffer[0..p.len], p);
5959 buffer[p.len] = '/';
60 std.mem.copy(u8, buffer[p.len + 1 ..], n);
60 @memcpy(buffer[p.len + 1 ..][0..n.len], n);
6161 return buffer[0 .. p.len + 1 + n.len];
6262 }
6363
......@@ -101,8 +101,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
101101 var end: usize = 0;
102102 header: while (true) {
103103 if (buffer.len - start < 1024) {
104 std.mem.copy(u8, &buffer, buffer[start..end]);
105 end -= start;
104 const dest_end = end - start;
105 @memcpy(buffer[0..dest_end], buffer[start..end]);
106 end = dest_end;
106107 start = 0;
107108 }
108109 const ask_header = @min(buffer.len - end, 1024 -| (end - start));
......@@ -138,8 +139,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
138139 var file_off: usize = 0;
139140 while (true) {
140141 if (buffer.len - start < 1024) {
141 std.mem.copy(u8, &buffer, buffer[start..end]);
142 end -= start;
142 const dest_end = end - start;
143 @memcpy(buffer[0..dest_end], buffer[start..end]);
144 end = dest_end;
143145 start = 0;
144146 }
145147 // Ask for the rounded up file size + 512 for the next header.
lib/std/target.zig+2-2
......@@ -1596,7 +1596,7 @@ pub const Target = struct {
15961596 /// Asserts that the length is less than or equal to 255 bytes.
15971597 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
15981598 if (dl_or_null) |dl| {
1599 mem.copy(u8, &self.buffer, dl);
1599 @memcpy(self.buffer[0..dl.len], dl);
16001600 self.max_byte = @intCast(u8, dl.len - 1);
16011601 } else {
16021602 self.max_byte = null;
......@@ -1612,7 +1612,7 @@ pub const Target = struct {
16121612 return r.*;
16131613 }
16141614 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
1615 mem.copy(u8, &r.buffer, s);
1615 @memcpy(r.buffer[0..s.len], s);
16161616 r.max_byte = @intCast(u8, s.len - 1);
16171617 return r.*;
16181618 }
lib/std/testing/failing_allocator.zig+1-1
......@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {
6666 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
6767 if (self.index == self.fail_index) {
6868 if (!self.has_induced_failure) {
69 mem.set(usize, &self.stack_addresses, 0);
69 @memset(&self.stack_addresses, 0);
7070 var stack_trace = std.builtin.StackTrace{
7171 .instruction_addresses = &self.stack_addresses,
7272 .index = 0,
lib/std/tz.zig+1-1
......@@ -137,7 +137,7 @@ pub const Tz = struct {
137137 const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);
138138 // We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.
139139 if (name.len > 6) return error.Malformed; // rfc8536: Time zone designations SHOULD consist of at least three (3) and no more than six (6) ASCII characters.
140 std.mem.copy(u8, tt.name_data[0..], name);
140 @memcpy(tt.name_data[0..name.len], name);
141141 tt.name_data[name.len] = 0;
142142 }
143143
lib/std/zig/render.zig+2-2
......@@ -1889,11 +1889,11 @@ fn renderArrayInit(
18891889 // A place to store the width of each expression and its column's maximum
18901890 const widths = try gpa.alloc(usize, row_exprs.len + row_size);
18911891 defer gpa.free(widths);
1892 mem.set(usize, widths, 0);
1892 @memset(widths, 0);
18931893
18941894 const expr_newlines = try gpa.alloc(bool, row_exprs.len);
18951895 defer gpa.free(expr_newlines);
1896 mem.set(bool, expr_newlines, false);
1896 @memset(expr_newlines, false);
18971897
18981898 const expr_widths = widths[0..row_exprs.len];
18991899 const column_widths = widths[row_exprs.len..];
lib/std/zig/system/NativeTargetInfo.zig+4-4
......@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(
877877 const cpu_arch = @tagName(result.target.cpu.arch);
878878 const os_tag = @tagName(result.target.os.tag);
879879 const abi = @tagName(result.target.abi);
880 mem.copy(u8, path_buf[index..], prefix);
880 @memcpy(path_buf[index..][0..prefix.len], prefix);
881881 index += prefix.len;
882 mem.copy(u8, path_buf[index..], cpu_arch);
882 @memcpy(path_buf[index..][0..cpu_arch.len], cpu_arch);
883883 index += cpu_arch.len;
884884 path_buf[index] = '-';
885885 index += 1;
886 mem.copy(u8, path_buf[index..], os_tag);
886 @memcpy(path_buf[index..][0..os_tag.len], os_tag);
887887 index += os_tag.len;
888888 path_buf[index] = '-';
889889 index += 1;
890 mem.copy(u8, path_buf[index..], abi);
890 @memcpy(path_buf[index..][0..abi.len], abi);
891891 index += abi.len;
892892 const rpath = path_buf[0..index];
893893 if (glibcVerFromRPath(rpath)) |ver| {
lib/std/zig/system/windows.zig+2-2
......@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
171171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);
172172 switch (@field(args, field.name).value_type) {
173173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {
174 mem.copy(u8, @field(args, field.name).value_buf[0..4], entry[0..4]);
174 @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);
175175 },
176176 REG.QWORD => {
177 mem.copy(u8, @field(args, field.name).value_buf[0..8], entry[0..8]);
177 @memcpy(@field(args, field.name).value_buf[0..8], entry[0..8]);
178178 },
179179 else => unreachable,
180180 }
src/AstGen.zig+1-1
......@@ -3604,7 +3604,7 @@ const WipMembers = struct {
36043604
36053605 fn appendToDeclSlice(self: *Self, data: []const u32) void {
36063606 assert(self.decls_end + data.len <= self.field_bits_start);
3607 mem.copy(u32, self.payload.items[self.decls_end..], data);
3607 @memcpy(self.payload.items[self.decls_end..][0..data.len], data);
36083608 self.decls_end += @intCast(u32, data.len);
36093609 }
36103610
src/Autodoc.zig+1-1
......@@ -1146,7 +1146,7 @@ fn walkInstruction(
11461146 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
11471147
11481148 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
1149 std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
1149 @memcpy(std.mem.sliceAsBytes(limbs)[0..limb_bytes.len], limb_bytes);
11501150
11511151 const big_int = std.math.big.int.Const{
11521152 .limbs = limbs,
src/Compilation.zig+3-3
......@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
21652165 const digest_start = 2; // "o/[digest]/[basename]"
21662166
21672167 if (comp.whole_bin_sub_path) |sub_path| {
2168 mem.copy(u8, sub_path[digest_start..], digest);
2168 @memcpy(sub_path[digest_start..][0..digest.len], digest);
21692169
21702170 comp.bin_file.options.emit = .{
21712171 .directory = comp.local_cache_directory,
......@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
21742174 }
21752175
21762176 if (comp.whole_implib_sub_path) |sub_path| {
2177 mem.copy(u8, sub_path[digest_start..], digest);
2177 @memcpy(sub_path[digest_start..][0..digest.len], digest);
21782178
21792179 comp.bin_file.options.implib_emit = .{
21802180 .directory = comp.local_cache_directory,
......@@ -4432,7 +4432,7 @@ pub fn addCCArgs(
44324432 assert(prefix.len == prefix_len);
44334433 var march_buf: [prefix_len + letters.len + 1]u8 = undefined;
44344434 var march_index: usize = prefix_len;
4435 mem.copy(u8, &march_buf, prefix);
4435 @memcpy(march_buf[0..prefix.len], prefix);
44364436
44374437 if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {
44384438 march_buf[march_index] = 'e';
src/Liveness.zig+7-7
......@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
156156 errdefer a.special.deinit(gpa);
157157 defer a.extra.deinit(gpa);
158158
159 std.mem.set(usize, a.tomb_bits, 0);
159 @memset(a.tomb_bits, 0);
160160
161161 const main_body = air.getMainBody();
162162
......@@ -1150,7 +1150,7 @@ fn analyzeInst(
11501150 if (args.len + 1 <= bpi - 1) {
11511151 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
11521152 buf[0] = callee;
1153 std.mem.copy(Air.Inst.Ref, buf[1..], args);
1153 @memcpy(buf[1..][0..args.len], args);
11541154 return analyzeOperands(a, pass, data, inst, buf);
11551155 }
11561156
......@@ -1189,7 +1189,7 @@ fn analyzeInst(
11891189
11901190 if (elements.len <= bpi - 1) {
11911191 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
1192 std.mem.copy(Air.Inst.Ref, &buf, elements);
1192 @memcpy(buf[0..elements.len], elements);
11931193 return analyzeOperands(a, pass, data, inst, buf);
11941194 }
11951195
......@@ -1255,7 +1255,7 @@ fn analyzeInst(
12551255 if (buf_index + inputs.len > buf.len) {
12561256 break :simple buf_index + inputs.len;
12571257 }
1258 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
1258 @memcpy(buf[buf_index..][0..inputs.len], inputs);
12591259 return analyzeOperands(a, pass, data, inst, buf);
12601260 };
12611261
......@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(
18411841 var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else
18421842 defer gpa.free(case_infos);
18431843
1844 std.mem.set(ControlBranchInfo, case_infos, .{});
1844 @memset(case_infos, .{});
18451845 defer for (case_infos) |*info| {
18461846 info.branch_deaths.deinit(gpa);
18471847 info.live_set.deinit(gpa);
......@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(
18981898 const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);
18991899 defer gpa.free(mirrored_deaths);
19001900
1901 std.mem.set(DeathList, mirrored_deaths, .{});
1901 @memset(mirrored_deaths, .{});
19021902 defer for (mirrored_deaths) |*md| md.deinit(gpa);
19031903
19041904 {
......@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
19931993 };
19941994 errdefer a.gpa.free(extra_tombs);
19951995
1996 std.mem.set(u32, extra_tombs, 0);
1996 @memset(extra_tombs, 0);
19971997
19981998 const will_die_immediately: bool = switch (pass) {
19991999 .loop_analysis => false, // track everything, since we don't have full liveness information yet
src/Sema.zig+29-23
......@@ -206,9 +206,9 @@ pub const InstMap = struct {
206206
207207 const start_diff = old_start - better_start;
208208 const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);
209 mem.set(Air.Inst.Ref, new_items[0..start_diff], .none);
210 mem.copy(Air.Inst.Ref, new_items[start_diff..], map.items);
211 mem.set(Air.Inst.Ref, new_items[start_diff + map.items.len ..], .none);
209 @memset(new_items[0..start_diff], .none);
210 @memcpy(new_items[start_diff..][0..map.items.len], map.items);
211 @memset(new_items[start_diff + map.items.len ..], .none);
212212
213213 allocator.free(map.items);
214214 map.items = new_items;
......@@ -4307,7 +4307,7 @@ fn validateStructInit(
43074307 // Maps field index to field_ptr index of where it was already initialized.
43084308 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());
43094309 defer gpa.free(found_fields);
4310 mem.set(Zir.Inst.Index, found_fields, 0);
4310 @memset(found_fields, 0);
43114311
43124312 var struct_ptr_zir_ref: Zir.Inst.Ref = undefined;
43134313
......@@ -5113,7 +5113,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
51135113 const byte_count = int.len * @sizeOf(std.math.big.Limb);
51145114 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
51155115 const limbs = try arena.alloc(std.math.big.Limb, int.len);
5116 mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);
5116 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
51175117
51185118 return sema.addConstant(
51195119 Type.initTag(.comptime_int),
......@@ -5967,7 +5967,7 @@ fn addDbgVar(
59675967 const elements_used = name.len / 4 + 1;
59685968 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
59695969 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
5970 mem.copy(u8, buffer, name);
5970 @memcpy(buffer[0..name.len], name);
59715971 buffer[name.len] = 0;
59725972 sema.air_extra.items.len += elements_used;
59735973
......@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1035410354 .Enum => {
1035510355 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());
1035610356 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum();
10357 mem.set(?Module.SwitchProngSrc, seen_enum_fields, null);
10357 @memset(seen_enum_fields, null);
1035810358 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
1035910359
1036010360 var extra_index: usize = special.end;
......@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(
1280912809 }
1281012810 i = 0;
1281112811 while (i < factor) : (i += 1) {
12812 mem.copy(Type, types[tuple_len * i ..], types[0..tuple_len]);
12813 mem.copy(Value, values[tuple_len * i ..], values[0..tuple_len]);
12812 mem.copyForwards(Type, types[tuple_len * i ..], types[0..tuple_len]);
12813 mem.copyForwards(Value, values[tuple_len * i ..], values[0..tuple_len]);
1281412814 }
1281512815 break :rs runtime_src;
1281612816 };
......@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(
1283512835 }
1283612836 i = 1;
1283712837 while (i < factor) : (i += 1) {
12838 mem.copy(Air.Inst.Ref, element_refs[tuple_len * i ..], element_refs[0..tuple_len]);
12838 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
1283912839 }
1284012840
1284112841 return block.addAggregateInit(tuple_ty, element_refs);
......@@ -15057,29 +15057,29 @@ fn zirAsm(
1505715057 sema.appendRefsAssumeCapacity(args);
1505815058 for (outputs) |o| {
1505915059 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15060 mem.copy(u8, buffer, o.c);
15060 @memcpy(buffer[0..o.c.len], o.c);
1506115061 buffer[o.c.len] = 0;
15062 mem.copy(u8, buffer[o.c.len + 1 ..], o.n);
15062 @memcpy(buffer[o.c.len + 1 ..][0..o.n.len], o.n);
1506315063 buffer[o.c.len + 1 + o.n.len] = 0;
1506415064 sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;
1506515065 }
1506615066 for (inputs) |input| {
1506715067 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15068 mem.copy(u8, buffer, input.c);
15068 @memcpy(buffer[0..input.c.len], input.c);
1506915069 buffer[input.c.len] = 0;
15070 mem.copy(u8, buffer[input.c.len + 1 ..], input.n);
15070 @memcpy(buffer[input.c.len + 1 ..][0..input.n.len], input.n);
1507115071 buffer[input.c.len + 1 + input.n.len] = 0;
1507215072 sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;
1507315073 }
1507415074 for (clobbers) |clobber| {
1507515075 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15076 mem.copy(u8, buffer, clobber);
15076 @memcpy(buffer[0..clobber.len], clobber);
1507715077 buffer[clobber.len] = 0;
1507815078 sema.air_extra.items.len += clobber.len / 4 + 1;
1507915079 }
1508015080 {
1508115081 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15082 mem.copy(u8, buffer, asm_source);
15082 @memcpy(buffer[0..asm_source.len], asm_source);
1508315083 sema.air_extra.items.len += (asm_source.len + 3) / 4;
1508415084 }
1508515085 return asm_air;
......@@ -17582,7 +17582,7 @@ fn structInitEmpty(
1758217582 // The init values to use for the struct instance.
1758317583 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());
1758417584 defer gpa.free(field_inits);
17585 mem.set(Air.Inst.Ref, field_inits, .none);
17585 @memset(field_inits, .none);
1758617586
1758717587 return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);
1758817588}
......@@ -17675,7 +17675,7 @@ fn zirStructInit(
1767517675 // The init values to use for the struct instance.
1767617676 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());
1767717677 defer gpa.free(field_inits);
17678 mem.set(Air.Inst.Ref, field_inits, .none);
17678 @memset(field_inits, .none);
1767917679
1768017680 var field_i: u32 = 0;
1768117681 var extra_index = extra.end;
......@@ -22039,7 +22039,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2203922039 if (try sema.resolveMaybeUndefVal(uncoerced_elem)) |_| {
2204022040 for (0..len) |i| {
2204122041 const elem_index = try sema.addIntUnsigned(Type.usize, i);
22042 const elem_ptr = try sema.elemPtr(
22042 const elem_ptr = try sema.elemPtrOneLayerOnly(
2204322043 block,
2204422044 src,
2204522045 dest_ptr,
......@@ -26953,9 +26953,13 @@ fn storePtrVal(
2695326953 defer sema.gpa.free(buffer);
2695426954 reinterpret.val_ptr.*.writeToMemory(mut_kit.ty, sema.mod, buffer) catch |err| switch (err) {
2695526955 error.ReinterpretDeclRef => unreachable,
26956 error.IllDefinedMemoryLayout => unreachable, // Sema was supposed to emit a compile error already
26957 error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{mut_kit.ty.fmt(sema.mod)}),
2695626958 };
2695726959 operand_val.writeToMemory(operand_ty, sema.mod, buffer[reinterpret.byte_offset..]) catch |err| switch (err) {
2695826960 error.ReinterpretDeclRef => unreachable,
26961 error.IllDefinedMemoryLayout => unreachable, // Sema was supposed to emit a compile error already
26962 error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{mut_kit.ty.fmt(sema.mod)}),
2695926963 };
2696026964
2696126965 const arena = mut_kit.beginArena(sema.mod);
......@@ -27075,7 +27079,7 @@ fn beginComptimePtrMutation(
2707527079 const array_len_including_sentinel =
2707627080 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
2707727081 const elems = try arena.alloc(Value, array_len_including_sentinel);
27078 mem.set(Value, elems, Value.undef);
27082 @memset(elems, Value.undef);
2707927083
2708027084 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2708127085
......@@ -27273,7 +27277,7 @@ fn beginComptimePtrMutation(
2727327277 switch (parent.ty.zigTypeTag()) {
2727427278 .Struct => {
2727527279 const fields = try arena.alloc(Value, parent.ty.structFieldCount());
27276 mem.set(Value, fields, Value.undef);
27280 @memset(fields, Value.undef);
2727727281
2727827282 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
2727927283
......@@ -27905,6 +27909,8 @@ fn bitCastVal(
2790527909 defer sema.gpa.free(buffer);
2790627910 val.writeToMemory(old_ty, sema.mod, buffer) catch |err| switch (err) {
2790727911 error.ReinterpretDeclRef => return null,
27912 error.IllDefinedMemoryLayout => unreachable, // Sema was supposed to emit a compile error already
27913 error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{old_ty.fmt(sema.mod)}),
2790827914 };
2790927915 return try Value.readFromMemory(new_ty, sema.mod, buffer[buffer_offset..], sema.arena);
2791027916}
......@@ -28419,7 +28425,7 @@ fn coerceTupleToStruct(
2841928425 const fields = struct_ty.structFields();
2842028426 const field_vals = try sema.arena.alloc(Value, fields.count());
2842128427 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
28422 mem.set(Air.Inst.Ref, field_refs, .none);
28428 @memset(field_refs, .none);
2842328429
2842428430 const inst_ty = sema.typeOf(inst);
2842528431 var runtime_src: ?LazySrcLoc = null;
......@@ -28508,7 +28514,7 @@ fn coerceTupleToTuple(
2850828514 const dest_field_count = tuple_ty.structFieldCount();
2850928515 const field_vals = try sema.arena.alloc(Value, dest_field_count);
2851028516 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
28511 mem.set(Air.Inst.Ref, field_refs, .none);
28517 @memset(field_refs, .none);
2851228518
2851328519 const inst_ty = sema.typeOf(inst);
2851428520 const inst_field_count = inst_ty.structFieldCount();
src/arch/aarch64/CodeGen.zig+4-4
......@@ -1630,7 +1630,7 @@ fn allocRegs(
16301630 const read_locks = locks[0..read_args.len];
16311631 const write_locks = locks[read_args.len..];
16321632
1633 std.mem.set(?RegisterLock, locks, null);
1633 @memset(locks, null);
16341634 defer for (locks) |lock| {
16351635 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
16361636 };
......@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43954395 if (args.len + 1 <= Liveness.bpi - 1) {
43964396 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
43974397 buf[0] = callee;
4398 std.mem.copy(Air.Inst.Ref, buf[1..], args);
4398 @memcpy(buf[1..][0..args.len], args);
43994399 return self.finishAir(inst, result, buf);
44004400 }
44014401 var bt = try self.iterateBigTomb(inst, 1 + args.len);
......@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
53485348 buf_index += 1;
53495349 }
53505350 if (buf_index + inputs.len > buf.len) break :simple;
5351 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
5351 @memcpy(buf[buf_index..][0..inputs.len], inputs);
53525352 return self.finishAir(inst, result, buf);
53535353 }
53545354 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
......@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60556055
60566056 if (elements.len <= Liveness.bpi - 1) {
60576057 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
6058 std.mem.copy(Air.Inst.Ref, &buf, elements);
6058 @memcpy(buf[0..elements.len], elements);
60596059 return self.finishAir(inst, result, buf);
60606060 }
60616061 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/arm/CodeGen.zig+4-4
......@@ -3114,7 +3114,7 @@ fn allocRegs(
31143114 const read_locks = locks[0..read_args.len];
31153115 const write_locks = locks[read_args.len..];
31163116
3117 std.mem.set(?RegisterLock, locks, null);
3117 @memset(locks, null);
31183118 defer for (locks) |lock| {
31193119 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
31203120 };
......@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43414341 if (args.len <= Liveness.bpi - 2) {
43424342 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
43434343 buf[0] = callee;
4344 std.mem.copy(Air.Inst.Ref, buf[1..], args);
4344 @memcpy(buf[1..][0..args.len], args);
43454345 return self.finishAir(inst, result, buf);
43464346 }
43474347 var bt = try self.iterateBigTomb(inst, 1 + args.len);
......@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
52635263 buf_index += 1;
52645264 }
52655265 if (buf_index + inputs.len > buf.len) break :simple;
5266 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
5266 @memcpy(buf[buf_index..][0..inputs.len], inputs);
52675267 return self.finishAir(inst, result, buf);
52685268 }
52695269 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
......@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60006000
60016001 if (elements.len <= Liveness.bpi - 1) {
60026002 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
6003 std.mem.copy(Air.Inst.Ref, &buf, elements);
6003 @memcpy(buf[0..elements.len], elements);
60046004 return self.finishAir(inst, result, buf);
60056005 }
60066006 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/riscv64/CodeGen.zig+3-3
......@@ -1784,7 +1784,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
17841784 if (args.len <= Liveness.bpi - 2) {
17851785 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
17861786 buf[0] = callee;
1787 std.mem.copy(Air.Inst.Ref, buf[1..], args);
1787 @memcpy(buf[1..][0..args.len], args);
17881788 return self.finishAir(inst, result, buf);
17891789 }
17901790 var bt = try self.iterateBigTomb(inst, 1 + args.len);
......@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
22252225 buf_index += 1;
22262226 }
22272227 if (buf_index + inputs.len > buf.len) break :simple;
2228 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
2228 @memcpy(buf[buf_index..][0..inputs.len], inputs);
22292229 return self.finishAir(inst, result, buf);
22302230 }
22312231 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
......@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25002500
25012501 if (elements.len <= Liveness.bpi - 1) {
25022502 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
2503 std.mem.copy(Air.Inst.Ref, &buf, elements);
2503 @memcpy(buf[0..elements.len], elements);
25042504 return self.finishAir(inst, result, buf);
25052505 }
25062506 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/sparc64/CodeGen.zig+3-3
......@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
843843
844844 if (elements.len <= Liveness.bpi - 1) {
845845 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
846 std.mem.copy(Air.Inst.Ref, &buf, elements);
846 @memcpy(buf[0..elements.len], elements);
847847 return self.finishAir(inst, result, buf);
848848 }
849849 var bt = try self.iterateBigTomb(inst, elements.len);
......@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
987987 buf_index += 1;
988988 }
989989 if (buf_index + inputs.len > buf.len) break :simple;
990 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
990 @memcpy(buf[buf_index..][0..inputs.len], inputs);
991991 return self.finishAir(inst, result, buf);
992992 }
993993
......@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13141314 if (args.len + 1 <= Liveness.bpi - 1) {
13151315 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
13161316 buf[0] = callee;
1317 std.mem.copy(Air.Inst.Ref, buf[1..], args);
1317 @memcpy(buf[1..][0..args.len], args);
13181318 return self.finishAir(inst, result, buf);
13191319 }
13201320
src/arch/x86_64/CodeGen.zig+2-2
......@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
71177117 buf_index += 1;
71187118 }
71197119 if (buf_index + inputs.len > buf.len) break :simple;
7120 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
7120 @memcpy(buf[buf_index..][0..inputs.len], inputs);
71217121 return self.finishAir(inst, result, buf);
71227122 }
71237123 var bt = self.liveness.iterateBigTomb(inst);
......@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
85058505
85068506 if (elements.len <= Liveness.bpi - 1) {
85078507 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
8508 std.mem.copy(Air.Inst.Ref, &buf, elements);
8508 @memcpy(buf[0..elements.len], elements);
85098509 return self.finishAir(inst, result, buf);
85108510 }
85118511 var bt = self.liveness.iterateBigTomb(inst);
src/arch/x86_64/Encoding.zig+5-3
......@@ -546,7 +546,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
546546 .encoding = encoding,
547547 .ops = [1]Operand{.none} ** 4,
548548 };
549 std.mem.copy(Operand, &inst.ops, ops);
549 @memcpy(inst.ops[0..ops.len], ops);
550550
551551 var cwriter = std.io.countingWriter(std.io.null_writer);
552552 inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.
......@@ -575,8 +575,10 @@ const mnemonic_to_encodings_map = init: {
575575 .modrm_ext = entry[4],
576576 .mode = entry[5],
577577 };
578 std.mem.copy(Op, &data.ops, entry[2]);
579 std.mem.copy(u8, &data.opc, entry[3]);
578 // TODO: use `@memcpy` for these. When I did that, I got a false positive
579 // compile error for this copy happening at compile time.
580 std.mem.copyForwards(Op, &data.ops, entry[2]);
581 std.mem.copyForwards(u8, &data.opc, entry[3]);
580582
581583 while (mnemonic_int < @enumToInt(entry[0])) : (mnemonic_int += 1) {
582584 mnemonic_map[mnemonic_int] = data_storage[mnemonic_start..data_index];
src/arch/x86_64/abi.zig+1-1
......@@ -321,7 +321,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class {
321321 byte_i = 0;
322322 result_i += 1;
323323 }
324 std.mem.copy(Class, result[result_i..], field_class);
324 @memcpy(result[result_i..][0..field_class.len], field_class);
325325 result_i += field_class.len;
326326 // If there are any bytes leftover, we have to try to combine
327327 // the next field with them.
src/arch/x86_64/encoder.zig+2-2
......@@ -182,7 +182,7 @@ pub const Instruction = struct {
182182 .encoding = encoding,
183183 .ops = [1]Operand{.none} ** 4,
184184 };
185 std.mem.copy(Operand, &inst.ops, ops);
185 @memcpy(inst.ops[0..ops.len], ops);
186186 return inst;
187187 }
188188
......@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co
859859 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
860860 var padding = try testing.allocator.alloc(u8, idx + 5);
861861 defer testing.allocator.free(padding);
862 std.mem.set(u8, padding, ' ');
862 @memset(padding, ' ');
863863 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{
864864 assembly,
865865 expected_fmt,
src/codegen.zig+1-1
......@@ -552,7 +552,7 @@ pub fn generateSymbol(
552552 .ty = field_ty,
553553 .val = field_val,
554554 }, &tmp_list, debug_output, reloc_info)) {
555 .ok => mem.copy(u8, code.items[current_pos..], tmp_list.items),
555 .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
556556 .fail => |em| return Result{ .fail = em },
557557 }
558558 } else {
src/codegen/c.zig+85-32
......@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {
24112411 const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);
24122412 defer o.dg.gpa.free(name_buf);
24132413
2414 mem.copy(u8, name_buf, name_prefix);
2414 @memcpy(name_buf[0..name_prefix.len], name_prefix);
24152415 for (o.dg.module.error_name_list.items) |name| {
2416 mem.copy(u8, name_buf[name_prefix.len..], name);
2416 @memcpy(name_buf[name_prefix.len..][0..name.len], name);
24172417 const identifier = name_buf[0 .. name_prefix.len + name.len];
24182418
24192419 var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };
......@@ -3858,7 +3858,7 @@ fn airCmpOp(
38583858 try reap(f, inst, &.{ data.lhs, data.rhs });
38593859
38603860 const rhs_ty = f.air.typeOf(data.rhs);
3861 const need_cast = lhs_ty.isSinglePointer() != rhs_ty.isSinglePointer();
3861 const need_cast = lhs_ty.isSinglePointer() or rhs_ty.isSinglePointer();
38623862 const writer = f.object.writer();
38633863 const local = try f.allocLocal(inst, inst_ty);
38643864 const v = try Vectorize.start(f, inst, writer, lhs_ty);
......@@ -4419,51 +4419,94 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
44194419 const dest_ty = f.air.typeOfIndex(inst);
44204420
44214421 const operand = try f.resolveInst(ty_op.operand);
4422 try reap(f, inst, &.{ty_op.operand});
44234422 const operand_ty = f.air.typeOf(ty_op.operand);
4424 const target = f.object.dg.module.getTarget();
4425 const writer = f.object.writer();
44264423
4427 const local = try f.allocLocal(inst, dest_ty);
4424 const bitcasted = try bitcast(f, dest_ty, operand, operand_ty);
4425 try reap(f, inst, &.{ty_op.operand});
4426 return bitcasted.move(f, inst, dest_ty);
4427}
4428
4429const LocalResult = struct {
4430 c_value: CValue,
4431 need_free: bool,
4432
4433 fn move(lr: LocalResult, f: *Function, inst: Air.Inst.Index, dest_ty: Type) !CValue {
4434 if (lr.need_free) {
4435 // Move the freshly allocated local to be owned by this instruction,
4436 // by returning it here instead of freeing it.
4437 return lr.c_value;
4438 }
4439
4440 const local = try f.allocLocal(inst, dest_ty);
4441 try lr.free(f);
4442 const writer = f.object.writer();
4443 try f.writeCValue(writer, local, .Other);
4444 if (dest_ty.isAbiInt()) {
4445 try writer.writeAll(" = ");
4446 } else {
4447 try writer.writeAll(" = (");
4448 try f.renderType(writer, dest_ty);
4449 try writer.writeByte(')');
4450 }
4451 try f.writeCValue(writer, lr.c_value, .Initializer);
4452 try writer.writeAll(";\n");
4453 return local;
4454 }
4455
4456 fn free(lr: LocalResult, f: *Function) !void {
4457 if (lr.need_free) {
4458 try freeLocal(f, 0, lr.c_value.new_local, 0);
4459 }
4460 }
4461};
44284462
4429 // If the assignment looks like 'x = x', we don't need it
4430 const can_elide = operand == .local and operand.local == local.new_local;
4463fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !LocalResult {
4464 const target = f.object.dg.module.getTarget();
4465 const writer = f.object.writer();
44314466
44324467 if (operand_ty.isAbiInt() and dest_ty.isAbiInt()) {
4433 if (can_elide) return local;
44344468 const src_info = dest_ty.intInfo(target);
44354469 const dest_info = operand_ty.intInfo(target);
44364470 if (src_info.signedness == dest_info.signedness and
44374471 src_info.bits == dest_info.bits)
44384472 {
4439 try f.writeCValue(writer, local, .Other);
4440 try writer.writeAll(" = ");
4441 try f.writeCValue(writer, operand, .Initializer);
4442 try writer.writeAll(";\n");
4443 return local;
4473 return .{
4474 .c_value = operand,
4475 .need_free = false,
4476 };
44444477 }
44454478 }
44464479
44474480 if (dest_ty.isPtrAtRuntime() and operand_ty.isPtrAtRuntime()) {
4448 if (can_elide) return local;
4481 const local = try f.allocLocal(0, dest_ty);
44494482 try f.writeCValue(writer, local, .Other);
44504483 try writer.writeAll(" = (");
44514484 try f.renderType(writer, dest_ty);
44524485 try writer.writeByte(')');
44534486 try f.writeCValue(writer, operand, .Other);
44544487 try writer.writeAll(";\n");
4455 return local;
4488 return .{
4489 .c_value = local,
4490 .need_free = true,
4491 };
44564492 }
44574493
44584494 const operand_lval = if (operand == .constant) blk: {
4459 const operand_local = try f.allocLocal(inst, operand_ty);
4495 const operand_local = try f.allocLocal(0, operand_ty);
44604496 try f.writeCValue(writer, operand_local, .Other);
4461 try writer.writeAll(" = ");
4497 if (operand_ty.isAbiInt()) {
4498 try writer.writeAll(" = ");
4499 } else {
4500 try writer.writeAll(" = (");
4501 try f.renderType(writer, operand_ty);
4502 try writer.writeByte(')');
4503 }
44624504 try f.writeCValue(writer, operand, .Initializer);
44634505 try writer.writeAll(";\n");
44644506 break :blk operand_local;
44654507 } else operand;
44664508
4509 const local = try f.allocLocal(0, dest_ty);
44674510 try writer.writeAll("memcpy(&");
44684511 try f.writeCValue(writer, local, .Other);
44694512 try writer.writeAll(", &");
......@@ -4528,10 +4571,13 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
45284571 }
45294572
45304573 if (operand == .constant) {
4531 try freeLocal(f, inst, operand_lval.new_local, 0);
4574 try freeLocal(f, 0, operand_lval.new_local, 0);
45324575 }
45334576
4534 return local;
4577 return .{
4578 .c_value = local,
4579 .need_free = true,
4580 };
45354581}
45364582
45374583fn airTrap(writer: anytype) !CValue {
......@@ -4831,7 +4877,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
48314877 const literal = mem.sliceTo(asm_source[src_i..], '%');
48324878 src_i += literal.len;
48334879
4834 mem.copy(u8, fixed_asm_source[dst_i..], literal);
4880 @memcpy(fixed_asm_source[dst_i..][0..literal.len], literal);
48354881 dst_i += literal.len;
48364882
48374883 if (src_i >= asm_source.len) break;
......@@ -4856,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
48564902 const name = desc[0..colon];
48574903 const modifier = desc[colon + 1 ..];
48584904
4859 mem.copy(u8, fixed_asm_source[dst_i..], modifier);
4905 @memcpy(fixed_asm_source[dst_i..][0..modifier.len], modifier);
48604906 dst_i += modifier.len;
4861 mem.copy(u8, fixed_asm_source[dst_i..], name);
4907 @memcpy(fixed_asm_source[dst_i..][0..name.len], name);
48624908 dst_i += name.len;
48634909
48644910 src_i += desc.len;
......@@ -6288,15 +6334,19 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
62886334 }
62896335 try writer.writeAll("; ++");
62906336 try f.writeCValue(writer, index, .Other);
6291 try writer.writeAll(") ((");
6337 try writer.writeAll(") ");
6338
6339 const a = try Assignment.start(f, writer, elem_ty);
6340 try writer.writeAll("((");
62926341 try f.renderType(writer, elem_ptr_ty);
62936342 try writer.writeByte(')');
62946343 try writeSliceOrPtr(f, writer, dest_slice, dest_ty);
62956344 try writer.writeAll(")[");
62966345 try f.writeCValue(writer, index, .Other);
6297 try writer.writeAll("] = ");
6298 try f.writeCValue(writer, value, .FunctionArgument);
6299 try writer.writeAll(";\n");
6346 try writer.writeByte(']');
6347 try a.assign(f, writer);
6348 try f.writeCValue(writer, value, .Other);
6349 try a.end(f, writer);
63006350
63016351 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
63026352 try freeLocal(f, inst, index.new_local, 0);
......@@ -6304,12 +6354,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63046354 return .none;
63056355 }
63066356
6357 const bitcasted = try bitcast(f, Type.u8, value, elem_ty);
6358
63076359 try writer.writeAll("memset(");
63086360 switch (dest_ty.ptrSize()) {
63096361 .Slice => {
63106362 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });
63116363 try writer.writeAll(", ");
6312 try f.writeCValue(writer, value, .FunctionArgument);
6364 try f.writeCValue(writer, bitcasted.c_value, .FunctionArgument);
63136365 try writer.writeAll(", ");
63146366 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });
63156367 try writer.writeAll(");\n");
......@@ -6320,11 +6372,12 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63206372
63216373 try f.writeCValue(writer, dest_slice, .FunctionArgument);
63226374 try writer.writeAll(", ");
6323 try f.writeCValue(writer, value, .FunctionArgument);
6375 try f.writeCValue(writer, bitcasted.c_value, .FunctionArgument);
63246376 try writer.print(", {d});\n", .{len});
63256377 },
63266378 .Many, .C => unreachable,
63276379 }
6380 try bitcasted.free(f);
63286381 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
63296382 return .none;
63306383}
......@@ -7394,7 +7447,7 @@ fn formatIntLiteral(
73947447 var int_buf: Value.BigIntSpace = undefined;
73957448 const int = if (data.val.isUndefDeep()) blk: {
73967449 undef_limbs = try allocator.alloc(BigIntLimb, BigInt.calcTwosCompLimbCount(data.int_info.bits));
7397 mem.set(BigIntLimb, undef_limbs, undefPattern(BigIntLimb));
7450 @memset(undef_limbs, undefPattern(BigIntLimb));
73987451
73997452 var undef_int = BigInt.Mutable{
74007453 .limbs = undef_limbs,
......@@ -7489,7 +7542,7 @@ fn formatIntLiteral(
74897542 } else {
74907543 try data.cty.renderLiteralPrefix(writer, data.kind);
74917544 wrap.convertToTwosComplement(int, data.int_info.signedness, c_bits);
7492 mem.set(BigIntLimb, wrap.limbs[wrap.len..], 0);
7545 @memset(wrap.limbs[wrap.len..], 0);
74937546 wrap.len = wrap.limbs.len;
74947547 const limbs_per_c_limb = @divExact(wrap.len, c_limb_info.count);
74957548
src/codegen/llvm.zig+62-20
......@@ -7939,11 +7939,15 @@ pub const FuncGen = struct {
79397939 return self.builder.buildPtrToInt(operand_ptr, dest_llvm_ty, "");
79407940 }
79417941
7942 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
7942 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !*llvm.Value {
79437943 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
79447944 const operand_ty = self.air.typeOf(ty_op.operand);
79457945 const inst_ty = self.air.typeOfIndex(inst);
79467946 const operand = try self.resolveInst(ty_op.operand);
7947 return self.bitCast(operand, operand_ty, inst_ty);
7948 }
7949
7950 fn bitCast(self: *FuncGen, operand: *llvm.Value, operand_ty: Type, inst_ty: Type) !*llvm.Value {
79477951 const operand_is_ref = isByRef(operand_ty);
79487952 const result_is_ref = isByRef(inst_ty);
79497953 const llvm_dest_ty = try self.dg.lowerType(inst_ty);
......@@ -7954,6 +7958,12 @@ pub const FuncGen = struct {
79547958 return operand;
79557959 }
79567960
7961 if (llvm_dest_ty.getTypeKind() == .Integer and
7962 operand.typeOf().getTypeKind() == .Integer)
7963 {
7964 return self.builder.buildZExtOrBitCast(operand, llvm_dest_ty, "");
7965 }
7966
79577967 if (operand_ty.zigTypeTag() == .Int and inst_ty.isPtrAtRuntime()) {
79587968 return self.builder.buildIntToPtr(operand, llvm_dest_ty, "");
79597969 }
......@@ -8414,27 +8424,45 @@ pub const FuncGen = struct {
84148424 const dest_slice = try self.resolveInst(bin_op.lhs);
84158425 const ptr_ty = self.air.typeOf(bin_op.lhs);
84168426 const elem_ty = self.air.typeOf(bin_op.rhs);
8417 const target = self.dg.module.getTarget();
8418 const val_is_undef = if (self.air.value(bin_op.rhs)) |val| val.isUndefDeep() else false;
8427 const module = self.dg.module;
8428 const target = module.getTarget();
84198429 const dest_ptr_align = ptr_ty.ptrAlignment(target);
84208430 const u8_llvm_ty = self.context.intType(8);
84218431 const dest_ptr = self.sliceOrArrayPtr(dest_slice, ptr_ty);
8432 const is_volatile = ptr_ty.isVolatilePtr();
8433
8434 if (self.air.value(bin_op.rhs)) |elem_val| {
8435 if (elem_val.isUndefDeep()) {
8436 // Even if safety is disabled, we still emit a memset to undefined since it conveys
8437 // extra information to LLVM. However, safety makes the difference between using
8438 // 0xaa or actual undefined for the fill byte.
8439 const fill_byte = if (safety)
8440 u8_llvm_ty.constInt(0xaa, .False)
8441 else
8442 u8_llvm_ty.getUndef();
8443 const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8444 _ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
84228445
8423 if (val_is_undef) {
8424 // Even if safety is disabled, we still emit a memset to undefined since it conveys
8425 // extra information to LLVM. However, safety makes the difference between using
8426 // 0xaa or actual undefined for the fill byte.
8427 const fill_byte = if (safety)
8428 u8_llvm_ty.constInt(0xaa, .False)
8429 else
8430 u8_llvm_ty.getUndef();
8431 const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8432 _ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, ptr_ty.isVolatilePtr());
8446 if (safety and module.comp.bin_file.options.valgrind) {
8447 self.valgrindMarkUndef(dest_ptr, len);
8448 }
8449 return null;
8450 }
84338451
8434 if (safety and self.dg.module.comp.bin_file.options.valgrind) {
8435 self.valgrindMarkUndef(dest_ptr, len);
8452 // Test if the element value is compile-time known to be a
8453 // repeating byte pattern, for example, `@as(u64, 0)` has a
8454 // repeating byte pattern of 0 bytes. In such case, the memset
8455 // intrinsic can be used.
8456 var value_buffer: Value.Payload.U64 = undefined;
8457 if (try elem_val.hasRepeatedByteRepr(elem_ty, module, &value_buffer)) |byte_val| {
8458 const fill_byte = try self.resolveValue(.{
8459 .ty = Type.u8,
8460 .val = byte_val,
8461 });
8462 const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8463 _ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
8464 return null;
84368465 }
8437 return null;
84388466 }
84398467
84408468 const value = try self.resolveInst(bin_op.rhs);
......@@ -8442,9 +8470,9 @@ pub const FuncGen = struct {
84428470
84438471 if (elem_abi_size == 1) {
84448472 // In this case we can take advantage of LLVM's intrinsic.
8445 const fill_byte = self.builder.buildBitCast(value, u8_llvm_ty, "");
8473 const fill_byte = try self.bitCast(value, elem_ty, Type.u8);
84468474 const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8447 _ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, ptr_ty.isVolatilePtr());
8475 _ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
84488476 return null;
84498477 }
84508478
......@@ -8486,8 +8514,22 @@ pub const FuncGen = struct {
84868514 _ = self.builder.buildCondBr(end, body_block, end_block);
84878515
84888516 self.builder.positionBuilderAtEnd(body_block);
8489 const store_inst = self.builder.buildStore(value, it_ptr);
8490 store_inst.setAlignment(@min(elem_ty.abiAlignment(target), dest_ptr_align));
8517 const elem_abi_alignment = elem_ty.abiAlignment(target);
8518 const it_ptr_alignment = @min(elem_abi_alignment, dest_ptr_align);
8519 if (isByRef(elem_ty)) {
8520 _ = self.builder.buildMemCpy(
8521 it_ptr,
8522 it_ptr_alignment,
8523 value,
8524 elem_abi_alignment,
8525 llvm_usize_ty.constInt(elem_abi_size, .False),
8526 is_volatile,
8527 );
8528 } else {
8529 const store_inst = self.builder.buildStore(value, it_ptr);
8530 store_inst.setAlignment(it_ptr_alignment);
8531 store_inst.setVolatile(llvm.Bool.fromBool(is_volatile));
8532 }
84918533 const one_gep = [_]*llvm.Value{llvm_usize_ty.constInt(1, .False)};
84928534 const next_ptr = self.builder.buildInBoundsGEP(elem_llvm_ty, it_ptr, &one_gep, one_gep.len, "");
84938535 _ = self.builder.buildBr(loop_block);
src/link/Coff.zig+27-15
......@@ -1916,7 +1916,7 @@ fn writeImportTables(self: *Coff) !void {
19161916 .name_rva = header.virtual_address + dll_names_offset,
19171917 .import_address_table_rva = header.virtual_address + iat_offset,
19181918 };
1919 mem.copy(u8, buffer.items[dir_table_offset..], mem.asBytes(&lookup_header));
1919 @memcpy(buffer.items[dir_table_offset..][0..@sizeOf(coff.ImportDirectoryEntry)], mem.asBytes(&lookup_header));
19201920 dir_table_offset += dir_header_size;
19211921
19221922 for (itable.entries.items) |entry| {
......@@ -1924,15 +1924,21 @@ fn writeImportTables(self: *Coff) !void {
19241924
19251925 // IAT and lookup table entry
19261926 const lookup = coff.ImportLookupEntry64.ByName{ .name_table_rva = @intCast(u31, header.virtual_address + names_table_offset) };
1927 mem.copy(u8, buffer.items[iat_offset..], mem.asBytes(&lookup));
1927 @memcpy(
1928 buffer.items[iat_offset..][0..@sizeOf(coff.ImportLookupEntry64.ByName)],
1929 mem.asBytes(&lookup),
1930 );
19281931 iat_offset += lookup_entry_size;
1929 mem.copy(u8, buffer.items[lookup_table_offset..], mem.asBytes(&lookup));
1932 @memcpy(
1933 buffer.items[lookup_table_offset..][0..@sizeOf(coff.ImportLookupEntry64.ByName)],
1934 mem.asBytes(&lookup),
1935 );
19301936 lookup_table_offset += lookup_entry_size;
19311937
19321938 // Names table entry
19331939 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // Hint set to 0 until we learn how to parse DLLs
19341940 names_table_offset += 2;
1935 mem.copy(u8, buffer.items[names_table_offset..], import_name);
1941 @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name);
19361942 names_table_offset += @intCast(u32, import_name.len);
19371943 buffer.items[names_table_offset] = 0;
19381944 names_table_offset += 1;
......@@ -1947,13 +1953,16 @@ fn writeImportTables(self: *Coff) !void {
19471953 iat_offset += 8;
19481954
19491955 // Lookup table sentinel
1950 mem.copy(u8, buffer.items[lookup_table_offset..], mem.asBytes(&coff.ImportLookupEntry64.ByName{ .name_table_rva = 0 }));
1956 @memcpy(
1957 buffer.items[lookup_table_offset..][0..@sizeOf(coff.ImportLookupEntry64.ByName)],
1958 mem.asBytes(&coff.ImportLookupEntry64.ByName{ .name_table_rva = 0 }),
1959 );
19511960 lookup_table_offset += lookup_entry_size;
19521961
19531962 // DLL name
1954 mem.copy(u8, buffer.items[dll_names_offset..], lib_name);
1963 @memcpy(buffer.items[dll_names_offset..][0..lib_name.len], lib_name);
19551964 dll_names_offset += @intCast(u32, lib_name.len);
1956 mem.copy(u8, buffer.items[dll_names_offset..], ext);
1965 @memcpy(buffer.items[dll_names_offset..][0..ext.len], ext);
19571966 dll_names_offset += @intCast(u32, ext.len);
19581967 buffer.items[dll_names_offset] = 0;
19591968 dll_names_offset += 1;
......@@ -1967,7 +1976,10 @@ fn writeImportTables(self: *Coff) !void {
19671976 .name_rva = 0,
19681977 .import_address_table_rva = 0,
19691978 };
1970 mem.copy(u8, buffer.items[dir_table_offset..], mem.asBytes(&lookup_header));
1979 @memcpy(
1980 buffer.items[dir_table_offset..][0..@sizeOf(coff.ImportDirectoryEntry)],
1981 mem.asBytes(&lookup_header),
1982 );
19711983 dir_table_offset += dir_header_size;
19721984
19731985 assert(dll_names_offset == needed_size);
......@@ -2366,13 +2378,13 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In
23662378
23672379fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {
23682380 if (name.len <= 8) {
2369 mem.copy(u8, &header.name, name);
2370 mem.set(u8, header.name[name.len..], 0);
2381 @memcpy(header.name[0..name.len], name);
2382 @memset(header.name[name.len..], 0);
23712383 return;
23722384 }
23732385 const offset = try self.strtab.insert(self.base.allocator, name);
23742386 const name_offset = fmt.bufPrint(&header.name, "/{d}", .{offset}) catch unreachable;
2375 mem.set(u8, header.name[name_offset.len..], 0);
2387 @memset(header.name[name_offset.len..], 0);
23762388}
23772389
23782390fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {
......@@ -2385,17 +2397,17 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const
23852397
23862398fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {
23872399 if (name.len <= 8) {
2388 mem.copy(u8, &symbol.name, name);
2389 mem.set(u8, symbol.name[name.len..], 0);
2400 @memcpy(symbol.name[0..name.len], name);
2401 @memset(symbol.name[name.len..], 0);
23902402 return;
23912403 }
23922404 const offset = try self.strtab.insert(self.base.allocator, name);
2393 mem.set(u8, symbol.name[0..4], 0);
2405 @memset(symbol.name[0..4], 0);
23942406 mem.writeIntLittle(u32, symbol.name[4..8], offset);
23952407}
23962408
23972409fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {
2398 mem.set(u8, buf[0..4], '_');
2410 @memset(buf[0..4], '_');
23992411 switch (sym.section_number) {
24002412 .UNDEFINED => {
24012413 buf[3] = 'u';
src/link/Dwarf.zig+15-12
......@@ -1189,7 +1189,7 @@ pub fn commitDeclState(
11891189 if (needed_size > segment_size) {
11901190 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});
11911191 try debug_line.resize(self.allocator, needed_size);
1192 mem.set(u8, debug_line.items[segment_size..], 0);
1192 @memset(debug_line.items[segment_size..], 0);
11931193 }
11941194 debug_line.items.len = needed_size;
11951195 }
......@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
14581458 if (needed_size > segment_size) {
14591459 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});
14601460 try debug_info.resize(self.allocator, needed_size);
1461 mem.set(u8, debug_info.items[segment_size..], 0);
1461 @memset(debug_info.items[segment_size..], 0);
14621462 }
14631463 debug_info.items.len = needed_size;
14641464 }
......@@ -1515,7 +1515,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, module: *Module, decl_index: Module.De
15151515 const wasm_file = self.bin_file.cast(File.Wasm).?;
15161516 const offset = atom.off + self.getRelocDbgLineOff();
15171517 const line_atom_index = wasm_file.debug_line_atom.?;
1518 mem.copy(u8, wasm_file.getAtomPtr(line_atom_index).code.items[offset..], &data);
1518 wasm_file.getAtomPtr(line_atom_index).code.items[offset..][0..data.len].* = data;
15191519 },
15201520 else => unreachable,
15211521 }
......@@ -1734,7 +1734,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {
17341734 const wasm_file = self.bin_file.cast(File.Wasm).?;
17351735 const debug_abbrev = &wasm_file.getAtomPtr(wasm_file.debug_abbrev_atom.?).code;
17361736 try debug_abbrev.resize(wasm_file.base.allocator, needed_size);
1737 mem.copy(u8, debug_abbrev.items, &abbrev_buf);
1737 debug_abbrev.items[0..abbrev_buf.len].* = abbrev_buf;
17381738 },
17391739 else => unreachable,
17401740 }
......@@ -1976,7 +1976,7 @@ fn writeDbgLineNopsBuffered(
19761976 }
19771977 }
19781978
1979 mem.copy(u8, buf[offset..], content);
1979 @memcpy(buf[offset..][0..content.len], content);
19801980
19811981 {
19821982 var padding_left = next_padding_size;
......@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(
20762076 buffer.items.len,
20772077 offset + content.len + next_padding_size + 1,
20782078 ));
2079 mem.set(u8, buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));
2080 mem.copy(u8, buffer.items[offset..], content);
2081 mem.set(u8, buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));
2079 @memset(buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));
2080 @memcpy(buffer.items[offset..][0..content.len], content);
2081 @memset(buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));
20822082
20832083 if (trailing_zero) {
20842084 buffer.items[offset + content.len + next_padding_size] = 0;
......@@ -2168,7 +2168,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
21682168 const wasm_file = self.bin_file.cast(File.Wasm).?;
21692169 const debug_ranges = &wasm_file.getAtomPtr(wasm_file.debug_ranges_atom.?).code;
21702170 try debug_ranges.resize(wasm_file.base.allocator, needed_size);
2171 mem.copy(u8, debug_ranges.items, di_buf.items);
2171 @memcpy(debug_ranges.items[0..di_buf.items.len], di_buf.items);
21722172 },
21732173 else => unreachable,
21742174 }
......@@ -2341,9 +2341,12 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
23412341 .wasm => {
23422342 const wasm_file = self.bin_file.cast(File.Wasm).?;
23432343 const debug_line = &wasm_file.getAtomPtr(wasm_file.debug_line_atom.?).code;
2344 mem.copy(u8, buffer, debug_line.items[first_fn.off..]);
2344 {
2345 const src = debug_line.items[first_fn.off..];
2346 @memcpy(buffer[0..src.len], src);
2347 }
23452348 try debug_line.resize(self.allocator, debug_line.items.len + delta);
2346 mem.copy(u8, debug_line.items[first_fn.off + delta ..], buffer);
2349 @memcpy(debug_line.items[first_fn.off + delta ..][0..buffer.len], buffer);
23472350 },
23482351 else => unreachable,
23492352 }
......@@ -2537,7 +2540,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
25372540 .wasm => {
25382541 const wasm_file = self.bin_file.cast(File.Wasm).?;
25392542 const debug_info = wasm_file.getAtomPtr(wasm_file.debug_info_atom.?).code;
2540 mem.copy(u8, debug_info.items[atom.off + reloc.offset ..], &buf);
2543 debug_info.items[atom.off + reloc.offset ..][0..buf.len].* = buf;
25412544 },
25422545 else => unreachable,
25432546 }
src/link/Elf.zig+1-1
......@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {
19971997 // OS ABI, often set to 0 regardless of target platform
19981998 // ABI Version, possibly used by glibc but not by static executables
19991999 // padding
2000 mem.set(u8, hdr_buf[index..][0..9], 0);
2000 @memset(hdr_buf[index..][0..9], 0);
20012001 index += 9;
20022002
20032003 assert(index == 16);
src/link/MachO.zig+7-8
......@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S
14541454 });
14551455
14561456 var code: [size]u8 = undefined;
1457 mem.set(u8, &code, 0);
1457 @memset(&code, 0);
14581458 try self.writeAtom(atom_index, &code);
14591459
14601460 return atom_index;
......@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {
32343234
32353235 var buffer = try gpa.alloc(u8, needed_size);
32363236 defer gpa.free(buffer);
3237 mem.set(u8, buffer, 0);
3237 @memset(buffer, 0);
32383238
32393239 var stream = std.io.fixedBufferStream(buffer);
32403240 const writer = stream.writer();
......@@ -3389,8 +3389,8 @@ fn writeStrtab(self: *MachO) !void {
33893389
33903390 const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
33913391 defer gpa.free(buffer);
3392 mem.set(u8, buffer, 0);
3393 mem.copy(u8, buffer, self.strtab.buffer.items);
3392 @memcpy(buffer[0..self.strtab.buffer.items.len], self.strtab.buffer.items);
3393 @memset(buffer[self.strtab.buffer.items.len..], 0);
33943394
33953395 try self.base.file.?.pwriteAll(buffer, offset);
33963396
......@@ -3668,8 +3668,7 @@ fn addUndefined(self: *MachO, name: []const u8, action: ResolveAction.Kind) !u32
36683668
36693669pub fn makeStaticString(bytes: []const u8) [16]u8 {
36703670 var buf = [_]u8{0} ** 16;
3671 assert(bytes.len <= buf.len);
3672 mem.copy(u8, &buf, bytes);
3671 @memcpy(buf[0..bytes.len], bytes);
36733672 return buf;
36743673}
36753674
......@@ -4096,8 +4095,8 @@ pub fn logSections(self: *MachO) void {
40964095}
40974096
40984097fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
4099 mem.set(u8, buf[0..4], '_');
4100 mem.set(u8, buf[4..], ' ');
4098 @memset(buf[0..4], '_');
4099 @memset(buf[4..], ' ');
41014100 if (sym.sect()) {
41024101 buf[0] = 's';
41034102 }
src/link/MachO/CodeSignature.zig+1-1
......@@ -100,7 +100,7 @@ const CodeDirectory = struct {
100100 fn addSpecialHash(self: *CodeDirectory, index: u32, hash: [hash_size]u8) void {
101101 assert(index > 0);
102102 self.inner.nSpecialSlots = std.math.max(self.inner.nSpecialSlots, index);
103 mem.copy(u8, &self.special_slots[index - 1], &hash);
103 self.special_slots[index - 1] = hash;
104104 }
105105
106106 fn slotType(self: CodeDirectory) u32 {
src/link/MachO/Object.zig+6-6
......@@ -156,7 +156,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
156156
157157 // Prepopulate relocations per section lookup table.
158158 try self.section_relocs_lookup.resize(allocator, nsects);
159 mem.set(u32, self.section_relocs_lookup.items, 0);
159 @memset(self.section_relocs_lookup.items, 0);
160160
161161 // Parse symtab.
162162 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {
......@@ -189,10 +189,10 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
189189 };
190190 }
191191
192 mem.set(i64, self.globals_lookup, -1);
193 mem.set(AtomIndex, self.atom_by_index_table, 0);
194 mem.set(Entry, self.source_section_index_lookup, .{});
195 mem.set(Entry, self.relocs_lookup, .{});
192 @memset(self.globals_lookup, -1);
193 @memset(self.atom_by_index_table, 0);
194 @memset(self.source_section_index_lookup, .{});
195 @memset(self.relocs_lookup, .{});
196196
197197 // You would expect that the symbol table is at least pre-sorted based on symbol's type:
198198 // local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance,
......@@ -252,7 +252,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
252252 self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");
253253 if (self.hasUnwindRecords()) {
254254 self.unwind_relocs_lookup = try allocator.alloc(Record, self.getUnwindRecords().len);
255 mem.set(Record, self.unwind_relocs_lookup, .{ .dead = true, .reloc = .{} });
255 @memset(self.unwind_relocs_lookup, .{ .dead = true, .reloc = .{} });
256256 }
257257}
258258
src/link/MachO/Trie.zig+1-1
......@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
499499 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
500500 var padding = try testing.allocator.alloc(u8, idx + 5);
501501 defer testing.allocator.free(padding);
502 mem.set(u8, padding, ' ');
502 @memset(padding, ' ');
503503 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
504504 return error.TestFailed;
505505}
src/link/MachO/UnwindInfo.zig+1-1
......@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
659659 const padding = buffer.items.len - cwriter.bytes_written;
660660 if (padding > 0) {
661661 const offset = math.cast(usize, cwriter.bytes_written) orelse return error.Overflow;
662 mem.set(u8, buffer.items[offset..], 0);
662 @memset(buffer.items[offset..], 0);
663663 }
664664
665665 try zld.file.pwriteAll(buffer.items, sect.offset);
src/link/MachO/zld.zig+11-9
......@@ -2140,7 +2140,7 @@ pub const Zld = struct {
21402140
21412141 var buffer = try gpa.alloc(u8, needed_size);
21422142 defer gpa.free(buffer);
2143 mem.set(u8, buffer, 0);
2143 @memset(buffer, 0);
21442144
21452145 var stream = std.io.fixedBufferStream(buffer);
21462146 const writer = stream.writer();
......@@ -2352,8 +2352,11 @@ pub const Zld = struct {
23522352
23532353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
23542354 defer self.gpa.free(buffer);
2355 mem.set(u8, buffer, 0);
2356 mem.copy(u8, buffer, mem.sliceAsBytes(out_dice.items));
2355 {
2356 const src = mem.sliceAsBytes(out_dice.items);
2357 @memcpy(buffer[0..src.len], src);
2358 @memset(buffer[src.len..], 0);
2359 }
23572360
23582361 log.debug("writing data-in-code from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
23592362
......@@ -2484,8 +2487,8 @@ pub const Zld = struct {
24842487
24852488 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
24862489 defer self.gpa.free(buffer);
2487 mem.set(u8, buffer, 0);
2488 mem.copy(u8, buffer, self.strtab.buffer.items);
2490 @memcpy(buffer[0..self.strtab.buffer.items.len], self.strtab.buffer.items);
2491 @memset(buffer[self.strtab.buffer.items.len..], 0);
24892492
24902493 try self.file.pwriteAll(buffer, offset);
24912494
......@@ -2805,8 +2808,7 @@ pub const Zld = struct {
28052808
28062809 pub fn makeStaticString(bytes: []const u8) [16]u8 {
28072810 var buf = [_]u8{0} ** 16;
2808 assert(bytes.len <= buf.len);
2809 mem.copy(u8, &buf, bytes);
2811 @memcpy(buf[0..bytes.len], bytes);
28102812 return buf;
28112813 }
28122814
......@@ -3199,7 +3201,7 @@ pub const Zld = struct {
31993201 scoped_log.debug(" object({d}): {s}", .{ id, object.name });
32003202 if (object.in_symtab == null) continue;
32013203 for (object.symtab, 0..) |sym, sym_id| {
3202 mem.set(u8, &buf, '_');
3204 @memset(&buf, '_');
32033205 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
32043206 sym_id,
32053207 object.getSymbolName(@intCast(u32, sym_id)),
......@@ -4007,7 +4009,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
40074009 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
40084010 var padding = try zld.gpa.alloc(u8, size);
40094011 defer zld.gpa.free(padding);
4010 mem.set(u8, padding, 0);
4012 @memset(padding, 0);
40114013 try zld.file.pwriteAll(padding, start);
40124014 }
40134015 }
src/link/Plan9.zig+1-1
......@@ -681,7 +681,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
681681 .pcsz = @intCast(u32, linecountinfo.items.len),
682682 .entry = @intCast(u32, self.entry_val.?),
683683 };
684 std.mem.copy(u8, hdr_slice, self.hdr.toU8s()[0..hdr_size]);
684 @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]);
685685 // write the fat header for 64 bit entry points
686686 if (self.sixtyfour_bit) {
687687 mem.writeIntSliceBig(u64, hdr_buf[32..40], self.entry_val.?);
src/link/Wasm.zig+7-4
......@@ -1976,7 +1976,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
19761976 // We do not have to do this when exporting the memory (the default) because the runtime
19771977 // will do it for us, and we do not emit the bss segment at all.
19781978 if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
1979 std.mem.set(u8, atom.code.items, 0);
1979 @memset(atom.code.items, 0);
19801980 }
19811981
19821982 const should_merge = wasm.base.options.output_mode != .Obj;
......@@ -3852,7 +3852,10 @@ fn writeToFile(
38523852 // Only when writing all sections executed properly we write the magic
38533853 // bytes. This allows us to easily detect what went wrong while generating
38543854 // the final binary.
3855 mem.copy(u8, binary_bytes.items, &(std.wasm.magic ++ std.wasm.version));
3855 {
3856 const src = std.wasm.magic ++ std.wasm.version;
3857 binary_bytes.items[0..src.len].* = src;
3858 }
38563859
38573860 // finally, write the entire binary into the file.
38583861 var iovec = [_]std.os.iovec_const{.{
......@@ -4559,14 +4562,14 @@ fn writeVecSectionHeader(buffer: []u8, offset: u32, section: std.wasm.Section, s
45594562 buf[0] = @enumToInt(section);
45604563 leb.writeUnsignedFixed(5, buf[1..6], size);
45614564 leb.writeUnsignedFixed(5, buf[6..], items);
4562 mem.copy(u8, buffer[offset..], &buf);
4565 buffer[offset..][0..buf.len].* = buf;
45634566}
45644567
45654568fn writeCustomSectionHeader(buffer: []u8, offset: u32, size: u32) !void {
45664569 var buf: [1 + 5]u8 = undefined;
45674570 buf[0] = 0; // 0 = 'custom' section
45684571 leb.writeUnsignedFixed(5, buf[1..6], size);
4569 mem.copy(u8, buffer[offset..], &buf);
4572 buffer[offset..][0..buf.len].* = buf;
45704573}
45714574
45724575fn emitLinkSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table: *std.AutoArrayHashMap(SymbolLoc, u32)) !void {
src/objcopy.zig+19-19
......@@ -860,7 +860,7 @@ fn ElfFile(comptime is_64: bool) type {
860860 if (section.payload) |data| {
861861 switch (section.section.sh_type) {
862862 elf.DT_VERSYM => {
863 std.debug.assert(section.section.sh_entsize == @sizeOf(Elf_Verdef));
863 assert(section.section.sh_entsize == @sizeOf(Elf_Verdef));
864864 const defs = @ptrCast([*]const Elf_Verdef, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(Elf_Verdef)];
865865 for (defs) |def| {
866866 if (def.vd_ndx != elf.SHN_UNDEF)
......@@ -868,7 +868,7 @@ fn ElfFile(comptime is_64: bool) type {
868868 }
869869 },
870870 elf.SHT_SYMTAB, elf.SHT_DYNSYM => {
871 std.debug.assert(section.section.sh_entsize == @sizeOf(Elf_Sym));
871 assert(section.section.sh_entsize == @sizeOf(Elf_Sym));
872872 const syms = @ptrCast([*]const Elf_Sym, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(Elf_Sym)];
873873
874874 for (syms) |sym| {
......@@ -952,11 +952,11 @@ fn ElfFile(comptime is_64: bool) type {
952952 const name: []const u8 = ".gnu_debuglink";
953953 const new_offset = @intCast(u32, strtab.payload.?.len);
954954 const buf = try allocator.alignedAlloc(u8, section_memory_align, new_offset + name.len + 1);
955 std.mem.copy(u8, buf[0..new_offset], strtab.payload.?);
956 std.mem.copy(u8, buf[new_offset .. new_offset + name.len], name);
955 @memcpy(buf[0..new_offset], strtab.payload.?);
956 @memcpy(buf[new_offset..][0..name.len], name);
957957 buf[new_offset + name.len] = 0;
958958
959 std.debug.assert(update.action == .keep);
959 assert(update.action == .keep);
960960 update.payload = buf;
961961
962962 break :blk new_offset;
......@@ -978,9 +978,9 @@ fn ElfFile(comptime is_64: bool) type {
978978 // program header as-is.
979979 // nb: for only-debug files, removing it appears to work, but is invalid by ELF specifcation.
980980 {
981 std.debug.assert(updated_elf_header.e_phoff == @sizeOf(Elf_Ehdr));
981 assert(updated_elf_header.e_phoff == @sizeOf(Elf_Ehdr));
982982 const data = std.mem.sliceAsBytes(self.program_segments);
983 std.debug.assert(data.len == @as(usize, updated_elf_header.e_phentsize) * updated_elf_header.e_phnum);
983 assert(data.len == @as(usize, updated_elf_header.e_phentsize) * updated_elf_header.e_phnum);
984984 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = data, .out_offset = updated_elf_header.e_phoff } });
985985 eof_offset = updated_elf_header.e_phoff + @intCast(Elf_OffSize, data.len);
986986 }
......@@ -1006,7 +1006,7 @@ fn ElfFile(comptime is_64: bool) type {
10061006 var dest_section_idx: u32 = 1;
10071007 for (self.sections[1..], sections_update[1..]) |section, update| {
10081008 if (update.action == .strip) continue;
1009 std.debug.assert(update.remap_idx == dest_section_idx);
1009 assert(update.remap_idx == dest_section_idx);
10101010
10111011 const src = if (update.section) |*s| s else &section.section;
10121012 const dest = &dest_sections[dest_section_idx];
......@@ -1032,7 +1032,7 @@ fn ElfFile(comptime is_64: bool) type {
10321032 fatal("zig objcopy: cannot adjust program segments", .{});
10331033 }
10341034 }
1035 std.debug.assert(dest.sh_addr % addralign == dest.sh_offset % addralign);
1035 assert(dest.sh_addr % addralign == dest.sh_offset % addralign);
10361036
10371037 if (update.action == .empty)
10381038 dest.sh_type = elf.SHT_NOBITS;
......@@ -1043,7 +1043,7 @@ fn ElfFile(comptime is_64: bool) type {
10431043 const dest_data = switch (src.sh_type) {
10441044 elf.DT_VERSYM => dst_data: {
10451045 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);
1046 std.mem.copy(u8, data, src_data);
1046 @memcpy(data, src_data);
10471047
10481048 const defs = @ptrCast([*]Elf_Verdef, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Verdef)];
10491049 for (defs) |*def| {
......@@ -1055,7 +1055,7 @@ fn ElfFile(comptime is_64: bool) type {
10551055 },
10561056 elf.SHT_SYMTAB, elf.SHT_DYNSYM => dst_data: {
10571057 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);
1058 std.mem.copy(u8, data, src_data);
1058 @memcpy(data, src_data);
10591059
10601060 const syms = @ptrCast([*]Elf_Sym, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Sym)];
10611061 for (syms) |*sym| {
......@@ -1068,7 +1068,7 @@ fn ElfFile(comptime is_64: bool) type {
10681068 else => src_data,
10691069 };
10701070
1071 std.debug.assert(dest_data.len == dest.sh_size);
1071 assert(dest_data.len == dest.sh_size);
10721072 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = dest_data, .out_offset = dest.sh_offset } });
10731073 eof_offset = dest.sh_offset + dest.sh_size;
10741074 } else {
......@@ -1087,9 +1087,9 @@ fn ElfFile(comptime is_64: bool) type {
10871087 const payload = payload: {
10881088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);
10891089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);
1090 std.mem.copy(u8, buf[0..link.name.len], link.name);
1091 std.mem.set(u8, buf[link.name.len..crc_offset], 0);
1092 std.mem.copy(u8, buf[crc_offset..], std.mem.asBytes(&link.crc32));
1090 @memcpy(buf[0..link.name.len], link.name);
1091 @memset(buf[link.name.len..crc_offset], 0);
1092 @memcpy(buf[crc_offset..], std.mem.asBytes(&link.crc32));
10931093 break :payload buf;
10941094 };
10951095
......@@ -1111,7 +1111,7 @@ fn ElfFile(comptime is_64: bool) type {
11111111 eof_offset += @intCast(Elf_OffSize, payload.len);
11121112 }
11131113
1114 std.debug.assert(dest_section_idx == new_shnum);
1114 assert(dest_section_idx == new_shnum);
11151115 break :blk dest_sections;
11161116 };
11171117
......@@ -1120,7 +1120,7 @@ fn ElfFile(comptime is_64: bool) type {
11201120 const offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr));
11211121
11221122 const data = std.mem.sliceAsBytes(updated_section_header);
1123 std.debug.assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum);
1123 assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum);
11241124 updated_elf_header.e_shoff = offset;
11251125 updated_elf_header.e_shnum = new_shnum;
11261126
......@@ -1215,7 +1215,7 @@ const ElfFileHelper = struct {
12151215 for (cmds) |cmd| {
12161216 switch (cmd) {
12171217 .write_data => |data| {
1218 std.debug.assert(data.out_offset >= offset);
1218 assert(data.out_offset >= offset);
12191219 if (fused_cmd) |prev| {
12201220 consolidated.appendAssumeCapacity(prev);
12211221 fused_cmd = null;
......@@ -1227,7 +1227,7 @@ const ElfFileHelper = struct {
12271227 offset = data.out_offset + data.data.len;
12281228 },
12291229 .copy_range => |range| {
1230 std.debug.assert(range.out_offset >= offset);
1230 assert(range.out_offset >= offset);
12311231 if (fused_cmd) |prev| {
12321232 if (range.in_offset >= prev.copy_range.in_offset + prev.copy_range.len and (range.out_offset - prev.copy_range.out_offset == range.in_offset - prev.copy_range.in_offset)) {
12331233 fused_cmd = .{ .copy_range = .{
src/print_air.zig+1-1
......@@ -846,7 +846,7 @@ const Writer = struct {
846846 else blk: {
847847 const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch
848848 @panic("out of memory");
849 std.mem.set([]const Air.Inst.Index, slice, &.{});
849 @memset(slice, &.{});
850850 break :blk Liveness.SwitchBrTable{ .deaths = slice };
851851 };
852852 defer w.gpa.free(liveness.deaths);
src/print_zir.zig+1-1
......@@ -682,7 +682,7 @@ const Writer = struct {
682682 const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);
683683 defer self.gpa.free(limbs);
684684
685 mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);
685 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
686686 const big_int: std.math.big.int.Const = .{
687687 .limbs = limbs,
688688 .positive = true,
src/translate_c.zig+1-1
......@@ -113,7 +113,7 @@ const Scope = struct {
113113 const alloc_len = self.statements.items.len + @boolToInt(self.base.parent.?.id == .do_loop);
114114 var stmts = try c.arena.alloc(Node, alloc_len);
115115 stmts.len = self.statements.items.len;
116 mem.copy(Node, stmts, self.statements.items);
116 @memcpy(stmts[0..self.statements.items.len], self.statements.items);
117117 return Tag.block.create(c.arena, .{
118118 .label = self.label,
119119 .stmts = stmts,
src/type.zig+1-1
......@@ -4767,7 +4767,7 @@ pub const Type = extern union {
47674767 .fn_ccc_void_no_args => return,
47684768 .function => {
47694769 const payload = self.castTag(.function).?.data;
4770 std.mem.copy(Type, types, payload.param_types);
4770 @memcpy(types[0..payload.param_types.len], payload.param_types);
47714771 },
47724772
47734773 else => unreachable,
src/value.zig+44-9
......@@ -875,7 +875,7 @@ pub const Value = extern union {
875875 .repeated => {
876876 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));
877877 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
878 std.mem.set(u8, result, byte);
878 @memset(result, byte);
879879 return result;
880880 },
881881 .decl_ref => {
......@@ -1278,12 +1278,16 @@ pub const Value = extern union {
12781278 ///
12791279 /// Asserts that buffer.len >= ty.abiSize(). The buffer is allowed to extend past
12801280 /// the end of the value in memory.
1281 pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{ReinterpretDeclRef}!void {
1281 pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
1282 ReinterpretDeclRef,
1283 IllDefinedMemoryLayout,
1284 Unimplemented,
1285 }!void {
12821286 const target = mod.getTarget();
12831287 const endian = target.cpu.arch.endian();
12841288 if (val.isUndef()) {
12851289 const size = @intCast(usize, ty.abiSize(target));
1286 std.mem.set(u8, buffer[0..size], 0xaa);
1290 @memset(buffer[0..size], 0xaa);
12871291 return;
12881292 }
12891293 switch (ty.zigTypeTag()) {
......@@ -1345,7 +1349,7 @@ pub const Value = extern union {
13451349 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
13461350 },
13471351 .Struct => switch (ty.containerLayout()) {
1348 .Auto => unreachable, // Sema is supposed to have emitted a compile error already
1352 .Auto => return error.IllDefinedMemoryLayout,
13491353 .Extern => {
13501354 const fields = ty.structFields().values();
13511355 const field_vals = val.castTag(.aggregate).?.data;
......@@ -1366,20 +1370,20 @@ pub const Value = extern union {
13661370 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian);
13671371 },
13681372 .Union => switch (ty.containerLayout()) {
1369 .Auto => unreachable,
1370 .Extern => @panic("TODO implement writeToMemory for extern unions"),
1373 .Auto => return error.IllDefinedMemoryLayout,
1374 .Extern => return error.Unimplemented,
13711375 .Packed => {
13721376 const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8;
13731377 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
13741378 },
13751379 },
13761380 .Pointer => {
1377 assert(!ty.isSlice()); // No well defined layout.
1381 if (ty.isSlice()) return error.IllDefinedMemoryLayout;
13781382 if (val.isDeclRef()) return error.ReinterpretDeclRef;
13791383 return val.writeToMemory(Type.usize, mod, buffer);
13801384 },
13811385 .Optional => {
1382 assert(ty.isPtrLikeOptional());
1386 if (!ty.isPtrLikeOptional()) return error.IllDefinedMemoryLayout;
13831387 var buf: Type.Payload.ElemType = undefined;
13841388 const child = ty.optionalChild(&buf);
13851389 const opt_val = val.optionalValue();
......@@ -1389,7 +1393,7 @@ pub const Value = extern union {
13891393 return writeToMemory(Value.zero, Type.usize, mod, buffer);
13901394 }
13911395 },
1392 else => @panic("TODO implement writeToMemory for more types"),
1396 else => return error.Unimplemented,
13931397 }
13941398 }
13951399
......@@ -2785,6 +2789,7 @@ pub const Value = extern union {
27852789 .field_ptr => isComptimeMutablePtr(val.castTag(.field_ptr).?.data.container_ptr),
27862790 .eu_payload_ptr => isComptimeMutablePtr(val.castTag(.eu_payload_ptr).?.data.container_ptr),
27872791 .opt_payload_ptr => isComptimeMutablePtr(val.castTag(.opt_payload_ptr).?.data.container_ptr),
2792 .slice => isComptimeMutablePtr(val.castTag(.slice).?.data.ptr),
27882793
27892794 else => false,
27902795 };
......@@ -5381,6 +5386,36 @@ pub const Value = extern union {
53815386 }
53825387 }
53835388
5389 /// If the value is represented in-memory as a series of bytes that all
5390 /// have the same value, return that byte value, otherwise null.
5391 pub fn hasRepeatedByteRepr(val: Value, ty: Type, mod: *Module, value_buffer: *Payload.U64) !?Value {
5392 const target = mod.getTarget();
5393 const abi_size = ty.abiSize(target);
5394 assert(abi_size >= 1);
5395 const byte_buffer = try mod.gpa.alloc(u8, abi_size);
5396 defer mod.gpa.free(byte_buffer);
5397
5398 writeToMemory(val, ty, mod, byte_buffer) catch |err| switch (err) {
5399 error.ReinterpretDeclRef => return null,
5400 // TODO: The writeToMemory function was originally created for the purpose
5401 // of comptime pointer casting. However, it is now additionally being used
5402 // for checking the actual memory layout that will be generated by machine
5403 // code late in compilation. So, this error handling is too aggressive and
5404 // causes some false negatives, causing less-than-ideal code generation.
5405 error.IllDefinedMemoryLayout => return null,
5406 error.Unimplemented => return null,
5407 };
5408 const first_byte = byte_buffer[0];
5409 for (byte_buffer[1..]) |byte| {
5410 if (byte != first_byte) return null;
5411 }
5412 value_buffer.* = .{
5413 .base = .{ .tag = .int_u64 },
5414 .data = first_byte,
5415 };
5416 return initPayload(&value_buffer.base);
5417 }
5418
53845419 /// This type is not copyable since it may contain pointers to its inner data.
53855420 pub const Payload = struct {
53865421 tag: Tag,
stage1/zig.h+8
......@@ -188,6 +188,14 @@ typedef char bool;
188188#define zig_export(sig, symbol, name) __asm(name " = " symbol)
189189#endif
190190
191#if zig_has_attribute(weak) || defined(zig_gnuc)
192#define zig_weak_linkage __attribute__((weak))
193#elif _MSC_VER
194#define zig_weak_linkage __declspec(selectany)
195#else
196#define zig_weak_linkage zig_weak_linkage_unavailable
197#endif
198
191199#if zig_has_builtin(trap)
192200#define zig_trap() __builtin_trap()
193201#elif _MSC_VER && (_M_IX86 || _M_X64)
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior.zig+2
......@@ -177,6 +177,8 @@ test {
177177 _ = @import("behavior/math.zig");
178178 _ = @import("behavior/maximum_minimum.zig");
179179 _ = @import("behavior/member_func.zig");
180 _ = @import("behavior/memcpy.zig");
181 _ = @import("behavior/memset.zig");
180182 _ = @import("behavior/merge_error_sets.zig");
181183 _ = @import("behavior/muladd.zig");
182184 _ = @import("behavior/namespace_depends_on_compile_var.zig");
test/behavior/basic.zig-90
......@@ -353,96 +353,6 @@ fn f2(x: bool) []const u8 {
353353 return (if (x) &fA else &fB)();
354354}
355355
356test "@memset on array pointers" {
357 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
358 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
359 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
360 if (builtin.zig_backend == .stage2_wasm) {
361 // TODO: implement memset when element ABI size > 1
362 return error.SkipZigTest;
363 }
364
365 try testMemsetArray();
366 try comptime testMemsetArray();
367}
368
369fn testMemsetArray() !void {
370 {
371 // memset array to non-undefined, ABI size == 1
372 var foo: [20]u8 = undefined;
373 @memset(&foo, 'A');
374 try expect(foo[0] == 'A');
375 try expect(foo[11] == 'A');
376 try expect(foo[19] == 'A');
377 }
378 {
379 // memset array to non-undefined, ABI size > 1
380 var foo: [20]u32 = undefined;
381 @memset(&foo, 1234);
382 try expect(foo[0] == 1234);
383 try expect(foo[11] == 1234);
384 try expect(foo[19] == 1234);
385 }
386}
387
388test "@memset on slices" {
389 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
390 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
391 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
392 if (builtin.zig_backend == .stage2_wasm) {
393 // TODO: implement memset when element ABI size > 1
394 // TODO: implement memset on slices
395 return error.SkipZigTest;
396 }
397
398 try testMemsetSlice();
399 try comptime testMemsetSlice();
400}
401
402fn testMemsetSlice() !void {
403 {
404 // memset slice to non-undefined, ABI size == 1
405 var array: [20]u8 = undefined;
406 var len = array.len;
407 var slice = array[0..len];
408 @memset(slice, 'A');
409 try expect(slice[0] == 'A');
410 try expect(slice[11] == 'A');
411 try expect(slice[19] == 'A');
412 }
413 {
414 // memset slice to non-undefined, ABI size > 1
415 var array: [20]u32 = undefined;
416 var len = array.len;
417 var slice = array[0..len];
418 @memset(slice, 1234);
419 try expect(slice[0] == 1234);
420 try expect(slice[11] == 1234);
421 try expect(slice[19] == 1234);
422 }
423}
424
425test "memcpy and memset intrinsics" {
426 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
427 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
428 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
429
430 try testMemcpyMemset();
431 try comptime testMemcpyMemset();
432}
433
434fn testMemcpyMemset() !void {
435 var foo: [20]u8 = undefined;
436 var bar: [20]u8 = undefined;
437
438 @memset(&foo, 'A');
439 @memcpy(&bar, &foo);
440
441 try expect(bar[0] == 'A');
442 try expect(bar[11] == 'A');
443 try expect(bar[19] == 'A');
444}
445
446356test "variable is allowed to be a pointer to an opaque type" {
447357 var x: i32 = 1234;
448358 _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));
test/behavior/memcpy.zig created+44
......@@ -0,0 +1,44 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const expect = std.testing.expect;
4
5test "memcpy and memset intrinsics" {
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
9
10 try testMemcpyMemset();
11 try comptime testMemcpyMemset();
12}
13
14fn testMemcpyMemset() !void {
15 var foo: [20]u8 = undefined;
16 var bar: [20]u8 = undefined;
17
18 @memset(&foo, 'A');
19 @memcpy(&bar, &foo);
20
21 try expect(bar[0] == 'A');
22 try expect(bar[11] == 'A');
23 try expect(bar[19] == 'A');
24}
25
26test "@memcpy with both operands single-ptr-to-array, one is null-terminated" {
27 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
28 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
30
31 try testMemcpyBothSinglePtrArrayOneIsNullTerminated();
32 try comptime testMemcpyBothSinglePtrArrayOneIsNullTerminated();
33}
34
35fn testMemcpyBothSinglePtrArrayOneIsNullTerminated() !void {
36 var buf: [100]u8 = undefined;
37 const suffix = "hello";
38 @memcpy(buf[buf.len - suffix.len ..], suffix);
39 try expect(buf[95] == 'h');
40 try expect(buf[96] == 'e');
41 try expect(buf[97] == 'l');
42 try expect(buf[98] == 'l');
43 try expect(buf[99] == 'o');
44}
test/behavior/memset.zig created+146
......@@ -0,0 +1,146 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const expect = std.testing.expect;
4
5test "@memset on array pointers" {
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_wasm) {
10 // TODO: implement memset when element ABI size > 1
11 return error.SkipZigTest;
12 }
13
14 try testMemsetArray();
15 try comptime testMemsetArray();
16}
17
18fn testMemsetArray() !void {
19 {
20 // memset array to non-undefined, ABI size == 1
21 var foo: [20]u8 = undefined;
22 @memset(&foo, 'A');
23 try expect(foo[0] == 'A');
24 try expect(foo[11] == 'A');
25 try expect(foo[19] == 'A');
26 }
27 {
28 // memset array to non-undefined, ABI size > 1
29 var foo: [20]u32 = undefined;
30 @memset(&foo, 1234);
31 try expect(foo[0] == 1234);
32 try expect(foo[11] == 1234);
33 try expect(foo[19] == 1234);
34 }
35}
36
37test "@memset on slices" {
38 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
39 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
40 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
41 if (builtin.zig_backend == .stage2_wasm) {
42 // TODO: implement memset when element ABI size > 1
43 // TODO: implement memset on slices
44 return error.SkipZigTest;
45 }
46
47 try testMemsetSlice();
48 try comptime testMemsetSlice();
49}
50
51fn testMemsetSlice() !void {
52 {
53 // memset slice to non-undefined, ABI size == 1
54 var array: [20]u8 = undefined;
55 var len = array.len;
56 var slice = array[0..len];
57 @memset(slice, 'A');
58 try expect(slice[0] == 'A');
59 try expect(slice[11] == 'A');
60 try expect(slice[19] == 'A');
61 }
62 {
63 // memset slice to non-undefined, ABI size > 1
64 var array: [20]u32 = undefined;
65 var len = array.len;
66 var slice = array[0..len];
67 @memset(slice, 1234);
68 try expect(slice[0] == 1234);
69 try expect(slice[11] == 1234);
70 try expect(slice[19] == 1234);
71 }
72}
73
74test "memset with bool element" {
75 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
76 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
77 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
78 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
79
80 var buf: [5]bool = undefined;
81 @memset(&buf, true);
82 try expect(buf[2]);
83 try expect(buf[4]);
84}
85
86test "memset with 1-byte struct element" {
87 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
88 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
89 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
90 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
91
92 const S = struct { x: bool };
93 var buf: [5]S = undefined;
94 @memset(&buf, .{ .x = true });
95 try expect(buf[2].x);
96 try expect(buf[4].x);
97}
98
99test "memset with 1-byte array element" {
100 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
101 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
102 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
103 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
104
105 const A = [1]bool;
106 var buf: [5]A = undefined;
107 @memset(&buf, .{true});
108 try expect(buf[2][0]);
109 try expect(buf[4][0]);
110}
111
112test "memset with large array element, runtime known" {
113 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
114 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
115 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
116 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
117 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
118
119 const A = [128]u64;
120 var buf: [5]A = undefined;
121 var runtime_known_element = [_]u64{0} ** 128;
122 @memset(&buf, runtime_known_element);
123 for (buf[0]) |elem| try expect(elem == 0);
124 for (buf[1]) |elem| try expect(elem == 0);
125 for (buf[2]) |elem| try expect(elem == 0);
126 for (buf[3]) |elem| try expect(elem == 0);
127 for (buf[4]) |elem| try expect(elem == 0);
128}
129
130test "memset with large array element, comptime known" {
131 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
132 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
133 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
134 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
135 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
136
137 const A = [128]u64;
138 var buf: [5]A = undefined;
139 const comptime_known_element = [_]u64{0} ** 128;
140 @memset(&buf, comptime_known_element);
141 for (buf[0]) |elem| try expect(elem == 0);
142 for (buf[1]) |elem| try expect(elem == 0);
143 for (buf[2]) |elem| try expect(elem == 0);
144 for (buf[3]) |elem| try expect(elem == 0);
145 for (buf[4]) |elem| try expect(elem == 0);
146}