authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-27 15:40:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 13:24:43-07:00
log42973d73e6b045f242cc67015fba023ff46e9929
tree6b8e24acc670e86a6fc97ab5012ba02e348e6824
parent125221cce9e985e9062f7b599431f3ff50ed79eb

compiler: use `@memcpy` instead of `std.mem.copy`


15 files changed, 82 insertions(+), 61 deletions(-)

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/Liveness.zig+3-3
...@@ -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
src/arch/x86_64/Encoding.zig+4-2
...@@ -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 an 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/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/link/Coff.zig+22-10
...@@ -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,7 +2378,7 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In...@@ -2366,7 +2378,7 @@ 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 @memset(header.name[name.len..], 0);2382 @memset(header.name[name.len..], 0);
2371 return;2383 return;
2372 }2384 }
...@@ -2385,7 +2397,7 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const...@@ -2385,7 +2397,7 @@ 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 @memset(symbol.name[name.len..], 0);2401 @memset(symbol.name[name.len..], 0);
2390 return;2402 return;
2391 }2403 }
src/link/Dwarf.zig+11-8
...@@ -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;
...@@ -2077,7 +2077,7 @@ fn writeDbgInfoNopsToArrayList(...@@ -2077,7 +2077,7 @@ fn writeDbgInfoNopsToArrayList(
2077 offset + content.len + next_padding_size + 1,2077 offset + content.len + next_padding_size + 1,
2078 ));2078 ));
2079 @memset(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 @memset(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) {
...@@ -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/MachO.zig+3-4
...@@ -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 @memset(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
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/zld.zig+8-6
...@@ -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 @memset(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 @memset(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
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+6-3
...@@ -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+18-18
...@@ -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 @memset(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/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,