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 {...@@ -29,8 +29,8 @@ inline fn limb_set(x: []u32, i: usize, v: u32) void {
2929
30// Uses Knuth's Algorithm D, 4.3.1, p. 272.30// Uses Knuth's Algorithm D, 4.3.1, p. 272.
31fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {31fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
32 if (q) |q_| std.mem.set(u32, q_[0..], 0);32 if (q) |q_| @memset(q_[0..], 0);
33 if (r) |r_| std.mem.set(u32, r_[0..], 0);33 if (r) |r_| @memset(r_[0..], 0);
3434
35 if (u.len == 0 or v.len == 0) return error.DivisionByZero;35 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 {...@@ -44,7 +44,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
44 }44 }
4545
46 if (n > m) {46 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);
48 return;48 return;
49 }49 }
5050
lib/std/Build.zig+2-2
...@@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u...@@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u
1693 u8,1693 u8,
1694 name.len + if (value) |value_slice| value_slice.len + 1 else 0,1694 name.len + if (value) |value_slice| value_slice.len + 1 else 0,
1695 ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable;1695 ) 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);
1697 if (value) |value_slice| {1697 if (value) |value_slice| {
1698 macro[name.len] = '=';1698 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);
1700 }1700 }
1701 return macro;1701 return macro;
1702}1702}
lib/std/Build/Cache.zig+1-1
...@@ -388,7 +388,7 @@ pub const Manifest = struct {...@@ -388,7 +388,7 @@ pub const Manifest = struct {
388 self.hash.hasher = hasher_init;388 self.hash.hasher = hasher_init;
389 self.hash.hasher.update(&bin_digest);389 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);
392 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;392 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
393393
394 if (self.files.items.len == 0) {394 if (self.files.items.len == 0) {
lib/std/Build/CompileStep.zig+1-1
...@@ -1139,7 +1139,7 @@ fn appendModuleArgs(...@@ -1139,7 +1139,7 @@ fn appendModuleArgs(
1139 // We'll use this buffer to store the name we decide on1139 // We'll use this buffer to store the name we decide on
1140 var buf = try b.allocator.alloc(u8, dep.name.len + 32);1140 var buf = try b.allocator.alloc(u8, dep.name.len + 32);
1141 // First, try just the exposed dependency name1141 // First, try just the exposed dependency name
1142 std.mem.copy(u8, buf, dep.name);1142 @memcpy(buf[0..dep.name.len], dep.name);
1143 var name = buf[0..dep.name.len];1143 var name = buf[0..dep.name.len];
1144 var n: usize = 0;1144 var n: usize = 0;
1145 while (names.contains(name)) {1145 while (names.contains(name)) {
lib/std/Build/RunStep.zig+16-3
...@@ -822,9 +822,19 @@ fn runCommand(...@@ -822,9 +822,19 @@ fn runCommand(
822 },822 },
823 },823 },
824 .zig_test => {824 .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 };
825 const expected_term: std.process.Child.Term = .{ .Exited = 0 };834 const expected_term: std.process.Child.Term = .{ .Exited = 0 };
826 if (!termMatches(expected_term, result.term)) {835 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,
828 fmtTerm(result.term),838 fmtTerm(result.term),
829 fmtTerm(expected_term),839 fmtTerm(expected_term),
830 try Step.allocPrintCmd(arena, self.cwd, final_argv),840 try Step.allocPrintCmd(arena, self.cwd, final_argv),
...@@ -832,8 +842,8 @@ fn runCommand(...@@ -832,8 +842,8 @@ fn runCommand(
832 }842 }
833 if (!result.stdio.test_results.isSuccess()) {843 if (!result.stdio.test_results.isSuccess()) {
834 return step.fail(844 return step.fail(
835 "the following test command failed:\n{s}",845 "{s}the following test command failed:\n{s}",
836 .{try Step.allocPrintCmd(arena, self.cwd, final_argv)},846 .{ prefix, try Step.allocPrintCmd(arena, self.cwd, final_argv) },
837 );847 );
838 }848 }
839 },849 },
...@@ -922,6 +932,7 @@ const StdIoResult = struct {...@@ -922,6 +932,7 @@ const StdIoResult = struct {
922 stdout_null: bool,932 stdout_null: bool,
923 stderr_null: bool,933 stderr_null: bool,
924 test_results: Step.TestResults,934 test_results: Step.TestResults,
935 test_metadata: ?TestMetadata,
925};936};
926937
927fn evalZigTest(938fn evalZigTest(
...@@ -1057,6 +1068,7 @@ fn evalZigTest(...@@ -1057,6 +1068,7 @@ fn evalZigTest(
1057 .skip_count = skip_count,1068 .skip_count = skip_count,
1058 .leak_count = leak_count,1069 .leak_count = leak_count,
1059 },1070 },
1071 .test_metadata = metadata,
1060 };1072 };
1061}1073}
10621074
...@@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {...@@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
1172 .stdout_null = stdout_null,1184 .stdout_null = stdout_null,
1173 .stderr_null = stderr_null,1185 .stderr_null = stderr_null,
1174 .test_results = .{},1186 .test_results = .{},
1187 .test_metadata = null,
1175 };1188 };
1176}1189}
11771190
lib/std/Progress.zig+1-1
...@@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any...@@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
374 self.columns_written += self.output_buffer.len - end.*;374 self.columns_written += self.output_buffer.len - end.*;
375 end.* = self.output_buffer.len;375 end.* = self.output_buffer.len;
376 const suffix = "... ";376 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);
378 },378 },
379 }379 }
380}380}
lib/std/Thread.zig+1-1
...@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
5656
57 const name_with_terminator = blk: {57 const name_with_terminator = blk: {
58 var name_buf: [max_name_len:0]u8 = undefined;58 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);
60 name_buf[name.len] = 0;60 name_buf[name.len] = 0;
61 break :blk name_buf[0..name.len :0];61 break :blk name_buf[0..name.len :0];
62 };62 };
lib/std/array_hash_map.zig+3-3
...@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(...@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(
578 self.entries.len = 0;578 self.entries.len = 0;
579 if (self.index_header) |header| {579 if (self.index_header) |header| {
580 switch (header.capacityIndexType()) {580 switch (header.capacityIndexType()) {
581 .u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),581 .u8 => @memset(header.indexes(u8), Index(u8).empty),
582 .u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),582 .u16 => @memset(header.indexes(u16), Index(u16).empty),
583 .u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),583 .u32 => @memset(header.indexes(u32), Index(u32).empty),
584 }584 }
585 }585 }
586 }586 }
lib/std/array_list.zig+28-20
...@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
120 }120 }
121121
122 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);122 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);
124 @memset(self.items, undefined);124 @memset(self.items, undefined);
125 self.clearAndFree();125 self.clearAndFree();
126 return new_memory;126 return new_memory;
...@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
170 self.items.len += items.len;170 self.items.len += items.len;
171171
172 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);172 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);
174 }174 }
175175
176 /// Replace range of elements `list[start..start+len]` with `new_items`.176 /// 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 {...@@ -182,15 +182,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
182 const range = self.items[start..after_range];182 const range = self.items[start..after_range];
183183
184 if (range.len == new_items.len)184 if (range.len == new_items.len)
185 mem.copy(T, range, new_items)185 @memcpy(range[0..new_items.len], new_items)
186 else if (range.len < new_items.len) {186 else if (range.len < new_items.len) {
187 const first = new_items[0..range.len];187 const first = new_items[0..range.len];
188 const rest = new_items[range.len..];188 const rest = new_items[range.len..];
189189
190 mem.copy(T, range, first);190 @memcpy(range[0..first.len], first);
191 try self.insertSlice(after_range, rest);191 try self.insertSlice(after_range, rest);
192 } else {192 } else {
193 mem.copy(T, range, new_items);193 @memcpy(range[0..new_items.len], new_items);
194 const after_subrange = start + new_items.len;194 const after_subrange = start + new_items.len;
195195
196 for (self.items[after_range..], 0..) |item, i| {196 for (self.items[after_range..], 0..) |item, i| {
...@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
260 const new_len = old_len + items.len;260 const new_len = old_len + items.len;
261 assert(new_len <= self.capacity);261 assert(new_len <= self.capacity);
262 self.items.len = new_len;262 self.items.len = new_len;
263 mem.copy(T, self.items[old_len..], items);263 @memcpy(self.items[old_len..][0..items.len], items);
264 }264 }
265265
266 /// Append an unaligned slice of items to the list. Allocates more266 /// 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 {...@@ -306,18 +306,22 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
306 /// Append a value to the list `n` times.306 /// Append a value to the list `n` times.
307 /// Allocates more memory as necessary.307 /// Allocates more memory as necessary.
308 /// Invalidates pointers if additional memory is needed.308 /// 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 {
310 const old_len = self.items.len;312 const old_len = self.items.len;
311 try self.resize(self.items.len + n);313 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);
313 }315 }
314316
315 /// Append a value to the list `n` times.317 /// Append a value to the list `n` times.
316 /// Asserts the capacity is enough. **Does not** invalidate pointers.318 /// 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 {
318 const new_len = self.items.len + n;322 const new_len = self.items.len + n;
319 assert(new_len <= self.capacity);323 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);
321 self.items.len = new_len;325 self.items.len = new_len;
322 }326 }
323327
...@@ -397,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -397,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
397 self.capacity = new_capacity;401 self.capacity = new_capacity;
398 } else {402 } else {
399 const new_memory = try self.allocator.alignedAlloc(T, alignment, new_capacity);403 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);
401 self.allocator.free(old_memory);405 self.allocator.free(old_memory);
402 self.items.ptr = new_memory.ptr;406 self.items.ptr = new_memory.ptr;
403 self.capacity = new_memory.len;407 self.capacity = new_memory.len;
...@@ -596,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -596,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
596 }600 }
597601
598 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);602 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);
600 @memset(self.items, undefined);604 @memset(self.items, undefined);
601 self.clearAndFree(allocator);605 self.clearAndFree(allocator);
602 return new_memory;606 return new_memory;
...@@ -647,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -647,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
647 self.items.len += items.len;651 self.items.len += items.len;
648652
649 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);653 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);
651 }655 }
652656
653 /// Replace range of elements `list[start..start+len]` with `new_items`657 /// 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...@@ -716,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
716 const new_len = old_len + items.len;720 const new_len = old_len + items.len;
717 assert(new_len <= self.capacity);721 assert(new_len <= self.capacity);
718 self.items.len = new_len;722 self.items.len = new_len;
719 mem.copy(T, self.items[old_len..], items);723 @memcpy(self.items[old_len..][0..items.len], items);
720 }724 }
721725
722 /// Append the slice of items to the list. Allocates more726 /// Append the slice of items to the list. Allocates more
...@@ -766,19 +770,23 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -766,19 +770,23 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
766 /// Append a value to the list `n` times.770 /// Append a value to the list `n` times.
767 /// Allocates more memory as necessary.771 /// Allocates more memory as necessary.
768 /// Invalidates pointers if additional memory is needed.772 /// 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 {
770 const old_len = self.items.len;776 const old_len = self.items.len;
771 try self.resize(allocator, self.items.len + n);777 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);
773 }779 }
774780
775 /// Append a value to the list `n` times.781 /// Append a value to the list `n` times.
776 /// **Does not** invalidate pointers.782 /// **Does not** invalidate pointers.
777 /// Asserts the capacity is enough.783 /// 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 {
779 const new_len = self.items.len + n;787 const new_len = self.items.len + n;
780 assert(new_len <= self.capacity);788 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);
782 self.items.len = new_len;790 self.items.len = new_len;
783 }791 }
784792
...@@ -815,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -815,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
815 },823 },
816 };824 };
817825
818 mem.copy(T, new_memory, self.items[0..new_len]);826 @memcpy(new_memory, self.items[0..new_len]);
819 allocator.free(old_memory);827 allocator.free(old_memory);
820 self.items = new_memory;828 self.items = new_memory;
821 self.capacity = new_memory.len;829 self.capacity = new_memory.len;
...@@ -877,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -877,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
877 self.capacity = new_capacity;885 self.capacity = new_capacity;
878 } else {886 } else {
879 const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity);887 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);
881 allocator.free(old_memory);889 allocator.free(old_memory);
882 self.items.ptr = new_memory.ptr;890 self.items.ptr = new_memory.ptr;
883 self.capacity = new_memory.len;891 self.capacity = new_memory.len;
lib/std/base64.zig+2-2
...@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {...@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {
309 const input = "foo";309 const input = "foo";
310310
311 var expect: [128]u8 = undefined;311 var expect: [128]u8 = undefined;
312 std.mem.set(u8, &expect, 0);312 @memset(&expect, 0);
313 _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);313 _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);
314314
315 var got: [128]u8 = undefined;315 var got: [128]u8 = undefined;
316 std.mem.set(u8, &got, 0);316 @memset(&got, 0);
317 _ = url_safe.Encoder.encode(&got, input);317 _ = url_safe.Encoder.encode(&got, input);
318318
319 try std.testing.expectEqualSlices(u8, &expect, &got);319 try std.testing.expectEqualSlices(u8, &expect, &got);
lib/std/bit_set.zig+2-2
...@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {
738 // fill in any new masks738 // fill in any new masks
739 if (new_masks > old_masks) {739 if (new_masks > old_masks) {
740 const fill_value = std.math.boolMask(MaskInt, fill);740 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);
742 }742 }
743 }743 }
744744
...@@ -765,7 +765,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -765,7 +765,7 @@ pub const DynamicBitSetUnmanaged = struct {
765 const num_masks = numMasks(self.bit_length);765 const num_masks = numMasks(self.bit_length);
766 var copy = Self{};766 var copy = Self{};
767 try copy.resize(new_allocator, self.bit_length, false);767 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]);
769 return copy;769 return copy;
770 }770 }
771771
lib/std/bounded_array.zig+10-10
...@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(...@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(
73 /// Copy the content of an existing slice.73 /// Copy the content of an existing slice.
74 pub fn fromSlice(m: []const T) error{Overflow}!Self {74 pub fn fromSlice(m: []const T) error{Overflow}!Self {
75 var list = try init(m.len);75 var list = try init(m.len);
76 std.mem.copy(T, list.slice(), m);76 @memcpy(list.slice(), m);
77 return list;77 return list;
78 }78 }
7979
...@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(...@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(
165 try self.ensureUnusedCapacity(items.len);165 try self.ensureUnusedCapacity(items.len);
166 self.len += items.len;166 self.len += items.len;
167 mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);167 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);
169 }169 }
170170
171 /// Replace range of elements `slice[start..start+len]` with `new_items`.171 /// Replace range of elements `slice[start..start+len]` with `new_items`.
...@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(...@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(
181 var range = self.slice()[start..after_range];181 var range = self.slice()[start..after_range];
182182
183 if (range.len == new_items.len) {183 if (range.len == new_items.len) {
184 mem.copy(T, range, new_items);184 @memcpy(range[0..new_items.len], new_items);
185 } else if (range.len < new_items.len) {185 } else if (range.len < new_items.len) {
186 const first = new_items[0..range.len];186 const first = new_items[0..range.len];
187 const rest = new_items[range.len..];187 const rest = new_items[range.len..];
188 mem.copy(T, range, first);188 @memcpy(range[0..first.len], first);
189 try self.insertSlice(after_range, rest);189 try self.insertSlice(after_range, rest);
190 } else {190 } else {
191 mem.copy(T, range, new_items);191 @memcpy(range[0..new_items.len], new_items);
192 const after_subrange = start + new_items.len;192 const after_subrange = start + new_items.len;
193 for (self.constSlice()[after_range..], 0..) |item, i| {193 for (self.constSlice()[after_range..], 0..) |item, i| {
194 self.slice()[after_subrange..][i] = item;194 self.slice()[after_subrange..][i] = item;
...@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(...@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(
243 /// Append the slice of items to the slice, asserting the capacity is already243 /// Append the slice of items to the slice, asserting the capacity is already
244 /// enough to store the new items.244 /// enough to store the new items.
245 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {245 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
246 const oldlen = self.len;246 const old_len = self.len;
247 self.len += items.len;247 self.len += items.len;
248 mem.copy(T, self.slice()[oldlen..], items);248 @memcpy(self.slice()[old_len..][0..items.len], items);
249 }249 }
250250
251 /// Append a value to the slice `n` times.251 /// Append a value to the slice `n` times.
...@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(...@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(
253 pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {253 pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {
254 const old_len = self.len;254 const old_len = self.len;
255 try self.resize(old_len + n);255 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);
257 }257 }
258258
259 /// Append a value to the slice `n` times.259 /// Append a value to the slice `n` times.
...@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(...@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(
262 const old_len = self.len;262 const old_len = self.len;
263 self.len += n;263 self.len += n;
264 assert(self.len <= buffer_capacity);264 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);
266 }266 }
267267
268 pub const Writer = if (T != u8)268 pub const Writer = if (T != u8)
...@@ -329,7 +329,7 @@ test "BoundedArray" {...@@ -329,7 +329,7 @@ test "BoundedArray" {
329 try testing.expectEqual(a.popOrNull(), 0);329 try testing.expectEqual(a.popOrNull(), 0);
330 try testing.expectEqual(a.popOrNull(), null);330 try testing.expectEqual(a.popOrNull(), null);
331 var unused = a.unusedCapacitySlice();331 var unused = a.unusedCapacitySlice();
332 mem.set(u8, unused[0..8], 2);332 @memset(unused[0..8], 2);
333 unused[8] = 3;333 unused[8] = 3;
334 unused[9] = 4;334 unused[9] = 4;
335 try testing.expectEqual(unused.len, a.capacity());335 try testing.expectEqual(unused.len, a.capacity());
lib/std/buf_set.zig+1-1
...@@ -97,7 +97,7 @@ pub const BufSet = struct {...@@ -97,7 +97,7 @@ pub const BufSet = struct {
9797
98 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {98 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
99 const result = try self.hash_map.allocator.alloc(u8, value.len);99 const result = try self.hash_map.allocator.alloc(u8, value.len);
100 mem.copy(u8, result, value);100 @memcpy(result, value);
101 return result;101 return result;
102 }102 }
103};103};
lib/std/child_process.zig+3-3
...@@ -259,7 +259,7 @@ pub const ChildProcess = struct {...@@ -259,7 +259,7 @@ pub const ChildProcess = struct {
259259
260 fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {260 fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {
261 if (fifo.head > 0) {261 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]);
263 }263 }
264 const result = std.ArrayList(u8){264 const result = std.ArrayList(u8){
265 .items = fifo.buf[0..fifo.count],265 .items = fifo.buf[0..fifo.count],
...@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !...@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
1436 var i: usize = 0;1436 var i: usize = 0;
1437 while (it.next()) |pair| : (i += 1) {1437 while (it.next()) |pair| : (i += 1) {
1438 const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);1438 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.*);
1440 env_buf[pair.key_ptr.len] = '=';1440 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.*);
1442 envp_buf[i] = env_buf.ptr;1442 envp_buf[i] = env_buf.ptr;
1443 }1443 }
1444 assert(i == envp_count);1444 assert(i == envp_count);
lib/std/compress/deflate.zig+14
...@@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;...@@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;
12pub const compressor = deflate.compressor;12pub const compressor = deflate.compressor;
13pub const decompressor = inflate.decompressor;13pub 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
15test {29test {
16 _ = @import("deflate/token.zig");30 _ = @import("deflate/token.zig");
17 _ = @import("deflate/bits_utils.zig");31 _ = @import("deflate/bits_utils.zig");
lib/std/compress/deflate/compressor.zig+12-13
...@@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;...@@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;
10const deflate_const = @import("deflate_const.zig");10const deflate_const = @import("deflate_const.zig");
11const fast = @import("deflate_fast.zig");11const fast = @import("deflate_fast.zig");
12const hm_bw = @import("huffman_bit_writer.zig");12const hm_bw = @import("huffman_bit_writer.zig");
13const mu = @import("mem_utils.zig");
14const token = @import("token.zig");13const token = @import("token.zig");
1514
16pub const Compression = enum(i5) {15pub const Compression = enum(i5) {
...@@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
296 fn fillDeflate(self: *Self, b: []const u8) u32 {295 fn fillDeflate(self: *Self, b: []const u8) u32 {
297 if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {296 if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {
298 // shift the window by window_size297 // 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]);
300 self.index -= window_size;299 self.index -= window_size;
301 self.window_end -= window_size;300 self.window_end -= window_size;
302 if (self.block_start >= window_size) {301 if (self.block_start >= window_size) {
...@@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
328 }327 }
329 }328 }
330 }329 }
331 var n = mu.copy(self.window[self.window_end..], b);330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
332 self.window_end += n;331 self.window_end += n;
333 return @intCast(u32, n);332 return @intCast(u32, n);
334 }333 }
...@@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
369 b = b[b.len - window_size ..];368 b = b[b.len - window_size ..];
370 }369 }
371 // Add all to window.370 // Add all to window.
372 mem.copy(u8, self.window, b);371 @memcpy(self.window[0..b.len], b);
373 var n = b.len;372 var n = b.len;
374373
375 // Calculate 256 hashes at the time (more L1 cache hits)374 // Calculate 256 hashes at the time (more L1 cache hits)
...@@ -543,7 +542,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -543,7 +542,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
543 self.hash_offset = 1;542 self.hash_offset = 1;
544 self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);543 self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);
545 self.tokens_count = 0;544 self.tokens_count = 0;
546 mem.set(token.Token, self.tokens, 0);545 @memset(self.tokens, 0);
547 self.length = min_match_length - 1;546 self.length = min_match_length - 1;
548 self.offset = 0;547 self.offset = 0;
549 self.byte_available = false;548 self.byte_available = false;
...@@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
706 }705 }
707706
708 fn fillStore(self: *Self, b: []const u8) u32 {707 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);
710 self.window_end += n;709 self.window_end += n;
711 return @intCast(u32, n);710 return @intCast(u32, n);
712 }711 }
...@@ -841,9 +840,9 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -841,9 +840,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
841 s.hash_head = try allocator.alloc(u32, hash_size);840 s.hash_head = try allocator.alloc(u32, hash_size);
842 s.hash_prev = try allocator.alloc(u32, window_size);841 s.hash_prev = try allocator.alloc(u32, window_size);
843 s.hash_match = try allocator.alloc(u32, max_match_length - 1);842 s.hash_match = try allocator.alloc(u32, max_match_length - 1);
844 mem.set(u32, s.hash_head, 0);843 @memset(s.hash_head, 0);
845 mem.set(u32, s.hash_prev, 0);844 @memset(s.hash_prev, 0);
846 mem.set(u32, s.hash_match, 0);845 @memset(s.hash_match, 0);
847846
848 switch (options.level) {847 switch (options.level) {
849 .no_compression => {848 .no_compression => {
...@@ -936,8 +935,8 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -936,8 +935,8 @@ pub fn Compressor(comptime WriterType: anytype) type {
936 .best_compression,935 .best_compression,
937 => {936 => {
938 self.chain_head = 0;937 self.chain_head = 0;
939 mem.set(u32, self.hash_head, 0);938 @memset(self.hash_head, 0);
940 mem.set(u32, self.hash_prev, 0);939 @memset(self.hash_prev, 0);
941 self.hash_offset = 1;940 self.hash_offset = 1;
942 self.index = 0;941 self.index = 0;
943 self.window_end = 0;942 self.window_end = 0;
...@@ -1091,8 +1090,8 @@ test "bulkHash4" {...@@ -1091,8 +1090,8 @@ test "bulkHash4" {
1091 // double the test data1090 // double the test data
1092 var out = try testing.allocator.alloc(u8, x.out.len * 2);1091 var out = try testing.allocator.alloc(u8, x.out.len * 2);
1093 defer testing.allocator.free(out);1092 defer testing.allocator.free(out);
1094 mem.copy(u8, out[0..x.out.len], x.out);1093 @memcpy(out[0..x.out.len], x.out);
1095 mem.copy(u8, out[x.out.len..], x.out);1094 @memcpy(out[x.out.len..], x.out);
10961095
1097 var j: usize = 4;1096 var j: usize = 4;
1098 while (j < out.len) : (j += 1) {1097 while (j < out.len) : (j += 1) {
lib/std/compress/deflate/decompressor.zig+2-3
...@@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;...@@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;
9const bu = @import("bits_utils.zig");9const bu = @import("bits_utils.zig");
10const ddec = @import("dict_decoder.zig");10const ddec = @import("dict_decoder.zig");
11const deflate_const = @import("deflate_const.zig");11const deflate_const = @import("deflate_const.zig");
12const mu = @import("mem_utils.zig");
1312
14const max_match_offset = deflate_const.max_match_offset;13const max_match_offset = deflate_const.max_match_offset;
15const end_block_marker = deflate_const.end_block_marker;14const end_block_marker = deflate_const.end_block_marker;
...@@ -159,7 +158,7 @@ const HuffmanDecoder = struct {...@@ -159,7 +158,7 @@ const HuffmanDecoder = struct {
159 if (sanity) {158 if (sanity) {
160 // initialize to a known invalid chunk code (0) to see if we overwrite159 // initialize to a known invalid chunk code (0) to see if we overwrite
161 // this value later on160 // this value later on
162 mem.set(u16, self.links[off], 0);161 @memset(self.links[off], 0);
163 }162 }
164 try self.sub_chunks.append(off);163 try self.sub_chunks.append(off);
165 }164 }
...@@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
451 pub fn read(self: *Self, output: []u8) Error!usize {450 pub fn read(self: *Self, output: []u8) Error!usize {
452 while (true) {451 while (true) {
453 if (self.to_read.len > 0) {452 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);
455 self.to_read = self.to_read[n..];454 self.to_read = self.to_read[n..];
456 if (self.to_read.len == 0 and455 if (self.to_read.len == 0 and
457 self.err != null)456 self.err != null)
lib/std/compress/deflate/deflate_fast.zig+3-3
...@@ -237,7 +237,7 @@ pub const DeflateFast = struct {...@@ -237,7 +237,7 @@ pub const DeflateFast = struct {
237 }237 }
238 self.cur += @intCast(i32, src.len);238 self.cur += @intCast(i32, src.len);
239 self.prev_len = @intCast(u32, src.len);239 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);
241 return;241 return;
242 }242 }
243243
...@@ -566,11 +566,11 @@ test "best speed match 2/2" {...@@ -566,11 +566,11 @@ test "best speed match 2/2" {
566 for (cases) |c| {566 for (cases) |c| {
567 var previous = try testing.allocator.alloc(u8, c.previous);567 var previous = try testing.allocator.alloc(u8, c.previous);
568 defer testing.allocator.free(previous);568 defer testing.allocator.free(previous);
569 mem.set(u8, previous, 0);569 @memset(previous, 0);
570570
571 var current = try testing.allocator.alloc(u8, c.current);571 var current = try testing.allocator.alloc(u8, c.current);
572 defer testing.allocator.free(current);572 defer testing.allocator.free(current);
573 mem.set(u8, current, 0);573 @memset(current, 0);
574574
575 var e = DeflateFast{575 var e = DeflateFast{
576 .prev = previous,576 .prev = previous,
lib/std/compress/deflate/deflate_fast_test.zig+5-5
...@@ -123,13 +123,13 @@ test "best speed max match offset" {...@@ -123,13 +123,13 @@ test "best speed max match offset" {
123 var src = try testing.allocator.alloc(u8, src_len);123 var src = try testing.allocator.alloc(u8, src_len);
124 defer testing.allocator.free(src);124 defer testing.allocator.free(src);
125125
126 mem.copy(u8, src, abc);126 @memcpy(src[0..abc.len], abc);
127 if (!do_match_before) {127 if (!do_match_before) {
128 var src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));128 const src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
129 mem.copy(u8, src[src_offset..], xyz);129 @memcpy(src[src_offset..][0..xyz.len], xyz);
130 }130 }
131 var src_offset: usize = @intCast(usize, offset);131 const src_offset: usize = @intCast(usize, offset);
132 mem.copy(u8, src[src_offset..], abc);132 @memcpy(src[src_offset..][0..abc.len], abc);
133133
134 var compressed = ArrayList(u8).init(testing.allocator);134 var compressed = ArrayList(u8).init(testing.allocator);
135 defer compressed.deinit();135 defer compressed.deinit();
lib/std/compress/deflate/dict_decoder.zig+7-3
...@@ -47,7 +47,8 @@ pub const DictDecoder = struct {...@@ -47,7 +47,8 @@ pub const DictDecoder = struct {
47 self.wr_pos = 0;47 self.wr_pos = 0;
4848
49 if (dict != null) {49 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);
51 self.wr_pos = @intCast(u32, dict.?.len);52 self.wr_pos = @intCast(u32, dict.?.len);
52 }53 }
5354
...@@ -103,12 +104,15 @@ pub const DictDecoder = struct {...@@ -103,12 +104,15 @@ pub const DictDecoder = struct {
103 self.wr_pos += 1;104 self.wr_pos += 1;
104 }105 }
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`.
106 fn copy(dst: []u8, src: []const u8) u32 {110 fn copy(dst: []u8, src: []const u8) u32 {
107 if (src.len > dst.len) {111 if (src.len > dst.len) {
108 mem.copy(u8, dst, src[0..dst.len]);112 mem.copyForwards(u8, dst, src[0..dst.len]);
109 return @intCast(u32, dst.len);113 return @intCast(u32, dst.len);
110 }114 }
111 mem.copy(u8, dst, src);115 mem.copyForwards(u8, dst[0..src.len], src);
112 return @intCast(u32, src.len);116 return @intCast(u32, src.len);
113 }117 }
114118
lib/std/compress/deflate/huffman_code.zig+1-1
...@@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {...@@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {
202 // more values in the level below202 // more values in the level below
203 l.last_freq = l.next_pair_freq;203 l.last_freq = l.next_pair_freq;
204 // Take leaf counts from the lower level, except counts[level] remains the same.204 // 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]);
206 levels[l.level - 1].needed = 2;206 levels[l.level - 1].needed = 2;
207 }207 }
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 {...@@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {
75 }75 }
76 }76 }
77 const input = self.to_read.items;77 const input = self.to_read.items;
78 const n = math.min(input.len, output.len);78 const n = @min(input.len, output.len);
79 mem.copy(u8, output[0..n], input[0..n]);79 @memcpy(output[0..n], input[0..n]);
80 mem.copy(u8, input, input[n..]);80 @memcpy(input[0 .. input.len - n], input[n..]);
81 self.to_read.shrinkRetainingCapacity(input.len - n);81 self.to_read.shrinkRetainingCapacity(input.len - n);
82 return n;82 return n;
83 }83 }
lib/std/compress/lzma/decode/rangecoder.zig+1-1
...@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {...@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {
143 }143 }
144144
145 pub fn reset(self: *Self) void {145 pub fn reset(self: *Self) void {
146 mem.set(u16, &self.probs, 0x400);146 @memset(&self.probs, 0x400);
147 }147 }
148 };148 };
149}149}
lib/std/compress/lzma/vec2d.zig+2-2
...@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {...@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {
13 pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {13 pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {
14 const len = try math.mul(usize, size[0], size[1]);14 const len = try math.mul(usize, size[0], size[1]);
15 const data = try allocator.alloc(T, len);15 const data = try allocator.alloc(T, len);
16 mem.set(T, data, value);16 @memset(data, value);
17 return Self{17 return Self{
18 .data = data,18 .data = data,
19 .cols = size[1],19 .cols = size[1],
...@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {...@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {
26 }26 }
2727
28 pub fn fill(self: *Self, value: T) void {28 pub fn fill(self: *Self, value: T) void {
29 mem.set(T, self.data, value);29 @memset(self.data, value);
30 }30 }
3131
32 inline fn _get(self: Self, row: usize) ![]T {32 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 {...@@ -59,9 +59,9 @@ pub fn Decoder(comptime ReaderType: type) type {
59 while (true) {59 while (true) {
60 if (self.to_read.items.len > 0) {60 if (self.to_read.items.len > 0) {
61 const input = self.to_read.items;61 const input = self.to_read.items;
62 const n = std.math.min(input.len, output.len);62 const n = @min(input.len, output.len);
63 std.mem.copy(u8, output[0..n], input[0..n]);63 @memcpy(output[0..n], input[0..n]);
64 std.mem.copy(u8, input, input[n..]);64 std.mem.copyForwards(u8, input, input[n..]);
65 self.to_read.shrinkRetainingCapacity(input.len - n);65 self.to_read.shrinkRetainingCapacity(input.len - n);
66 if (self.to_read.items.len == 0 and self.err != null) {66 if (self.to_read.items.len == 0 and self.err != null) {
67 if (self.err.? == DecodeError.EndOfStreamWithNoError) {67 if (self.err.? == DecodeError.EndOfStreamWithNoError) {
lib/std/compress/zstandard/decode/block.zig+7-10
...@@ -293,10 +293,10 @@ pub const DecodeState = struct {...@@ -293,10 +293,10 @@ pub const DecodeState = struct {
293293
294 try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);294 try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);
295 const copy_start = write_pos + sequence.literal_length - sequence.offset;295 const copy_start = write_pos + sequence.literal_length - sequence.offset;
296 const copy_end = copy_start + sequence.match_length;296 for (
297 // NOTE: we ignore the usage message for std.mem.copy and copy with dest.ptr >= src.ptr297 dest[write_pos + sequence.literal_length ..][0..sequence.match_length],
298 // to allow repeats298 dest[copy_start..][0..sequence.match_length],
299 std.mem.copy(u8, dest[write_pos + sequence.literal_length ..], dest[copy_start..copy_end]);299 ) |*d, s| d.* = s;
300 self.written_count += sequence.match_length;300 self.written_count += sequence.match_length;
301 }301 }
302302
...@@ -311,7 +311,6 @@ pub const DecodeState = struct {...@@ -311,7 +311,6 @@ pub const DecodeState = struct {
311 try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);311 try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);
312 const copy_start = dest.write_index + dest.data.len - sequence.offset;312 const copy_start = dest.write_index + dest.data.len - sequence.offset;
313 const copy_slice = dest.sliceAt(copy_start, sequence.match_length);313 const copy_slice = dest.sliceAt(copy_start, sequence.match_length);
314 // TODO: would std.mem.copy and figuring out dest slice be better/faster?
315 for (copy_slice.first) |b| dest.writeAssumeCapacity(b);314 for (copy_slice.first) |b| dest.writeAssumeCapacity(b);
316 for (copy_slice.second) |b| dest.writeAssumeCapacity(b);315 for (copy_slice.second) |b| dest.writeAssumeCapacity(b);
317 self.written_count += sequence.match_length;316 self.written_count += sequence.match_length;
...@@ -444,9 +443,8 @@ pub const DecodeState = struct {...@@ -444,9 +443,8 @@ pub const DecodeState = struct {
444443
445 switch (self.literal_header.block_type) {444 switch (self.literal_header.block_type) {
446 .raw => {445 .raw => {
447 const literals_end = self.literal_written_count + len;446 const literal_data = self.literal_streams.one[self.literal_written_count..][0..len];
448 const literal_data = self.literal_streams.one[self.literal_written_count..literals_end];447 @memcpy(dest[0..len], literal_data);
449 std.mem.copy(u8, dest, literal_data);
450 self.literal_written_count += len;448 self.literal_written_count += len;
451 self.written_count += len;449 self.written_count += len;
452 },450 },
...@@ -615,8 +613,7 @@ pub fn decodeBlock(...@@ -615,8 +613,7 @@ pub fn decodeBlock(
615 .raw => {613 .raw => {
616 if (src.len < block_size) return error.MalformedBlockSize;614 if (src.len < block_size) return error.MalformedBlockSize;
617 if (dest[written_count..].len < block_size) return error.DestTooSmall;615 if (dest[written_count..].len < block_size) return error.DestTooSmall;
618 const data = src[0..block_size];616 @memcpy(dest[written_count..][0..block_size], src[0..block_size]);
619 std.mem.copy(u8, dest[written_count..], data);
620 consumed_count.* += block_size;617 consumed_count.* += block_size;
621 decode_state.written_count += block_size;618 decode_state.written_count += block_size;
622 return block_size;619 return block_size;
lib/std/crypto/25519/ed25519.zig+9-9
...@@ -79,8 +79,8 @@ pub const Ed25519 = struct {...@@ -79,8 +79,8 @@ pub const Ed25519 = struct {
79 const r_bytes = r.toBytes();79 const r_bytes = r.toBytes();
8080
81 var t: [64]u8 = undefined;81 var t: [64]u8 = undefined;
82 mem.copy(u8, t[0..32], &r_bytes);82 t[0..32].* = r_bytes;
83 mem.copy(u8, t[32..], &public_key.bytes);83 t[32..].* = public_key.bytes;
84 var h = Sha512.init(.{});84 var h = Sha512.init(.{});
85 h.update(&t);85 h.update(&t);
8686
...@@ -200,8 +200,8 @@ pub const Ed25519 = struct {...@@ -200,8 +200,8 @@ pub const Ed25519 = struct {
200 /// Return the raw signature (r, s) in little-endian format.200 /// Return the raw signature (r, s) in little-endian format.
201 pub fn toBytes(self: Signature) [encoded_length]u8 {201 pub fn toBytes(self: Signature) [encoded_length]u8 {
202 var bytes: [encoded_length]u8 = undefined;202 var bytes: [encoded_length]u8 = undefined;
203 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);203 bytes[0 .. encoded_length / 2].* = self.r;
204 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);204 bytes[encoded_length / 2 ..].* = self.s;
205 return bytes;205 return bytes;
206 }206 }
207207
...@@ -260,8 +260,8 @@ pub const Ed25519 = struct {...@@ -260,8 +260,8 @@ pub const Ed25519 = struct {
260 const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;260 const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;
261 const pk_bytes = pk_p.toBytes();261 const pk_bytes = pk_p.toBytes();
262 var sk_bytes: [SecretKey.encoded_length]u8 = undefined;262 var sk_bytes: [SecretKey.encoded_length]u8 = undefined;
263 mem.copy(u8, &sk_bytes, &ss);263 sk_bytes[0..ss.len].* = ss;
264 mem.copy(u8, sk_bytes[seed_length..], &pk_bytes);264 sk_bytes[seed_length..].* = pk_bytes;
265 return KeyPair{265 return KeyPair{
266 .public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,266 .public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,
267 .secret_key = try SecretKey.fromBytes(sk_bytes),267 .secret_key = try SecretKey.fromBytes(sk_bytes),
...@@ -373,7 +373,7 @@ pub const Ed25519 = struct {...@@ -373,7 +373,7 @@ pub const Ed25519 = struct {
373 var z_batch: [count]Curve.scalar.CompressedScalar = undefined;373 var z_batch: [count]Curve.scalar.CompressedScalar = undefined;
374 for (&z_batch) |*z| {374 for (&z_batch) |*z| {
375 crypto.random.bytes(z[0..16]);375 crypto.random.bytes(z[0..16]);
376 mem.set(u8, z[16..], 0);376 @memset(z[16..], 0);
377 }377 }
378378
379 var zs_sum = Curve.scalar.zero;379 var zs_sum = Curve.scalar.zero;
...@@ -444,8 +444,8 @@ pub const Ed25519 = struct {...@@ -444,8 +444,8 @@ pub const Ed25519 = struct {
444 };444 };
445445
446 var prefix: [64]u8 = undefined;446 var prefix: [64]u8 = undefined;
447 mem.copy(u8, prefix[0..32], h[32..64]);447 prefix[0..32].* = h[32..64].*;
448 mem.copy(u8, prefix[32..64], blind_h[32..64]);448 prefix[32..64].* = blind_h[32..64].*;
449449
450 const blind_secret_key = BlindSecretKey{450 const blind_secret_key = BlindSecretKey{
451 .prefix = prefix,451 .prefix = prefix,
lib/std/crypto/25519/edwards25519.zig+4-4
...@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {...@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {
306 var pcs: [count][9]Edwards25519 = undefined;306 var pcs: [count][9]Edwards25519 = undefined;
307307
308 var bpc: [9]Edwards25519 = undefined;308 var bpc: [9]Edwards25519 = undefined;
309 mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]);309 @memcpy(&bpc, basePointPc[0..bpc.len]);
310310
311 for (ps, 0..) |p, i| {311 for (ps, 0..) |p, i| {
312 if (p.is_base) {312 if (p.is_base) {
...@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {...@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {
439 var u: [n * H.digest_length]u8 = undefined;439 var u: [n * H.digest_length]u8 = undefined;
440 var i: usize = 0;440 var i: usize = 0;
441 while (i < n * H.digest_length) : (i += H.digest_length) {441 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;
443 var j: usize = 0;443 var j: usize = 0;
444 while (i > 0 and j < H.digest_length) : (j += 1) {444 while (i > 0 and j < H.digest_length) : (j += 1) {
445 u[i + j] ^= u[i + j - H.digest_length];445 u[i + j] ^= u[i + j - H.digest_length];
...@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {...@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {
455 var px: [n]Edwards25519 = undefined;455 var px: [n]Edwards25519 = undefined;
456 i = 0;456 i = 0;
457 while (i < n) : (i += 1) {457 while (i < n) : (i += 1) {
458 mem.set(u8, u_0[0 .. H.digest_length - h_l], 0);458 @memset(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]);459 u_0[H.digest_length - h_l ..][0..h_l].* = u[i * h_l ..][0..h_l].*;
460 px[i] = fromHash(u_0);460 px[i] = fromHash(u_0);
461 }461 }
462 return px;462 return px;
lib/std/crypto/25519/scalar.zig+3-3
...@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {...@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
83pub fn neg(s: CompressedScalar) CompressedScalar {83pub fn neg(s: CompressedScalar) CompressedScalar {
84 const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;84 const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;
85 var sx: [64]u8 = undefined;85 var sx: [64]u8 = undefined;
86 mem.copy(u8, sx[0..32], s[0..]);86 sx[0..32].* = s;
87 mem.set(u8, sx[32..], 0);87 @memset(sx[32..], 0);
88 var carry: u32 = 0;88 var carry: u32 = 0;
89 var i: usize = 0;89 var i: usize = 0;
90 while (i < 64) : (i += 1) {90 while (i < 64) : (i += 1) {
...@@ -593,7 +593,7 @@ const ScalarDouble = struct {...@@ -593,7 +593,7 @@ const ScalarDouble = struct {
593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
594 }594 }
595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
596 mem.set(u64, limbs[5..], 0);596 @memset(limbs[5..], 0);
597 return ScalarDouble{ .limbs = limbs };597 return ScalarDouble{ .limbs = limbs };
598 }598 }
599599
lib/std/crypto/25519/x25519.zig+7-7
...@@ -37,7 +37,7 @@ pub const X25519 = struct {...@@ -37,7 +37,7 @@ pub const X25519 = struct {
37 break :sk random_seed;37 break :sk random_seed;
38 };38 };
39 var kp: KeyPair = undefined;39 var kp: KeyPair = undefined;
40 mem.copy(u8, &kp.secret_key, sk[0..]);40 kp.secret_key = sk;
41 kp.public_key = try X25519.recoverPublicKey(sk);41 kp.public_key = try X25519.recoverPublicKey(sk);
42 return kp;42 return kp;
43 }43 }
...@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {...@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {
120 var i: usize = 0;120 var i: usize = 0;
121 while (i < 1) : (i += 1) {121 while (i < 1) : (i += 1) {
122 const output = try X25519.scalarmult(k, u);122 const output = try X25519.scalarmult(k, u);
123 mem.copy(u8, u[0..], k[0..]);123 u = k;
124 mem.copy(u8, k[0..], output[0..]);124 k = output;
125 }125 }
126126
127 try std.testing.expectEqual(k, expected_output);127 try std.testing.expectEqual(k, expected_output);
...@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {
142 var i: usize = 0;142 var i: usize = 0;
143 while (i < 1000) : (i += 1) {143 while (i < 1000) : (i += 1) {
144 const output = try X25519.scalarmult(&k, &u);144 const output = try X25519.scalarmult(&k, &u);
145 mem.copy(u8, u[0..], k[0..]);145 u = k;
146 mem.copy(u8, k[0..], output[0..]);146 k = output;
147 }147 }
148148
149 try std.testing.expectEqual(k, expected_output);149 try std.testing.expectEqual(k, expected_output);
...@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
163 var i: usize = 0;163 var i: usize = 0;
164 while (i < 1000000) : (i += 1) {164 while (i < 1000000) : (i += 1) {
165 const output = try X25519.scalarmult(&k, &u);165 const output = try X25519.scalarmult(&k, &u);
166 mem.copy(u8, u[0..], k[0..]);166 u = k;
167 mem.copy(u8, k[0..], output[0..]);167 k = output;
168 }168 }
169169
170 try std.testing.expectEqual(k[0..], expected_output);170 try std.testing.expectEqual(k[0..], expected_output);
lib/std/crypto/Certificate.zig+7-7
...@@ -928,7 +928,7 @@ pub const rsa = struct {...@@ -928,7 +928,7 @@ pub const rsa = struct {
928 pub const PSSSignature = struct {928 pub const PSSSignature = struct {
929 pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {929 pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {
930 var result = [1]u8{0} ** modulus_len;930 var result = [1]u8{0} ** modulus_len;
931 std.mem.copy(u8, &result, msg);931 std.mem.copyForwards(u8, &result, msg);
932 return result;932 return result;
933 }933 }
934934
...@@ -1025,9 +1025,9 @@ pub const rsa = struct {...@@ -1025,9 +1025,9 @@ pub const rsa = struct {
1025 // initial zero octets.1025 // initial zero octets.
1026 var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);1026 var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);
1027 defer allocator.free(m_p);1027 defer allocator.free(m_p);
1028 std.mem.copy(u8, m_p, &([_]u8{0} ** 8));1028 std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8));
1029 std.mem.copy(u8, m_p[8..], &mHash);1029 std.mem.copyForwards(u8, m_p[8..], &mHash);
1030 std.mem.copy(u8, m_p[(8 + Hash.digest_length)..], salt);1030 std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
10311031
1032 // 13. Let H' = Hash(M'), an octet string of length hLen.1032 // 13. Let H' = Hash(M'), an octet string of length hLen.
1033 var h_p: [Hash.digest_length]u8 = undefined;1033 var h_p: [Hash.digest_length]u8 = undefined;
...@@ -1047,7 +1047,7 @@ pub const rsa = struct {...@@ -1047,7 +1047,7 @@ pub const rsa = struct {
10471047
1048 var hash = try allocator.alloc(u8, seed.len + c.len);1048 var hash = try allocator.alloc(u8, seed.len + c.len);
1049 defer allocator.free(hash);1049 defer allocator.free(hash);
1050 std.mem.copy(u8, hash, seed);1050 std.mem.copyForwards(u8, hash, seed);
1051 var hashed: [Hash.digest_length]u8 = undefined;1051 var hashed: [Hash.digest_length]u8 = undefined;
10521052
1053 while (idx < len) {1053 while (idx < len) {
...@@ -1056,10 +1056,10 @@ pub const rsa = struct {...@@ -1056,10 +1056,10 @@ pub const rsa = struct {
1056 c[2] = @intCast(u8, (counter >> 8) & 0xFF);1056 c[2] = @intCast(u8, (counter >> 8) & 0xFF);
1057 c[3] = @intCast(u8, counter & 0xFF);1057 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);
1060 Hash.hash(hash, &hashed, .{});1060 Hash.hash(hash, &hashed, .{});
10611061
1062 std.mem.copy(u8, out[idx..], &hashed);1062 std.mem.copyForwards(u8, out[idx..], &hashed);
1063 idx += hashed.len;1063 idx += hashed.len;
10641064
1065 counter += 1;1065 counter += 1;
lib/std/crypto/aegis.zig+25-25
...@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
152 state.absorb(ad[i..][0..32]);152 state.absorb(ad[i..][0..32]);
153 }153 }
154 if (ad.len % 32 != 0) {154 if (ad.len % 32 != 0) {
155 mem.set(u8, src[0..], 0);155 @memset(src[0..], 0);
156 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);156 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
157 state.absorb(&src);157 state.absorb(&src);
158 }158 }
159 i = 0;159 i = 0;
...@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
161 state.enc(c[i..][0..32], m[i..][0..32]);161 state.enc(c[i..][0..32], m[i..][0..32]);
162 }162 }
163 if (m.len % 32 != 0) {163 if (m.len % 32 != 0) {
164 mem.set(u8, src[0..], 0);164 @memset(src[0..], 0);
165 mem.copy(u8, src[0 .. m.len % 32], m[i .. i + m.len % 32]);165 @memcpy(src[0 .. m.len % 32], m[i..][0 .. m.len % 32]);
166 state.enc(&dst, &src);166 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]);
168 }168 }
169 tag.* = state.mac(tag_bits, ad.len, m.len);169 tag.* = state.mac(tag_bits, ad.len, m.len);
170 }170 }
...@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
185 state.absorb(ad[i..][0..32]);185 state.absorb(ad[i..][0..32]);
186 }186 }
187 if (ad.len % 32 != 0) {187 if (ad.len % 32 != 0) {
188 mem.set(u8, src[0..], 0);188 @memset(src[0..], 0);
189 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);189 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
190 state.absorb(&src);190 state.absorb(&src);
191 }191 }
192 i = 0;192 i = 0;
...@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
194 state.dec(m[i..][0..32], c[i..][0..32]);194 state.dec(m[i..][0..32], c[i..][0..32]);
195 }195 }
196 if (m.len % 32 != 0) {196 if (m.len % 32 != 0) {
197 mem.set(u8, src[0..], 0);197 @memset(src[0..], 0);
198 mem.copy(u8, src[0 .. m.len % 32], c[i .. i + m.len % 32]);198 @memcpy(src[0 .. m.len % 32], c[i..][0 .. m.len % 32]);
199 state.dec(&dst, &src);199 state.dec(&dst, &src);
200 mem.copy(u8, m[i .. i + m.len % 32], dst[0 .. m.len % 32]);200 @memcpy(m[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
201 mem.set(u8, dst[0 .. m.len % 32], 0);201 @memset(dst[0 .. m.len % 32], 0);
202 const blocks = &state.blocks;202 const blocks = &state.blocks;
203 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));203 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));
204 blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));204 blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));
...@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
334 state.enc(&dst, ad[i..][0..16]);334 state.enc(&dst, ad[i..][0..16]);
335 }335 }
336 if (ad.len % 16 != 0) {336 if (ad.len % 16 != 0) {
337 mem.set(u8, src[0..], 0);337 @memset(src[0..], 0);
338 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);338 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
339 state.enc(&dst, &src);339 state.enc(&dst, &src);
340 }340 }
341 i = 0;341 i = 0;
...@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
343 state.enc(c[i..][0..16], m[i..][0..16]);343 state.enc(c[i..][0..16], m[i..][0..16]);
344 }344 }
345 if (m.len % 16 != 0) {345 if (m.len % 16 != 0) {
346 mem.set(u8, src[0..], 0);346 @memset(src[0..], 0);
347 mem.copy(u8, src[0 .. m.len % 16], m[i .. i + m.len % 16]);347 @memcpy(src[0 .. m.len % 16], m[i..][0 .. m.len % 16]);
348 state.enc(&dst, &src);348 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]);
350 }350 }
351 tag.* = state.mac(tag_bits, ad.len, m.len);351 tag.* = state.mac(tag_bits, ad.len, m.len);
352 }352 }
...@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
367 state.enc(&dst, ad[i..][0..16]);367 state.enc(&dst, ad[i..][0..16]);
368 }368 }
369 if (ad.len % 16 != 0) {369 if (ad.len % 16 != 0) {
370 mem.set(u8, src[0..], 0);370 @memset(src[0..], 0);
371 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);371 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
372 state.enc(&dst, &src);372 state.enc(&dst, &src);
373 }373 }
374 i = 0;374 i = 0;
...@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
376 state.dec(m[i..][0..16], c[i..][0..16]);376 state.dec(m[i..][0..16], c[i..][0..16]);
377 }377 }
378 if (m.len % 16 != 0) {378 if (m.len % 16 != 0) {
379 mem.set(u8, src[0..], 0);379 @memset(src[0..], 0);
380 mem.copy(u8, src[0 .. m.len % 16], c[i .. i + m.len % 16]);380 @memcpy(src[0 .. m.len % 16], c[i..][0 .. m.len % 16]);
381 state.dec(&dst, &src);381 state.dec(&dst, &src);
382 mem.copy(u8, m[i .. i + m.len % 16], dst[0 .. m.len % 16]);382 @memcpy(m[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
383 mem.set(u8, dst[0 .. m.len % 16], 0);383 @memset(dst[0 .. m.len % 16], 0);
384 const blocks = &state.blocks;384 const blocks = &state.blocks;
385 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));385 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));
386 }386 }
...@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {...@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {
457 self.msg_len += b.len;457 self.msg_len += b.len;
458458
459 const len_partial = @min(b.len, block_length - self.off);459 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]);
461 self.off += len_partial;461 self.off += len_partial;
462 if (self.off < block_length) {462 if (self.off < block_length) {
463 return;463 return;
...@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {...@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {
470 self.state.absorb(b[i..][0..block_length]);470 self.state.absorb(b[i..][0..block_length]);
471 }471 }
472 if (i != b.len) {472 if (i != b.len) {
473 mem.copy(u8, self.buf[0..], b[i..]);473 @memcpy(self.buf[0..], b[i..]);
474 self.off = b.len - i;474 self.off = b.len - i;
475 }475 }
476 }476 }
...@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {...@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {
479 pub fn final(self: *Self, out: *[mac_length]u8) void {479 pub fn final(self: *Self, out: *[mac_length]u8) void {
480 if (self.off > 0) {480 if (self.off > 0) {
481 var pad = [_]u8{0} ** block_length;481 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]);
483 self.state.absorb(&pad);483 self.state.absorb(&pad);
484 }484 }
485 out.* = self.state.mac(T.tag_length * 8, self.msg_len, 0);485 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 {...@@ -31,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
3131
32 var t: [16]u8 = undefined;32 var t: [16]u8 = undefined;
33 var j: [16]u8 = undefined;33 var j: [16]u8 = undefined;
34 mem.copy(u8, j[0..nonce_length], npub[0..]);34 j[0..nonce_length].* = npub;
35 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);35 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
36 aes.encrypt(&t, &j);36 aes.encrypt(&t, &j);
3737
...@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {...@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {
6464
65 var t: [16]u8 = undefined;65 var t: [16]u8 = undefined;
66 var j: [16]u8 = undefined;66 var j: [16]u8 = undefined;
67 mem.copy(u8, j[0..nonce_length], npub[0..]);67 j[0..nonce_length].* = npub;
68 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);68 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
69 aes.encrypt(&t, &j);69 aes.encrypt(&t, &j);
7070
lib/std/crypto/aes_ocb.zig+10-10
...@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {
75 if (leftover > 0) {75 if (leftover > 0) {
76 xorWith(&offset, lx.star);76 xorWith(&offset, lx.star);
77 var padded = [_]u8{0} ** 16;77 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]);
79 padded[leftover] = 1;79 padded[leftover] = 1;
80 var e = xorBlocks(offset, padded);80 var e = xorBlocks(offset, padded);
81 aes_enc_ctx.encrypt(&e, &e);81 aes_enc_ctx.encrypt(&e, &e);
...@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {
88 var nx = [_]u8{0} ** 16;88 var nx = [_]u8{0} ** 16;
89 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);89 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);
90 nx[16 - nonce_length - 1] = 1;90 nx[16 - nonce_length - 1] = 1;
91 mem.copy(u8, nx[16 - nonce_length ..], &npub);91 nx[nx.len - nonce_length ..].* = npub;
9292
93 const bottom = @truncate(u6, nx[15]);93 const bottom = @truncate(u6, nx[15]);
94 nx[15] &= 0xc0;94 nx[15] &= 0xc0;
...@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {
132 xorWith(&offset, lt[@ctz(i + 1 + j)]);132 xorWith(&offset, lt[@ctz(i + 1 + j)]);
133 offsets[j] = offset;133 offsets[j] = offset;
134 const p = m[(i + j) * 16 ..][0..16].*;134 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]);
136 xorWith(&sum, p);136 xorWith(&sum, p);
137 }137 }
138 aes_enc_ctx.encryptWide(wb, &es, &es);138 aes_enc_ctx.encryptWide(wb, &es, &es);
139 j = 0;139 j = 0;
140 while (j < wb) : (j += 1) {140 while (j < wb) : (j += 1) {
141 const e = es[j * 16 ..][0..16].*;141 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]);
143 }143 }
144 }144 }
145 while (i < full_blocks) : (i += 1) {145 while (i < full_blocks) : (i += 1) {
...@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {
147 const p = m[i * 16 ..][0..16].*;147 const p = m[i * 16 ..][0..16].*;
148 var e = xorBlocks(p, offset);148 var e = xorBlocks(p, offset);
149 aes_enc_ctx.encrypt(&e, &e);149 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);
151 xorWith(&sum, p);151 xorWith(&sum, p);
152 }152 }
153 const leftover = m.len % 16;153 const leftover = m.len % 16;
...@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {
159 c[i * 16 + j] = pad[j] ^ x;159 c[i * 16 + j] = pad[j] ^ x;
160 }160 }
161 var e = [_]u8{0} ** 16;161 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]);
163 e[leftover] = 0x80;163 e[leftover] = 0x80;
164 xorWith(&sum, e);164 xorWith(&sum, e);
165 }165 }
...@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {
196 xorWith(&offset, lt[@ctz(i + 1 + j)]);196 xorWith(&offset, lt[@ctz(i + 1 + j)]);
197 offsets[j] = offset;197 offsets[j] = offset;
198 const q = c[(i + j) * 16 ..][0..16].*;198 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]);
200 }200 }
201 aes_dec_ctx.decryptWide(wb, &es, &es);201 aes_dec_ctx.decryptWide(wb, &es, &es);
202 j = 0;202 j = 0;
203 while (j < wb) : (j += 1) {203 while (j < wb) : (j += 1) {
204 const p = xorBlocks(es[j * 16 ..][0..16].*, offsets[j]);204 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;
206 xorWith(&sum, p);206 xorWith(&sum, p);
207 }207 }
208 }208 }
...@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {
212 var e = xorBlocks(q, offset);212 var e = xorBlocks(q, offset);
213 aes_dec_ctx.decrypt(&e, &e);213 aes_dec_ctx.decrypt(&e, &e);
214 const p = xorBlocks(e, offset);214 const p = xorBlocks(e, offset);
215 mem.copy(u8, m[i * 16 ..][0..16], &p);215 m[i * 16 ..][0..16].* = p;
216 xorWith(&sum, p);216 xorWith(&sum, p);
217 }217 }
218 const leftover = m.len % 16;218 const leftover = m.len % 16;
...@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {
224 m[i * 16 + j] = pad[j] ^ x;224 m[i * 16 + j] = pad[j] ^ x;
225 }225 }
226 var e = [_]u8{0} ** 16;226 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]);
228 e[leftover] = 0x80;228 e[leftover] = 0x80;
229 xorWith(&sum, e);229 xorWith(&sum, e);
230 }230 }
lib/std/crypto/argon2.zig+8-8
...@@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {...@@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {
149 h.update(&outlen_bytes);149 h.update(&outlen_bytes);
150 h.update(in);150 h.update(in);
151 h.final(&out_buf);151 h.final(&out_buf);
152 mem.copy(u8, out, out_buf[0..out.len]);152 @memcpy(out, out_buf[0..out.len]);
153 return;153 return;
154 }154 }
155155
...@@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {...@@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {
158 h.update(in);158 h.update(in);
159 h.final(&out_buf);159 h.final(&out_buf);
160 var out_slice = out;160 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].*;
162 out_slice = out_slice[H.digest_length / 2 ..];162 out_slice = out_slice[H.digest_length / 2 ..];
163163
164 var in_buf: [H.digest_length]u8 = undefined;164 var in_buf: [H.digest_length]u8 = undefined;
165 while (out_slice.len > H.digest_length) {165 while (out_slice.len > H.digest_length) {
166 mem.copy(u8, &in_buf, &out_buf);166 in_buf = out_buf;
167 H.hash(&in_buf, &out_buf, .{});167 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].*;
169 out_slice = out_slice[H.digest_length / 2 ..];169 out_slice = out_slice[H.digest_length / 2 ..];
170 }170 }
171 mem.copy(u8, &in_buf, &out_buf);171 in_buf = out_buf;
172 H.hash(&in_buf, &out_buf, .{ .expected_out_bits = out_slice.len * 8 });172 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]);
174}174}
175175
176fn initBlocks(176fn initBlocks(
...@@ -494,7 +494,7 @@ pub fn kdf(...@@ -494,7 +494,7 @@ pub fn kdf(
494 if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;494 if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
495495
496 var h0 = initHash(password, salt, params, derived_key.len, mode);496 var h0 = initHash(password, salt, params, derived_key.len, mode);
497 const memory = math.max(497 const memory = @max(
498 params.m / (sync_points * params.p) * (sync_points * params.p),498 params.m / (sync_points * params.p) * (sync_points * params.p),
499 2 * sync_points * params.p,499 2 * sync_points * params.p,
500 );500 );
...@@ -877,7 +877,7 @@ test "kdf" {...@@ -877,7 +877,7 @@ test "kdf" {
877 .hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",877 .hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",
878 },878 },
879 };879 };
880 inline for (test_vectors) |v| {880 for (test_vectors) |v| {
881 var want: [24]u8 = undefined;881 var want: [24]u8 = undefined;
882 _ = try std.fmt.hexToBytes(&want, v.hash);882 _ = 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 {...@@ -34,7 +34,7 @@ pub fn State(comptime endian: builtin.Endian) type {
34 /// Initialize the state from a slice of bytes.34 /// Initialize the state from a slice of bytes.
35 pub fn init(initial_state: [block_bytes]u8) Self {35 pub fn init(initial_state: [block_bytes]u8) Self {
36 var state = Self{ .st = undefined };36 var state = Self{ .st = undefined };
37 mem.copy(u8, state.asBytes(), &initial_state);37 @memcpy(state.asBytes(), &initial_state);
38 state.endianSwap();38 state.endianSwap();
39 return state;39 return state;
40 }40 }
...@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {
87 }87 }
88 if (i < bytes.len) {88 if (i < bytes.len) {
89 var padded = [_]u8{0} ** 8;89 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..]);
91 self.st[i / 8] = mem.readInt(u64, padded[0..], endian);91 self.st[i / 8] = mem.readInt(u64, padded[0..], endian);
92 }92 }
93 }93 }
...@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {
109 }109 }
110 if (i < bytes.len) {110 if (i < bytes.len) {
111 var padded = [_]u8{0} ** 8;111 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..]);
113 self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);113 self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);
114 }114 }
115 }115 }
...@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {
123 if (i < out.len) {123 if (i < out.len) {
124 var padded = [_]u8{0} ** 8;124 var padded = [_]u8{0} ** 8;
125 mem.writeInt(u64, padded[0..], self.st[i / 8], endian);125 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]);
127 }127 }
128 }128 }
129129
...@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {
138 }138 }
139 if (i < in.len) {139 if (i < in.len) {
140 var padded = [_]u8{0} ** 8;140 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..]);
142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
143 mem.writeIntNative(u64, &padded, x);143 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]);
145 }145 }
146 }146 }
147147
148 /// Set the words storing the bytes of a given range to zero.148 /// Set the words storing the bytes of a given range to zero.
149 pub fn clear(self: *Self, from: usize, to: usize) void {149 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);
151 }151 }
152152
153 /// Clear the entire state, disabling compiler optimizations.153 /// Clear the entire state, disabling compiler optimizations.
lib/std/crypto/bcrypt.zig+3-3
...@@ -416,8 +416,8 @@ pub fn bcrypt(...@@ -416,8 +416,8 @@ pub fn bcrypt(
416) [dk_length]u8 {416) [dk_length]u8 {
417 var state = State{};417 var state = State{};
418 var password_buf: [73]u8 = undefined;418 var password_buf: [73]u8 = undefined;
419 const trimmed_len = math.min(password.len, password_buf.len - 1);419 const trimmed_len = @min(password.len, password_buf.len - 1);
420 mem.copy(u8, password_buf[0..], password[0..trimmed_len]);420 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
421 password_buf[trimmed_len] = 0;421 password_buf[trimmed_len] = 0;
422 var passwordZ = password_buf[0 .. trimmed_len + 1];422 var passwordZ = password_buf[0 .. trimmed_len + 1];
423 state.expand(salt[0..], passwordZ);423 state.expand(salt[0..], passwordZ);
...@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {...@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {
626 crypto.random.bytes(&salt);626 crypto.random.bytes(&salt);
627627
628 const hash = crypt_format.strHashInternal(password, salt, params);628 const hash = crypt_format.strHashInternal(password, salt, params);
629 mem.copy(u8, buf, &hash);629 @memcpy(buf[0..hash.len], &hash);
630630
631 return buf[0..pwhash_str_length];631 return buf[0..pwhash_str_length];
632 }632 }
lib/std/crypto/benchmark.zig+2-2
...@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c...@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
113 var i: usize = 0;113 var i: usize = 0;
114 while (i < exchange_count) : (i += 1) {114 while (i < exchange_count) : (i += 1) {
115 const out = try DhKeyExchange.scalarmult(secret, public);115 const out = try DhKeyExchange.scalarmult(secret, public);
116 mem.copy(u8, secret[0..16], out[0..16]);116 secret[0..16].* = out[0..16].*;
117 mem.copy(u8, public[0..16], out[16..32]);117 public[0..16].* = out[16..32].*;
118 mem.doNotOptimizeAway(&out);118 mem.doNotOptimizeAway(&out);
119 }119 }
120 }120 }
lib/std/crypto/blake2.zig+16-14
...@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
76 comptime debug.assert(8 <= out_bits and out_bits <= 256);76 comptime debug.assert(8 <= out_bits and out_bits <= 256);
7777
78 var d: Self = undefined;78 var d: Self = undefined;
79 mem.copy(u32, d.h[0..], iv[0..]);79 d.h = iv;
8080
81 const key_len = if (options.key) |key| key.len else 0;81 const key_len = if (options.key) |key| key.len else 0;
82 // default parameters82 // default parameters
...@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
93 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);93 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
94 }94 }
95 if (key_len > 0) {95 if (key_len > 0) {
96 mem.set(u8, d.buf[key_len..], 0);96 @memset(d.buf[key_len..], 0);
97 d.update(options.key.?);97 d.update(options.key.?);
98 d.buf_len = 64;98 d.buf_len = 64;
99 }99 }
...@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
112 // Partial buffer exists from previous update. Copy into buffer then hash.112 // Partial buffer exists from previous update. Copy into buffer then hash.
113 if (d.buf_len != 0 and d.buf_len + b.len > 64) {113 if (d.buf_len != 0 and d.buf_len + b.len > 64) {
114 off += 64 - d.buf_len;114 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]);
116 d.t += 64;116 d.t += 64;
117 d.round(d.buf[0..], false);117 d.round(d.buf[0..], false);
118 d.buf_len = 0;118 d.buf_len = 0;
...@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {
125 }125 }
126126
127 // Copy any remainder for next pass.127 // Copy any remainder for next pass.
128 mem.copy(u8, d.buf[d.buf_len..], b[off..]);128 const b_slice = b[off..];
129 d.buf_len += @intCast(u8, b[off..].len);129 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
130 d.buf_len += @intCast(u8, b_slice.len);
130 }131 }
131132
132 pub fn final(d: *Self, out: *[digest_length]u8) void {133 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);
134 d.t += d.buf_len;135 d.t += d.buf_len;
135 d.round(d.buf[0..], true);136 d.round(d.buf[0..], true);
136 for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);137 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).*;
138 }139 }
139140
140 fn round(d: *Self, b: *const [64]u8, last: bool) void {141 fn round(d: *Self, b: *const [64]u8, last: bool) void {
...@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
511 comptime debug.assert(8 <= out_bits and out_bits <= 512);512 comptime debug.assert(8 <= out_bits and out_bits <= 512);
512513
513 var d: Self = undefined;514 var d: Self = undefined;
514 mem.copy(u64, d.h[0..], iv[0..]);515 d.h = iv;
515516
516 const key_len = if (options.key) |key| key.len else 0;517 const key_len = if (options.key) |key| key.len else 0;
517 // default parameters518 // default parameters
...@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
528 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);529 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
529 }530 }
530 if (key_len > 0) {531 if (key_len > 0) {
531 mem.set(u8, d.buf[key_len..], 0);532 @memset(d.buf[key_len..], 0);
532 d.update(options.key.?);533 d.update(options.key.?);
533 d.buf_len = 128;534 d.buf_len = 128;
534 }535 }
...@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
547 // Partial buffer exists from previous update. Copy into buffer then hash.548 // Partial buffer exists from previous update. Copy into buffer then hash.
548 if (d.buf_len != 0 and d.buf_len + b.len > 128) {549 if (d.buf_len != 0 and d.buf_len + b.len > 128) {
549 off += 128 - d.buf_len;550 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]);
551 d.t += 128;552 d.t += 128;
552 d.round(d.buf[0..], false);553 d.round(d.buf[0..], false);
553 d.buf_len = 0;554 d.buf_len = 0;
...@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {
560 }561 }
561562
562 // Copy any remainder for next pass.563 // Copy any remainder for next pass.
563 mem.copy(u8, d.buf[d.buf_len..], b[off..]);564 const b_slice = b[off..];
564 d.buf_len += @intCast(u8, b[off..].len);565 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
566 d.buf_len += @intCast(u8, b_slice.len);
565 }567 }
566568
567 pub fn final(d: *Self, out: *[digest_length]u8) void {569 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);
569 d.t += d.buf_len;571 d.t += d.buf_len;
570 d.round(d.buf[0..], true);572 d.round(d.buf[0..], true);
571 for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);573 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).*;
573 }575 }
574576
575 fn round(d: *Self, b: *const [128]u8, last: bool) void {577 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 {...@@ -253,7 +253,7 @@ const Output = struct {
253 while (out_word_it.next()) |out_word| {253 while (out_word_it.next()) |out_word| {
254 var word_bytes: [4]u8 = undefined;254 var word_bytes: [4]u8 = undefined;
255 mem.writeIntLittle(u32, &word_bytes, words[word_counter]);255 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]);
257 word_counter += 1;257 word_counter += 1;
258 }258 }
259 output_block_counter += 1;259 output_block_counter += 1;
...@@ -284,7 +284,7 @@ const ChunkState = struct {...@@ -284,7 +284,7 @@ const ChunkState = struct {
284 fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {284 fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {
285 const want = BLOCK_LEN - self.block_len;285 const want = BLOCK_LEN - self.block_len;
286 const take = math.min(want, input.len);286 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]);
288 self.block_len += @truncate(u8, take);288 self.block_len += @truncate(u8, take);
289 return input[take..];289 return input[take..];
290 }290 }
...@@ -336,8 +336,8 @@ fn parentOutput(...@@ -336,8 +336,8 @@ fn parentOutput(
336 flags: u8,336 flags: u8,
337) Output {337) Output {
338 var block_words: [16]u32 align(16) = undefined;338 var block_words: [16]u32 align(16) = undefined;
339 mem.copy(u32, block_words[0..8], left_child_cv[0..]);339 block_words[0..8].* = left_child_cv;
340 mem.copy(u32, block_words[8..], right_child_cv[0..]);340 block_words[8..].* = right_child_cv;
341 return Output{341 return Output{
342 .input_chaining_value = key,342 .input_chaining_value = key,
343 .block_words = block_words,343 .block_words = block_words,
lib/std/crypto/chacha20.zig+4-4
...@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {...@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {
211211
212 var buf: [64]u8 = undefined;212 var buf: [64]u8 = undefined;
213 hashToBytes(buf[0..], x);213 hashToBytes(buf[0..], x);
214 mem.copy(u8, out[i..], buf[0 .. out.len - i]);214 @memcpy(out[i..], buf[0 .. out.len - i]);
215 }215 }
216 }216 }
217217
...@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {...@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
372372
373 var buf: [64]u8 = undefined;373 var buf: [64]u8 = undefined;
374 hashToBytes(buf[0..], x);374 hashToBytes(buf[0..], x);
375 mem.copy(u8, out[i..], buf[0 .. out.len - i]);375 @memcpy(out[i..], buf[0 .. out.len - i]);
376 }376 }
377 }377 }
378378
...@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {...@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {
413413
414fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {414fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {
415 var subnonce: [12]u8 = undefined;415 var subnonce: [12]u8 = undefined;
416 mem.set(u8, subnonce[0..4], 0);416 @memset(subnonce[0..4], 0);
417 mem.copy(u8, subnonce[4..], nonce[16..24]);417 subnonce[4..].* = nonce[16..24].*;
418 return .{418 return .{
419 .key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),419 .key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),
420 .nonce = subnonce,420 .nonce = subnonce,
lib/std/crypto/ecdsa.zig+9-11
...@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
102 /// Return the raw signature (r, s) in big-endian format.102 /// Return the raw signature (r, s) in big-endian format.
103 pub fn toBytes(self: Signature) [encoded_length]u8 {103 pub fn toBytes(self: Signature) [encoded_length]u8 {
104 var bytes: [encoded_length]u8 = undefined;104 var bytes: [encoded_length]u8 = undefined;
105 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);105 @memcpy(bytes[0 .. encoded_length / 2], &self.r);
106 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);106 @memcpy(bytes[encoded_length / 2 ..], &self.s);
107 return bytes;107 return bytes;
108 }108 }
109109
...@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
325 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {325 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
326 if (unreduced_len >= 48) {326 if (unreduced_len >= 48) {
327 var xs = [_]u8{0} ** 64;327 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..]);
329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);
330 }330 }
331 var xs = [_]u8{0} ** 48;331 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..]);
333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);
334 }334 }
335335
...@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
345 const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];345 const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];
346 const m_h = m[m.len - h.len ..];346 const m_h = m[m.len - h.len ..];
347347
348 mem.set(u8, m_v, 0x01);348 @memset(m_v, 0x01);
349 m_i.* = 0x00;349 m_i.* = 0x00;
350 if (noise) |n| mem.copy(u8, m_z, &n);350 if (noise) |n| @memcpy(m_z, &n);
351 mem.copy(u8, m_x, &secret_key);351 @memcpy(m_x, &secret_key);
352 mem.copy(u8, m_h, &h);352 @memcpy(m_h, &h);
353 Hmac.create(&k, &m, &k);353 Hmac.create(&k, &m, &k);
354 Hmac.create(m_v, m_v, &k);354 Hmac.create(m_v, m_v, &k);
355 mem.copy(u8, m_v, m_v);
356 m_i.* = 0x01;355 m_i.* = 0x01;
357 Hmac.create(&k, &m, &k);356 Hmac.create(&k, &m, &k);
358 Hmac.create(m_v, m_v, &k);357 Hmac.create(m_v, m_v, &k);
...@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
361 while (t_off < t.len) : (t_off += m_v.len) {360 while (t_off < t.len) : (t_off += m_v.len) {
362 const t_end = @min(t_off + m_v.len, t.len);361 const t_end = @min(t_off + m_v.len, t.len);
363 Hmac.create(m_v, m_v, &k);362 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]);
365 }364 }
366 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}365 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
367 mem.copy(u8, m_v, m_v);
368 m_i.* = 0x00;366 m_i.* = 0x00;
369 Hmac.create(&k, m[0 .. m_v.len + 1], &k);367 Hmac.create(&k, m[0 .. m_v.len + 1], &k);
370 Hmac.create(m_v, m_v, &k);368 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 {...@@ -63,7 +63,7 @@ pub fn Hkdf(comptime Hmac: type) type {
63 st.update(&counter);63 st.update(&counter);
64 var tmp: [prk_length]u8 = undefined;64 var tmp: [prk_length]u8 = undefined;
65 st.final(tmp[0..prk_length]);65 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]);
67 }67 }
68 }68 }
69 };69 };
lib/std/crypto/hmac.zig+4-4
...@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {...@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {
38 // Normalize key length to block size of hash38 // Normalize key length to block size of hash
39 if (key.len > Hash.block_length) {39 if (key.len > Hash.block_length) {
40 Hash.hash(key, scratch[0..mac_length], .{});40 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);
42 } else if (key.len < Hash.block_length) {42 } else if (key.len < Hash.block_length) {
43 mem.copy(u8, scratch[0..key.len], key);43 @memcpy(scratch[0..key.len], key);
44 mem.set(u8, scratch[key.len..Hash.block_length], 0);44 @memset(scratch[key.len..Hash.block_length], 0);
45 } else {45 } else {
46 mem.copy(u8, scratch[0..], key);46 @memcpy(&scratch, key);
47 }47 }
4848
49 for (&ctx.o_key_pad, 0..) |*b, i| {49 for (&ctx.o_key_pad, 0..) |*b, i| {
lib/std/crypto/isap.zig+1-1
...@@ -43,7 +43,7 @@ pub const IsapA128A = struct {...@@ -43,7 +43,7 @@ pub const IsapA128A = struct {
43 }43 }
44 } else {44 } else {
45 var padded = [_]u8{0} ** 8;45 var padded = [_]u8{0} ** 8;
46 mem.copy(u8, padded[0..left], m[i..]);46 @memcpy(padded[0..left], m[i..]);
47 padded[left] = 0x80;47 padded[left] = 0x80;
48 isap.st.addBytes(&padded);48 isap.st.addBytes(&padded);
49 isap.st.permute();49 isap.st.permute();
lib/std/crypto/keccak_p.zig+8-8
...@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {
68 }68 }
69 if (i < bytes.len) {69 if (i < bytes.len) {
70 var padded = [_]u8{0} ** @sizeOf(T);70 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..]);
72 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);72 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
73 }73 }
74 }74 }
...@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {
87 }87 }
88 if (i < bytes.len) {88 if (i < bytes.len) {
89 var padded = [_]u8{0} ** @sizeOf(T);89 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..]);
91 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);91 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
92 }92 }
93 }93 }
...@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {
101 if (i < out.len) {101 if (i < out.len) {
102 var padded = [_]u8{0} ** @sizeOf(T);102 var padded = [_]u8{0} ** @sizeOf(T);
103 mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);103 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]);
105 }105 }
106 }106 }
107107
...@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {...@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {
116 }116 }
117 if (i < in.len) {117 if (i < in.len) {
118 var padded = [_]u8{0} ** @sizeOf(T);118 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..]);
120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
121 mem.writeIntNative(T, &padded, x);121 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]);
123 }123 }
124 }124 }
125125
126 /// Set the words storing the bytes of a given range to zero.126 /// Set the words storing the bytes of a given range to zero.
127 pub fn clear(self: *Self, from: usize, to: usize) void {127 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);
129 }129 }
130130
131 /// Clear the entire state, disabling compiler optimizations.131 /// Clear the entire state, disabling compiler optimizations.
...@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti...@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
215 var bytes = bytes_;215 var bytes = bytes_;
216 if (self.offset > 0) {216 if (self.offset > 0) {
217 const left = math.min(rate - self.offset, bytes.len);217 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]);
219 self.offset += left;219 self.offset += left;
220 if (self.offset == rate) {220 if (self.offset == rate) {
221 self.offset = 0;221 self.offset = 0;
...@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti...@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
231 bytes = bytes[rate..];231 bytes = bytes[rate..];
232 }232 }
233 if (bytes.len > 0) {233 if (bytes.len > 0) {
234 mem.copy(u8, &self.buf, bytes);234 @memcpy(self.buf[0..bytes.len], bytes);
235 self.offset = bytes.len;235 self.offset = bytes.len;
236 }236 }
237 }237 }
lib/std/crypto/kyber_d00.zig+14-18
...@@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {...@@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {
323 s += InnerSk.bytes_length;323 s += InnerSk.bytes_length;
324 ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);324 ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);
325 s += InnerPk.bytes_length;325 s += InnerPk.bytes_length;
326 mem.copy(u8, &ret.hpk, buf[s .. s + h_length]);326 ret.hpk = buf[s..][0..h_length].*;
327 s += h_length;327 s += h_length;
328 mem.copy(u8, &ret.z, buf[s .. s + shared_length]);328 ret.z = buf[s..][0..shared_length].*;
329 return ret;329 return ret;
330 }330 }
331 };331 };
...@@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {...@@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {
345 break :sk random_seed;345 break :sk random_seed;
346 };346 };
347 var ret: KeyPair = undefined;347 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
350 // Generate inner key350 // Generate inner key
351 innerKeyFromSeed(351 innerKeyFromSeed(
...@@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {...@@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {
356 ret.secret_key.pk = ret.public_key.pk;356 ret.secret_key.pk = ret.public_key.pk;
357357
358 // Copy over z from seed.358 // 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
361 // Compute H(pk)361 // Compute H(pk)
362 var h = sha3.Sha3_256.init(.{});362 var h = sha3.Sha3_256.init(.{});
...@@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {...@@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {
418 fn fromBytes(buf: *const [bytes_length]u8) InnerPk {418 fn fromBytes(buf: *const [bytes_length]u8) InnerPk {
419 var ret: InnerPk = undefined;419 var ret: InnerPk = undefined;
420 ret.th = V.fromBytes(buf[0..V.bytes_length]).normalize();420 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].*;
422 ret.aT = M.uniform(ret.rho, true);422 ret.aT = M.uniform(ret.rho, true);
423 return ret;423 return ret;
424 }424 }
...@@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {...@@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {
459 var h = sha3.Sha3_512.init(.{});459 var h = sha3.Sha3_512.init(.{});
460 h.update(&seed);460 h.update(&seed);
461 h.final(&expanded_seed);461 h.final(&expanded_seed);
462 mem.copy(u8, &pk.rho, expanded_seed[0..32]);462 pk.rho = expanded_seed[0..32].*;
463 const sigma = expanded_seed[32..64];463 const sigma = expanded_seed[32..64];
464 pk.aT = M.uniform(pk.rho, false); // Expand ρ to A; we'll transpose later on464 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 {...@@ -1381,7 +1381,7 @@ fn Vec(comptime K: u8) type {
1381 const cs = comptime Poly.compressedSize(d);1381 const cs = comptime Poly.compressedSize(d);
1382 var ret: [compressedSize(d)]u8 = undefined;1382 var ret: [compressedSize(d)]u8 = undefined;
1383 inline for (0..K) |i| {1383 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);
1385 }1385 }
1386 return ret;1386 return ret;
1387 }1387 }
...@@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {...@@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {
1399 fn toBytes(v: Self) [bytes_length]u8 {1399 fn toBytes(v: Self) [bytes_length]u8 {
1400 var ret: [bytes_length]u8 = undefined;1400 var ret: [bytes_length]u8 = undefined;
1401 inline for (0..K) |i| {1401 inline for (0..K) |i| {
1402 mem.copy(1402 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length].* = v.ps[i].toBytes();
1403 u8,
1404 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length],
1405 &v.ps[i].toBytes(),
1406 );
1407 }1403 }
1408 return ret;1404 return ret;
1409 }1405 }
...@@ -1479,7 +1475,7 @@ test "MulHat" {...@@ -1479,7 +1475,7 @@ test "MulHat" {
1479 const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();1475 const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();
1480 var p: Poly = undefined;1476 var p: Poly = undefined;
14811477
1482 mem.set(i16, &p.cs, 0);1478 @memset(&p.cs, 0);
14831479
1484 for (0..N) |i| {1480 for (0..N) |i| {
1485 for (0..N) |j| {1481 for (0..N) |j| {
...@@ -1742,15 +1738,15 @@ const NistDRBG = struct {...@@ -1742,15 +1738,15 @@ const NistDRBG = struct {
1742 g.incV();1738 g.incV();
1743 var block: [16]u8 = undefined;1739 var block: [16]u8 = undefined;
1744 ctx.encrypt(&block, &g.v);1740 ctx.encrypt(&block, &g.v);
1745 mem.copy(u8, buf[i * 16 .. (i + 1) * 16], &block);1741 buf[i * 16 ..][0..16].* = block;
1746 }1742 }
1747 if (pd) |p| {1743 if (pd) |p| {
1748 for (&buf, p) |*b, x| {1744 for (&buf, p) |*b, x| {
1749 b.* ^= x;1745 b.* ^= x;
1750 }1746 }
1751 }1747 }
1752 mem.copy(u8, &g.key, buf[0..32]);1748 g.key = buf[0..32].*;
1753 mem.copy(u8, &g.v, buf[32..48]);1749 g.v = buf[32..48].*;
1754 }1750 }
17551751
1756 // randombytes.1752 // randombytes.
...@@ -1763,10 +1759,10 @@ const NistDRBG = struct {...@@ -1763,10 +1759,10 @@ const NistDRBG = struct {
1763 g.incV();1759 g.incV();
1764 ctx.encrypt(&block, &g.v);1760 ctx.encrypt(&block, &g.v);
1765 if (dst.len < 16) {1761 if (dst.len < 16) {
1766 mem.copy(u8, dst, block[0..dst.len]);1762 @memcpy(dst, block[0..dst.len]);
1767 break;1763 break;
1768 }1764 }
1769 mem.copy(u8, dst, &block);1765 dst[0..block.len].* = block;
1770 dst = dst[16..dst.len];1766 dst = dst[16..dst.len];
1771 }1767 }
1772 g.update(null);1768 g.update(null);
lib/std/crypto/md5.zig+6-5
...@@ -66,7 +66,7 @@ pub const Md5 = struct {...@@ -66,7 +66,7 @@ pub const Md5 = struct {
66 // Partial buffer exists from previous update. Copy into buffer then hash.66 // Partial buffer exists from previous update. Copy into buffer then hash.
67 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {67 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
68 off += 64 - d.buf_len;68 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
71 d.round(&d.buf);71 d.round(&d.buf);
72 d.buf_len = 0;72 d.buf_len = 0;
...@@ -78,8 +78,9 @@ pub const Md5 = struct {...@@ -78,8 +78,9 @@ pub const Md5 = struct {
78 }78 }
7979
80 // Copy any remainder for next pass.80 // Copy any remainder for next pass.
81 mem.copy(u8, d.buf[d.buf_len..], b[off..]);81 const b_slice = b[off..];
82 d.buf_len += @intCast(u8, b[off..].len);82 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
83 d.buf_len += @intCast(u8, b_slice.len);
8384
84 // Md5 uses the bottom 64-bits for length padding85 // Md5 uses the bottom 64-bits for length padding
85 d.total_len +%= b.len;86 d.total_len +%= b.len;
...@@ -87,7 +88,7 @@ pub const Md5 = struct {...@@ -87,7 +88,7 @@ pub const Md5 = struct {
8788
88 pub fn final(d: *Self, out: *[digest_length]u8) void {89 pub fn final(d: *Self, out: *[digest_length]u8) void {
89 // The buffer here will never be completely full.90 // 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
92 // Append padding bits.93 // Append padding bits.
93 d.buf[d.buf_len] = 0x80;94 d.buf[d.buf_len] = 0x80;
...@@ -96,7 +97,7 @@ pub const Md5 = struct {...@@ -96,7 +97,7 @@ pub const Md5 = struct {
96 // > 448 mod 512 so need to add an extra round to wrap around.97 // > 448 mod 512 so need to add an extra round to wrap around.
97 if (64 - d.buf_len < 8) {98 if (64 - d.buf_len < 8) {
98 d.round(d.buf[0..]);99 d.round(d.buf[0..]);
99 mem.set(u8, d.buf[0..], 0);100 @memset(d.buf[0..], 0);
100 }101 }
101102
102 // Append message length.103 // 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,...@@ -38,8 +38,10 @@ pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8,
38 if (i < src.len) {38 if (i < src.len) {
39 mem.writeInt(u128, &counter, counterInt, endian);39 mem.writeInt(u128, &counter, counterInt, endian);
40 var pad = [_]u8{0} ** block_length;40 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);
42 block_cipher.xor(&pad, &pad, counter);43 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);
44 }46 }
45}47}
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...@@ -129,13 +129,13 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
129 const offset = block * h_len;129 const offset = block * h_len;
130 const block_len = if (block != blocks_count - 1) h_len else r;130 const block_len = if (block != blocks_count - 1) h_len else r;
131 const dk_block: []u8 = dk[offset..][0..block_len];131 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
134 var i: u32 = 1;134 var i: u32 = 1;
135 while (i < rounds) : (i += 1) {135 while (i < rounds) : (i += 1) {
136 // U_c = PRF (P, U_{c-1})136 // U_c = PRF (P, U_{c-1})
137 Prf.create(&new_block, prev_block[0..], password);137 Prf.create(&new_block, prev_block[0..], password);
138 mem.copy(u8, prev_block[0..], new_block[0..]);138 prev_block = new_block;
139139
140 // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c140 // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
141 for (dk_block, 0..) |_, j| {141 for (dk_block, 0..) |_, j| {
lib/std/crypto/pcurves/common.zig+2-2
...@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {...@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {
228 }228 }
229 if (iterations % 2 != 0) {229 if (iterations % 2 != 0) {
230 fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);230 fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);
231 mem.copy(Word, &v, &out4);231 v = out4;
232 mem.copy(Word, &f, &out2);232 f = out2;
233 }233 }
234 var v_opp: Limbs = undefined;234 var v_opp: Limbs = undefined;
235 fiat.opp(&v_opp, v);235 fiat.opp(&v_opp, v);
lib/std/crypto/pcurves/p256.zig+3-3
...@@ -105,7 +105,7 @@ pub const P256 = struct {...@@ -105,7 +105,7 @@ pub const P256 = struct {
105 var out: [33]u8 = undefined;105 var out: [33]u8 = undefined;
106 const xy = p.affineCoordinates();106 const xy = p.affineCoordinates();
107 out[0] = if (xy.y.isOdd()) 3 else 2;107 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);
109 return out;109 return out;
110 }110 }
111111
...@@ -114,8 +114,8 @@ pub const P256 = struct {...@@ -114,8 +114,8 @@ pub const P256 = struct {
114 var out: [65]u8 = undefined;114 var out: [65]u8 = undefined;
115 out[0] = 4;115 out[0] = 4;
116 const xy = p.affineCoordinates();116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));117 out[1..33].* = xy.x.toBytes(.Big);
118 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));118 out[33..65].* = xy.y.toBytes(.Big);
119 return out;119 return out;
120 }120 }
121121
lib/std/crypto/pcurves/p256/scalar.zig+5-5
...@@ -192,20 +192,20 @@ const ScalarDouble = struct {...@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193 {193 {
194 var b = [_]u8{0} ** encoded_length;194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);195 const len = @min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);196 b[0..len].* = s[0..len].*;
197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198 }198 }
199 if (s_.len >= 24) {199 if (s_.len >= 24) {
200 var b = [_]u8{0} ** encoded_length;200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);201 const len = @min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);202 b[0..len].* = s[24..][0..len].*;
203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204 }204 }
205 if (s_.len >= 48) {205 if (s_.len >= 48) {
206 var b = [_]u8{0} ** encoded_length;206 var b = [_]u8{0} ** encoded_length;
207 const len = s.len - 48;207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);208 b[0..len].* = s[48..][0..len].*;
209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210 }210 }
211 return t;211 return t;
lib/std/crypto/pcurves/p384.zig+3-3
...@@ -105,7 +105,7 @@ pub const P384 = struct {...@@ -105,7 +105,7 @@ pub const P384 = struct {
105 var out: [49]u8 = undefined;105 var out: [49]u8 = undefined;
106 const xy = p.affineCoordinates();106 const xy = p.affineCoordinates();
107 out[0] = if (xy.y.isOdd()) 3 else 2;107 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);
109 return out;109 return out;
110 }110 }
111111
...@@ -114,8 +114,8 @@ pub const P384 = struct {...@@ -114,8 +114,8 @@ pub const P384 = struct {
114 var out: [97]u8 = undefined;114 var out: [97]u8 = undefined;
115 out[0] = 4;115 out[0] = 4;
116 const xy = p.affineCoordinates();116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..49], &xy.x.toBytes(.Big));117 out[1..49].* = xy.x.toBytes(.Big);
118 mem.copy(u8, out[49..97], &xy.y.toBytes(.Big));118 out[49..97].* = xy.y.toBytes(.Big);
119 return out;119 return out;
120 }120 }
121121
lib/std/crypto/pcurves/p384/scalar.zig+4-4
...@@ -180,14 +180,14 @@ const ScalarDouble = struct {...@@ -180,14 +180,14 @@ const ScalarDouble = struct {
180 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };180 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
181 {181 {
182 var b = [_]u8{0} ** encoded_length;182 var b = [_]u8{0} ** encoded_length;
183 const len = math.min(s.len, 32);183 const len = @min(s.len, 32);
184 mem.copy(u8, b[0..len], s[0..len]);184 b[0..len].* = s[0..len].*;
185 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;185 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
186 }186 }
187 if (s_.len >= 32) {187 if (s_.len >= 32) {
188 var b = [_]u8{0} ** encoded_length;188 var b = [_]u8{0} ** encoded_length;
189 const len = math.min(s.len - 32, 32);189 const len = @min(s.len - 32, 32);
190 mem.copy(u8, b[0..len], s[32..][0..len]);190 b[0..len].* = s[32..][0..len].*;
191 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;191 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
192 }192 }
193 return t;193 return t;
lib/std/crypto/pcurves/secp256k1.zig+3-3
...@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {...@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {
158 var out: [33]u8 = undefined;158 var out: [33]u8 = undefined;
159 const xy = p.affineCoordinates();159 const xy = p.affineCoordinates();
160 out[0] = if (xy.y.isOdd()) 3 else 2;160 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);
162 return out;162 return out;
163 }163 }
164164
...@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {...@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {
167 var out: [65]u8 = undefined;167 var out: [65]u8 = undefined;
168 out[0] = 4;168 out[0] = 4;
169 const xy = p.affineCoordinates();169 const xy = p.affineCoordinates();
170 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));170 out[1..33].* = xy.x.toBytes(.Big);
171 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));171 out[33..65].* = xy.y.toBytes(.Big);
172 return out;172 return out;
173 }173 }
174174
lib/std/crypto/pcurves/secp256k1/scalar.zig+5-5
...@@ -192,20 +192,20 @@ const ScalarDouble = struct {...@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193 {193 {
194 var b = [_]u8{0} ** encoded_length;194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);195 const len = @min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);196 b[0..len].* = s[0..len].*;
197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198 }198 }
199 if (s_.len >= 24) {199 if (s_.len >= 24) {
200 var b = [_]u8{0} ** encoded_length;200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);201 const len = @min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);202 b[0..len].* = s[24..][0..len].*;
203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204 }204 }
205 if (s_.len >= 48) {205 if (s_.len >= 48) {
206 var b = [_]u8{0} ** encoded_length;206 var b = [_]u8{0} ** encoded_length;
207 const len = s.len - 48;207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);208 b[0..len].* = s[48..][0..len].*;
209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210 }210 }
211 return t;211 return t;
lib/std/crypto/phc_encoding.zig+1-1
...@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {...@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {
35 pub fn fromSlice(slice: []const u8) Error!Self {35 pub fn fromSlice(slice: []const u8) Error!Self {
36 if (slice.len > capacity) return Error.NoSpaceLeft;36 if (slice.len > capacity) return Error.NoSpaceLeft;
37 var bin_value: Self = undefined;37 var bin_value: Self = undefined;
38 mem.copy(u8, &bin_value.buf, slice);38 @memcpy(bin_value.buf[0..slice.len], slice);
39 bin_value.len = slice.len;39 bin_value.len = slice.len;
40 return bin_value;40 return bin_value;
41 }41 }
lib/std/crypto/salsa20.zig+6-6
...@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {...@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {
383 debug.assert(c.len == m.len);383 debug.assert(c.len == m.len);
384 const extended = extend(rounds, k, npub);384 const extended = extend(rounds, k, npub);
385 var block0 = [_]u8{0} ** 64;385 var block0 = [_]u8{0} ** 64;
386 const mlen0 = math.min(32, m.len);386 const mlen0 = @min(32, m.len);
387 mem.copy(u8, block0[32..][0..mlen0], m[0..mlen0]);387 @memcpy(block0[32..][0..mlen0], m[0..mlen0]);
388 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);388 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]);
390 Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);390 Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);
391 var mac = Poly1305.init(block0[0..32]);391 var mac = Poly1305.init(block0[0..32]);
392 mac.update(ad);392 mac.update(ad);
...@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {...@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {
405 const extended = extend(rounds, k, npub);405 const extended = extend(rounds, k, npub);
406 var block0 = [_]u8{0} ** 64;406 var block0 = [_]u8{0} ** 64;
407 const mlen0 = math.min(32, c.len);407 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]);
409 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);409 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
410 var mac = Poly1305.init(block0[0..32]);410 var mac = Poly1305.init(block0[0..32]);
411 mac.update(ad);411 mac.update(ad);
...@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {...@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {
420 utils.secureZero(u8, &computedTag);420 utils.secureZero(u8, &computedTag);
421 return error.AuthenticationFailed;421 return error.AuthenticationFailed;
422 }422 }
423 mem.copy(u8, m[0..mlen0], block0[32..][0..mlen0]);423 @memcpy(m[0..mlen0], block0[32..][0..mlen0]);
424 Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);424 Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);
425 }425 }
426};426};
...@@ -533,7 +533,7 @@ pub const SealedBox = struct {...@@ -533,7 +533,7 @@ pub const SealedBox = struct {
533 debug.assert(c.len == m.len + seal_length);533 debug.assert(c.len == m.len + seal_length);
534 var ekp = try KeyPair.create(null);534 var ekp = try KeyPair.create(null);
535 const nonce = createNonce(ekp.public_key, public_key);535 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;
537 try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);537 try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);
538 utils.secureZero(u8, ekp.secret_key[0..]);538 utils.secureZero(u8, ekp.secret_key[0..]);
539 }539 }
lib/std/crypto/scrypt.zig+3-3
...@@ -27,7 +27,7 @@ const max_salt_len = 64;...@@ -27,7 +27,7 @@ const max_salt_len = 64;
27const max_hash_len = 64;27const max_hash_len = 64;
2828
29fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {29fn 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]);
31}31}
3232
33fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {33fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
...@@ -242,7 +242,7 @@ const crypt_format = struct {...@@ -242,7 +242,7 @@ const crypt_format = struct {
242 pub fn fromSlice(slice: []const u8) EncodingError!Self {242 pub fn fromSlice(slice: []const u8) EncodingError!Self {
243 if (slice.len > capacity) return EncodingError.NoSpaceLeft;243 if (slice.len > capacity) return EncodingError.NoSpaceLeft;
244 var bin_value: Self = undefined;244 var bin_value: Self = undefined;
245 mem.copy(u8, &bin_value.buf, slice);245 @memcpy(bin_value.buf[0..slice.len], slice);
246 bin_value.len = slice.len;246 bin_value.len = slice.len;
247 return bin_value;247 return bin_value;
248 }248 }
...@@ -314,7 +314,7 @@ const crypt_format = struct {...@@ -314,7 +314,7 @@ const crypt_format = struct {
314314
315 fn serializeTo(params: anytype, out: anytype) !void {315 fn serializeTo(params: anytype, out: anytype) !void {
316 var header: [14]u8 = undefined;316 var header: [14]u8 = undefined;
317 mem.copy(u8, header[0..3], prefix);317 header[0..3].* = prefix.*;
318 Codec.intEncode(header[3..4], params.ln);318 Codec.intEncode(header[3..4], params.ln);
319 Codec.intEncode(header[4..9], params.r);319 Codec.intEncode(header[4..9], params.r);
320 Codec.intEncode(header[9..14], params.p);320 Codec.intEncode(header[9..14], params.p);
lib/std/crypto/sha1.zig+4-4
...@@ -62,7 +62,7 @@ pub const Sha1 = struct {...@@ -62,7 +62,7 @@ pub const Sha1 = struct {
62 // Partial buffer exists from previous update. Copy into buffer then hash.62 // Partial buffer exists from previous update. Copy into buffer then hash.
63 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {63 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
64 off += 64 - d.buf_len;64 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
67 d.round(d.buf[0..]);67 d.round(d.buf[0..]);
68 d.buf_len = 0;68 d.buf_len = 0;
...@@ -74,7 +74,7 @@ pub const Sha1 = struct {...@@ -74,7 +74,7 @@ pub const Sha1 = struct {
74 }74 }
7575
76 // Copy any remainder for next pass.76 // 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..]);
78 d.buf_len += @intCast(u8, b[off..].len);78 d.buf_len += @intCast(u8, b[off..].len);
7979
80 d.total_len += b.len;80 d.total_len += b.len;
...@@ -82,7 +82,7 @@ pub const Sha1 = struct {...@@ -82,7 +82,7 @@ pub const Sha1 = struct {
8282
83 pub fn final(d: *Self, out: *[digest_length]u8) void {83 pub fn final(d: *Self, out: *[digest_length]u8) void {
84 // The buffer here will never be completely full.84 // 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
87 // Append padding bits.87 // Append padding bits.
88 d.buf[d.buf_len] = 0x80;88 d.buf[d.buf_len] = 0x80;
...@@ -91,7 +91,7 @@ pub const Sha1 = struct {...@@ -91,7 +91,7 @@ pub const Sha1 = struct {
91 // > 448 mod 512 so need to add an extra round to wrap around.91 // > 448 mod 512 so need to add an extra round to wrap around.
92 if (64 - d.buf_len < 8) {92 if (64 - d.buf_len < 8) {
93 d.round(d.buf[0..]);93 d.round(d.buf[0..]);
94 mem.set(u8, d.buf[0..], 0);94 @memset(d.buf[0..], 0);
95 }95 }
9696
97 // Append message length.97 // Append message length.
lib/std/crypto/sha2.zig+10-8
...@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
118 // Partial buffer exists from previous update. Copy into buffer then hash.118 // Partial buffer exists from previous update. Copy into buffer then hash.
119 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {119 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
120 off += 64 - d.buf_len;120 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
123 d.round(&d.buf);123 d.round(&d.buf);
124 d.buf_len = 0;124 d.buf_len = 0;
...@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {
130 }130 }
131131
132 // Copy any remainder for next pass.132 // 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);
134 d.buf_len += @intCast(u8, b[off..].len);135 d.buf_len += @intCast(u8, b[off..].len);
135136
136 d.total_len += b.len;137 d.total_len += b.len;
...@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
143144
144 pub fn final(d: *Self, out: *[digest_length]u8) void {145 pub fn final(d: *Self, out: *[digest_length]u8) void {
145 // The buffer here will never be completely full.146 // 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
148 // Append padding bits.149 // Append padding bits.
149 d.buf[d.buf_len] = 0x80;150 d.buf[d.buf_len] = 0x80;
...@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
152 // > 448 mod 512 so need to add an extra round to wrap around.153 // > 448 mod 512 so need to add an extra round to wrap around.
153 if (64 - d.buf_len < 8) {154 if (64 - d.buf_len < 8) {
154 d.round(&d.buf);155 d.round(&d.buf);
155 mem.set(u8, d.buf[0..], 0);156 @memset(d.buf[0..], 0);
156 }157 }
157158
158 // Append message length.159 // Append message length.
...@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
609 // Partial buffer exists from previous update. Copy into buffer then hash.610 // Partial buffer exists from previous update. Copy into buffer then hash.
610 if (d.buf_len != 0 and d.buf_len + b.len >= 128) {611 if (d.buf_len != 0 and d.buf_len + b.len >= 128) {
611 off += 128 - d.buf_len;612 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
614 d.round(&d.buf);615 d.round(&d.buf);
615 d.buf_len = 0;616 d.buf_len = 0;
...@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {
621 }622 }
622623
623 // Copy any remainder for next pass.624 // 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);
625 d.buf_len += @intCast(u8, b[off..].len);627 d.buf_len += @intCast(u8, b[off..].len);
626628
627 d.total_len += b.len;629 d.total_len += b.len;
...@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
634636
635 pub fn final(d: *Self, out: *[digest_length]u8) void {637 pub fn final(d: *Self, out: *[digest_length]u8) void {
636 // The buffer here will never be completely full.638 // 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
639 // Append padding bits.641 // Append padding bits.
640 d.buf[d.buf_len] = 0x80;642 d.buf[d.buf_len] = 0x80;
...@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
643 // > 896 mod 1024 so need to add an extra round to wrap around.645 // > 896 mod 1024 so need to add an extra round to wrap around.
644 if (128 - d.buf_len < 16) {646 if (128 - d.buf_len < 16) {
645 d.round(d.buf[0..]);647 d.round(d.buf[0..]);
646 mem.set(u8, d.buf[0..], 0);648 @memset(d.buf[0..], 0);
647 }649 }
648650
649 // Append message length.651 // 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:...@@ -149,7 +149,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
149 const left = self.buf.len - self.offset;149 const left = self.buf.len - self.offset;
150 if (left > 0) {150 if (left > 0) {
151 const n = math.min(left, out.len);151 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]);
153 out = out[n..];153 out = out[n..];
154 self.offset += n;154 self.offset += n;
155 if (out.len == 0) {155 if (out.len == 0) {
...@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:...@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
164 }164 }
165 if (out.len > 0) {165 if (out.len > 0) {
166 self.st.squeeze(self.buf[0..]);166 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]);
168 self.offset = out.len;168 self.offset = out.len;
169 }169 }
170 }170 }
lib/std/crypto/siphash.zig+5-4
...@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round...@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
98 self.msg_len +%= @truncate(u8, b.len);98 self.msg_len +%= @truncate(u8, b.len);
9999
100 var buf = [_]u8{0} ** 8;100 var buf = [_]u8{0} ** 8;
101 mem.copy(u8, buf[0..], b[0..]);101 @memcpy(buf[0..b.len], b);
102 buf[7] = self.msg_len;102 buf[7] = self.msg_len;
103 self.round(buf);103 self.round(buf);
104104
...@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
203203
204 if (self.buf_len != 0 and self.buf_len + b.len >= 8) {204 if (self.buf_len != 0 and self.buf_len + b.len >= 8) {
205 off += 8 - self.buf_len;205 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]);
207 self.state.update(self.buf[0..]);207 self.state.update(self.buf[0..]);
208 self.buf_len = 0;208 self.buf_len = 0;
209 }209 }
...@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
212 const aligned_len = remain_len - (remain_len % 8);212 const aligned_len = remain_len - (remain_len % 8);
213 self.state.update(b[off .. off + aligned_len]);213 self.state.update(b[off .. off + aligned_len]);
214214
215 mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);215 const b_slice = b[off + aligned_len ..];
216 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);216 @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
217 self.buf_len += @intCast(u8, b_slice.len);
217 }218 }
218219
219 pub fn peek(self: Self) [mac_length]u8 {220 pub fn peek(self: Self) [mac_length]u8 {
lib/std/crypto/tls.zig+2-2
...@@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(...@@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(
312 buf[2] = @intCast(u8, tls13.len + label.len);312 buf[2] = @intCast(u8, tls13.len + label.len);
313 buf[3..][0..tls13.len].* = tls13.*;313 buf[3..][0..tls13.len].* = tls13.*;
314 var i: usize = 3 + tls13.len;314 var i: usize = 3 + tls13.len;
315 mem.copy(u8, buf[i..], label);315 @memcpy(buf[i..][0..label.len], label);
316 i += label.len;316 i += label.len;
317 buf[i] = @intCast(u8, context.len);317 buf[i] = @intCast(u8, context.len);
318 i += 1;318 i += 1;
319 mem.copy(u8, buf[i..], context);319 @memcpy(buf[i..][0..context.len], context);
320 i += context.len;320 i += context.len;
321321
322 var result: [len]u8 = undefined;322 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...@@ -685,7 +685,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
685 .application_cipher = app_cipher,685 .application_cipher = app_cipher,
686 .partially_read_buffer = undefined,686 .partially_read_buffer = undefined,
687 };687 };
688 mem.copy(u8, &client.partially_read_buffer, leftover);688 @memcpy(client.partially_read_buffer[0..leftover.len], leftover);
689 return client;689 return client;
690 },690 },
691 else => {691 else => {
...@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(...@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(
809 .overhead_len = overhead_len,809 .overhead_len = overhead_len,
810 };810 };
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]);
813 cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);813 cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);
814 bytes_i += encrypted_content_len;814 bytes_i += encrypted_content_len;
815 const ciphertext_len = encrypted_content_len + 1;815 const ciphertext_len = encrypted_content_len + 1;
...@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1029 if (frag1.len < second_len)1029 if (frag1.len < second_len)
1030 return finishRead2(c, first, frag1, vp.total);1030 return finishRead2(c, first, frag1, vp.total);
10311031
1032 mem.copy(u8, frag[0..in], first);1032 @memcpy(frag[0..in], first);
1033 mem.copy(u8, frag[first.len..], frag1[0..second_len]);1033 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
1034 frag = frag[0..full_record_len];1034 frag = frag[0..full_record_len];
1035 frag1 = frag1[second_len..];1035 frag1 = frag1[second_len..];
1036 in = 0;1036 in = 0;
...@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1059 if (frag1.len < second_len)1059 if (frag1.len < second_len)
1060 return finishRead2(c, first, frag1, vp.total);1060 return finishRead2(c, first, frag1, vp.total);
10611061
1062 mem.copy(u8, frag[0..in], first);1062 @memcpy(frag[0..in], first);
1063 mem.copy(u8, frag[first.len..], frag1[0..second_len]);1063 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
1064 frag = frag[0..full_record_len];1064 frag = frag[0..full_record_len];
1065 frag1 = frag1[second_len..];1065 frag1 = frag1[second_len..];
1066 in = 0;1066 in = 0;
...@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1177 // We have already run out of room in iovecs. Continue1177 // We have already run out of room in iovecs. Continue
1178 // appending to `partially_read_buffer`.1178 // appending to `partially_read_buffer`.
1179 const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];1179 const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];
1180 mem.copy(u8, dest, msg);1180 @memcpy(dest[0..msg.len], msg);
1181 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);1181 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);
1182 } else {1182 } else {
1183 const amt = vp.put(msg);1183 const amt = vp.put(msg);
...@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1185 const rest = msg[amt..];1185 const rest = msg[amt..];
1186 c.partial_cleartext_idx = 0;1186 c.partial_cleartext_idx = 0;
1187 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);1187 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);
1189 }1189 }
1190 }1190 }
1191 } else {1191 } else {
...@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {...@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
1213 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {1213 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
1214 // There is cleartext at the beginning already which we need to preserve.1214 // There is cleartext at the beginning already which we need to preserve.
1215 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);1215 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);
1217 } else {1217 } else {
1218 c.partial_cleartext_idx = 0;1218 c.partial_cleartext_idx = 0;
1219 c.partial_ciphertext_idx = 0;1219 c.partial_ciphertext_idx = 0;
1220 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);1220 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);
1222 }1222 }
1223 return out;1223 return out;
1224}1224}
...@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi...@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi
1227 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {1227 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
1228 // There is cleartext at the beginning already which we need to preserve.1228 // There is cleartext at the beginning already which we need to preserve.
1229 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);1229 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);1230 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
1231 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..], frag1);1231 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
1232 } else {1232 } else {
1233 c.partial_cleartext_idx = 0;1233 c.partial_cleartext_idx = 0;
1234 c.partial_ciphertext_idx = 0;1234 c.partial_ciphertext_idx = 0;
1235 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);1235 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);
1236 mem.copy(u8, &c.partially_read_buffer, first);1236 @memcpy(c.partially_read_buffer[0..first.len], first);
1237 mem.copy(u8, c.partially_read_buffer[first.len..], frag1);1237 @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
1238 }1238 }
1239 return out;1239 return out;
1240}1240}
...@@ -1282,7 +1282,7 @@ const VecPut = struct {...@@ -1282,7 +1282,7 @@ const VecPut = struct {
1282 const v = vp.iovecs[vp.idx];1282 const v = vp.iovecs[vp.idx];
1283 const dest = v.iov_base[vp.off..v.iov_len];1283 const dest = v.iov_base[vp.off..v.iov_len];
1284 const src = bytes[bytes_i..][0..@min(dest.len, bytes.len - bytes_i)];1284 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);
1286 bytes_i += src.len;1286 bytes_i += src.len;
1287 vp.off += src.len;1287 vp.off += src.len;
1288 if (vp.off >= v.iov_len) {1288 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,...@@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
134134
135/// Sets a slice to zeroes.135/// Sets a slice to zeroes.
136/// Prevents the store from being optimized out.136/// Prevents the store from being optimized out.
137pub fn secureZero(comptime T: type, s: []T) void {137pub inline fn secureZero(comptime T: type, s: []T) void {
138 // TODO: implement `@memset` for non-byte-sized element type in the llvm backend138 @memset(@as([]volatile T, s), 0);
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);
143}139}
144140
145test "crypto.utils.timingSafeEql" {141test "crypto.utils.timingSafeEql" {
...@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {...@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
148 random.bytes(a[0..]);144 random.bytes(a[0..]);
149 random.bytes(b[0..]);145 random.bytes(b[0..]);
150 try testing.expect(!timingSafeEql([100]u8, a, b));146 try testing.expect(!timingSafeEql([100]u8, a, b));
151 mem.copy(u8, a[0..], b[0..]);147 a = b;
152 try testing.expect(timingSafeEql([100]u8, a, b));148 try testing.expect(timingSafeEql([100]u8, a, b));
153}149}
154150
...@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {...@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
201 var a = [_]u8{0xfe} ** 8;197 var a = [_]u8{0xfe} ** 8;
202 var b = [_]u8{0xfe} ** 8;198 var b = [_]u8{0xfe} ** 8;
203199
204 mem.set(u8, a[0..], 0);200 @memset(a[0..], 0);
205 secureZero(u8, b[0..]);201 secureZero(u8, b[0..]);
206202
207 try testing.expectEqualSlices(u8, a[0..], b[0..]);203 try testing.expectEqualSlices(u8, a[0..], b[0..]);
lib/std/cstr.zig+2-2
...@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {...@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {
34/// Caller owns the returned memory.34/// Caller owns the returned memory.
35pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {35pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {
36 const result = try allocator.alloc(u8, slice.len + 1);36 const result = try allocator.alloc(u8, slice.len + 1);
37 mem.copy(u8, result, slice);37 @memcpy(result[0..slice.len], slice);
38 result[slice.len] = 0;38 result[slice.len] = 0;
39 return result[0..slice.len :0];39 return result[0..slice.len :0];
40}40}
...@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {...@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {
78 for (slice) |inner| {78 for (slice) |inner| {
79 index_buf[i] = buf.ptr + write_index;79 index_buf[i] = buf.ptr + write_index;
80 i += 1;80 i += 1;
81 mem.copy(u8, buf[write_index..], inner);81 @memcpy(buf[write_index..][0..inner.len], inner);
82 write_index += inner.len;82 write_index += inner.len;
83 buf[write_index] = 0;83 buf[write_index] = 0;
84 write_index += 1;84 write_index += 1;
lib/std/debug.zig+2-2
...@@ -309,8 +309,8 @@ pub fn panicExtra(...@@ -309,8 +309,8 @@ pub fn panicExtra(
309 // error being part of the @panic stack trace (but that error should309 // error being part of the @panic stack trace (but that error should
310 // only happen rarely)310 // only happen rarely)
311 const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {311 const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {
312 std.fmt.BufPrintError.NoSpaceLeft => blk: {312 error.NoSpaceLeft => blk: {
313 std.mem.copy(u8, buf[size..], trunc_msg);313 @memcpy(buf[size..], trunc_msg);
314 break :blk &buf;314 break :blk &buf;
315 },315 },
316 };316 };
lib/std/dynamic_library.zig+1-1
...@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {...@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {
210 -1,210 -1,
211 0,211 0,
212 );212 );
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]);
214 }214 }
215 },215 },
216 else => {},216 else => {},
lib/std/enums.zig+2-2
...@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {...@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
275 .bits = Self.BitSet.initFull(),275 .bits = Self.BitSet.initFull(),
276 .values = undefined,276 .values = undefined,
277 };277 };
278 std.mem.set(V, &result.values, value);278 @memset(&result.values, value);
279 return result;279 return result;
280 }280 }
281 /// Initializes a full mapping with supplied values.281 /// Initializes a full mapping with supplied values.
...@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)...@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)
11751175
1176 pub fn initFill(v: Value) Self {1176 pub fn initFill(v: Value) Self {
1177 var self: Self = undefined;1177 var self: Self = undefined;
1178 std.mem.set(Value, &self.values, v);1178 @memset(&self.values, v);
1179 return self;1179 return self;
1180 }1180 }
11811181
lib/std/fifo.zig+12-14
...@@ -86,19 +86,17 @@ pub fn LinearFifo(...@@ -86,19 +86,17 @@ pub fn LinearFifo(
8686
87 pub fn realign(self: *Self) void {87 pub fn realign(self: *Self) void {
88 if (self.buf.len - self.head >= self.count) {88 if (self.buf.len - self.head >= self.count) {
89 // this copy overlaps89 mem.copyForwards(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
90 mem.copy(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
91 self.head = 0;90 self.head = 0;
92 } else {91 } else {
93 var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;92 var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;
9493
95 while (self.head != 0) {94 while (self.head != 0) {
96 const n = math.min(self.head, tmp.len);95 const n = @min(self.head, tmp.len);
97 const m = self.buf.len - n;96 const m = self.buf.len - n;
98 mem.copy(T, tmp[0..n], self.buf[0..n]);97 @memcpy(tmp[0..n], self.buf[0..n]);
99 // this middle copy overlaps; the others here don't98 mem.copyForwards(T, self.buf[0..m], self.buf[n..][0..m]);
100 mem.copy(T, self.buf[0..m], self.buf[n..][0..m]);99 @memcpy(self.buf[m..][0..n], tmp[0..n]);
101 mem.copy(T, self.buf[m..], tmp[0..n]);
102 self.head -= n;100 self.head -= n;
103 }101 }
104 }102 }
...@@ -223,8 +221,8 @@ pub fn LinearFifo(...@@ -223,8 +221,8 @@ pub fn LinearFifo(
223 while (dst_left.len > 0) {221 while (dst_left.len > 0) {
224 const slice = self.readableSlice(0);222 const slice = self.readableSlice(0);
225 if (slice.len == 0) break;223 if (slice.len == 0) break;
226 const n = math.min(slice.len, dst_left.len);224 const n = @min(slice.len, dst_left.len);
227 mem.copy(T, dst_left, slice[0..n]);225 @memcpy(dst_left[0..n], slice[0..n]);
228 self.discard(n);226 self.discard(n);
229 dst_left = dst_left[n..];227 dst_left = dst_left[n..];
230 }228 }
...@@ -289,8 +287,8 @@ pub fn LinearFifo(...@@ -289,8 +287,8 @@ pub fn LinearFifo(
289 while (src_left.len > 0) {287 while (src_left.len > 0) {
290 const writable_slice = self.writableSlice(0);288 const writable_slice = self.writableSlice(0);
291 assert(writable_slice.len != 0);289 assert(writable_slice.len != 0);
292 const n = math.min(writable_slice.len, src_left.len);290 const n = @min(writable_slice.len, src_left.len);
293 mem.copy(T, writable_slice, src_left[0..n]);291 @memcpy(writable_slice[0..n], src_left[0..n]);
294 self.update(n);292 self.update(n);
295 src_left = src_left[n..];293 src_left = src_left[n..];
296 }294 }
...@@ -354,11 +352,11 @@ pub fn LinearFifo(...@@ -354,11 +352,11 @@ pub fn LinearFifo(
354352
355 const slice = self.readableSliceMut(0);353 const slice = self.readableSliceMut(0);
356 if (src.len < slice.len) {354 if (src.len < slice.len) {
357 mem.copy(T, slice, src);355 @memcpy(slice[0..src.len], src);
358 } else {356 } else {
359 mem.copy(T, slice, src[0..slice.len]);357 @memcpy(slice, src[0..slice.len]);
360 const slice2 = self.readableSliceMut(slice.len);358 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..]);
362 }360 }
363 }361 }
364362
lib/std/fmt/errol.zig+2-2
...@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {...@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
84 const i = tableLowerBound(bits);84 const i = tableLowerBound(bits);
85 if (i < enum3.len and enum3[i] == bits) {85 if (i < enum3.len and enum3[i] == bits) {
86 const data = enum3_data[i];86 const data = enum3_data[i];
87 const digits = buffer[1 .. data.str.len + 1];87 const digits = buffer[1..][0..data.str.len];
88 mem.copy(u8, digits, data.str);88 @memcpy(digits, data.str);
89 return FloatDecimal{89 return FloatDecimal{
90 .digits = digits,90 .digits = digits,
91 .exp = data.exp,91 .exp = data.exp,
lib/std/fs.zig+19-15
...@@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:...@@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:
106 var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;106 var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;
107 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));107 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));
108 defer allocator.free(tmp_path);108 defer allocator.free(tmp_path);
109 mem.copy(u8, tmp_path[0..], dirname);109 @memcpy(tmp_path[0..dirname.len], dirname);
110 tmp_path[dirname.len] = path.sep;110 tmp_path[dirname.len] = path.sep;
111 while (true) {111 while (true) {
112 crypto.random.bytes(rand_buf[0..]);112 crypto.random.bytes(rand_buf[0..]);
...@@ -1541,9 +1541,9 @@ pub const Dir = struct {...@@ -1541,9 +1541,9 @@ pub const Dir = struct {
1541 return error.NameTooLong;1541 return error.NameTooLong;
1542 }1542 }
15431543
1544 mem.copy(u8, out_buffer, out_path);1544 const result = out_buffer[0..out_path.len];
15451545 @memcpy(result, out_path);
1546 return out_buffer[0..out_path.len];1546 return result;
1547 }1547 }
15481548
1549 /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.1549 /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.
...@@ -1593,9 +1593,9 @@ pub const Dir = struct {...@@ -1593,9 +1593,9 @@ pub const Dir = struct {
1593 return error.NameTooLong;1593 return error.NameTooLong;
1594 }1594 }
15951595
1596 mem.copy(u8, out_buffer, out_path);1596 const result = out_buffer[0..out_path.len];
15971597 @memcpy(result, out_path);
1598 return out_buffer[0..out_path.len];1598 return result;
1599 }1599 }
16001600
1601 /// Same as `Dir.realpath` except caller must free the returned memory.1601 /// Same as `Dir.realpath` except caller must free the returned memory.
...@@ -2346,8 +2346,9 @@ pub const Dir = struct {...@@ -2346,8 +2346,9 @@ pub const Dir = struct {
2346 if (cleanup_dir_parent) |*d| d.close();2346 if (cleanup_dir_parent) |*d| d.close();
2347 cleanup_dir_parent = iterable_dir;2347 cleanup_dir_parent = iterable_dir;
2348 iterable_dir = new_dir;2348 iterable_dir = new_dir;
2349 mem.copy(u8, &dir_name_buf, entry.name);2349 const result = dir_name_buf[0..entry.name.len];
2350 dir_name = dir_name_buf[0..entry.name.len];2350 @memcpy(result, entry.name);
2351 dir_name = result;
2351 continue :scan_dir;2352 continue :scan_dir;
2352 } else {2353 } else {
2353 if (iterable_dir.dir.deleteFile(entry.name)) {2354 if (iterable_dir.dir.deleteFile(entry.name)) {
...@@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
2974 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;2975 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2975 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);2976 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);
2976 if (real_path.len > out_buffer.len) return error.NameTooLong;2977 if (real_path.len > out_buffer.len) return error.NameTooLong;
2977 std.mem.copy(u8, out_buffer, real_path);2978 const result = out_buffer[0..real_path.len];
2978 return out_buffer[0..real_path.len];2979 @memcpy(result, real_path);
2980 return result;
2979 }2981 }
2980 switch (builtin.os.tag) {2982 switch (builtin.os.tag) {
2981 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),2983 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),
...@@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
3014 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);3016 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);
3015 if (real_path.len > out_buffer.len)3017 if (real_path.len > out_buffer.len)
3016 return error.NameTooLong;3018 return error.NameTooLong;
3017 mem.copy(u8, out_buffer, real_path);3019 const result = out_buffer[0..real_path.len];
3018 return out_buffer[0..real_path.len];3020 @memcpy(result, real_path);
3021 return result;
3019 } else if (argv0.len != 0) {3022 } else if (argv0.len != 0) {
3020 // argv[0] is not empty (and not a path): search it inside PATH3023 // argv[0] is not empty (and not a path): search it inside PATH
3021 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;3024 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;
...@@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
3032 // found a file, and hope it is the right file3035 // found a file, and hope it is the right file
3033 if (real_path.len > out_buffer.len)3036 if (real_path.len > out_buffer.len)
3034 return error.NameTooLong;3037 return error.NameTooLong;
3035 mem.copy(u8, out_buffer, real_path);3038 const result = out_buffer[0..real_path.len];
3036 return out_buffer[0..real_path.len];3039 @memcpy(result, real_path);
3040 return result;
3037 } else |_| continue;3041 } else |_| continue;
3038 }3042 }
3039 }3043 }
lib/std/fs/path.zig+6-6
...@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn...@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
79 const buf = try allocator.alloc(u8, total_len);79 const buf = try allocator.alloc(u8, total_len);
80 errdefer allocator.free(buf);80 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]);
83 var buf_index: usize = paths[first_path_index].len;83 var buf_index: usize = paths[first_path_index].len;
84 var prev_path = paths[first_path_index];84 var prev_path = paths[first_path_index];
85 assert(prev_path.len > 0);85 assert(prev_path.len > 0);
...@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn...@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
94 buf_index += 1;94 buf_index += 1;
95 }95 }
96 const adjusted_path = if (prev_sep and this_sep) this_path[1..] else this_path;96 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);
98 buf_index += adjusted_path.len;98 buf_index += adjusted_path.len;
99 prev_path = this_path;99 prev_path = this_path;
100 }100 }
...@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {...@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
631 real_result[i..][0..3].* = "..\\".*;631 real_result[i..][0..3].* = "..\\".*;
632 i += 3;632 i += 3;
633 }633 }
634 mem.copy(u8, real_result[i..], result.items);634 @memcpy(real_result[i..][0..result.items.len], result.items);
635 return real_result;635 return real_result;
636 }636 }
637}637}
...@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E...@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
710 real_result[i..][0..3].* = "../".*;710 real_result[i..][0..3].* = "../".*;
711 i += 3;711 i += 3;
712 }712 }
713 mem.copy(u8, real_result[i..], result.items);713 @memcpy(real_result[i..][0..result.items.len], result.items);
714 return real_result;714 return real_result;
715 }715 }
716}716}
...@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !...@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
1106 while (rest_it.next()) |to_component| {1106 while (rest_it.next()) |to_component| {
1107 result[result_index] = '\\';1107 result[result_index] = '\\';
1108 result_index += 1;1108 result_index += 1;
1109 mem.copy(u8, result[result_index..], to_component);1109 @memcpy(result[result_index..][0..to_component.len], to_component);
1110 result_index += to_component.len;1110 result_index += to_component.len;
1111 }1111 }
11121112
...@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]...@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
1151 return allocator.realloc(result, result_index - 1);1151 return allocator.realloc(result, result_index - 1);
1152 }1152 }
11531153
1154 mem.copy(u8, result[result_index..], to_rest);1154 @memcpy(result[result_index..][0..to_rest.len], to_rest);
1155 return result;1155 return result;
1156 }1156 }
11571157
lib/std/hash/cityhash.zig+2-2
...@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {...@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
348 var key: [256]u8 = undefined;348 var key: [256]u8 = undefined;
349 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;349 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
350350
351 std.mem.set(u8, &key, 0);351 @memset(&key, 0);
352 std.mem.set(u8, &hashes_bytes, 0);352 @memset(&hashes_bytes, 0);
353353
354 var i: u32 = 0;354 var i: u32 = 0;
355 while (i < 256) : (i += 1) {355 while (i < 256) : (i += 1) {
lib/std/hash/wyhash.zig+3-2
...@@ -147,7 +147,7 @@ pub const Wyhash = struct {...@@ -147,7 +147,7 @@ pub const Wyhash = struct {
147147
148 if (self.buf_len != 0 and self.buf_len + b.len >= 32) {148 if (self.buf_len != 0 and self.buf_len + b.len >= 32) {
149 off += 32 - self.buf_len;149 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]);
151 self.state.update(self.buf[0..]);151 self.state.update(self.buf[0..]);
152 self.buf_len = 0;152 self.buf_len = 0;
153 }153 }
...@@ -156,7 +156,8 @@ pub const Wyhash = struct {...@@ -156,7 +156,8 @@ pub const Wyhash = struct {
156 const aligned_len = remain_len - (remain_len % 32);156 const aligned_len = remain_len - (remain_len % 32);
157 self.state.update(b[off .. off + aligned_len]);157 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);
160 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);161 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
161 }162 }
162163
lib/std/hash/xxhash.zig+6-6
...@@ -36,7 +36,7 @@ pub const XxHash64 = struct {...@@ -36,7 +36,7 @@ pub const XxHash64 = struct {
3636
37 pub fn update(self: *XxHash64, input: []const u8) void {37 pub fn update(self: *XxHash64, input: []const u8) void {
38 if (input.len < 32 - self.buf_len) {38 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);
40 self.buf_len += input.len;40 self.buf_len += input.len;
41 return;41 return;
42 }42 }
...@@ -45,7 +45,7 @@ pub const XxHash64 = struct {...@@ -45,7 +45,7 @@ pub const XxHash64 = struct {
4545
46 if (self.buf_len > 0) {46 if (self.buf_len > 0) {
47 i = 32 - self.buf_len;47 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]);
49 self.processStripe(&self.buf);49 self.processStripe(&self.buf);
50 self.buf_len = 0;50 self.buf_len = 0;
51 }51 }
...@@ -55,7 +55,7 @@ pub const XxHash64 = struct {...@@ -55,7 +55,7 @@ pub const XxHash64 = struct {
55 }55 }
5656
57 const remaining_bytes = input[i..];57 const remaining_bytes = input[i..];
58 mem.copy(u8, &self.buf, remaining_bytes);58 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
59 self.buf_len = remaining_bytes.len;59 self.buf_len = remaining_bytes.len;
60 }60 }
6161
...@@ -165,7 +165,7 @@ pub const XxHash32 = struct {...@@ -165,7 +165,7 @@ pub const XxHash32 = struct {
165165
166 pub fn update(self: *XxHash32, input: []const u8) void {166 pub fn update(self: *XxHash32, input: []const u8) void {
167 if (input.len < 16 - self.buf_len) {167 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);
169 self.buf_len += input.len;169 self.buf_len += input.len;
170 return;170 return;
171 }171 }
...@@ -174,7 +174,7 @@ pub const XxHash32 = struct {...@@ -174,7 +174,7 @@ pub const XxHash32 = struct {
174174
175 if (self.buf_len > 0) {175 if (self.buf_len > 0) {
176 i = 16 - self.buf_len;176 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]);
178 self.processStripe(&self.buf);178 self.processStripe(&self.buf);
179 self.buf_len = 0;179 self.buf_len = 0;
180 }180 }
...@@ -184,7 +184,7 @@ pub const XxHash32 = struct {...@@ -184,7 +184,7 @@ pub const XxHash32 = struct {
184 }184 }
185185
186 const remaining_bytes = input[i..];186 const remaining_bytes = input[i..];
187 mem.copy(u8, &self.buf, remaining_bytes);187 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
188 self.buf_len = remaining_bytes.len;188 self.buf_len = remaining_bytes.len;
189 }189 }
190190
lib/std/heap/WasmAllocator.zig+1-1
...@@ -230,7 +230,7 @@ test "shrink" {...@@ -230,7 +230,7 @@ test "shrink" {
230 var slice = try test_ally.alloc(u8, 20);230 var slice = try test_ally.alloc(u8, 20);
231 defer test_ally.free(slice);231 defer test_ally.free(slice);
232232
233 mem.set(u8, slice, 0x11);233 @memset(slice, 0x11);
234234
235 try std.testing.expect(test_ally.resize(slice, 17));235 try std.testing.expect(test_ally.resize(slice, 17));
236 slice = slice[0..17];236 slice = slice[0..17];
lib/std/heap/WasmPageAllocator.zig+1-1
...@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {...@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {
153153
154 extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];154 extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];
155 // Since this is the first page being freed and we consume it, assume *nothing* is free.155 // 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);
157 }157 }
158 const clamped_start = @max(extendedOffset(), start);158 const clamped_start = @max(extendedOffset(), start);
159 extended.recycle(clamped_start - extendedOffset(), new_end - clamped_start);159 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 {...@@ -448,7 +448,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
448448
449 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {449 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
450 if (stack_n == 0) return;450 if (stack_n == 0) return;
451 mem.set(usize, addresses, 0);451 @memset(addresses, 0);
452 var stack_trace = StackTrace{452 var stack_trace = StackTrace{
453 .instruction_addresses = addresses,453 .instruction_addresses = addresses,
454 .index = 0,454 .index = 0,
...@@ -1113,7 +1113,7 @@ test "shrink" {...@@ -1113,7 +1113,7 @@ test "shrink" {
1113 var slice = try allocator.alloc(u8, 20);1113 var slice = try allocator.alloc(u8, 20);
1114 defer allocator.free(slice);1114 defer allocator.free(slice);
11151115
1116 mem.set(u8, slice, 0x11);1116 @memset(slice, 0x11);
11171117
1118 try std.testing.expect(allocator.resize(slice, 17));1118 try std.testing.expect(allocator.resize(slice, 17));
1119 slice = slice[0..17];1119 slice = slice[0..17];
lib/std/http/Client.zig+1-1
...@@ -284,7 +284,7 @@ pub const BufferedConnection = struct {...@@ -284,7 +284,7 @@ pub const BufferedConnection = struct {
284 if (available > 0) {284 if (available > 0) {
285 const can_read = @truncate(u16, @min(available, left));285 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]);
288 out_index += can_read;288 out_index += can_read;
289 bconn.start += can_read;289 bconn.start += can_read;
290290
lib/std/http/Headers.zig+2-1
...@@ -38,7 +38,8 @@ pub const Field = struct {...@@ -38,7 +38,8 @@ pub const Field = struct {
3838
39 pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {39 pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {
40 if (entry.value.len <= new_value.len) {40 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);
42 } else {43 } else {
43 allocator.free(entry.value);44 allocator.free(entry.value);
4445
lib/std/http/Server.zig+1-1
...@@ -128,7 +128,7 @@ pub const BufferedConnection = struct {...@@ -128,7 +128,7 @@ pub const BufferedConnection = struct {
128 if (available > 0) {128 if (available > 0) {
129 const can_read = @truncate(u16, @min(available, left));129 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]);
132 out_index += can_read;132 out_index += can_read;
133 bconn.start += can_read;133 bconn.start += can_read;
134134
lib/std/http/protocol.zig+1-1
...@@ -654,7 +654,7 @@ const MockBufferedConnection = struct {...@@ -654,7 +654,7 @@ const MockBufferedConnection = struct {
654 if (available > 0) {654 if (available > 0) {
655 const can_read = @truncate(u16, @min(available, left));655 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]);
658 out_index += can_read;658 out_index += can_read;
659 bconn.start += can_read;659 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...@@ -20,8 +20,8 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
20 var dest_index: usize = 0;20 var dest_index: usize = 0;
2121
22 while (dest_index < dest.len) {22 while (dest_index < dest.len) {
23 const written = std.math.min(dest.len - dest_index, self.end - self.start);23 const written = @min(dest.len - dest_index, self.end - self.start);
24 std.mem.copy(u8, dest[dest_index..], self.buf[self.start .. self.start + written]);24 @memcpy(dest[dest_index..][0..written], self.buf[self.start..][0..written]);
25 if (written == 0) {25 if (written == 0) {
26 // buf empty, fill it26 // buf empty, fill it
27 const n = try self.unbuffered_reader.read(self.buf[0..]);27 const n = try self.unbuffered_reader.read(self.buf[0..]);
...@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {...@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {
115 }115 }
116116
117 fn read(self: *Self, dest: []u8) Error!usize {117 fn read(self: *Self, dest: []u8) Error!usize {
118 if (self.curr_read >= self.reads_allowed) {118 if (self.curr_read >= self.reads_allowed) return 0;
119 return 0;119 @memcpy(dest[0..self.block.len], self.block);
120 }
121 std.debug.assert(dest.len >= self.block.len);
122 std.mem.copy(u8, dest, self.block);
123120
124 self.curr_read += 1;121 self.curr_read += 1;
125 return self.block.len;122 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...@@ -30,8 +30,9 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty
30 return self.unbuffered_writer.write(bytes);30 return self.unbuffered_writer.write(bytes);
31 }31 }
3232
33 mem.copy(u8, self.buf[self.end..], bytes);33 const new_end = self.end + bytes.len;
34 self.end += bytes.len;34 @memcpy(self.buf[self.end..new_end], bytes);
35 self.end = new_end;
35 return bytes.len;36 return bytes.len;
36 }37 }
37 };38 };
lib/std/io/fixed_buffer_stream.zig+3-3
...@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {...@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
45 }45 }
4646
47 pub fn read(self: *Self, dest: []u8) ReadError!usize {47 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);
49 const end = self.pos + size;49 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]);
52 self.pos = end;52 self.pos = end;
5353
54 return size;54 return size;
...@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {...@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
67 else67 else
68 self.buffer.len - self.pos;68 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]);
71 self.pos += n;71 self.pos += n;
7272
73 if (n == 0) return error.NoSpaceLeft;73 if (n == 0) return error.NoSpaceLeft;
lib/std/io/writer.zig+1-1
...@@ -35,7 +35,7 @@ pub fn Writer(...@@ -35,7 +35,7 @@ pub fn Writer(
3535
36 pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {36 pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {
37 var bytes: [256]u8 = undefined;37 var bytes: [256]u8 = undefined;
38 mem.set(u8, bytes[0..], byte);38 @memset(bytes[0..], byte);
3939
40 var remaining: usize = n;40 var remaining: usize = n;
41 while (remaining > 0) {41 while (remaining > 0) {
lib/std/json.zig+2-2
...@@ -1667,7 +1667,7 @@ fn parseInternal(...@@ -1667,7 +1667,7 @@ fn parseInternal(
1667 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);1667 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
1668 if (r.len != stringToken.decodedLength()) return error.LengthMismatch;1668 if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
1669 switch (stringToken.escapes) {1669 switch (stringToken.escapes) {
1670 .None => mem.copy(u8, &r, source_slice),1670 .None => @memcpy(r[0..source_slice.len], source_slice),
1671 .Some => try unescapeValidString(&r, source_slice),1671 .Some => try unescapeValidString(&r, source_slice),
1672 }1672 }
1673 return r;1673 return r;
...@@ -1733,7 +1733,7 @@ fn parseInternal(...@@ -1733,7 +1733,7 @@ fn parseInternal(
1733 try allocator.alloc(u8, len);1733 try allocator.alloc(u8, len);
1734 errdefer allocator.free(output);1734 errdefer allocator.free(output);
1735 switch (stringToken.escapes) {1735 switch (stringToken.escapes) {
1736 .None => mem.copy(u8, output, source_slice),1736 .None => @memcpy(output[0..source_slice.len], source_slice),
1737 .Some => try unescapeValidString(output, source_slice),1737 .Some => try unescapeValidString(output, source_slice),
1738 }1738 }
17391739
lib/std/json/test.zig+1-1
...@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {...@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {
2811 // StreamingParser has multiple internal fields set to undefined. This causes issues when using2811 // StreamingParser has multiple internal fields set to undefined. This causes issues when using
2812 // expectEqual so these are zeroed. We are testing for equality here only because this is a2812 // expectEqual so these are zeroed. We are testing for equality here only because this is a
2813 // known small test reproduction which hits the relevant LLVM issue.2813 // 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);
2815 try std.testing.expectEqual(parser, parser);2815 try std.testing.expectEqual(parser, parser);
2816}2816}
28172817
lib/std/math/big/int.zig+32-32
...@@ -176,7 +176,7 @@ pub const Mutable = struct {...@@ -176,7 +176,7 @@ pub const Mutable = struct {
176 /// Asserts the value fits in the limbs buffer.176 /// Asserts the value fits in the limbs buffer.
177 pub fn copy(self: *Mutable, other: Const) void {177 pub fn copy(self: *Mutable, other: Const) void {
178 if (self.limbs.ptr != other.limbs.ptr) {178 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]);
180 }180 }
181 self.positive = other.positive;181 self.positive = other.positive;
182 self.len = other.limbs.len;182 self.len = other.limbs.len;
...@@ -199,7 +199,7 @@ pub const Mutable = struct {...@@ -199,7 +199,7 @@ pub const Mutable = struct {
199 /// can be modified separately from the original.199 /// can be modified separately from the original.
200 /// Asserts that limbs is big enough to store the value.200 /// Asserts that limbs is big enough to store the value.
201 pub fn clone(other: Mutable, limbs: []Limb) Mutable {201 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]);
203 return .{203 return .{
204 .limbs = limbs,204 .limbs = limbs,
205 .len = other.len,205 .len = other.len,
...@@ -344,7 +344,7 @@ pub const Mutable = struct {...@@ -344,7 +344,7 @@ pub const Mutable = struct {
344 .min => {344 .min => {
345 // Negative bound, signed = -0x80.345 // Negative bound, signed = -0x80.
346 r.len = req_limbs;346 r.len = req_limbs;
347 mem.set(Limb, r.limbs[0 .. r.len - 1], 0);347 @memset(r.limbs[0 .. r.len - 1], 0);
348 r.limbs[r.len - 1] = signmask;348 r.limbs[r.len - 1] = signmask;
349 r.positive = false;349 r.positive = false;
350 },350 },
...@@ -363,7 +363,7 @@ pub const Mutable = struct {...@@ -363,7 +363,7 @@ pub const Mutable = struct {
363 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.363 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
364364
365 r.len = new_req_limbs;365 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));
367 r.limbs[r.len - 1] = new_mask;367 r.limbs[r.len - 1] = new_mask;
368 }368 }
369 },369 },
...@@ -376,7 +376,7 @@ pub const Mutable = struct {...@@ -376,7 +376,7 @@ pub const Mutable = struct {
376 .max => {376 .max => {
377 // Max bound, unsigned = 0xFF377 // Max bound, unsigned = 0xFF
378 r.len = req_limbs;378 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));
380 r.limbs[r.len - 1] = mask;380 r.limbs[r.len - 1] = mask;
381 },381 },
382 },382 },
...@@ -489,7 +489,7 @@ pub const Mutable = struct {...@@ -489,7 +489,7 @@ pub const Mutable = struct {
489 if (msl < req_limbs) {489 if (msl < req_limbs) {
490 r.limbs[msl] = 1;490 r.limbs[msl] = 1;
491 r.len = req_limbs;491 r.len = req_limbs;
492 mem.set(Limb, r.limbs[msl + 1 .. req_limbs], 0);492 @memset(r.limbs[msl + 1 .. req_limbs], 0);
493 } else {493 } else {
494 carry_truncated = true;494 carry_truncated = true;
495 }495 }
...@@ -637,14 +637,14 @@ pub const Mutable = struct {...@@ -637,14 +637,14 @@ pub const Mutable = struct {
637637
638 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {638 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
639 const start = buf_index;639 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);
641 buf_index += a.limbs.len;641 buf_index += a.limbs.len;
642 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();642 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
643 } else a;643 } else a;
644644
645 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {645 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
646 const start = buf_index;646 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);
648 buf_index += b.limbs.len;648 buf_index += b.limbs.len;
649 break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();649 break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();
650 } else b;650 } else b;
...@@ -676,7 +676,7 @@ pub const Mutable = struct {...@@ -676,7 +676,7 @@ pub const Mutable = struct {
676 }676 }
677 }677 }
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
681 llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);681 llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);
682682
...@@ -708,7 +708,7 @@ pub const Mutable = struct {...@@ -708,7 +708,7 @@ pub const Mutable = struct {
708 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {708 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
709 const start = buf_index;709 const start = buf_index;
710 const a_len = math.min(req_limbs, a.limbs.len);710 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]);
712 buf_index += a_len;712 buf_index += a_len;
713 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();713 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
714 } else a;714 } else a;
...@@ -716,7 +716,7 @@ pub const Mutable = struct {...@@ -716,7 +716,7 @@ pub const Mutable = struct {
716 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {716 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
717 const start = buf_index;717 const start = buf_index;
718 const b_len = math.min(req_limbs, b.limbs.len);718 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]);
720 buf_index += b_len;720 buf_index += b_len;
721 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();721 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
722 } else b;722 } else b;
...@@ -751,7 +751,7 @@ pub const Mutable = struct {...@@ -751,7 +751,7 @@ pub const Mutable = struct {
751 const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];751 const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];
752 const b_limbs = b.limbs[0..math.min(req_limbs, b.limbs.len)];752 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
756 llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);756 llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);
757 rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));757 rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));
...@@ -919,7 +919,7 @@ pub const Mutable = struct {...@@ -919,7 +919,7 @@ pub const Mutable = struct {
919 _ = opt_allocator;919 _ = opt_allocator;
920 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing920 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
921921
922 mem.set(Limb, rma.limbs, 0);922 @memset(rma.limbs, 0);
923923
924 llsquareBasecase(rma.limbs, a.limbs);924 llsquareBasecase(rma.limbs, a.limbs);
925925
...@@ -1522,7 +1522,7 @@ pub const Mutable = struct {...@@ -1522,7 +1522,7 @@ pub const Mutable = struct {
1522 if (xy_trailing != 0) {1522 if (xy_trailing != 0) {
1523 // Manually shift here since we know its limb aligned.1523 // Manually shift here since we know its limb aligned.
1524 mem.copyBackwards(Limb, r.limbs[xy_trailing..], r.limbs[0..r.len]);1524 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);
1526 r.len += xy_trailing;1526 r.len += xy_trailing;
1527 }1527 }
1528 }1528 }
...@@ -1556,7 +1556,7 @@ pub const Mutable = struct {...@@ -1556,7 +1556,7 @@ pub const Mutable = struct {
1556 // for 0 <= j <= n - t, set q[j] to 01556 // for 0 <= j <= n - t, set q[j] to 0
1557 q.len = shift + 1;1557 q.len = shift + 1;
1558 q.positive = true;1558 q.positive = true;
1559 mem.set(Limb, q.limbs[0..q.len], 0);1559 @memset(q.limbs[0..q.len], 0);
15601560
1561 // 2.1561 // 2.
1562 // while x >= y * b^(n - t):1562 // while x >= y * b^(n - t):
...@@ -1691,7 +1691,7 @@ pub const Mutable = struct {...@@ -1691,7 +1691,7 @@ pub const Mutable = struct {
16911691
1692 r.addScalar(a.abs(), -1);1692 r.addScalar(a.abs(), -1);
1693 if (req_limbs > r.len) {1693 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);
1695 }1695 }
16961696
1697 assert(r.limbs.len >= req_limbs);1697 assert(r.limbs.len >= req_limbs);
...@@ -1730,7 +1730,7 @@ pub const Mutable = struct {...@@ -1730,7 +1730,7 @@ pub const Mutable = struct {
17301730
1731 // Zero-extend the result1731 // Zero-extend the result
1732 if (req_limbs > r.len) {1732 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);
1734 }1734 }
17351735
1736 // Truncate to required number of limbs.1736 // Truncate to required number of limbs.
...@@ -1921,8 +1921,8 @@ pub const Const = struct {...@@ -1921,8 +1921,8 @@ pub const Const = struct {
19211921
1922 /// The result is an independent resource which is managed by the caller.1922 /// The result is an independent resource which is managed by the caller.
1923 pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {1923 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));1924 const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
1925 mem.copy(Limb, limbs, self.limbs);1925 @memcpy(limbs[0..self.limbs.len], self.limbs);
1926 return Managed{1926 return Managed{
1927 .allocator = allocator,1927 .allocator = allocator,
1928 .limbs = limbs,1928 .limbs = limbs,
...@@ -1935,7 +1935,7 @@ pub const Const = struct {...@@ -1935,7 +1935,7 @@ pub const Const = struct {
19351935
1936 /// Asserts `limbs` is big enough to store the value.1936 /// Asserts `limbs` is big enough to store the value.
1937 pub fn toMutable(self: Const, limbs: []Limb) Mutable {1937 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]);
1939 return .{1939 return .{
1940 .limbs = limbs,1940 .limbs = limbs,
1941 .positive = self.positive,1941 .positive = self.positive,
...@@ -2253,7 +2253,7 @@ pub const Const = struct {...@@ -2253,7 +2253,7 @@ pub const Const = struct {
2253 .positive = true, // Make absolute by ignoring self.positive.2253 .positive = true, // Make absolute by ignoring self.positive.
2254 .len = self.limbs.len,2254 .len = self.limbs.len,
2255 };2255 };
2256 mem.copy(Limb, q.limbs, self.limbs);2256 @memcpy(q.limbs[0..self.limbs.len], self.limbs);
22572257
2258 var r: Mutable = .{2258 var r: Mutable = .{
2259 .limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],2259 .limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],
...@@ -2587,8 +2587,8 @@ pub const Managed = struct {...@@ -2587,8 +2587,8 @@ pub const Managed = struct {
2587 .allocator = allocator,2587 .allocator = allocator,
2588 .metadata = other.metadata,2588 .metadata = other.metadata,
2589 .limbs = block: {2589 .limbs = block: {
2590 var limbs = try allocator.alloc(Limb, other.len());2590 const limbs = try allocator.alloc(Limb, other.len());
2591 mem.copy(Limb, limbs[0..], other.limbs[0..other.len()]);2591 @memcpy(limbs, other.limbs[0..other.len()]);
2592 break :block limbs;2592 break :block limbs;
2593 },2593 },
2594 };2594 };
...@@ -2600,7 +2600,7 @@ pub const Managed = struct {...@@ -2600,7 +2600,7 @@ pub const Managed = struct {
2600 if (self.limbs.ptr == other.limbs.ptr) return;2600 if (self.limbs.ptr == other.limbs.ptr) return;
26012601
2602 try self.ensureCapacity(other.limbs.len);2602 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]);
2604 self.setMetadata(other.positive, other.limbs.len);2604 self.setMetadata(other.positive, other.limbs.len);
2605 }2605 }
26062606
...@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(...@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(
3302 // Note, we don't need to compute all of p2, just enough limbs to satisfy r.3302 // Note, we don't need to compute all of p2, just enough limbs to satisfy r.
3303 const p2_limbs = math.min(limbs_after_split, a1.len + b1.len);3303 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);
3306 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);3306 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
3307 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];3307 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
33083308
...@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(...@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(
3317 // Compute p0.3317 // Compute p0.
3318 // Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.3318 // Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.
3319 const p0_limbs = a0.len + b0.len;3319 const p0_limbs = a0.len + b0.len;
3320 mem.set(Limb, tmp[0..p0_limbs], 0);3320 @memset(tmp[0..p0_limbs], 0);
3321 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);3321 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
3322 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];3322 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
33233323
...@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(...@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(
3341 return;3341 return;
3342 }3342 }
33433343
3344 mem.set(Limb, tmp, 0);3344 @memset(tmp, 0);
33453345
3346 // p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.3346 // p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.
3347 // Note that in this case, we again need some storage for intermediary results3347 // 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 {...@@ -3666,7 +3666,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
3666 }3666 }
36673667
3668 r[limb_shift - 1] = carry;3668 r[limb_shift - 1] = carry;
3669 mem.set(Limb, r[0 .. limb_shift - 1], 0);3669 @memset(r[0 .. limb_shift - 1], 0);
3670}3670}
36713671
3672fn llshr(r: []Limb, a: []const Limb, shift: usize) void {3672fn 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 {...@@ -4061,8 +4061,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
4061 tmp2 = tmp_limbs;4061 tmp2 = tmp_limbs;
4062 }4062 }
40634063
4064 mem.copy(Limb, tmp1, a);4064 @memcpy(tmp1[0..a.len], a);
4065 mem.set(Limb, tmp1[a.len..], 0);4065 @memset(tmp1[a.len..], 0);
40664066
4067 // Scan the exponent as a binary number, from left to right, dropping the4067 // Scan the exponent as a binary number, from left to right, dropping the
4068 // most significant bit set.4068 // most significant bit set.
...@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {...@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
4074 var i: usize = 0;4074 var i: usize = 0;
4075 while (i < exp_bits) : (i += 1) {4075 while (i < exp_bits) : (i += 1) {
4076 // Square4076 // Square
4077 mem.set(Limb, tmp2, 0);4077 @memset(tmp2, 0);
4078 llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);4078 llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);
4079 mem.swap([]Limb, &tmp1, &tmp2);4079 mem.swap([]Limb, &tmp1, &tmp2);
4080 // Multiply by a4080 // Multiply by a
4081 const ov = @shlWithOverflow(exp, 1);4081 const ov = @shlWithOverflow(exp, 1);
4082 exp = ov[0];4082 exp = ov[0];
4083 if (ov[1] != 0) {4083 if (ov[1] != 0) {
4084 mem.set(Limb, tmp2, 0);4084 @memset(tmp2, 0);
4085 llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);4085 llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);
4086 mem.swap([]Limb, &tmp1, &tmp2);4086 mem.swap([]Limb, &tmp1, &tmp2);
4087 }4087 }
lib/std/mem.zig+14-15
...@@ -192,12 +192,15 @@ test "Allocator.resize" {...@@ -192,12 +192,15 @@ test "Allocator.resize" {
192 }192 }
193}193}
194194
195/// Deprecated: use `@memcpy` if the arguments do not overlap, or
196/// `copyForwards` if they do.
197pub const copy = copyForwards;
198
195/// Copy all of source into dest at position 0.199/// Copy all of source into dest at position 0.
196/// dest.len must be >= source.len.200/// dest.len must be >= source.len.
197/// If the slices overlap, dest.ptr must be <= src.ptr.201/// If the slices overlap, dest.ptr must be <= src.ptr.
198pub fn copy(comptime T: type, dest: []T, source: []const T) void {202pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void {
199 for (dest[0..source.len], source) |*d, s|203 for (dest[0..source.len], source) |*d, s| d.* = s;
200 d.* = s;
201}204}
202205
203/// Copy all of source into dest at position 0.206/// 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 {...@@ -216,11 +219,7 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
216 }219 }
217}220}
218221
219/// Sets all elements of `dest` to `value`.222pub const set = @compileError("deprecated; use @memset instead");
220pub fn set(comptime T: type, dest: []T, value: T) void {
221 for (dest) |*d|
222 d.* = value;
223}
224223
225/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.224/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
226/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when225/// 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 {...@@ -249,7 +248,7 @@ pub fn zeroes(comptime T: type) T {
249 if (@sizeOf(T) == 0) return undefined;248 if (@sizeOf(T) == 0) return undefined;
250 if (struct_info.layout == .Extern) {249 if (struct_info.layout == .Extern) {
251 var item: T = undefined;250 var item: T = undefined;
252 set(u8, asBytes(&item), 0);251 @memset(asBytes(&item), 0);
253 return item;252 return item;
254 } else {253 } else {
255 var structure: T = undefined;254 var structure: T = undefined;
...@@ -1667,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {...@@ -1667,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
1667 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));1666 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16681667
1669 if (@typeInfo(T).Int.bits == 0) {1668 if (@typeInfo(T).Int.bits == 0) {
1670 return set(u8, buffer, 0);1669 return @memset(buffer, 0);
1671 } else if (@typeInfo(T).Int.bits == 8) {1670 } else if (@typeInfo(T).Int.bits == 8) {
1672 set(u8, buffer, 0);1671 @memset(buffer, 0);
1673 buffer[0] = @bitCast(u8, value);1672 buffer[0] = @bitCast(u8, value);
1674 return;1673 return;
1675 }1674 }
...@@ -1691,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {...@@ -1691,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
1691 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));1690 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16921691
1693 if (@typeInfo(T).Int.bits == 0) {1692 if (@typeInfo(T).Int.bits == 0) {
1694 return set(u8, buffer, 0);1693 return @memset(buffer, 0);
1695 } else if (@typeInfo(T).Int.bits == 8) {1694 } else if (@typeInfo(T).Int.bits == 8) {
1696 set(u8, buffer, 0);1695 @memset(buffer, 0);
1697 buffer[buffer.len - 1] = @bitCast(u8, value);1696 buffer[buffer.len - 1] = @bitCast(u8, value);
1698 return;1697 return;
1699 }1698 }
...@@ -2706,7 +2705,7 @@ fn testReadIntImpl() !void {...@@ -2706,7 +2705,7 @@ fn testReadIntImpl() !void {
2706 }2705 }
2707}2706}
27082707
2709test "writeIntSlice" {2708test writeIntSlice {
2710 try testWriteIntImpl();2709 try testWriteIntImpl();
2711 comptime try testWriteIntImpl();2710 comptime try testWriteIntImpl();
2712}2711}
...@@ -3124,7 +3123,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen...@@ -3124,7 +3123,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen
3124 var replacements: usize = 0;3123 var replacements: usize = 0;
3125 while (slide < input.len) {3124 while (slide < input.len) {
3126 if (mem.startsWith(T, input[slide..], needle)) {3125 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);
3128 i += replacement.len;3127 i += replacement.len;
3129 slide += needle.len;3128 slide += needle.len;
3130 replacements += 1;3129 replacements += 1;
lib/std/mem/Allocator.zig+2-2
...@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {...@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {
307/// Copies `m` to newly allocated memory. Caller owns the memory.307/// Copies `m` to newly allocated memory. Caller owns the memory.
308pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {308pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {
309 const new_buf = try allocator.alloc(T, m.len);309 const new_buf = try allocator.alloc(T, m.len);
310 mem.copy(T, new_buf, m);310 @memcpy(new_buf, m);
311 return new_buf;311 return new_buf;
312}312}
313313
314/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.314/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
315pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {315pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {
316 const new_buf = try allocator.alloc(T, m.len + 1);316 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);
318 new_buf[m.len] = 0;318 new_buf[m.len] = 0;
319 return new_buf[0..m.len :0];319 return new_buf[0..m.len :0];
320}320}
lib/std/multi_array_list.zig+3-3
...@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {
380 inline for (fields, 0..) |field_info, i| {380 inline for (fields, 0..) |field_info, i| {
381 if (@sizeOf(field_info.type) != 0) {381 if (@sizeOf(field_info.type) != 0) {
382 const field = @intToEnum(Field, i);382 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));
384 }384 }
385 }385 }
386 gpa.free(self.allocatedBytes());386 gpa.free(self.allocatedBytes());
...@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {
441 inline for (fields, 0..) |field_info, i| {441 inline for (fields, 0..) |field_info, i| {
442 if (@sizeOf(field_info.type) != 0) {442 if (@sizeOf(field_info.type) != 0) {
443 const field = @intToEnum(Field, i);443 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));
445 }445 }
446 }446 }
447 gpa.free(self.allocatedBytes());447 gpa.free(self.allocatedBytes());
...@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {
460 inline for (fields, 0..) |field_info, i| {460 inline for (fields, 0..) |field_info, i| {
461 if (@sizeOf(field_info.type) != 0) {461 if (@sizeOf(field_info.type) != 0) {
462 const field = @intToEnum(Field, i);462 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));
464 }464 }
465 }465 }
466 return result;466 return result;
lib/std/net.zig+14-14
...@@ -106,8 +106,8 @@ pub const Address = extern union {...@@ -106,8 +106,8 @@ pub const Address = extern union {
106 // Add 1 to ensure a terminating 0 is present in the path array for maximum portability.106 // Add 1 to ensure a terminating 0 is present in the path array for maximum portability.
107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
108108
109 mem.set(u8, &sock_addr.path, 0);109 @memset(&sock_addr.path, 0);
110 mem.copy(u8, &sock_addr.path, path);110 @memcpy(sock_addr.path[0..path.len], path);
111111
112 return Address{ .un = sock_addr };112 return Address{ .un = sock_addr };
113 }113 }
...@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {...@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {
346 if (!saw_any_digits) {346 if (!saw_any_digits) {
347 if (abbrv) return error.InvalidCharacter; // ':::'347 if (abbrv) return error.InvalidCharacter; // ':::'
348 if (i != 0) abbrv = true;348 if (i != 0) abbrv = true;
349 mem.set(u8, ip_slice[index..], 0);349 @memset(ip_slice[index..], 0);
350 ip_slice = tail[0..];350 ip_slice = tail[0..];
351 index = 0;351 index = 0;
352 continue;352 continue;
...@@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {...@@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {
416 index += 1;416 index += 1;
417 ip_slice[index] = @truncate(u8, x);417 ip_slice[index] = @truncate(u8, x);
418 index += 1;418 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]);
420 return result;420 return result;
421 }421 }
422 }422 }
...@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {...@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {
465 if (!saw_any_digits) {465 if (!saw_any_digits) {
466 if (abbrv) return error.InvalidCharacter; // ':::'466 if (abbrv) return error.InvalidCharacter; // ':::'
467 if (i != 0) abbrv = true;467 if (i != 0) abbrv = true;
468 mem.set(u8, ip_slice[index..], 0);468 @memset(ip_slice[index..], 0);
469 ip_slice = tail[0..];469 ip_slice = tail[0..];
470 index = 0;470 index = 0;
471 continue;471 continue;
...@@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {...@@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {
550 index += 1;550 index += 1;
551 ip_slice[index] = @truncate(u8, x);551 ip_slice[index] = @truncate(u8, x);
552 index += 1;552 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]);
554 return result;554 return result;
555 }555 }
556 }556 }
...@@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {...@@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {
662 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);662 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
663 defer os.closeSocket(sockfd);663 defer os.closeSocket(sockfd);
664664
665 std.mem.copy(u8, &ifr.ifrn.name, name);665 @memcpy(ifr.ifrn.name[0..name.len], name);
666 ifr.ifrn.name[name.len] = 0;666 ifr.ifrn.name[name.len] = 0;
667667
668 // TODO investigate if this needs to be integrated with evented I/O.668 // TODO investigate if this needs to be integrated with evented I/O.
...@@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {...@@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {
676 return error.NameTooLong;676 return error.NameTooLong;
677677
678 var if_name: [os.IFNAMESIZE:0]u8 = undefined;678 var if_name: [os.IFNAMESIZE:0]u8 = undefined;
679 std.mem.copy(u8, &if_name, name);679 @memcpy(if_name[0..name.len], name);
680 if_name[name.len] = 0;680 if_name[name.len] = 0;
681 const if_slice = if_name[0..name.len :0];681 const if_slice = if_name[0..name.len :0];
682 const index = os.system.if_nametoindex(if_slice);682 const index = os.system.if_nametoindex(if_slice);
...@@ -1041,14 +1041,14 @@ fn linuxLookupName(...@@ -1041,14 +1041,14 @@ fn linuxLookupName(
1041 var salen: os.socklen_t = undefined;1041 var salen: os.socklen_t = undefined;
1042 var dalen: os.socklen_t = undefined;1042 var dalen: os.socklen_t = undefined;
1043 if (addr.addr.any.family == os.AF.INET6) {1043 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;
1045 da = @ptrCast(*os.sockaddr, &da6);1045 da = @ptrCast(*os.sockaddr, &da6);
1046 dalen = @sizeOf(os.sockaddr.in6);1046 dalen = @sizeOf(os.sockaddr.in6);
1047 sa = @ptrCast(*os.sockaddr, &sa6);1047 sa = @ptrCast(*os.sockaddr, &sa6);
1048 salen = @sizeOf(os.sockaddr.in6);1048 salen = @sizeOf(os.sockaddr.in6);
1049 } else {1049 } else {
1050 mem.copy(u8, &sa6.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 mem.copy(u8, &da6.addr, "\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".*;
1052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);1052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
1053 da4.addr = addr.addr.in.sa.addr;1053 da4.addr = addr.addr.in.sa.addr;
1054 da = @ptrCast(*os.sockaddr, &da4);1054 da = @ptrCast(*os.sockaddr, &da4);
...@@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(...@@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(
1343 // name is not a CNAME record) and serves as a buffer for passing1343 // name is not a CNAME record) and serves as a buffer for passing
1344 // the full requested name to name_from_dns.1344 // the full requested name to name_from_dns.
1345 try canon.resize(canon_name.len);1345 try canon.resize(canon_name.len);
1346 mem.copy(u8, canon.items, canon_name);1346 @memcpy(canon.items, canon_name);
1347 try canon.append('.');1347 try canon.append('.');
13481348
1349 var tok_it = mem.tokenize(u8, search, " \t");1349 var tok_it = mem.tokenize(u8, search, " \t");
...@@ -1567,7 +1567,7 @@ fn resMSendRc(...@@ -1567,7 +1567,7 @@ fn resMSendRc(
1567 for (0..ns.len) |i| {1567 for (0..ns.len) |i| {
1568 if (ns[i].any.family != os.AF.INET) continue;1568 if (ns[i].any.family != os.AF.INET) continue;
1569 mem.writeIntNative(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr);1569 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".*;
1571 ns[i].any.family = os.AF.INET6;1571 ns[i].any.family = os.AF.INET6;
1572 ns[i].in6.sa.flowinfo = 0;1572 ns[i].in6.sa.flowinfo = 0;
1573 ns[i].in6.sa.scope_id = 0;1573 ns[i].in6.sa.scope_id = 0;
...@@ -1665,7 +1665,7 @@ fn resMSendRc(...@@ -1665,7 +1665,7 @@ fn resMSendRc(
1665 if (i == next) {1665 if (i == next) {
1666 while (next < queries.len and answers[next].len != 0) : (next += 1) {}1666 while (next < queries.len and answers[next].len != 0) : (next += 1) {}
1667 } else {1667 } 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]);
1669 }1669 }
16701670
1671 if (next == queries.len) break :outer;1671 if (next == queries.len) break :outer;
lib/std/os.zig+19-15
...@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(...@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(
1881 while (it.next()) |search_path| {1881 while (it.next()) |search_path| {
1882 const path_len = search_path.len + file_slice.len + 1;1882 const path_len = search_path.len + file_slice.len + 1;
1883 if (path_buf.len < path_len + 1) return error.NameTooLong;1883 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);
1885 path_buf[search_path.len] = '/';1885 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);
1887 path_buf[path_len] = 0;1887 path_buf[path_len] = 0;
1888 const full_path = path_buf[0..path_len :0].ptr;1888 const full_path = path_buf[0..path_len :0].ptr;
1889 switch (arg0_expand) {1889 switch (arg0_expand) {
...@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {...@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
1917 if (builtin.link_libc) {1917 if (builtin.link_libc) {
1918 var small_key_buf: [64]u8 = undefined;1918 var small_key_buf: [64]u8 = undefined;
1919 if (key.len < small_key_buf.len) {1919 if (key.len < small_key_buf.len) {
1920 mem.copy(u8, &small_key_buf, key);1920 @memcpy(small_key_buf[0..key.len], key);
1921 small_key_buf[key.len] = 0;1921 small_key_buf[key.len] = 0;
1922 const key0 = small_key_buf[0..key.len :0];1922 const key0 = small_key_buf[0..key.len :0];
1923 return getenvZ(key0);1923 return getenvZ(key0);
...@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
2022 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {2022 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
2023 const path = ".";2023 const path = ".";
2024 if (out_buffer.len < path.len) return error.NameTooLong;2024 if (out_buffer.len < path.len) return error.NameTooLong;
2025 std.mem.copy(u8, out_buffer, path);2025 const result = out_buffer[0..path.len];
2026 return out_buffer[0..path.len];2026 @memcpy(result, path);
2027 return result;
2027 }2028 }
20282029
2029 const err = if (builtin.link_libc) blk: {2030 const err = if (builtin.link_libc) blk: {
...@@ -2673,7 +2674,7 @@ pub fn renameatW(...@@ -2673,7 +2674,7 @@ pub fn renameatW(
2673 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong2674 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong
2674 .FileName = undefined,2675 .FileName = undefined,
2675 };2676 };
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
2678 var io_status_block: windows.IO_STATUS_BLOCK = undefined;2679 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 {...@@ -5264,8 +5265,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5264 }5265 }
5265 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;5266 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;
5266 if (len == 0) return error.NameTooLong;5267 if (len == 0) return error.NameTooLong;
5267 mem.copy(u8, out_buffer, kfile.path[0..len]);5268 const result = out_buffer[0..len];
5268 return out_buffer[0..len];5269 @memcpy(result, kfile.path[0..len]);
5270 return result;
5269 } else {5271 } else {
5270 // This fallback implementation reimplements libutil's `kinfo_getfile()`.5272 // This fallback implementation reimplements libutil's `kinfo_getfile()`.
5271 // The motivation is to avoid linking -lutil when building zig or general5273 // 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 {...@@ -5296,8 +5298,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5296 if (kf.fd == fd) {5298 if (kf.fd == fd) {
5297 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;5299 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
5298 if (len == 0) return error.NameTooLong;5300 if (len == 0) return error.NameTooLong;
5299 mem.copy(u8, out_buffer, kf.path[0..len]);5301 const result = out_buffer[0..len];
5300 return out_buffer[0..len];5302 @memcpy(result, kf.path[0..len]);
5303 return result;
5301 }5304 }
5302 i += @intCast(usize, kf.structsize);5305 i += @intCast(usize, kf.structsize);
5303 }5306 }
...@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {...@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
5686 if (builtin.os.tag == .linux) {5689 if (builtin.os.tag == .linux) {
5687 const uts = uname();5690 const uts = uname();
5688 const hostname = mem.sliceTo(&uts.nodename, 0);5691 const hostname = mem.sliceTo(&uts.nodename, 0);
5689 mem.copy(u8, name_buffer, hostname);5692 const result = name_buffer[0..hostname.len];
5690 return name_buffer[0..hostname.len];5693 @memcpy(result, hostname);
5694 return result;
5691 }5695 }
56925696
5693 @compileError("TODO implement gethostname for this OS");5697 @compileError("TODO implement gethostname for this OS");
...@@ -5725,7 +5729,7 @@ pub fn res_mkquery(...@@ -5725,7 +5729,7 @@ pub fn res_mkquery(
5725 @memset(q[0..n], 0);5729 @memset(q[0..n], 0);
5726 q[2] = @as(u8, op) * 8 + 1;5730 q[2] = @as(u8, op) * 8 + 1;
5727 q[5] = 1;5731 q[5] = 1;
5728 mem.copy(u8, q[13..], name);5732 @memcpy(q[13..][0..name.len], name);
5729 var i: usize = 13;5733 var i: usize = 13;
5730 var j: usize = undefined;5734 var j: usize = undefined;
5731 while (q[i] != 0) : (i = j + 1) {5735 while (q[i] != 0) : (i = j + 1) {
...@@ -5748,7 +5752,7 @@ pub fn res_mkquery(...@@ -5748,7 +5752,7 @@ pub fn res_mkquery(
5748 q[0] = @truncate(u8, id / 256);5752 q[0] = @truncate(u8, id / 256);
5749 q[1] = @truncate(u8, id);5753 q[1] = @truncate(u8, id);
57505754
5751 mem.copy(u8, buf, q[0..n]);5755 @memcpy(buf[0..n], q[0..n]);
5752 return n;5756 return n;
5753}5757}
57545758
...@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {...@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
6755 var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;6759 var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;
6756 // >= rather than > to make room for the null byte6760 // >= rather than > to make room for the null byte
6757 if (name.len >= MFD_MAX_NAME_LEN) return error.NameTooLong;6761 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);
6759 path_with_null[name.len] = 0;6763 path_with_null[name.len] = 0;
6760 return path_with_null;6764 return path_with_null;
6761}6765}
lib/std/os/linux/bpf.zig+1-1
...@@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {...@@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {
1631 const status = try map_get_next_key(map, &lookup_key, &next_key);1631 const status = try map_get_next_key(map, &lookup_key, &next_key);
1632 try expectEqual(status, true);1632 try expectEqual(status, true);
1633 try expectEqual(next_key, key);1633 try expectEqual(next_key, key);
1634 std.mem.copy(u8, &lookup_key, &next_key);1634 lookup_key = next_key;
1635 const status2 = try map_get_next_key(map, &lookup_key, &next_key);1635 const status2 = try map_get_next_key(map, &lookup_key, &next_key);
1636 try expectEqual(status2, false);1636 try expectEqual(status2, false);
16371637
lib/std/os/linux/io_uring.zig+5-5
...@@ -1855,8 +1855,8 @@ test "write_fixed/read_fixed" {...@@ -1855,8 +1855,8 @@ test "write_fixed/read_fixed" {
18551855
1856 var raw_buffers: [2][11]u8 = undefined;1856 var raw_buffers: [2][11]u8 = undefined;
1857 // First buffer will be written to the file.1857 // First buffer will be written to the file.
1858 std.mem.set(u8, &raw_buffers[0], 'z');1858 @memset(&raw_buffers[0], 'z');
1859 std.mem.copy(u8, &raw_buffers[0], "foobar");1859 raw_buffers[0][0.."foobar".len].* = "foobar".*;
18601860
1861 var buffers = [2]os.iovec{1861 var buffers = [2]os.iovec{
1862 .{ .iov_base = &raw_buffers[0], .iov_len = raw_buffers[0].len },1862 .{ .iov_base = &raw_buffers[0], .iov_len = raw_buffers[0].len },
...@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {...@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {
2966 // Provide 1 buffer again2966 // Provide 1 buffer again
29672967
2968 // Deliberately put something we don't expect in the buffers2968 // 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
2971 const reprovided_buffer_id = 2;2971 const reprovided_buffer_id = 2;
29722972
...@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {
3155 // Do 4 recv which should consume all buffers3155 // Do 4 recv which should consume all buffers
31563156
3157 // Deliberately put something we don't expect in the buffers3157 // 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
3160 var i: usize = 0;3160 var i: usize = 0;
3161 while (i < buffers.len) : (i += 1) {3161 while (i < buffers.len) : (i += 1) {
...@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {
3235 // Final recv which should work3235 // Final recv which should work
32363236
3237 // Deliberately put something we don't expect in the buffers3237 // 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
3240 {3240 {
3241 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3241 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 {...@@ -275,7 +275,7 @@ inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {
275/// architecture-specific value of the thread-pointer register275/// architecture-specific value of the thread-pointer register
276pub fn prepareTLS(area: []u8) usize {276pub fn prepareTLS(area: []u8) usize {
277 // Clear the area we're going to use, just to be safe277 // Clear the area we're going to use, just to be safe
278 mem.set(u8, area, 0);278 @memset(area, 0);
279 // Prepare the DTV279 // Prepare the DTV
280 const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);280 const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);
281 dtv.entries = 1;281 dtv.entries = 1;
...@@ -287,7 +287,7 @@ pub fn prepareTLS(area: []u8) usize {...@@ -287,7 +287,7 @@ pub fn prepareTLS(area: []u8) usize {
287 .VariantII => area.ptr + tls_image.tcb_offset,287 .VariantII => area.ptr + tls_image.tcb_offset,
288 };288 };
289 // Copy the data289 // 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
292 // Return the corrected value (if needed) for the tp register.292 // Return the corrected value (if needed) for the tp register.
293 // Overflow here is not a problem, the pointer arithmetic involving the tp293 // 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" {...@@ -587,7 +587,7 @@ test "mmap" {
587 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));587 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
588588
589 // Make sure the memory is writeable as requested589 // Make sure the memory is writeable as requested
590 std.mem.set(u8, data, 0x55);590 @memset(data, 0x55);
591 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));591 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
592 }592 }
593593
lib/std/os/uefi/protocols/device_path_protocol.zig+1-1
...@@ -48,7 +48,7 @@ pub const DevicePathProtocol = extern struct {...@@ -48,7 +48,7 @@ pub const DevicePathProtocol = extern struct {
48 // DevicePathProtocol for the extra node before the end48 // DevicePathProtocol for the extra node before the end
49 var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol));49 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
53 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer53 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
54 // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).54 // 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(...@@ -754,7 +754,7 @@ pub fn CreateSymbolicLink(
754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,
755 };755 };
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));
758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;
760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
...@@ -1208,8 +1208,8 @@ pub fn GetFinalPathNameByHandle(...@@ -1208,8 +1208,8 @@ pub fn GetFinalPathNameByHandle(
12081208
1209 if (out_buffer.len < drive_letter.len + file_name_u16.len) return error.NameTooLong;1209 if (out_buffer.len < drive_letter.len + file_name_u16.len) return error.NameTooLong;
12101210
1211 mem.copy(u16, out_buffer, drive_letter);1211 @memcpy(out_buffer[0..drive_letter.len], drive_letter);
1212 mem.copy(u16, out_buffer[drive_letter.len..], file_name_u16);1212 mem.copyForwards(u16, out_buffer[drive_letter.len..][0..file_name_u16.len], file_name_u16);
1213 const total_len = drive_letter.len + file_name_u16.len;1213 const total_len = drive_letter.len + file_name_u16.len;
12141214
1215 // Validate that DOS does not contain any spurious nul bytes.1215 // Validate that DOS does not contain any spurious nul bytes.
...@@ -2012,7 +2012,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {...@@ -2012,7 +2012,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
2012 }2012 }
2013 const prefix_u16 = [_]u16{ '\\', '?', '?', '\\' };2013 const prefix_u16 = [_]u16{ '\\', '?', '?', '\\' };
2014 const start_index = if (prefix_index > 0 or !std.fs.path.isAbsolute(s)) 0 else blk: {2014 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;
2016 break :blk prefix_u16.len;2016 break :blk prefix_u16.len;
2017 };2017 };
2018 path_space.len = start_index + try std.unicode.utf8ToUtf16Le(path_space.data[start_index..], s);2018 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 {...@@ -2025,7 +2025,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
2025 std.debug.assert(temp_path.len == path_space.len);2025 std.debug.assert(temp_path.len == path_space.len);
2026 temp_path.data[path_space.len] = 0;2026 temp_path.data[path_space.len] = 0;
2027 path_space.len = prefix_u16.len + try getFullPathNameW(&temp_path.data, path_space.data[prefix_u16.len..]);2027 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;
2029 std.debug.assert(path_space.data[path_space.len] == 0);2029 std.debug.assert(path_space.data[path_space.len] == 0);
2030 return path_space;2030 return path_space;
2031 }2031 }
...@@ -2053,12 +2053,12 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace {...@@ -2053,12 +2053,12 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace {
20532053
2054 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {2054 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {
2055 const prefix = [_]u16{ '\\', '?', '?', '\\' };2055 const prefix = [_]u16{ '\\', '?', '?', '\\' };
2056 mem.copy(u16, path_space.data[0..], &prefix);2056 path_space.data[0..prefix.len].* = prefix;
2057 break :blk prefix.len;2057 break :blk prefix.len;
2058 };2058 };
2059 path_space.len = start_index + s.len;2059 path_space.len = start_index + s.len;
2060 if (path_space.len > path_space.data.len) return error.NameTooLong;2060 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);
2062 // > File I/O functions in the Windows API convert "/" to "\" as part of2062 // > File I/O functions in the Windows API convert "/" to "\" as part of
2063 // > converting the name to an NT-style name, except when using the "\\?\"2063 // > converting the name to an NT-style name, except when using the "\\?\"
2064 // > prefix as detailed in the following sections.2064 // > prefix as detailed in the following sections.
lib/std/process.zig+1-1
...@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {...@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {
855855
856 const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);856 const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);
857 const result_contents = buf[slice_list_bytes..];857 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
860 var contents_index: usize = 0;860 var contents_index: usize = 0;
861 for (slice_sizes, 0..) |len, i| {861 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 {...@@ -40,7 +40,8 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
40 }40 }
41 if (i < bytes.len) {41 if (i < bytes.len) {
42 var k = [_]u8{0} ** Cipher.key_length;42 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);
44 Cipher.xor(45 Cipher.xor(
45 self.state[0..Cipher.key_length],46 self.state[0..Cipher.key_length],
46 self.state[0..Cipher.key_length],47 self.state[0..Cipher.key_length],
...@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {...@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {
72 if (avail > 0) {73 if (avail > 0) {
73 // Bytes from the current block74 // Bytes from the current block
74 const n = @min(avail, buf.len);75 const n = @min(avail, buf.len);
75 mem.copy(u8, buf[0..n], bytes[self.offset..][0..n]);76 @memcpy(buf[0..n], bytes[self.offset..][0..n]);
76 mem.set(u8, bytes[self.offset..][0..n], 0);77 @memset(bytes[self.offset..][0..n], 0);
77 buf = buf[n..];78 buf = buf[n..];
78 self.offset += n;79 self.offset += n;
79 }80 }
...@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {...@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {
8384
84 // Full blocks85 // Full blocks
85 while (buf.len >= bytes.len) {86 while (buf.len >= bytes.len) {
86 mem.copy(u8, buf[0..bytes.len], bytes);87 @memcpy(buf[0..bytes.len], bytes);
87 buf = buf[bytes.len..];88 buf = buf[bytes.len..];
88 self.refill();89 self.refill();
89 }90 }
9091
91 // Remaining bytes92 // Remaining bytes
92 if (buf.len > 0) {93 if (buf.len > 0) {
93 mem.copy(u8, buf, bytes[0..buf.len]);94 @memcpy(buf, bytes[0..buf.len]);
94 mem.set(u8, bytes[0..buf.len], 0);95 @memset(bytes[0..buf.len], 0);
95 self.offset = buf.len;96 self.offset = buf.len;
96 }97 }
97}98}
lib/std/rand/Isaac64.zig+2-2
...@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {...@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {
87fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {87fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
88 // We ignore the multi-pass requirement since we don't currently expose full access to88 // We ignore the multi-pass requirement since we don't currently expose full access to
89 // seeding the self.m array completely.89 // seeding the self.m array completely.
90 mem.set(u64, self.m[0..], 0);90 @memset(self.m[0..], 0);
91 self.m[0] = init_s;91 self.m[0] = init_s;
9292
93 // prescrambled golden ratio constants93 // prescrambled golden ratio constants
...@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {...@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
143 }143 }
144 }144 }
145145
146 mem.set(u64, self.r[0..], 0);146 @memset(self.r[0..], 0);
147 self.a = 0;147 self.a = 0;
148 self.b = 0;148 self.b = 0;
149 self.c = 0;149 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...@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
230 allocator.free(new_dynamic_segments);230 allocator.free(new_dynamic_segments);
231 } else {231 } else {
232 // Good thing we allocated that new memory slice.232 // 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]);
234 allocator.free(self.dynamic_segments);234 allocator.free(self.dynamic_segments);
235 self.dynamic_segments = new_dynamic_segments;235 self.dynamic_segments = new_dynamic_segments;
236 }236 }
...@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
248248
249 var i = start;249 var i = start;
250 if (end <= prealloc_item_count) {250 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);
252 return;253 return;
253 } else if (i < prealloc_item_count) {254 } 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);
255 i = prealloc_item_count;257 i = prealloc_item_count;
256 }258 }
257259
258 while (i < end) {260 while (i < end) {
259 const shelf_index = shelfIndex(i);261 const shelf_index = shelfIndex(i);
260 const copy_start = boxIndex(i, shelf_index);262 const copy_start = boxIndex(i, shelf_index);
261 const copy_end = std.math.min(shelfSize(shelf_index), copy_start + end - i);263 const copy_end = @min(shelfSize(shelf_index), copy_start + end - i);
262264 const src = self.dynamic_segments[shelf_index][copy_start..copy_end];
263 mem.copy(265 @memcpy(dest[i - start ..][0..src.len], src);
264 T,
265 dest[i - start ..],
266 self.dynamic_segments[shelf_index][copy_start..copy_end],
267 );
268
269 i += (copy_end - copy_start);266 i += (copy_end - copy_start);
270 }267 }
271 }268 }
...@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {...@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {
498 control[@intCast(usize, i)] = i + 1;495 control[@intCast(usize, i)] = i + 1;
499 }496 }
500497
501 mem.set(i32, dest[0..], 0);498 @memset(dest[0..], 0);
502 list.writeToSlice(dest[0..], 0);499 list.writeToSlice(dest[0..], 0);
503 try testing.expect(mem.eql(i32, control[0..], dest[0..]));500 try testing.expect(mem.eql(i32, control[0..], dest[0..]));
504501
505 mem.set(i32, dest[0..], 0);502 @memset(dest[0..], 0);
506 list.writeToSlice(dest[50..], 50);503 list.writeToSlice(dest[50..], 50);
507 try testing.expect(mem.eql(i32, control[50..], dest[50..]));504 try testing.expect(mem.eql(i32, control[50..], dest[50..]));
508 }505 }
lib/std/sort.zig+38-21
...@@ -361,8 +361,10 @@ pub fn sort(...@@ -361,8 +361,10 @@ pub fn sort(
361361
362 if (lessThan(context, items[B1.end - 1], items[A1.start])) {362 if (lessThan(context, items[B1.end - 1], items[A1.start])) {
363 // the two ranges are in reverse order, so copy them in reverse order into the cache363 // 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]);364 const a1_items = items[A1.start..A1.end];
365 mem.copy(T, cache[0..], items[B1.start..B1.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);
366 } else if (lessThan(context, items[B1.start], items[A1.end - 1])) {368 } else if (lessThan(context, items[B1.start], items[A1.end - 1])) {
367 // these two ranges weren't already in order, so merge them into the cache369 // these two ranges weren't already in order, so merge them into the cache
368 mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);370 mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);
...@@ -371,23 +373,29 @@ pub fn sort(...@@ -371,23 +373,29 @@ pub fn sort(
371 if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;373 if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;
372374
373 // copy A1 and B1 into the cache in the same order375 // copy A1 and B1 into the cache in the same order
374 mem.copy(T, cache[0..], items[A1.start..A1.end]);376 const a1_items = items[A1.start..A1.end];
375 mem.copy(T, cache[A1.length()..], items[B1.start..B1.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);
376 }380 }
377 A1 = Range.init(A1.start, B1.end);381 A1 = Range.init(A1.start, B1.end);
378382
379 // merge A2 and B2 into the cache383 // merge A2 and B2 into the cache
380 if (lessThan(context, items[B2.end - 1], items[A2.start])) {384 if (lessThan(context, items[B2.end - 1], items[A2.start])) {
381 // the two ranges are in reverse order, so copy them in reverse order into the cache385 // 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]);386 const a2_items = items[A2.start..A2.end];
383 mem.copy(T, cache[A1.length()..], items[B2.start..B2.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);
384 } else if (lessThan(context, items[B2.start], items[A2.end - 1])) {390 } else if (lessThan(context, items[B2.start], items[A2.end - 1])) {
385 // these two ranges weren't already in order, so merge them into the cache391 // these two ranges weren't already in order, so merge them into the cache
386 mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);392 mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);
387 } else {393 } else {
388 // copy A2 and B2 into the cache in the same order394 // copy A2 and B2 into the cache in the same order
389 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);395 const a2_items = items[A2.start..A2.end];
390 mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.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);
391 }399 }
392 A2 = Range.init(A2.start, B2.end);400 A2 = Range.init(A2.start, B2.end);
393401
...@@ -397,15 +405,19 @@ pub fn sort(...@@ -397,15 +405,19 @@ pub fn sort(
397405
398 if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {406 if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {
399 // the two ranges are in reverse order, so copy them in reverse order into the items407 // 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]);408 const a3_items = cache[A3.start..A3.end];
401 mem.copy(T, items[A1.start..], cache[B3.start..B3.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);
402 } else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {412 } else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {
403 // these two ranges weren't already in order, so merge them back into the items413 // these two ranges weren't already in order, so merge them back into the items
404 mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);414 mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);
405 } else {415 } else {
406 // copy A3 and B3 into the items in the same order416 // copy A3 and B3 into the items in the same order
407 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);417 const a3_items = cache[A3.start..A3.end];
408 mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.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);
409 }421 }
410 }422 }
411423
...@@ -423,7 +435,8 @@ pub fn sort(...@@ -423,7 +435,8 @@ pub fn sort(
423 mem.rotate(T, items[A.start..B.end], A.length());435 mem.rotate(T, items[A.start..B.end], A.length());
424 } else if (lessThan(context, items[B.start], items[A.end - 1])) {436 } else if (lessThan(context, items[B.start], items[A.end - 1])) {
425 // these two ranges weren't already in order, so we'll need to merge them!437 // 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);
427 mergeExternal(T, items, A, B, context, lessThan, cache[0..]);440 mergeExternal(T, items, A, B, context, lessThan, cache[0..]);
428 }441 }
429 }442 }
...@@ -718,7 +731,8 @@ pub fn sort(...@@ -718,7 +731,8 @@ pub fn sort(
718 // if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it731 // if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it
719 // otherwise, if the second buffer is available, block swap the contents into that732 // otherwise, if the second buffer is available, block swap the contents into that
720 if (lastA.length() <= cache.len) {733 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);
722 } else if (buffer2.length() > 0) {736 } else if (buffer2.length() > 0) {
723 blockSwap(T, items, lastA.start, buffer2.start, lastA.length());737 blockSwap(T, items, lastA.start, buffer2.start, lastA.length());
724 }738 }
...@@ -762,7 +776,7 @@ pub fn sort(...@@ -762,7 +776,7 @@ pub fn sort(
762 if (buffer2.length() > 0 or block_size <= cache.len) {776 if (buffer2.length() > 0 or block_size <= cache.len) {
763 // 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 anyway777 // 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
764 if (block_size <= cache.len) {778 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]);
766 } else {780 } else {
767 blockSwap(T, items, blockA.start, buffer2.start, block_size);781 blockSwap(T, items, blockA.start, buffer2.start, block_size);
768 }782 }
...@@ -1122,7 +1136,8 @@ fn mergeInto(...@@ -1122,7 +1136,8 @@ fn mergeInto(
1122 insert_index += 1;1136 insert_index += 1;
1123 if (A_index == A_last) {1137 if (A_index == A_last) {
1124 // copy the remainder of B into the final array1138 // 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);
1126 break;1141 break;
1127 }1142 }
1128 } else {1143 } else {
...@@ -1131,7 +1146,8 @@ fn mergeInto(...@@ -1131,7 +1146,8 @@ fn mergeInto(
1131 insert_index += 1;1146 insert_index += 1;
1132 if (B_index == B_last) {1147 if (B_index == B_last) {
1133 // copy the remainder of A into the final array1148 // 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);
1135 break;1151 break;
1136 }1152 }
1137 }1153 }
...@@ -1171,7 +1187,8 @@ fn mergeExternal(...@@ -1171,7 +1187,8 @@ fn mergeExternal(
1171 }1187 }
11721188
1173 // copy the remainder of A into the final array1189 // 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);
1175}1192}
11761193
1177fn swap(1194fn swap(
...@@ -1305,7 +1322,7 @@ test "sort" {...@@ -1305,7 +1322,7 @@ test "sort" {
1305 for (u8cases) |case| {1322 for (u8cases) |case| {
1306 var buf: [8]u8 = undefined;1323 var buf: [8]u8 = undefined;
1307 const slice = buf[0..case[0].len];1324 const slice = buf[0..case[0].len];
1308 mem.copy(u8, slice, case[0]);1325 @memcpy(slice, case[0]);
1309 sort(u8, slice, {}, asc_u8);1326 sort(u8, slice, {}, asc_u8);
1310 try testing.expect(mem.eql(u8, slice, case[1]));1327 try testing.expect(mem.eql(u8, slice, case[1]));
1311 }1328 }
...@@ -1340,7 +1357,7 @@ test "sort" {...@@ -1340,7 +1357,7 @@ test "sort" {
1340 for (i32cases) |case| {1357 for (i32cases) |case| {
1341 var buf: [8]i32 = undefined;1358 var buf: [8]i32 = undefined;
1342 const slice = buf[0..case[0].len];1359 const slice = buf[0..case[0].len];
1343 mem.copy(i32, slice, case[0]);1360 @memcpy(slice, case[0]);
1344 sort(i32, slice, {}, asc_i32);1361 sort(i32, slice, {}, asc_i32);
1345 try testing.expect(mem.eql(i32, slice, case[1]));1362 try testing.expect(mem.eql(i32, slice, case[1]));
1346 }1363 }
...@@ -1377,7 +1394,7 @@ test "sort descending" {...@@ -1377,7 +1394,7 @@ test "sort descending" {
1377 for (rev_cases) |case| {1394 for (rev_cases) |case| {
1378 var buf: [8]i32 = undefined;1395 var buf: [8]i32 = undefined;
1379 const slice = buf[0..case[0].len];1396 const slice = buf[0..case[0].len];
1380 mem.copy(i32, slice, case[0]);1397 @memcpy(slice, case[0]);
1381 sort(i32, slice, {}, desc_i32);1398 sort(i32, slice, {}, desc_i32);
1382 try testing.expect(mem.eql(i32, slice, case[1]));1399 try testing.expect(mem.eql(i32, slice, case[1]));
1383 }1400 }
lib/std/tar.zig+8-6
...@@ -55,9 +55,9 @@ pub const Header = struct {...@@ -55,9 +55,9 @@ pub const Header = struct {
55 const p = prefix(header);55 const p = prefix(header);
56 if (p.len == 0)56 if (p.len == 0)
57 return n;57 return n;
58 std.mem.copy(u8, buffer[0..p.len], p);58 @memcpy(buffer[0..p.len], p);
59 buffer[p.len] = '/';59 buffer[p.len] = '/';
60 std.mem.copy(u8, buffer[p.len + 1 ..], n);60 @memcpy(buffer[p.len + 1 ..][0..n.len], n);
61 return buffer[0 .. p.len + 1 + n.len];61 return buffer[0 .. p.len + 1 + n.len];
62 }62 }
6363
...@@ -101,8 +101,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -101,8 +101,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
101 var end: usize = 0;101 var end: usize = 0;
102 header: while (true) {102 header: while (true) {
103 if (buffer.len - start < 1024) {103 if (buffer.len - start < 1024) {
104 std.mem.copy(u8, &buffer, buffer[start..end]);104 const dest_end = end - start;
105 end -= start;105 @memcpy(buffer[0..dest_end], buffer[start..end]);
106 end = dest_end;
106 start = 0;107 start = 0;
107 }108 }
108 const ask_header = @min(buffer.len - end, 1024 -| (end - start));109 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...@@ -138,8 +139,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
138 var file_off: usize = 0;139 var file_off: usize = 0;
139 while (true) {140 while (true) {
140 if (buffer.len - start < 1024) {141 if (buffer.len - start < 1024) {
141 std.mem.copy(u8, &buffer, buffer[start..end]);142 const dest_end = end - start;
142 end -= start;143 @memcpy(buffer[0..dest_end], buffer[start..end]);
144 end = dest_end;
143 start = 0;145 start = 0;
144 }146 }
145 // Ask for the rounded up file size + 512 for the next header.147 // 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 {...@@ -1596,7 +1596,7 @@ pub const Target = struct {
1596 /// Asserts that the length is less than or equal to 255 bytes.1596 /// Asserts that the length is less than or equal to 255 bytes.
1597 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {1597 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
1598 if (dl_or_null) |dl| {1598 if (dl_or_null) |dl| {
1599 mem.copy(u8, &self.buffer, dl);1599 @memcpy(self.buffer[0..dl.len], dl);
1600 self.max_byte = @intCast(u8, dl.len - 1);1600 self.max_byte = @intCast(u8, dl.len - 1);
1601 } else {1601 } else {
1602 self.max_byte = null;1602 self.max_byte = null;
...@@ -1612,7 +1612,7 @@ pub const Target = struct {...@@ -1612,7 +1612,7 @@ pub const Target = struct {
1612 return r.*;1612 return r.*;
1613 }1613 }
1614 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {1614 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
1615 mem.copy(u8, &r.buffer, s);1615 @memcpy(r.buffer[0..s.len], s);
1616 r.max_byte = @intCast(u8, s.len - 1);1616 r.max_byte = @intCast(u8, s.len - 1);
1617 return r.*;1617 return r.*;
1618 }1618 }
lib/std/testing/failing_allocator.zig+1-1
...@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {...@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {
66 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));66 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
67 if (self.index == self.fail_index) {67 if (self.index == self.fail_index) {
68 if (!self.has_induced_failure) {68 if (!self.has_induced_failure) {
69 mem.set(usize, &self.stack_addresses, 0);69 @memset(&self.stack_addresses, 0);
70 var stack_trace = std.builtin.StackTrace{70 var stack_trace = std.builtin.StackTrace{
71 .instruction_addresses = &self.stack_addresses,71 .instruction_addresses = &self.stack_addresses,
72 .index = 0,72 .index = 0,
lib/std/tz.zig+1-1
...@@ -137,7 +137,7 @@ pub const Tz = struct {...@@ -137,7 +137,7 @@ pub const Tz = struct {
137 const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);137 const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);
138 // We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.138 // We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.
139 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.139 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);
141 tt.name_data[name.len] = 0;141 tt.name_data[name.len] = 0;
142 }142 }
143143
lib/std/zig/render.zig+2-2
...@@ -1889,11 +1889,11 @@ fn renderArrayInit(...@@ -1889,11 +1889,11 @@ fn renderArrayInit(
1889 // A place to store the width of each expression and its column's maximum1889 // A place to store the width of each expression and its column's maximum
1890 const widths = try gpa.alloc(usize, row_exprs.len + row_size);1890 const widths = try gpa.alloc(usize, row_exprs.len + row_size);
1891 defer gpa.free(widths);1891 defer gpa.free(widths);
1892 mem.set(usize, widths, 0);1892 @memset(widths, 0);
18931893
1894 const expr_newlines = try gpa.alloc(bool, row_exprs.len);1894 const expr_newlines = try gpa.alloc(bool, row_exprs.len);
1895 defer gpa.free(expr_newlines);1895 defer gpa.free(expr_newlines);
1896 mem.set(bool, expr_newlines, false);1896 @memset(expr_newlines, false);
18971897
1898 const expr_widths = widths[0..row_exprs.len];1898 const expr_widths = widths[0..row_exprs.len];
1899 const column_widths = widths[row_exprs.len..];1899 const column_widths = widths[row_exprs.len..];
lib/std/zig/system/NativeTargetInfo.zig+4-4
...@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(
877 const cpu_arch = @tagName(result.target.cpu.arch);877 const cpu_arch = @tagName(result.target.cpu.arch);
878 const os_tag = @tagName(result.target.os.tag);878 const os_tag = @tagName(result.target.os.tag);
879 const abi = @tagName(result.target.abi);879 const abi = @tagName(result.target.abi);
880 mem.copy(u8, path_buf[index..], prefix);880 @memcpy(path_buf[index..][0..prefix.len], prefix);
881 index += prefix.len;881 index += prefix.len;
882 mem.copy(u8, path_buf[index..], cpu_arch);882 @memcpy(path_buf[index..][0..cpu_arch.len], cpu_arch);
883 index += cpu_arch.len;883 index += cpu_arch.len;
884 path_buf[index] = '-';884 path_buf[index] = '-';
885 index += 1;885 index += 1;
886 mem.copy(u8, path_buf[index..], os_tag);886 @memcpy(path_buf[index..][0..os_tag.len], os_tag);
887 index += os_tag.len;887 index += os_tag.len;
888 path_buf[index] = '-';888 path_buf[index] = '-';
889 index += 1;889 index += 1;
890 mem.copy(u8, path_buf[index..], abi);890 @memcpy(path_buf[index..][0..abi.len], abi);
891 index += abi.len;891 index += abi.len;
892 const rpath = path_buf[0..index];892 const rpath = path_buf[0..index];
893 if (glibcVerFromRPath(rpath)) |ver| {893 if (glibcVerFromRPath(rpath)) |ver| {
lib/std/zig/system/windows.zig+2-2
...@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);
172 switch (@field(args, field.name).value_type) {172 switch (@field(args, field.name).value_type) {
173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {173 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]);
175 },175 },
176 REG.QWORD => {176 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]);
178 },178 },
179 else => unreachable,179 else => unreachable,
180 }180 }
src/AstGen.zig+1-1
...@@ -3604,7 +3604,7 @@ const WipMembers = struct {...@@ -3604,7 +3604,7 @@ const WipMembers = struct {
36043604
3605 fn appendToDeclSlice(self: *Self, data: []const u32) void {3605 fn appendToDeclSlice(self: *Self, data: []const u32) void {
3606 assert(self.decls_end + data.len <= self.field_bits_start);3606 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);
3608 self.decls_end += @intCast(u32, data.len);3608 self.decls_end += @intCast(u32, data.len);
3609 }3609 }
36103610
src/Autodoc.zig+1-1
...@@ -1146,7 +1146,7 @@ fn walkInstruction(...@@ -1146,7 +1146,7 @@ fn walkInstruction(
1146 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];1146 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
11471147
1148 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);1148 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
1151 const big_int = std.math.big.int.Const{1151 const big_int = std.math.big.int.Const{
1152 .limbs = limbs,1152 .limbs = limbs,
src/Compilation.zig+3-3
...@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di...@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
2165 const digest_start = 2; // "o/[digest]/[basename]"2165 const digest_start = 2; // "o/[digest]/[basename]"
21662166
2167 if (comp.whole_bin_sub_path) |sub_path| {2167 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
2170 comp.bin_file.options.emit = .{2170 comp.bin_file.options.emit = .{
2171 .directory = comp.local_cache_directory,2171 .directory = comp.local_cache_directory,
...@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di...@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
2174 }2174 }
21752175
2176 if (comp.whole_implib_sub_path) |sub_path| {2176 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
2179 comp.bin_file.options.implib_emit = .{2179 comp.bin_file.options.implib_emit = .{
2180 .directory = comp.local_cache_directory,2180 .directory = comp.local_cache_directory,
...@@ -4432,7 +4432,7 @@ pub fn addCCArgs(...@@ -4432,7 +4432,7 @@ pub fn addCCArgs(
4432 assert(prefix.len == prefix_len);4432 assert(prefix.len == prefix_len);
4433 var march_buf: [prefix_len + letters.len + 1]u8 = undefined;4433 var march_buf: [prefix_len + letters.len + 1]u8 = undefined;
4434 var march_index: usize = prefix_len;4434 var march_index: usize = prefix_len;
4435 mem.copy(u8, &march_buf, prefix);4435 @memcpy(march_buf[0..prefix.len], prefix);
44364436
4437 if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {4437 if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {
4438 march_buf[march_index] = 'e';4438 march_buf[march_index] = 'e';
src/Liveness.zig+7-7
...@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {...@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
156 errdefer a.special.deinit(gpa);156 errdefer a.special.deinit(gpa);
157 defer a.extra.deinit(gpa);157 defer a.extra.deinit(gpa);
158158
159 std.mem.set(usize, a.tomb_bits, 0);159 @memset(a.tomb_bits, 0);
160160
161 const main_body = air.getMainBody();161 const main_body = air.getMainBody();
162162
...@@ -1150,7 +1150,7 @@ fn analyzeInst(...@@ -1150,7 +1150,7 @@ fn analyzeInst(
1150 if (args.len + 1 <= bpi - 1) {1150 if (args.len + 1 <= bpi - 1) {
1151 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);1151 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
1152 buf[0] = callee;1152 buf[0] = callee;
1153 std.mem.copy(Air.Inst.Ref, buf[1..], args);1153 @memcpy(buf[1..][0..args.len], args);
1154 return analyzeOperands(a, pass, data, inst, buf);1154 return analyzeOperands(a, pass, data, inst, buf);
1155 }1155 }
11561156
...@@ -1189,7 +1189,7 @@ fn analyzeInst(...@@ -1189,7 +1189,7 @@ fn analyzeInst(
11891189
1190 if (elements.len <= bpi - 1) {1190 if (elements.len <= bpi - 1) {
1191 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);1191 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);
1193 return analyzeOperands(a, pass, data, inst, buf);1193 return analyzeOperands(a, pass, data, inst, buf);
1194 }1194 }
11951195
...@@ -1255,7 +1255,7 @@ fn analyzeInst(...@@ -1255,7 +1255,7 @@ fn analyzeInst(
1255 if (buf_index + inputs.len > buf.len) {1255 if (buf_index + inputs.len > buf.len) {
1256 break :simple buf_index + inputs.len;1256 break :simple buf_index + inputs.len;
1257 }1257 }
1258 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);1258 @memcpy(buf[buf_index..][0..inputs.len], inputs);
1259 return analyzeOperands(a, pass, data, inst, buf);1259 return analyzeOperands(a, pass, data, inst, buf);
1260 };1260 };
12611261
...@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(...@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(
1841 var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else1841 var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else
1842 defer gpa.free(case_infos);1842 defer gpa.free(case_infos);
18431843
1844 std.mem.set(ControlBranchInfo, case_infos, .{});1844 @memset(case_infos, .{});
1845 defer for (case_infos) |*info| {1845 defer for (case_infos) |*info| {
1846 info.branch_deaths.deinit(gpa);1846 info.branch_deaths.deinit(gpa);
1847 info.live_set.deinit(gpa);1847 info.live_set.deinit(gpa);
...@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(...@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(
1898 const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);1898 const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);
1899 defer gpa.free(mirrored_deaths);1899 defer gpa.free(mirrored_deaths);
19001900
1901 std.mem.set(DeathList, mirrored_deaths, .{});1901 @memset(mirrored_deaths, .{});
1902 defer for (mirrored_deaths) |*md| md.deinit(gpa);1902 defer for (mirrored_deaths) |*md| md.deinit(gpa);
19031903
1904 {1904 {
...@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1993 };1993 };
1994 errdefer a.gpa.free(extra_tombs);1994 errdefer a.gpa.free(extra_tombs);
19951995
1996 std.mem.set(u32, extra_tombs, 0);1996 @memset(extra_tombs, 0);
19971997
1998 const will_die_immediately: bool = switch (pass) {1998 const will_die_immediately: bool = switch (pass) {
1999 .loop_analysis => false, // track everything, since we don't have full liveness information yet1999 .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 {...@@ -206,9 +206,9 @@ pub const InstMap = struct {
206206
207 const start_diff = old_start - better_start;207 const start_diff = old_start - better_start;
208 const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);208 const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);
209 mem.set(Air.Inst.Ref, new_items[0..start_diff], .none);209 @memset(new_items[0..start_diff], .none);
210 mem.copy(Air.Inst.Ref, new_items[start_diff..], map.items);210 @memcpy(new_items[start_diff..][0..map.items.len], map.items);
211 mem.set(Air.Inst.Ref, new_items[start_diff + map.items.len ..], .none);211 @memset(new_items[start_diff + map.items.len ..], .none);
212212
213 allocator.free(map.items);213 allocator.free(map.items);
214 map.items = new_items;214 map.items = new_items;
...@@ -4307,7 +4307,7 @@ fn validateStructInit(...@@ -4307,7 +4307,7 @@ fn validateStructInit(
4307 // Maps field index to field_ptr index of where it was already initialized.4307 // Maps field index to field_ptr index of where it was already initialized.
4308 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());4308 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());
4309 defer gpa.free(found_fields);4309 defer gpa.free(found_fields);
4310 mem.set(Zir.Inst.Index, found_fields, 0);4310 @memset(found_fields, 0);
43114311
4312 var struct_ptr_zir_ref: Zir.Inst.Ref = undefined;4312 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....@@ -5113,7 +5113,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
5113 const byte_count = int.len * @sizeOf(std.math.big.Limb);5113 const byte_count = int.len * @sizeOf(std.math.big.Limb);
5114 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];5114 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
5115 const limbs = try arena.alloc(std.math.big.Limb, int.len);5115 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
5118 return sema.addConstant(5118 return sema.addConstant(
5119 Type.initTag(.comptime_int),5119 Type.initTag(.comptime_int),
...@@ -5967,7 +5967,7 @@ fn addDbgVar(...@@ -5967,7 +5967,7 @@ fn addDbgVar(
5967 const elements_used = name.len / 4 + 1;5967 const elements_used = name.len / 4 + 1;
5968 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);5968 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
5969 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());5969 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
5970 mem.copy(u8, buffer, name);5970 @memcpy(buffer[0..name.len], name);
5971 buffer[name.len] = 0;5971 buffer[name.len] = 0;
5972 sema.air_extra.items.len += elements_used;5972 sema.air_extra.items.len += elements_used;
59735973
...@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10354 .Enum => {10354 .Enum => {
10355 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());10355 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());
10356 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum();10356 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);
10358 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.10358 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
1035910359
10360 var extra_index: usize = special.end;10360 var extra_index: usize = special.end;
...@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(...@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(
12809 }12809 }
12810 i = 0;12810 i = 0;
12811 while (i < factor) : (i += 1) {12811 while (i < factor) : (i += 1) {
12812 mem.copy(Type, types[tuple_len * i ..], types[0..tuple_len]);12812 mem.copyForwards(Type, types[tuple_len * i ..], types[0..tuple_len]);
12813 mem.copy(Value, values[tuple_len * i ..], values[0..tuple_len]);12813 mem.copyForwards(Value, values[tuple_len * i ..], values[0..tuple_len]);
12814 }12814 }
12815 break :rs runtime_src;12815 break :rs runtime_src;
12816 };12816 };
...@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(...@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(
12835 }12835 }
12836 i = 1;12836 i = 1;
12837 while (i < factor) : (i += 1) {12837 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]);
12839 }12839 }
1284012840
12841 return block.addAggregateInit(tuple_ty, element_refs);12841 return block.addAggregateInit(tuple_ty, element_refs);
...@@ -15057,29 +15057,29 @@ fn zirAsm(...@@ -15057,29 +15057,29 @@ fn zirAsm(
15057 sema.appendRefsAssumeCapacity(args);15057 sema.appendRefsAssumeCapacity(args);
15058 for (outputs) |o| {15058 for (outputs) |o| {
15059 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15059 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15060 mem.copy(u8, buffer, o.c);15060 @memcpy(buffer[0..o.c.len], o.c);
15061 buffer[o.c.len] = 0;15061 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);
15063 buffer[o.c.len + 1 + o.n.len] = 0;15063 buffer[o.c.len + 1 + o.n.len] = 0;
15064 sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;15064 sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;
15065 }15065 }
15066 for (inputs) |input| {15066 for (inputs) |input| {
15067 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15067 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15068 mem.copy(u8, buffer, input.c);15068 @memcpy(buffer[0..input.c.len], input.c);
15069 buffer[input.c.len] = 0;15069 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);
15071 buffer[input.c.len + 1 + input.n.len] = 0;15071 buffer[input.c.len + 1 + input.n.len] = 0;
15072 sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;15072 sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;
15073 }15073 }
15074 for (clobbers) |clobber| {15074 for (clobbers) |clobber| {
15075 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15075 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15076 mem.copy(u8, buffer, clobber);15076 @memcpy(buffer[0..clobber.len], clobber);
15077 buffer[clobber.len] = 0;15077 buffer[clobber.len] = 0;
15078 sema.air_extra.items.len += clobber.len / 4 + 1;15078 sema.air_extra.items.len += clobber.len / 4 + 1;
15079 }15079 }
15080 {15080 {
15081 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15081 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15082 mem.copy(u8, buffer, asm_source);15082 @memcpy(buffer[0..asm_source.len], asm_source);
15083 sema.air_extra.items.len += (asm_source.len + 3) / 4;15083 sema.air_extra.items.len += (asm_source.len + 3) / 4;
15084 }15084 }
15085 return asm_air;15085 return asm_air;
...@@ -17582,7 +17582,7 @@ fn structInitEmpty(...@@ -17582,7 +17582,7 @@ fn structInitEmpty(
17582 // The init values to use for the struct instance.17582 // The init values to use for the struct instance.
17583 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());17583 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());
17584 defer gpa.free(field_inits);17584 defer gpa.free(field_inits);
17585 mem.set(Air.Inst.Ref, field_inits, .none);17585 @memset(field_inits, .none);
1758617586
17587 return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);17587 return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);
17588}17588}
...@@ -17675,7 +17675,7 @@ fn zirStructInit(...@@ -17675,7 +17675,7 @@ fn zirStructInit(
17675 // The init values to use for the struct instance.17675 // The init values to use for the struct instance.
17676 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());17676 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());
17677 defer gpa.free(field_inits);17677 defer gpa.free(field_inits);
17678 mem.set(Air.Inst.Ref, field_inits, .none);17678 @memset(field_inits, .none);
1767917679
17680 var field_i: u32 = 0;17680 var field_i: u32 = 0;
17681 var extra_index = extra.end;17681 var extra_index = extra.end;
...@@ -22039,7 +22039,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -22039,7 +22039,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
22039 if (try sema.resolveMaybeUndefVal(uncoerced_elem)) |_| {22039 if (try sema.resolveMaybeUndefVal(uncoerced_elem)) |_| {
22040 for (0..len) |i| {22040 for (0..len) |i| {
22041 const elem_index = try sema.addIntUnsigned(Type.usize, i);22041 const elem_index = try sema.addIntUnsigned(Type.usize, i);
22042 const elem_ptr = try sema.elemPtr(22042 const elem_ptr = try sema.elemPtrOneLayerOnly(
22043 block,22043 block,
22044 src,22044 src,
22045 dest_ptr,22045 dest_ptr,
...@@ -26953,9 +26953,13 @@ fn storePtrVal(...@@ -26953,9 +26953,13 @@ fn storePtrVal(
26953 defer sema.gpa.free(buffer);26953 defer sema.gpa.free(buffer);
26954 reinterpret.val_ptr.*.writeToMemory(mut_kit.ty, sema.mod, buffer) catch |err| switch (err) {26954 reinterpret.val_ptr.*.writeToMemory(mut_kit.ty, sema.mod, buffer) catch |err| switch (err) {
26955 error.ReinterpretDeclRef => unreachable,26955 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)}),
26956 };26958 };
26957 operand_val.writeToMemory(operand_ty, sema.mod, buffer[reinterpret.byte_offset..]) catch |err| switch (err) {26959 operand_val.writeToMemory(operand_ty, sema.mod, buffer[reinterpret.byte_offset..]) catch |err| switch (err) {
26958 error.ReinterpretDeclRef => unreachable,26960 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)}),
26959 };26963 };
2696026964
26961 const arena = mut_kit.beginArena(sema.mod);26965 const arena = mut_kit.beginArena(sema.mod);
...@@ -27075,7 +27079,7 @@ fn beginComptimePtrMutation(...@@ -27075,7 +27079,7 @@ fn beginComptimePtrMutation(
27075 const array_len_including_sentinel =27079 const array_len_including_sentinel =
27076 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());27080 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
27077 const elems = try arena.alloc(Value, array_len_including_sentinel);27081 const elems = try arena.alloc(Value, array_len_including_sentinel);
27078 mem.set(Value, elems, Value.undef);27082 @memset(elems, Value.undef);
2707927083
27080 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);27084 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2708127085
...@@ -27273,7 +27277,7 @@ fn beginComptimePtrMutation(...@@ -27273,7 +27277,7 @@ fn beginComptimePtrMutation(
27273 switch (parent.ty.zigTypeTag()) {27277 switch (parent.ty.zigTypeTag()) {
27274 .Struct => {27278 .Struct => {
27275 const fields = try arena.alloc(Value, parent.ty.structFieldCount());27279 const fields = try arena.alloc(Value, parent.ty.structFieldCount());
27276 mem.set(Value, fields, Value.undef);27280 @memset(fields, Value.undef);
2727727281
27278 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);27282 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
2727927283
...@@ -27905,6 +27909,8 @@ fn bitCastVal(...@@ -27905,6 +27909,8 @@ fn bitCastVal(
27905 defer sema.gpa.free(buffer);27909 defer sema.gpa.free(buffer);
27906 val.writeToMemory(old_ty, sema.mod, buffer) catch |err| switch (err) {27910 val.writeToMemory(old_ty, sema.mod, buffer) catch |err| switch (err) {
27907 error.ReinterpretDeclRef => return null,27911 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)}),
27908 };27914 };
27909 return try Value.readFromMemory(new_ty, sema.mod, buffer[buffer_offset..], sema.arena);27915 return try Value.readFromMemory(new_ty, sema.mod, buffer[buffer_offset..], sema.arena);
27910}27916}
...@@ -28419,7 +28425,7 @@ fn coerceTupleToStruct(...@@ -28419,7 +28425,7 @@ fn coerceTupleToStruct(
28419 const fields = struct_ty.structFields();28425 const fields = struct_ty.structFields();
28420 const field_vals = try sema.arena.alloc(Value, fields.count());28426 const field_vals = try sema.arena.alloc(Value, fields.count());
28421 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);28427 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
28424 const inst_ty = sema.typeOf(inst);28430 const inst_ty = sema.typeOf(inst);
28425 var runtime_src: ?LazySrcLoc = null;28431 var runtime_src: ?LazySrcLoc = null;
...@@ -28508,7 +28514,7 @@ fn coerceTupleToTuple(...@@ -28508,7 +28514,7 @@ fn coerceTupleToTuple(
28508 const dest_field_count = tuple_ty.structFieldCount();28514 const dest_field_count = tuple_ty.structFieldCount();
28509 const field_vals = try sema.arena.alloc(Value, dest_field_count);28515 const field_vals = try sema.arena.alloc(Value, dest_field_count);
28510 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);28516 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
28513 const inst_ty = sema.typeOf(inst);28519 const inst_ty = sema.typeOf(inst);
28514 const inst_field_count = inst_ty.structFieldCount();28520 const inst_field_count = inst_ty.structFieldCount();
src/arch/aarch64/CodeGen.zig+4-4
...@@ -1630,7 +1630,7 @@ fn allocRegs(...@@ -1630,7 +1630,7 @@ fn allocRegs(
1630 const read_locks = locks[0..read_args.len];1630 const read_locks = locks[0..read_args.len];
1631 const write_locks = locks[read_args.len..];1631 const write_locks = locks[read_args.len..];
16321632
1633 std.mem.set(?RegisterLock, locks, null);1633 @memset(locks, null);
1634 defer for (locks) |lock| {1634 defer for (locks) |lock| {
1635 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);1635 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
1636 };1636 };
...@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4395 if (args.len + 1 <= Liveness.bpi - 1) {4395 if (args.len + 1 <= Liveness.bpi - 1) {
4396 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);4396 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
4397 buf[0] = callee;4397 buf[0] = callee;
4398 std.mem.copy(Air.Inst.Ref, buf[1..], args);4398 @memcpy(buf[1..][0..args.len], args);
4399 return self.finishAir(inst, result, buf);4399 return self.finishAir(inst, result, buf);
4400 }4400 }
4401 var bt = try self.iterateBigTomb(inst, 1 + args.len);4401 var bt = try self.iterateBigTomb(inst, 1 + args.len);
...@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5348 buf_index += 1;5348 buf_index += 1;
5349 }5349 }
5350 if (buf_index + inputs.len > buf.len) break :simple;5350 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);
5352 return self.finishAir(inst, result, buf);5352 return self.finishAir(inst, result, buf);
5353 }5353 }
5354 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);5354 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
...@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60556055
6056 if (elements.len <= Liveness.bpi - 1) {6056 if (elements.len <= Liveness.bpi - 1) {
6057 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);6057 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);
6059 return self.finishAir(inst, result, buf);6059 return self.finishAir(inst, result, buf);
6060 }6060 }
6061 var bt = try self.iterateBigTomb(inst, elements.len);6061 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/arm/CodeGen.zig+4-4
...@@ -3114,7 +3114,7 @@ fn allocRegs(...@@ -3114,7 +3114,7 @@ fn allocRegs(
3114 const read_locks = locks[0..read_args.len];3114 const read_locks = locks[0..read_args.len];
3115 const write_locks = locks[read_args.len..];3115 const write_locks = locks[read_args.len..];
31163116
3117 std.mem.set(?RegisterLock, locks, null);3117 @memset(locks, null);
3118 defer for (locks) |lock| {3118 defer for (locks) |lock| {
3119 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);3119 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
3120 };3120 };
...@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4341 if (args.len <= Liveness.bpi - 2) {4341 if (args.len <= Liveness.bpi - 2) {
4342 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);4342 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
4343 buf[0] = callee;4343 buf[0] = callee;
4344 std.mem.copy(Air.Inst.Ref, buf[1..], args);4344 @memcpy(buf[1..][0..args.len], args);
4345 return self.finishAir(inst, result, buf);4345 return self.finishAir(inst, result, buf);
4346 }4346 }
4347 var bt = try self.iterateBigTomb(inst, 1 + args.len);4347 var bt = try self.iterateBigTomb(inst, 1 + args.len);
...@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5263 buf_index += 1;5263 buf_index += 1;
5264 }5264 }
5265 if (buf_index + inputs.len > buf.len) break :simple;5265 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);
5267 return self.finishAir(inst, result, buf);5267 return self.finishAir(inst, result, buf);
5268 }5268 }
5269 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);5269 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
...@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60006000
6001 if (elements.len <= Liveness.bpi - 1) {6001 if (elements.len <= Liveness.bpi - 1) {
6002 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);6002 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);
6004 return self.finishAir(inst, result, buf);6004 return self.finishAir(inst, result, buf);
6005 }6005 }
6006 var bt = try self.iterateBigTomb(inst, elements.len);6006 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...@@ -1784,7 +1784,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1784 if (args.len <= Liveness.bpi - 2) {1784 if (args.len <= Liveness.bpi - 2) {
1785 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);1785 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
1786 buf[0] = callee;1786 buf[0] = callee;
1787 std.mem.copy(Air.Inst.Ref, buf[1..], args);1787 @memcpy(buf[1..][0..args.len], args);
1788 return self.finishAir(inst, result, buf);1788 return self.finishAir(inst, result, buf);
1789 }1789 }
1790 var bt = try self.iterateBigTomb(inst, 1 + args.len);1790 var bt = try self.iterateBigTomb(inst, 1 + args.len);
...@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
2225 buf_index += 1;2225 buf_index += 1;
2226 }2226 }
2227 if (buf_index + inputs.len > buf.len) break :simple;2227 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);
2229 return self.finishAir(inst, result, buf);2229 return self.finishAir(inst, result, buf);
2230 }2230 }
2231 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);2231 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
...@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25002500
2501 if (elements.len <= Liveness.bpi - 1) {2501 if (elements.len <= Liveness.bpi - 1) {
2502 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);2502 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);
2504 return self.finishAir(inst, result, buf);2504 return self.finishAir(inst, result, buf);
2505 }2505 }
2506 var bt = try self.iterateBigTomb(inst, elements.len);2506 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 {...@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
843843
844 if (elements.len <= Liveness.bpi - 1) {844 if (elements.len <= Liveness.bpi - 1) {
845 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);845 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);
847 return self.finishAir(inst, result, buf);847 return self.finishAir(inst, result, buf);
848 }848 }
849 var bt = try self.iterateBigTomb(inst, elements.len);849 var bt = try self.iterateBigTomb(inst, elements.len);
...@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
987 buf_index += 1;987 buf_index += 1;
988 }988 }
989 if (buf_index + inputs.len > buf.len) break :simple;989 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);
991 return self.finishAir(inst, result, buf);991 return self.finishAir(inst, result, buf);
992 }992 }
993993
...@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1314 if (args.len + 1 <= Liveness.bpi - 1) {1314 if (args.len + 1 <= Liveness.bpi - 1) {
1315 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);1315 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
1316 buf[0] = callee;1316 buf[0] = callee;
1317 std.mem.copy(Air.Inst.Ref, buf[1..], args);1317 @memcpy(buf[1..][0..args.len], args);
1318 return self.finishAir(inst, result, buf);1318 return self.finishAir(inst, result, buf);
1319 }1319 }
13201320
src/arch/x86_64/CodeGen.zig+2-2
...@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
7117 buf_index += 1;7117 buf_index += 1;
7118 }7118 }
7119 if (buf_index + inputs.len > buf.len) break :simple;7119 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);
7121 return self.finishAir(inst, result, buf);7121 return self.finishAir(inst, result, buf);
7122 }7122 }
7123 var bt = self.liveness.iterateBigTomb(inst);7123 var bt = self.liveness.iterateBigTomb(inst);
...@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
85058505
8506 if (elements.len <= Liveness.bpi - 1) {8506 if (elements.len <= Liveness.bpi - 1) {
8507 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);8507 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);
8509 return self.finishAir(inst, result, buf);8509 return self.finishAir(inst, result, buf);
8510 }8510 }
8511 var bt = self.liveness.iterateBigTomb(inst);8511 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...@@ -546,7 +546,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
546 .encoding = encoding,546 .encoding = encoding,
547 .ops = [1]Operand{.none} ** 4,547 .ops = [1]Operand{.none} ** 4,
548 };548 };
549 std.mem.copy(Operand, &inst.ops, ops);549 @memcpy(inst.ops[0..ops.len], ops);
550550
551 var cwriter = std.io.countingWriter(std.io.null_writer);551 var cwriter = std.io.countingWriter(std.io.null_writer);
552 inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.552 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: {...@@ -575,8 +575,10 @@ const mnemonic_to_encodings_map = init: {
575 .modrm_ext = entry[4],575 .modrm_ext = entry[4],
576 .mode = entry[5],576 .mode = entry[5],
577 };577 };
578 std.mem.copy(Op, &data.ops, entry[2]);578 // TODO: use `@memcpy` for these. When I did that, I got a false positive
579 std.mem.copy(u8, &data.opc, entry[3]);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
581 while (mnemonic_int < @enumToInt(entry[0])) : (mnemonic_int += 1) {583 while (mnemonic_int < @enumToInt(entry[0])) : (mnemonic_int += 1) {
582 mnemonic_map[mnemonic_int] = data_storage[mnemonic_start..data_index];584 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 {...@@ -321,7 +321,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class {
321 byte_i = 0;321 byte_i = 0;
322 result_i += 1;322 result_i += 1;
323 }323 }
324 std.mem.copy(Class, result[result_i..], field_class);324 @memcpy(result[result_i..][0..field_class.len], field_class);
325 result_i += field_class.len;325 result_i += field_class.len;
326 // If there are any bytes leftover, we have to try to combine326 // If there are any bytes leftover, we have to try to combine
327 // the next field with them.327 // the next field with them.
src/arch/x86_64/encoder.zig+2-2
...@@ -182,7 +182,7 @@ pub const Instruction = struct {...@@ -182,7 +182,7 @@ pub const Instruction = struct {
182 .encoding = encoding,182 .encoding = encoding,
183 .ops = [1]Operand{.none} ** 4,183 .ops = [1]Operand{.none} ** 4,
184 };184 };
185 std.mem.copy(Operand, &inst.ops, ops);185 @memcpy(inst.ops[0..ops.len], ops);
186 return inst;186 return inst;
187 }187 }
188188
...@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co...@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co
859 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;859 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
860 var padding = try testing.allocator.alloc(u8, idx + 5);860 var padding = try testing.allocator.alloc(u8, idx + 5);
861 defer testing.allocator.free(padding);861 defer testing.allocator.free(padding);
862 std.mem.set(u8, padding, ' ');862 @memset(padding, ' ');
863 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{863 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{
864 assembly,864 assembly,
865 expected_fmt,865 expected_fmt,
src/codegen.zig+1-1
...@@ -552,7 +552,7 @@ pub fn generateSymbol(...@@ -552,7 +552,7 @@ pub fn generateSymbol(
552 .ty = field_ty,552 .ty = field_ty,
553 .val = field_val,553 .val = field_val,
554 }, &tmp_list, debug_output, reloc_info)) {554 }, &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),
556 .fail => |em| return Result{ .fail = em },556 .fail => |em| return Result{ .fail = em },
557 }557 }
558 } else {558 } else {
src/codegen/c.zig+85-32
...@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {
2411 const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);2411 const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);
2412 defer o.dg.gpa.free(name_buf);2412 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);
2415 for (o.dg.module.error_name_list.items) |name| {2415 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);
2417 const identifier = name_buf[0 .. name_prefix.len + name.len];2417 const identifier = name_buf[0 .. name_prefix.len + name.len];
24182418
2419 var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };2419 var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };
...@@ -3858,7 +3858,7 @@ fn airCmpOp(...@@ -3858,7 +3858,7 @@ fn airCmpOp(
3858 try reap(f, inst, &.{ data.lhs, data.rhs });3858 try reap(f, inst, &.{ data.lhs, data.rhs });
38593859
3860 const rhs_ty = f.air.typeOf(data.rhs);3860 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();
3862 const writer = f.object.writer();3862 const writer = f.object.writer();
3863 const local = try f.allocLocal(inst, inst_ty);3863 const local = try f.allocLocal(inst, inst_ty);
3864 const v = try Vectorize.start(f, inst, writer, lhs_ty);3864 const v = try Vectorize.start(f, inst, writer, lhs_ty);
...@@ -4419,51 +4419,94 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4419,51 +4419,94 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
4419 const dest_ty = f.air.typeOfIndex(inst);4419 const dest_ty = f.air.typeOfIndex(inst);
44204420
4421 const operand = try f.resolveInst(ty_op.operand);4421 const operand = try f.resolveInst(ty_op.operand);
4422 try reap(f, inst, &.{ty_op.operand});
4423 const operand_ty = f.air.typeOf(ty_op.operand);4422 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 it4463fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !LocalResult {
4430 const can_elide = operand == .local and operand.local == local.new_local;4464 const target = f.object.dg.module.getTarget();
4465 const writer = f.object.writer();
44314466
4432 if (operand_ty.isAbiInt() and dest_ty.isAbiInt()) {4467 if (operand_ty.isAbiInt() and dest_ty.isAbiInt()) {
4433 if (can_elide) return local;
4434 const src_info = dest_ty.intInfo(target);4468 const src_info = dest_ty.intInfo(target);
4435 const dest_info = operand_ty.intInfo(target);4469 const dest_info = operand_ty.intInfo(target);
4436 if (src_info.signedness == dest_info.signedness and4470 if (src_info.signedness == dest_info.signedness and
4437 src_info.bits == dest_info.bits)4471 src_info.bits == dest_info.bits)
4438 {4472 {
4439 try f.writeCValue(writer, local, .Other);4473 return .{
4440 try writer.writeAll(" = ");4474 .c_value = operand,
4441 try f.writeCValue(writer, operand, .Initializer);4475 .need_free = false,
4442 try writer.writeAll(";\n");4476 };
4443 return local;
4444 }4477 }
4445 }4478 }
44464479
4447 if (dest_ty.isPtrAtRuntime() and operand_ty.isPtrAtRuntime()) {4480 if (dest_ty.isPtrAtRuntime() and operand_ty.isPtrAtRuntime()) {
4448 if (can_elide) return local;4481 const local = try f.allocLocal(0, dest_ty);
4449 try f.writeCValue(writer, local, .Other);4482 try f.writeCValue(writer, local, .Other);
4450 try writer.writeAll(" = (");4483 try writer.writeAll(" = (");
4451 try f.renderType(writer, dest_ty);4484 try f.renderType(writer, dest_ty);
4452 try writer.writeByte(')');4485 try writer.writeByte(')');
4453 try f.writeCValue(writer, operand, .Other);4486 try f.writeCValue(writer, operand, .Other);
4454 try writer.writeAll(";\n");4487 try writer.writeAll(";\n");
4455 return local;4488 return .{
4489 .c_value = local,
4490 .need_free = true,
4491 };
4456 }4492 }
44574493
4458 const operand_lval = if (operand == .constant) blk: {4494 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);
4460 try f.writeCValue(writer, operand_local, .Other);4496 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 }
4462 try f.writeCValue(writer, operand, .Initializer);4504 try f.writeCValue(writer, operand, .Initializer);
4463 try writer.writeAll(";\n");4505 try writer.writeAll(";\n");
4464 break :blk operand_local;4506 break :blk operand_local;
4465 } else operand;4507 } else operand;
44664508
4509 const local = try f.allocLocal(0, dest_ty);
4467 try writer.writeAll("memcpy(&");4510 try writer.writeAll("memcpy(&");
4468 try f.writeCValue(writer, local, .Other);4511 try f.writeCValue(writer, local, .Other);
4469 try writer.writeAll(", &");4512 try writer.writeAll(", &");
...@@ -4528,10 +4571,13 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4528,10 +4571,13 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
4528 }4571 }
45294572
4530 if (operand == .constant) {4573 if (operand == .constant) {
4531 try freeLocal(f, inst, operand_lval.new_local, 0);4574 try freeLocal(f, 0, operand_lval.new_local, 0);
4532 }4575 }
45334576
4534 return local;4577 return .{
4578 .c_value = local,
4579 .need_free = true,
4580 };
4535}4581}
45364582
4537fn airTrap(writer: anytype) !CValue {4583fn airTrap(writer: anytype) !CValue {
...@@ -4831,7 +4877,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4831,7 +4877,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4831 const literal = mem.sliceTo(asm_source[src_i..], '%');4877 const literal = mem.sliceTo(asm_source[src_i..], '%');
4832 src_i += literal.len;4878 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);
4835 dst_i += literal.len;4881 dst_i += literal.len;
48364882
4837 if (src_i >= asm_source.len) break;4883 if (src_i >= asm_source.len) break;
...@@ -4856,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4856,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4856 const name = desc[0..colon];4902 const name = desc[0..colon];
4857 const modifier = desc[colon + 1 ..];4903 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);
4860 dst_i += modifier.len;4906 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);
4862 dst_i += name.len;4908 dst_i += name.len;
48634909
4864 src_i += desc.len;4910 src_i += desc.len;
...@@ -6288,15 +6334,19 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6288,15 +6334,19 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6288 }6334 }
6289 try writer.writeAll("; ++");6335 try writer.writeAll("; ++");
6290 try f.writeCValue(writer, index, .Other);6336 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("((");
6292 try f.renderType(writer, elem_ptr_ty);6341 try f.renderType(writer, elem_ptr_ty);
6293 try writer.writeByte(')');6342 try writer.writeByte(')');
6294 try writeSliceOrPtr(f, writer, dest_slice, dest_ty);6343 try writeSliceOrPtr(f, writer, dest_slice, dest_ty);
6295 try writer.writeAll(")[");6344 try writer.writeAll(")[");
6296 try f.writeCValue(writer, index, .Other);6345 try f.writeCValue(writer, index, .Other);
6297 try writer.writeAll("] = ");6346 try writer.writeByte(']');
6298 try f.writeCValue(writer, value, .FunctionArgument);6347 try a.assign(f, writer);
6299 try writer.writeAll(";\n");6348 try f.writeCValue(writer, value, .Other);
6349 try a.end(f, writer);
63006350
6301 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6351 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
6302 try freeLocal(f, inst, index.new_local, 0);6352 try freeLocal(f, inst, index.new_local, 0);
...@@ -6304,12 +6354,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6304,12 +6354,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6304 return .none;6354 return .none;
6305 }6355 }
63066356
6357 const bitcasted = try bitcast(f, Type.u8, value, elem_ty);
6358
6307 try writer.writeAll("memset(");6359 try writer.writeAll("memset(");
6308 switch (dest_ty.ptrSize()) {6360 switch (dest_ty.ptrSize()) {
6309 .Slice => {6361 .Slice => {
6310 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });6362 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });
6311 try writer.writeAll(", ");6363 try writer.writeAll(", ");
6312 try f.writeCValue(writer, value, .FunctionArgument);6364 try f.writeCValue(writer, bitcasted.c_value, .FunctionArgument);
6313 try writer.writeAll(", ");6365 try writer.writeAll(", ");
6314 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });6366 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });
6315 try writer.writeAll(");\n");6367 try writer.writeAll(");\n");
...@@ -6320,11 +6372,12 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6320,11 +6372,12 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63206372
6321 try f.writeCValue(writer, dest_slice, .FunctionArgument);6373 try f.writeCValue(writer, dest_slice, .FunctionArgument);
6322 try writer.writeAll(", ");6374 try writer.writeAll(", ");
6323 try f.writeCValue(writer, value, .FunctionArgument);6375 try f.writeCValue(writer, bitcasted.c_value, .FunctionArgument);
6324 try writer.print(", {d});\n", .{len});6376 try writer.print(", {d});\n", .{len});
6325 },6377 },
6326 .Many, .C => unreachable,6378 .Many, .C => unreachable,
6327 }6379 }
6380 try bitcasted.free(f);
6328 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6381 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
6329 return .none;6382 return .none;
6330}6383}
...@@ -7394,7 +7447,7 @@ fn formatIntLiteral(...@@ -7394,7 +7447,7 @@ fn formatIntLiteral(
7394 var int_buf: Value.BigIntSpace = undefined;7447 var int_buf: Value.BigIntSpace = undefined;
7395 const int = if (data.val.isUndefDeep()) blk: {7448 const int = if (data.val.isUndefDeep()) blk: {
7396 undef_limbs = try allocator.alloc(BigIntLimb, BigInt.calcTwosCompLimbCount(data.int_info.bits));7449 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
7399 var undef_int = BigInt.Mutable{7452 var undef_int = BigInt.Mutable{
7400 .limbs = undef_limbs,7453 .limbs = undef_limbs,
...@@ -7489,7 +7542,7 @@ fn formatIntLiteral(...@@ -7489,7 +7542,7 @@ fn formatIntLiteral(
7489 } else {7542 } else {
7490 try data.cty.renderLiteralPrefix(writer, data.kind);7543 try data.cty.renderLiteralPrefix(writer, data.kind);
7491 wrap.convertToTwosComplement(int, data.int_info.signedness, c_bits);7544 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);
7493 wrap.len = wrap.limbs.len;7546 wrap.len = wrap.limbs.len;
7494 const limbs_per_c_limb = @divExact(wrap.len, c_limb_info.count);7547 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 {...@@ -7939,11 +7939,15 @@ pub const FuncGen = struct {
7939 return self.builder.buildPtrToInt(operand_ptr, dest_llvm_ty, "");7939 return self.builder.buildPtrToInt(operand_ptr, dest_llvm_ty, "");
7940 }7940 }
79417941
7942 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {7942 fn airBitCast(self: *FuncGen, inst: Air.Inst.Index) !*llvm.Value {
7943 const ty_op = self.air.instructions.items(.data)[inst].ty_op;7943 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
7944 const operand_ty = self.air.typeOf(ty_op.operand);7944 const operand_ty = self.air.typeOf(ty_op.operand);
7945 const inst_ty = self.air.typeOfIndex(inst);7945 const inst_ty = self.air.typeOfIndex(inst);
7946 const operand = try self.resolveInst(ty_op.operand);7946 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 {
7947 const operand_is_ref = isByRef(operand_ty);7951 const operand_is_ref = isByRef(operand_ty);
7948 const result_is_ref = isByRef(inst_ty);7952 const result_is_ref = isByRef(inst_ty);
7949 const llvm_dest_ty = try self.dg.lowerType(inst_ty);7953 const llvm_dest_ty = try self.dg.lowerType(inst_ty);
...@@ -7954,6 +7958,12 @@ pub const FuncGen = struct {...@@ -7954,6 +7958,12 @@ pub const FuncGen = struct {
7954 return operand;7958 return operand;
7955 }7959 }
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
7957 if (operand_ty.zigTypeTag() == .Int and inst_ty.isPtrAtRuntime()) {7967 if (operand_ty.zigTypeTag() == .Int and inst_ty.isPtrAtRuntime()) {
7958 return self.builder.buildIntToPtr(operand, llvm_dest_ty, "");7968 return self.builder.buildIntToPtr(operand, llvm_dest_ty, "");
7959 }7969 }
...@@ -8414,27 +8424,45 @@ pub const FuncGen = struct {...@@ -8414,27 +8424,45 @@ pub const FuncGen = struct {
8414 const dest_slice = try self.resolveInst(bin_op.lhs);8424 const dest_slice = try self.resolveInst(bin_op.lhs);
8415 const ptr_ty = self.air.typeOf(bin_op.lhs);8425 const ptr_ty = self.air.typeOf(bin_op.lhs);
8416 const elem_ty = self.air.typeOf(bin_op.rhs);8426 const elem_ty = self.air.typeOf(bin_op.rhs);
8417 const target = self.dg.module.getTarget();8427 const module = self.dg.module;
8418 const val_is_undef = if (self.air.value(bin_op.rhs)) |val| val.isUndefDeep() else false;8428 const target = module.getTarget();
8419 const dest_ptr_align = ptr_ty.ptrAlignment(target);8429 const dest_ptr_align = ptr_ty.ptrAlignment(target);
8420 const u8_llvm_ty = self.context.intType(8);8430 const u8_llvm_ty = self.context.intType(8);
8421 const dest_ptr = self.sliceOrArrayPtr(dest_slice, ptr_ty);8431 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) {8446 if (safety and module.comp.bin_file.options.valgrind) {
8424 // Even if safety is disabled, we still emit a memset to undefined since it conveys8447 self.valgrindMarkUndef(dest_ptr, len);
8425 // extra information to LLVM. However, safety makes the difference between using8448 }
8426 // 0xaa or actual undefined for the fill byte.8449 return null;
8427 const fill_byte = if (safety)8450 }
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());
84338451
8434 if (safety and self.dg.module.comp.bin_file.options.valgrind) {8452 // Test if the element value is compile-time known to be a
8435 self.valgrindMarkUndef(dest_ptr, len);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;
8436 }8465 }
8437 return null;
8438 }8466 }
84398467
8440 const value = try self.resolveInst(bin_op.rhs);8468 const value = try self.resolveInst(bin_op.rhs);
...@@ -8442,9 +8470,9 @@ pub const FuncGen = struct {...@@ -8442,9 +8470,9 @@ pub const FuncGen = struct {
84428470
8443 if (elem_abi_size == 1) {8471 if (elem_abi_size == 1) {
8444 // In this case we can take advantage of LLVM's intrinsic.8472 // 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);
8446 const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);8474 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);
8448 return null;8476 return null;
8449 }8477 }
84508478
...@@ -8486,8 +8514,22 @@ pub const FuncGen = struct {...@@ -8486,8 +8514,22 @@ pub const FuncGen = struct {
8486 _ = self.builder.buildCondBr(end, body_block, end_block);8514 _ = self.builder.buildCondBr(end, body_block, end_block);
84878515
8488 self.builder.positionBuilderAtEnd(body_block);8516 self.builder.positionBuilderAtEnd(body_block);
8489 const store_inst = self.builder.buildStore(value, it_ptr);8517 const elem_abi_alignment = elem_ty.abiAlignment(target);
8490 store_inst.setAlignment(@min(elem_ty.abiAlignment(target), dest_ptr_align));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 }
8491 const one_gep = [_]*llvm.Value{llvm_usize_ty.constInt(1, .False)};8533 const one_gep = [_]*llvm.Value{llvm_usize_ty.constInt(1, .False)};
8492 const next_ptr = self.builder.buildInBoundsGEP(elem_llvm_ty, it_ptr, &one_gep, one_gep.len, "");8534 const next_ptr = self.builder.buildInBoundsGEP(elem_llvm_ty, it_ptr, &one_gep, one_gep.len, "");
8493 _ = self.builder.buildBr(loop_block);8535 _ = self.builder.buildBr(loop_block);
src/link/Coff.zig+27-15
...@@ -1916,7 +1916,7 @@ fn writeImportTables(self: *Coff) !void {...@@ -1916,7 +1916,7 @@ fn writeImportTables(self: *Coff) !void {
1916 .name_rva = header.virtual_address + dll_names_offset,1916 .name_rva = header.virtual_address + dll_names_offset,
1917 .import_address_table_rva = header.virtual_address + iat_offset,1917 .import_address_table_rva = header.virtual_address + iat_offset,
1918 };1918 };
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));
1920 dir_table_offset += dir_header_size;1920 dir_table_offset += dir_header_size;
19211921
1922 for (itable.entries.items) |entry| {1922 for (itable.entries.items) |entry| {
...@@ -1924,15 +1924,21 @@ fn writeImportTables(self: *Coff) !void {...@@ -1924,15 +1924,21 @@ fn writeImportTables(self: *Coff) !void {
19241924
1925 // IAT and lookup table entry1925 // IAT and lookup table entry
1926 const lookup = coff.ImportLookupEntry64.ByName{ .name_table_rva = @intCast(u31, header.virtual_address + names_table_offset) };1926 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 );
1928 iat_offset += lookup_entry_size;1931 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 );
1930 lookup_table_offset += lookup_entry_size;1936 lookup_table_offset += lookup_entry_size;
19311937
1932 // Names table entry1938 // Names table entry
1933 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // Hint set to 0 until we learn how to parse DLLs1939 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // Hint set to 0 until we learn how to parse DLLs
1934 names_table_offset += 2;1940 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);
1936 names_table_offset += @intCast(u32, import_name.len);1942 names_table_offset += @intCast(u32, import_name.len);
1937 buffer.items[names_table_offset] = 0;1943 buffer.items[names_table_offset] = 0;
1938 names_table_offset += 1;1944 names_table_offset += 1;
...@@ -1947,13 +1953,16 @@ fn writeImportTables(self: *Coff) !void {...@@ -1947,13 +1953,16 @@ fn writeImportTables(self: *Coff) !void {
1947 iat_offset += 8;1953 iat_offset += 8;
19481954
1949 // Lookup table sentinel1955 // 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 );
1951 lookup_table_offset += lookup_entry_size;1960 lookup_table_offset += lookup_entry_size;
19521961
1953 // DLL name1962 // 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);
1955 dll_names_offset += @intCast(u32, lib_name.len);1964 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);
1957 dll_names_offset += @intCast(u32, ext.len);1966 dll_names_offset += @intCast(u32, ext.len);
1958 buffer.items[dll_names_offset] = 0;1967 buffer.items[dll_names_offset] = 0;
1959 dll_names_offset += 1;1968 dll_names_offset += 1;
...@@ -1967,7 +1976,10 @@ fn writeImportTables(self: *Coff) !void {...@@ -1967,7 +1976,10 @@ fn writeImportTables(self: *Coff) !void {
1967 .name_rva = 0,1976 .name_rva = 0,
1968 .import_address_table_rva = 0,1977 .import_address_table_rva = 0,
1969 };1978 };
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 );
1971 dir_table_offset += dir_header_size;1983 dir_table_offset += dir_header_size;
19721984
1973 assert(dll_names_offset == needed_size);1985 assert(dll_names_offset == needed_size);
...@@ -2366,13 +2378,13 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In...@@ -2366,13 +2378,13 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In
23662378
2367fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {2379fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {
2368 if (name.len <= 8) {2380 if (name.len <= 8) {
2369 mem.copy(u8, &header.name, name);2381 @memcpy(header.name[0..name.len], name);
2370 mem.set(u8, header.name[name.len..], 0);2382 @memset(header.name[name.len..], 0);
2371 return;2383 return;
2372 }2384 }
2373 const offset = try self.strtab.insert(self.base.allocator, name);2385 const offset = try self.strtab.insert(self.base.allocator, name);
2374 const name_offset = fmt.bufPrint(&header.name, "/{d}", .{offset}) catch unreachable;2386 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);
2376}2388}
23772389
2378fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {2390fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {
...@@ -2385,17 +2397,17 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const...@@ -2385,17 +2397,17 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const
23852397
2386fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {2398fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {
2387 if (name.len <= 8) {2399 if (name.len <= 8) {
2388 mem.copy(u8, &symbol.name, name);2400 @memcpy(symbol.name[0..name.len], name);
2389 mem.set(u8, symbol.name[name.len..], 0);2401 @memset(symbol.name[name.len..], 0);
2390 return;2402 return;
2391 }2403 }
2392 const offset = try self.strtab.insert(self.base.allocator, name);2404 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);
2394 mem.writeIntLittle(u32, symbol.name[4..8], offset);2406 mem.writeIntLittle(u32, symbol.name[4..8], offset);
2395}2407}
23962408
2397fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {2409fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {
2398 mem.set(u8, buf[0..4], '_');2410 @memset(buf[0..4], '_');
2399 switch (sym.section_number) {2411 switch (sym.section_number) {
2400 .UNDEFINED => {2412 .UNDEFINED => {
2401 buf[3] = 'u';2413 buf[3] = 'u';
src/link/Dwarf.zig+15-12
...@@ -1189,7 +1189,7 @@ pub fn commitDeclState(...@@ -1189,7 +1189,7 @@ pub fn commitDeclState(
1189 if (needed_size > segment_size) {1189 if (needed_size > segment_size) {
1190 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});1190 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});
1191 try debug_line.resize(self.allocator, needed_size);1191 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);
1193 }1193 }
1194 debug_line.items.len = needed_size;1194 debug_line.items.len = needed_size;
1195 }1195 }
...@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons...@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
1458 if (needed_size > segment_size) {1458 if (needed_size > segment_size) {
1459 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});1459 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});
1460 try debug_info.resize(self.allocator, needed_size);1460 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);
1462 }1462 }
1463 debug_info.items.len = needed_size;1463 debug_info.items.len = needed_size;
1464 }1464 }
...@@ -1515,7 +1515,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, module: *Module, decl_index: Module.De...@@ -1515,7 +1515,7 @@ pub fn updateDeclLineNumber(self: *Dwarf, module: *Module, decl_index: Module.De
1515 const wasm_file = self.bin_file.cast(File.Wasm).?;1515 const wasm_file = self.bin_file.cast(File.Wasm).?;
1516 const offset = atom.off + self.getRelocDbgLineOff();1516 const offset = atom.off + self.getRelocDbgLineOff();
1517 const line_atom_index = wasm_file.debug_line_atom.?;1517 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;
1519 },1519 },
1520 else => unreachable,1520 else => unreachable,
1521 }1521 }
...@@ -1734,7 +1734,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {...@@ -1734,7 +1734,7 @@ pub fn writeDbgAbbrev(self: *Dwarf) !void {
1734 const wasm_file = self.bin_file.cast(File.Wasm).?;1734 const wasm_file = self.bin_file.cast(File.Wasm).?;
1735 const debug_abbrev = &wasm_file.getAtomPtr(wasm_file.debug_abbrev_atom.?).code;1735 const debug_abbrev = &wasm_file.getAtomPtr(wasm_file.debug_abbrev_atom.?).code;
1736 try debug_abbrev.resize(wasm_file.base.allocator, needed_size);1736 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;
1738 },1738 },
1739 else => unreachable,1739 else => unreachable,
1740 }1740 }
...@@ -1976,7 +1976,7 @@ fn writeDbgLineNopsBuffered(...@@ -1976,7 +1976,7 @@ fn writeDbgLineNopsBuffered(
1976 }1976 }
1977 }1977 }
19781978
1979 mem.copy(u8, buf[offset..], content);1979 @memcpy(buf[offset..][0..content.len], content);
19801980
1981 {1981 {
1982 var padding_left = next_padding_size;1982 var padding_left = next_padding_size;
...@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(...@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(
2076 buffer.items.len,2076 buffer.items.len,
2077 offset + content.len + next_padding_size + 1,2077 offset + content.len + next_padding_size + 1,
2078 ));2078 ));
2079 mem.set(u8, buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));2079 @memset(buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));
2080 mem.copy(u8, buffer.items[offset..], content);2080 @memcpy(buffer.items[offset..][0..content.len], content);
2081 mem.set(u8, buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));2081 @memset(buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));
20822082
2083 if (trailing_zero) {2083 if (trailing_zero) {
2084 buffer.items[offset + content.len + next_padding_size] = 0;2084 buffer.items[offset + content.len + next_padding_size] = 0;
...@@ -2168,7 +2168,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {...@@ -2168,7 +2168,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
2168 const wasm_file = self.bin_file.cast(File.Wasm).?;2168 const wasm_file = self.bin_file.cast(File.Wasm).?;
2169 const debug_ranges = &wasm_file.getAtomPtr(wasm_file.debug_ranges_atom.?).code;2169 const debug_ranges = &wasm_file.getAtomPtr(wasm_file.debug_ranges_atom.?).code;
2170 try debug_ranges.resize(wasm_file.base.allocator, needed_size);2170 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);
2172 },2172 },
2173 else => unreachable,2173 else => unreachable,
2174 }2174 }
...@@ -2341,9 +2341,12 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2341,9 +2341,12 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2341 .wasm => {2341 .wasm => {
2342 const wasm_file = self.bin_file.cast(File.Wasm).?;2342 const wasm_file = self.bin_file.cast(File.Wasm).?;
2343 const debug_line = &wasm_file.getAtomPtr(wasm_file.debug_line_atom.?).code;2343 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 }
2345 try debug_line.resize(self.allocator, debug_line.items.len + delta);2348 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);
2347 },2350 },
2348 else => unreachable,2351 else => unreachable,
2349 }2352 }
...@@ -2537,7 +2540,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {...@@ -2537,7 +2540,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
2537 .wasm => {2540 .wasm => {
2538 const wasm_file = self.bin_file.cast(File.Wasm).?;2541 const wasm_file = self.bin_file.cast(File.Wasm).?;
2539 const debug_info = wasm_file.getAtomPtr(wasm_file.debug_info_atom.?).code;2542 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;
2541 },2544 },
2542 else => unreachable,2545 else => unreachable,
2543 }2546 }
src/link/Elf.zig+1-1
...@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {...@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {
1997 // OS ABI, often set to 0 regardless of target platform1997 // OS ABI, often set to 0 regardless of target platform
1998 // ABI Version, possibly used by glibc but not by static executables1998 // ABI Version, possibly used by glibc but not by static executables
1999 // padding1999 // padding
2000 mem.set(u8, hdr_buf[index..][0..9], 0);2000 @memset(hdr_buf[index..][0..9], 0);
2001 index += 9;2001 index += 9;
20022002
2003 assert(index == 16);2003 assert(index == 16);
src/link/MachO.zig+7-8
...@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S...@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S
1454 });1454 });
14551455
1456 var code: [size]u8 = undefined;1456 var code: [size]u8 = undefined;
1457 mem.set(u8, &code, 0);1457 @memset(&code, 0);
1458 try self.writeAtom(atom_index, &code);1458 try self.writeAtom(atom_index, &code);
14591459
1460 return atom_index;1460 return atom_index;
...@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {...@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {
32343234
3235 var buffer = try gpa.alloc(u8, needed_size);3235 var buffer = try gpa.alloc(u8, needed_size);
3236 defer gpa.free(buffer);3236 defer gpa.free(buffer);
3237 mem.set(u8, buffer, 0);3237 @memset(buffer, 0);
32383238
3239 var stream = std.io.fixedBufferStream(buffer);3239 var stream = std.io.fixedBufferStream(buffer);
3240 const writer = stream.writer();3240 const writer = stream.writer();
...@@ -3389,8 +3389,8 @@ fn writeStrtab(self: *MachO) !void {...@@ -3389,8 +3389,8 @@ fn writeStrtab(self: *MachO) !void {
33893389
3390 const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);3390 const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
3391 defer gpa.free(buffer);3391 defer gpa.free(buffer);
3392 mem.set(u8, buffer, 0);3392 @memcpy(buffer[0..self.strtab.buffer.items.len], self.strtab.buffer.items);
3393 mem.copy(u8, buffer, self.strtab.buffer.items);3393 @memset(buffer[self.strtab.buffer.items.len..], 0);
33943394
3395 try self.base.file.?.pwriteAll(buffer, offset);3395 try self.base.file.?.pwriteAll(buffer, offset);
33963396
...@@ -3668,8 +3668,7 @@ fn addUndefined(self: *MachO, name: []const u8, action: ResolveAction.Kind) !u32...@@ -3668,8 +3668,7 @@ fn addUndefined(self: *MachO, name: []const u8, action: ResolveAction.Kind) !u32
36683668
3669pub fn makeStaticString(bytes: []const u8) [16]u8 {3669pub fn makeStaticString(bytes: []const u8) [16]u8 {
3670 var buf = [_]u8{0} ** 16;3670 var buf = [_]u8{0} ** 16;
3671 assert(bytes.len <= buf.len);3671 @memcpy(buf[0..bytes.len], bytes);
3672 mem.copy(u8, &buf, bytes);
3673 return buf;3672 return buf;
3674}3673}
36753674
...@@ -4096,8 +4095,8 @@ pub fn logSections(self: *MachO) void {...@@ -4096,8 +4095,8 @@ pub fn logSections(self: *MachO) void {
4096}4095}
40974096
4098fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {4097fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
4099 mem.set(u8, buf[0..4], '_');4098 @memset(buf[0..4], '_');
4100 mem.set(u8, buf[4..], ' ');4099 @memset(buf[4..], ' ');
4101 if (sym.sect()) {4100 if (sym.sect()) {
4102 buf[0] = 's';4101 buf[0] = 's';
4103 }4102 }
src/link/MachO/CodeSignature.zig+1-1
...@@ -100,7 +100,7 @@ const CodeDirectory = struct {...@@ -100,7 +100,7 @@ const CodeDirectory = struct {
100 fn addSpecialHash(self: *CodeDirectory, index: u32, hash: [hash_size]u8) void {100 fn addSpecialHash(self: *CodeDirectory, index: u32, hash: [hash_size]u8) void {
101 assert(index > 0);101 assert(index > 0);
102 self.inner.nSpecialSlots = std.math.max(self.inner.nSpecialSlots, index);102 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;
104 }104 }
105105
106 fn slotType(self: CodeDirectory) u32 {106 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)...@@ -156,7 +156,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
156156
157 // Prepopulate relocations per section lookup table.157 // Prepopulate relocations per section lookup table.
158 try self.section_relocs_lookup.resize(allocator, nsects);158 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
161 // Parse symtab.161 // Parse symtab.
162 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {162 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)...@@ -189,10 +189,10 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
189 };189 };
190 }190 }
191191
192 mem.set(i64, self.globals_lookup, -1);192 @memset(self.globals_lookup, -1);
193 mem.set(AtomIndex, self.atom_by_index_table, 0);193 @memset(self.atom_by_index_table, 0);
194 mem.set(Entry, self.source_section_index_lookup, .{});194 @memset(self.source_section_index_lookup, .{});
195 mem.set(Entry, self.relocs_lookup, .{});195 @memset(self.relocs_lookup, .{});
196196
197 // You would expect that the symbol table is at least pre-sorted based on symbol's type:197 // You would expect that the symbol table is at least pre-sorted based on symbol's type:
198 // local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance,198 // 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)...@@ -252,7 +252,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
252 self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");252 self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");
253 if (self.hasUnwindRecords()) {253 if (self.hasUnwindRecords()) {
254 self.unwind_relocs_lookup = try allocator.alloc(Record, self.getUnwindRecords().len);254 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 = .{} });
256 }256 }
257}257}
258258
src/link/MachO/Trie.zig+1-1
...@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {...@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
499 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;499 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
500 var padding = try testing.allocator.alloc(u8, idx + 5);500 var padding = try testing.allocator.alloc(u8, idx + 5);
501 defer testing.allocator.free(padding);501 defer testing.allocator.free(padding);
502 mem.set(u8, padding, ' ');502 @memset(padding, ' ');
503 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });503 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
504 return error.TestFailed;504 return error.TestFailed;
505}505}
src/link/MachO/UnwindInfo.zig+1-1
...@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {...@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
659 const padding = buffer.items.len - cwriter.bytes_written;659 const padding = buffer.items.len - cwriter.bytes_written;
660 if (padding > 0) {660 if (padding > 0) {
661 const offset = math.cast(usize, cwriter.bytes_written) orelse return error.Overflow;661 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);
663 }663 }
664664
665 try zld.file.pwriteAll(buffer.items, sect.offset);665 try zld.file.pwriteAll(buffer.items, sect.offset);
src/link/MachO/zld.zig+11-9
...@@ -2140,7 +2140,7 @@ pub const Zld = struct {...@@ -2140,7 +2140,7 @@ pub const Zld = struct {
21402140
2141 var buffer = try gpa.alloc(u8, needed_size);2141 var buffer = try gpa.alloc(u8, needed_size);
2142 defer gpa.free(buffer);2142 defer gpa.free(buffer);
2143 mem.set(u8, buffer, 0);2143 @memset(buffer, 0);
21442144
2145 var stream = std.io.fixedBufferStream(buffer);2145 var stream = std.io.fixedBufferStream(buffer);
2146 const writer = stream.writer();2146 const writer = stream.writer();
...@@ -2352,8 +2352,11 @@ pub const Zld = struct {...@@ -2352,8 +2352,11 @@ pub const Zld = struct {
23522352
2353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);2353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
2354 defer self.gpa.free(buffer);2354 defer self.gpa.free(buffer);
2355 mem.set(u8, buffer, 0);2355 {
2356 mem.copy(u8, buffer, mem.sliceAsBytes(out_dice.items));2356 const src = mem.sliceAsBytes(out_dice.items);
2357 @memcpy(buffer[0..src.len], src);
2358 @memset(buffer[src.len..], 0);
2359 }
23572360
2358 log.debug("writing data-in-code from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });2361 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 {...@@ -2484,8 +2487,8 @@ pub const Zld = struct {
24842487
2485 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);2488 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
2486 defer self.gpa.free(buffer);2489 defer self.gpa.free(buffer);
2487 mem.set(u8, buffer, 0);2490 @memcpy(buffer[0..self.strtab.buffer.items.len], self.strtab.buffer.items);
2488 mem.copy(u8, buffer, self.strtab.buffer.items);2491 @memset(buffer[self.strtab.buffer.items.len..], 0);
24892492
2490 try self.file.pwriteAll(buffer, offset);2493 try self.file.pwriteAll(buffer, offset);
24912494
...@@ -2805,8 +2808,7 @@ pub const Zld = struct {...@@ -2805,8 +2808,7 @@ pub const Zld = struct {
28052808
2806 pub fn makeStaticString(bytes: []const u8) [16]u8 {2809 pub fn makeStaticString(bytes: []const u8) [16]u8 {
2807 var buf = [_]u8{0} ** 16;2810 var buf = [_]u8{0} ** 16;
2808 assert(bytes.len <= buf.len);2811 @memcpy(buf[0..bytes.len], bytes);
2809 mem.copy(u8, &buf, bytes);
2810 return buf;2812 return buf;
2811 }2813 }
28122814
...@@ -3199,7 +3201,7 @@ pub const Zld = struct {...@@ -3199,7 +3201,7 @@ pub const Zld = struct {
3199 scoped_log.debug(" object({d}): {s}", .{ id, object.name });3201 scoped_log.debug(" object({d}): {s}", .{ id, object.name });
3200 if (object.in_symtab == null) continue;3202 if (object.in_symtab == null) continue;
3201 for (object.symtab, 0..) |sym, sym_id| {3203 for (object.symtab, 0..) |sym, sym_id| {
3202 mem.set(u8, &buf, '_');3204 @memset(&buf, '_');
3203 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{3205 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
3204 sym_id,3206 sym_id,
3205 object.getSymbolName(@intCast(u32, sym_id)),3207 object.getSymbolName(@intCast(u32, sym_id)),
...@@ -4007,7 +4009,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr...@@ -4007,7 +4009,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
4007 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });4009 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
4008 var padding = try zld.gpa.alloc(u8, size);4010 var padding = try zld.gpa.alloc(u8, size);
4009 defer zld.gpa.free(padding);4011 defer zld.gpa.free(padding);
4010 mem.set(u8, padding, 0);4012 @memset(padding, 0);
4011 try zld.file.pwriteAll(padding, start);4013 try zld.file.pwriteAll(padding, start);
4012 }4014 }
4013 }4015 }
src/link/Plan9.zig+1-1
...@@ -681,7 +681,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No...@@ -681,7 +681,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
681 .pcsz = @intCast(u32, linecountinfo.items.len),681 .pcsz = @intCast(u32, linecountinfo.items.len),
682 .entry = @intCast(u32, self.entry_val.?),682 .entry = @intCast(u32, self.entry_val.?),
683 };683 };
684 std.mem.copy(u8, hdr_slice, self.hdr.toU8s()[0..hdr_size]);684 @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]);
685 // write the fat header for 64 bit entry points685 // write the fat header for 64 bit entry points
686 if (self.sixtyfour_bit) {686 if (self.sixtyfour_bit) {
687 mem.writeIntSliceBig(u64, hdr_buf[32..40], self.entry_val.?);687 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 {...@@ -1976,7 +1976,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
1976 // We do not have to do this when exporting the memory (the default) because the runtime1976 // We do not have to do this when exporting the memory (the default) because the runtime
1977 // will do it for us, and we do not emit the bss segment at all.1977 // will do it for us, and we do not emit the bss segment at all.
1978 if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {1978 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);
1980 }1980 }
19811981
1982 const should_merge = wasm.base.options.output_mode != .Obj;1982 const should_merge = wasm.base.options.output_mode != .Obj;
...@@ -3852,7 +3852,10 @@ fn writeToFile(...@@ -3852,7 +3852,10 @@ fn writeToFile(
3852 // Only when writing all sections executed properly we write the magic3852 // Only when writing all sections executed properly we write the magic
3853 // bytes. This allows us to easily detect what went wrong while generating3853 // bytes. This allows us to easily detect what went wrong while generating
3854 // the final binary.3854 // 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
3857 // finally, write the entire binary into the file.3860 // finally, write the entire binary into the file.
3858 var iovec = [_]std.os.iovec_const{.{3861 var iovec = [_]std.os.iovec_const{.{
...@@ -4559,14 +4562,14 @@ fn writeVecSectionHeader(buffer: []u8, offset: u32, section: std.wasm.Section, s...@@ -4559,14 +4562,14 @@ fn writeVecSectionHeader(buffer: []u8, offset: u32, section: std.wasm.Section, s
4559 buf[0] = @enumToInt(section);4562 buf[0] = @enumToInt(section);
4560 leb.writeUnsignedFixed(5, buf[1..6], size);4563 leb.writeUnsignedFixed(5, buf[1..6], size);
4561 leb.writeUnsignedFixed(5, buf[6..], items);4564 leb.writeUnsignedFixed(5, buf[6..], items);
4562 mem.copy(u8, buffer[offset..], &buf);4565 buffer[offset..][0..buf.len].* = buf;
4563}4566}
45644567
4565fn writeCustomSectionHeader(buffer: []u8, offset: u32, size: u32) !void {4568fn writeCustomSectionHeader(buffer: []u8, offset: u32, size: u32) !void {
4566 var buf: [1 + 5]u8 = undefined;4569 var buf: [1 + 5]u8 = undefined;
4567 buf[0] = 0; // 0 = 'custom' section4570 buf[0] = 0; // 0 = 'custom' section
4568 leb.writeUnsignedFixed(5, buf[1..6], size);4571 leb.writeUnsignedFixed(5, buf[1..6], size);
4569 mem.copy(u8, buffer[offset..], &buf);4572 buffer[offset..][0..buf.len].* = buf;
4570}4573}
45714574
4572fn emitLinkSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), symbol_table: *std.AutoArrayHashMap(SymbolLoc, u32)) !void {4575fn 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 {...@@ -860,7 +860,7 @@ fn ElfFile(comptime is_64: bool) type {
860 if (section.payload) |data| {860 if (section.payload) |data| {
861 switch (section.section.sh_type) {861 switch (section.section.sh_type) {
862 elf.DT_VERSYM => {862 elf.DT_VERSYM => {
863 std.debug.assert(section.section.sh_entsize == @sizeOf(Elf_Verdef));863 assert(section.section.sh_entsize == @sizeOf(Elf_Verdef));
864 const defs = @ptrCast([*]const Elf_Verdef, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(Elf_Verdef)];864 const defs = @ptrCast([*]const Elf_Verdef, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(Elf_Verdef)];
865 for (defs) |def| {865 for (defs) |def| {
866 if (def.vd_ndx != elf.SHN_UNDEF)866 if (def.vd_ndx != elf.SHN_UNDEF)
...@@ -868,7 +868,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -868,7 +868,7 @@ fn ElfFile(comptime is_64: bool) type {
868 }868 }
869 },869 },
870 elf.SHT_SYMTAB, elf.SHT_DYNSYM => {870 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));
872 const syms = @ptrCast([*]const Elf_Sym, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(Elf_Sym)];872 const syms = @ptrCast([*]const Elf_Sym, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(Elf_Sym)];
873873
874 for (syms) |sym| {874 for (syms) |sym| {
...@@ -952,11 +952,11 @@ fn ElfFile(comptime is_64: bool) type {...@@ -952,11 +952,11 @@ fn ElfFile(comptime is_64: bool) type {
952 const name: []const u8 = ".gnu_debuglink";952 const name: []const u8 = ".gnu_debuglink";
953 const new_offset = @intCast(u32, strtab.payload.?.len);953 const new_offset = @intCast(u32, strtab.payload.?.len);
954 const buf = try allocator.alignedAlloc(u8, section_memory_align, new_offset + name.len + 1);954 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.?);955 @memcpy(buf[0..new_offset], strtab.payload.?);
956 std.mem.copy(u8, buf[new_offset .. new_offset + name.len], name);956 @memcpy(buf[new_offset..][0..name.len], name);
957 buf[new_offset + name.len] = 0;957 buf[new_offset + name.len] = 0;
958958
959 std.debug.assert(update.action == .keep);959 assert(update.action == .keep);
960 update.payload = buf;960 update.payload = buf;
961961
962 break :blk new_offset;962 break :blk new_offset;
...@@ -978,9 +978,9 @@ fn ElfFile(comptime is_64: bool) type {...@@ -978,9 +978,9 @@ fn ElfFile(comptime is_64: bool) type {
978 // program header as-is.978 // program header as-is.
979 // nb: for only-debug files, removing it appears to work, but is invalid by ELF specifcation.979 // nb: for only-debug files, removing it appears to work, but is invalid by ELF specifcation.
980 {980 {
981 std.debug.assert(updated_elf_header.e_phoff == @sizeOf(Elf_Ehdr));981 assert(updated_elf_header.e_phoff == @sizeOf(Elf_Ehdr));
982 const data = std.mem.sliceAsBytes(self.program_segments);982 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);
984 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = data, .out_offset = updated_elf_header.e_phoff } });984 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = data, .out_offset = updated_elf_header.e_phoff } });
985 eof_offset = updated_elf_header.e_phoff + @intCast(Elf_OffSize, data.len);985 eof_offset = updated_elf_header.e_phoff + @intCast(Elf_OffSize, data.len);
986 }986 }
...@@ -1006,7 +1006,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1006,7 +1006,7 @@ fn ElfFile(comptime is_64: bool) type {
1006 var dest_section_idx: u32 = 1;1006 var dest_section_idx: u32 = 1;
1007 for (self.sections[1..], sections_update[1..]) |section, update| {1007 for (self.sections[1..], sections_update[1..]) |section, update| {
1008 if (update.action == .strip) continue;1008 if (update.action == .strip) continue;
1009 std.debug.assert(update.remap_idx == dest_section_idx);1009 assert(update.remap_idx == dest_section_idx);
10101010
1011 const src = if (update.section) |*s| s else &section.section;1011 const src = if (update.section) |*s| s else &section.section;
1012 const dest = &dest_sections[dest_section_idx];1012 const dest = &dest_sections[dest_section_idx];
...@@ -1032,7 +1032,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1032,7 +1032,7 @@ fn ElfFile(comptime is_64: bool) type {
1032 fatal("zig objcopy: cannot adjust program segments", .{});1032 fatal("zig objcopy: cannot adjust program segments", .{});
1033 }1033 }
1034 }1034 }
1035 std.debug.assert(dest.sh_addr % addralign == dest.sh_offset % addralign);1035 assert(dest.sh_addr % addralign == dest.sh_offset % addralign);
10361036
1037 if (update.action == .empty)1037 if (update.action == .empty)
1038 dest.sh_type = elf.SHT_NOBITS;1038 dest.sh_type = elf.SHT_NOBITS;
...@@ -1043,7 +1043,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1043,7 +1043,7 @@ fn ElfFile(comptime is_64: bool) type {
1043 const dest_data = switch (src.sh_type) {1043 const dest_data = switch (src.sh_type) {
1044 elf.DT_VERSYM => dst_data: {1044 elf.DT_VERSYM => dst_data: {
1045 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);1045 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
1048 const defs = @ptrCast([*]Elf_Verdef, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Verdef)];1048 const defs = @ptrCast([*]Elf_Verdef, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Verdef)];
1049 for (defs) |*def| {1049 for (defs) |*def| {
...@@ -1055,7 +1055,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1055,7 +1055,7 @@ fn ElfFile(comptime is_64: bool) type {
1055 },1055 },
1056 elf.SHT_SYMTAB, elf.SHT_DYNSYM => dst_data: {1056 elf.SHT_SYMTAB, elf.SHT_DYNSYM => dst_data: {
1057 const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len);1057 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
1060 const syms = @ptrCast([*]Elf_Sym, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Sym)];1060 const syms = @ptrCast([*]Elf_Sym, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(Elf_Sym)];
1061 for (syms) |*sym| {1061 for (syms) |*sym| {
...@@ -1068,7 +1068,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1068,7 +1068,7 @@ fn ElfFile(comptime is_64: bool) type {
1068 else => src_data,1068 else => src_data,
1069 };1069 };
10701070
1071 std.debug.assert(dest_data.len == dest.sh_size);1071 assert(dest_data.len == dest.sh_size);
1072 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = dest_data, .out_offset = dest.sh_offset } });1072 cmdbuf.appendAssumeCapacity(.{ .write_data = .{ .data = dest_data, .out_offset = dest.sh_offset } });
1073 eof_offset = dest.sh_offset + dest.sh_size;1073 eof_offset = dest.sh_offset + dest.sh_size;
1074 } else {1074 } else {
...@@ -1087,9 +1087,9 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1087,9 +1087,9 @@ fn ElfFile(comptime is_64: bool) type {
1087 const payload = payload: {1087 const payload = payload: {
1088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);1088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);
1089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);1089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);
1090 std.mem.copy(u8, buf[0..link.name.len], link.name);1090 @memcpy(buf[0..link.name.len], link.name);
1091 std.mem.set(u8, buf[link.name.len..crc_offset], 0);1091 @memset(buf[link.name.len..crc_offset], 0);
1092 std.mem.copy(u8, buf[crc_offset..], std.mem.asBytes(&link.crc32));1092 @memcpy(buf[crc_offset..], std.mem.asBytes(&link.crc32));
1093 break :payload buf;1093 break :payload buf;
1094 };1094 };
10951095
...@@ -1111,7 +1111,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1111,7 +1111,7 @@ fn ElfFile(comptime is_64: bool) type {
1111 eof_offset += @intCast(Elf_OffSize, payload.len);1111 eof_offset += @intCast(Elf_OffSize, payload.len);
1112 }1112 }
11131113
1114 std.debug.assert(dest_section_idx == new_shnum);1114 assert(dest_section_idx == new_shnum);
1115 break :blk dest_sections;1115 break :blk dest_sections;
1116 };1116 };
11171117
...@@ -1120,7 +1120,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1120,7 +1120,7 @@ fn ElfFile(comptime is_64: bool) type {
1120 const offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr));1120 const offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr));
11211121
1122 const data = std.mem.sliceAsBytes(updated_section_header);1122 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);
1124 updated_elf_header.e_shoff = offset;1124 updated_elf_header.e_shoff = offset;
1125 updated_elf_header.e_shnum = new_shnum;1125 updated_elf_header.e_shnum = new_shnum;
11261126
...@@ -1215,7 +1215,7 @@ const ElfFileHelper = struct {...@@ -1215,7 +1215,7 @@ const ElfFileHelper = struct {
1215 for (cmds) |cmd| {1215 for (cmds) |cmd| {
1216 switch (cmd) {1216 switch (cmd) {
1217 .write_data => |data| {1217 .write_data => |data| {
1218 std.debug.assert(data.out_offset >= offset);1218 assert(data.out_offset >= offset);
1219 if (fused_cmd) |prev| {1219 if (fused_cmd) |prev| {
1220 consolidated.appendAssumeCapacity(prev);1220 consolidated.appendAssumeCapacity(prev);
1221 fused_cmd = null;1221 fused_cmd = null;
...@@ -1227,7 +1227,7 @@ const ElfFileHelper = struct {...@@ -1227,7 +1227,7 @@ const ElfFileHelper = struct {
1227 offset = data.out_offset + data.data.len;1227 offset = data.out_offset + data.data.len;
1228 },1228 },
1229 .copy_range => |range| {1229 .copy_range => |range| {
1230 std.debug.assert(range.out_offset >= offset);1230 assert(range.out_offset >= offset);
1231 if (fused_cmd) |prev| {1231 if (fused_cmd) |prev| {
1232 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)) {1232 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)) {
1233 fused_cmd = .{ .copy_range = .{1233 fused_cmd = .{ .copy_range = .{
src/print_air.zig+1-1
...@@ -846,7 +846,7 @@ const Writer = struct {...@@ -846,7 +846,7 @@ const Writer = struct {
846 else blk: {846 else blk: {
847 const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch847 const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch
848 @panic("out of memory");848 @panic("out of memory");
849 std.mem.set([]const Air.Inst.Index, slice, &.{});849 @memset(slice, &.{});
850 break :blk Liveness.SwitchBrTable{ .deaths = slice };850 break :blk Liveness.SwitchBrTable{ .deaths = slice };
851 };851 };
852 defer w.gpa.free(liveness.deaths);852 defer w.gpa.free(liveness.deaths);
src/print_zir.zig+1-1
...@@ -682,7 +682,7 @@ const Writer = struct {...@@ -682,7 +682,7 @@ const Writer = struct {
682 const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);682 const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);
683 defer self.gpa.free(limbs);683 defer self.gpa.free(limbs);
684684
685 mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);685 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
686 const big_int: std.math.big.int.Const = .{686 const big_int: std.math.big.int.Const = .{
687 .limbs = limbs,687 .limbs = limbs,
688 .positive = true,688 .positive = true,
src/translate_c.zig+1-1
...@@ -113,7 +113,7 @@ const Scope = struct {...@@ -113,7 +113,7 @@ const Scope = struct {
113 const alloc_len = self.statements.items.len + @boolToInt(self.base.parent.?.id == .do_loop);113 const alloc_len = self.statements.items.len + @boolToInt(self.base.parent.?.id == .do_loop);
114 var stmts = try c.arena.alloc(Node, alloc_len);114 var stmts = try c.arena.alloc(Node, alloc_len);
115 stmts.len = self.statements.items.len;115 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);
117 return Tag.block.create(c.arena, .{117 return Tag.block.create(c.arena, .{
118 .label = self.label,118 .label = self.label,
119 .stmts = stmts,119 .stmts = stmts,
src/type.zig+1-1
...@@ -4767,7 +4767,7 @@ pub const Type = extern union {...@@ -4767,7 +4767,7 @@ pub const Type = extern union {
4767 .fn_ccc_void_no_args => return,4767 .fn_ccc_void_no_args => return,
4768 .function => {4768 .function => {
4769 const payload = self.castTag(.function).?.data;4769 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);
4771 },4771 },
47724772
4773 else => unreachable,4773 else => unreachable,
src/value.zig+44-9
...@@ -875,7 +875,7 @@ pub const Value = extern union {...@@ -875,7 +875,7 @@ pub const Value = extern union {
875 .repeated => {875 .repeated => {
876 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));876 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));
877 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));877 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
878 std.mem.set(u8, result, byte);878 @memset(result, byte);
879 return result;879 return result;
880 },880 },
881 .decl_ref => {881 .decl_ref => {
...@@ -1278,12 +1278,16 @@ pub const Value = extern union {...@@ -1278,12 +1278,16 @@ pub const Value = extern union {
1278 ///1278 ///
1279 /// Asserts that buffer.len >= ty.abiSize(). The buffer is allowed to extend past1279 /// Asserts that buffer.len >= ty.abiSize(). The buffer is allowed to extend past
1280 /// the end of the value in memory.1280 /// 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 {
1282 const target = mod.getTarget();1286 const target = mod.getTarget();
1283 const endian = target.cpu.arch.endian();1287 const endian = target.cpu.arch.endian();
1284 if (val.isUndef()) {1288 if (val.isUndef()) {
1285 const size = @intCast(usize, ty.abiSize(target));1289 const size = @intCast(usize, ty.abiSize(target));
1286 std.mem.set(u8, buffer[0..size], 0xaa);1290 @memset(buffer[0..size], 0xaa);
1287 return;1291 return;
1288 }1292 }
1289 switch (ty.zigTypeTag()) {1293 switch (ty.zigTypeTag()) {
...@@ -1345,7 +1349,7 @@ pub const Value = extern union {...@@ -1345,7 +1349,7 @@ pub const Value = extern union {
1345 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);1349 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
1346 },1350 },
1347 .Struct => switch (ty.containerLayout()) {1351 .Struct => switch (ty.containerLayout()) {
1348 .Auto => unreachable, // Sema is supposed to have emitted a compile error already1352 .Auto => return error.IllDefinedMemoryLayout,
1349 .Extern => {1353 .Extern => {
1350 const fields = ty.structFields().values();1354 const fields = ty.structFields().values();
1351 const field_vals = val.castTag(.aggregate).?.data;1355 const field_vals = val.castTag(.aggregate).?.data;
...@@ -1366,20 +1370,20 @@ pub const Value = extern union {...@@ -1366,20 +1370,20 @@ pub const Value = extern union {
1366 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian);1370 std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian);
1367 },1371 },
1368 .Union => switch (ty.containerLayout()) {1372 .Union => switch (ty.containerLayout()) {
1369 .Auto => unreachable,1373 .Auto => return error.IllDefinedMemoryLayout,
1370 .Extern => @panic("TODO implement writeToMemory for extern unions"),1374 .Extern => return error.Unimplemented,
1371 .Packed => {1375 .Packed => {
1372 const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8;1376 const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8;
1373 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);1377 return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
1374 },1378 },
1375 },1379 },
1376 .Pointer => {1380 .Pointer => {
1377 assert(!ty.isSlice()); // No well defined layout.1381 if (ty.isSlice()) return error.IllDefinedMemoryLayout;
1378 if (val.isDeclRef()) return error.ReinterpretDeclRef;1382 if (val.isDeclRef()) return error.ReinterpretDeclRef;
1379 return val.writeToMemory(Type.usize, mod, buffer);1383 return val.writeToMemory(Type.usize, mod, buffer);
1380 },1384 },
1381 .Optional => {1385 .Optional => {
1382 assert(ty.isPtrLikeOptional());1386 if (!ty.isPtrLikeOptional()) return error.IllDefinedMemoryLayout;
1383 var buf: Type.Payload.ElemType = undefined;1387 var buf: Type.Payload.ElemType = undefined;
1384 const child = ty.optionalChild(&buf);1388 const child = ty.optionalChild(&buf);
1385 const opt_val = val.optionalValue();1389 const opt_val = val.optionalValue();
...@@ -1389,7 +1393,7 @@ pub const Value = extern union {...@@ -1389,7 +1393,7 @@ pub const Value = extern union {
1389 return writeToMemory(Value.zero, Type.usize, mod, buffer);1393 return writeToMemory(Value.zero, Type.usize, mod, buffer);
1390 }1394 }
1391 },1395 },
1392 else => @panic("TODO implement writeToMemory for more types"),1396 else => return error.Unimplemented,
1393 }1397 }
1394 }1398 }
13951399
...@@ -2785,6 +2789,7 @@ pub const Value = extern union {...@@ -2785,6 +2789,7 @@ pub const Value = extern union {
2785 .field_ptr => isComptimeMutablePtr(val.castTag(.field_ptr).?.data.container_ptr),2789 .field_ptr => isComptimeMutablePtr(val.castTag(.field_ptr).?.data.container_ptr),
2786 .eu_payload_ptr => isComptimeMutablePtr(val.castTag(.eu_payload_ptr).?.data.container_ptr),2790 .eu_payload_ptr => isComptimeMutablePtr(val.castTag(.eu_payload_ptr).?.data.container_ptr),
2787 .opt_payload_ptr => isComptimeMutablePtr(val.castTag(.opt_payload_ptr).?.data.container_ptr),2791 .opt_payload_ptr => isComptimeMutablePtr(val.castTag(.opt_payload_ptr).?.data.container_ptr),
2792 .slice => isComptimeMutablePtr(val.castTag(.slice).?.data.ptr),
27882793
2789 else => false,2794 else => false,
2790 };2795 };
...@@ -5381,6 +5386,36 @@ pub const Value = extern union {...@@ -5381,6 +5386,36 @@ pub const Value = extern union {
5381 }5386 }
5382 }5387 }
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
5384 /// This type is not copyable since it may contain pointers to its inner data.5419 /// This type is not copyable since it may contain pointers to its inner data.
5385 pub const Payload = struct {5420 pub const Payload = struct {
5386 tag: Tag,5421 tag: Tag,
stage1/zig.h+8
...@@ -188,6 +188,14 @@ typedef char bool;...@@ -188,6 +188,14 @@ typedef char bool;
188#define zig_export(sig, symbol, name) __asm(name " = " symbol)188#define zig_export(sig, symbol, name) __asm(name " = " symbol)
189#endif189#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
191#if zig_has_builtin(trap)199#if zig_has_builtin(trap)
192#define zig_trap() __builtin_trap()200#define zig_trap() __builtin_trap()
193#elif _MSC_VER && (_M_IX86 || _M_X64)201#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 {...@@ -177,6 +177,8 @@ test {
177 _ = @import("behavior/math.zig");177 _ = @import("behavior/math.zig");
178 _ = @import("behavior/maximum_minimum.zig");178 _ = @import("behavior/maximum_minimum.zig");
179 _ = @import("behavior/member_func.zig");179 _ = @import("behavior/member_func.zig");
180 _ = @import("behavior/memcpy.zig");
181 _ = @import("behavior/memset.zig");
180 _ = @import("behavior/merge_error_sets.zig");182 _ = @import("behavior/merge_error_sets.zig");
181 _ = @import("behavior/muladd.zig");183 _ = @import("behavior/muladd.zig");
182 _ = @import("behavior/namespace_depends_on_compile_var.zig");184 _ = @import("behavior/namespace_depends_on_compile_var.zig");
test/behavior/basic.zig-90
...@@ -353,96 +353,6 @@ fn f2(x: bool) []const u8 {...@@ -353,96 +353,6 @@ fn f2(x: bool) []const u8 {
353 return (if (x) &fA else &fB)();353 return (if (x) &fA else &fB)();
354}354}
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
446test "variable is allowed to be a pointer to an opaque type" {356test "variable is allowed to be a pointer to an opaque type" {
447 var x: i32 = 1234;357 var x: i32 = 1234;
448 _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));358 _ = 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}