authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-06-25 02:47:48-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:14-04:00
log6abf1fbfe6f7f3c06e70e331a3c9e5101624d501
tree6f2b2b0adfe08900a864b6888590c5f17043a483
parent84a1244b6c8d8b093d514cf267c832ad24d4400f

update to new builtin syntax


5 files changed, 26 insertions(+), 30 deletions(-)

lib/std/debug.zig+4-4
......@@ -987,7 +987,7 @@ pub fn readElfDebugInfo(
987987
988988 if (mem.eql(u8, name, ".gnu_debuglink")) {
989989 const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
990 const debug_filename = mem.sliceTo(@ptrCast([*:0]const u8, gnu_debuglink.ptr), 0);
990 const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0);
991991 const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr);
992992 const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4];
993993 separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes);
......@@ -1535,7 +1535,7 @@ pub const DebugInfo = struct {
15351535 switch (phdr.p_type) {
15361536 elf.PT_NOTE => {
15371537 // Look for .note.gnu.build-id
1538 const note_bytes = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
1538 const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
15391539 const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]);
15401540 if (name_size != 4) continue;
15411541 const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]);
......@@ -1545,7 +1545,7 @@ pub const DebugInfo = struct {
15451545 context.build_id = note_bytes[16..][0..desc_size];
15461546 },
15471547 elf.PT_GNU_EH_FRAME => {
1548 context.gnu_eh_frame = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
1548 context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
15491549 },
15501550 else => {},
15511551 }
......@@ -2094,7 +2094,7 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void
20942094 .arm,
20952095 .aarch64,
20962096 => {
2097 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
2097 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
20982098 dumpStackTraceFromBase(ctx);
20992099 },
21002100 else => {},
lib/std/dwarf.zig+8-12
......@@ -1538,9 +1538,7 @@ pub const DwarfInfo = struct {
15381538 .cie => {
15391539 const cie = try CommonInformationEntry.parse(
15401540 entry_header.entry_bytes,
1541 -@intCast(isize, @intFromPtr(binary_mem.ptr)),
1542 //@ptrToInt(eh_frame.ptr),
1543 //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
1541 -@as(i64, @intCast(@intFromPtr(binary_mem.ptr))),
15441542 true,
15451543 entry_header.length_offset,
15461544 @sizeOf(usize),
......@@ -1552,9 +1550,7 @@ pub const DwarfInfo = struct {
15521550 const cie = di.cie_map.get(cie_offset) orelse return badDwarf();
15531551 const fde = try FrameDescriptionEntry.parse(
15541552 entry_header.entry_bytes,
1555 -@intCast(isize, @intFromPtr(binary_mem.ptr)),
1556 //@ptrToInt(eh_frame.ptr),
1557 //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
1553 -@as(i64, @intCast(@intFromPtr(binary_mem.ptr))),
15581554 true,
15591555 cie,
15601556 @sizeOf(usize),
......@@ -1783,10 +1779,10 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
17831779 };
17841780
17851781 const ptr = if (base) |b| switch (value) {
1786 .signed => |s| @intCast(u64, s + @intCast(i64, b)),
1782 .signed => |s| @as(u64, @intCast(s + @as(i64, @intCast(b)))),
17871783 .unsigned => |u| u + b,
17881784 } else switch (value) {
1789 .signed => |s| @intCast(u64, s),
1785 .signed => |s| @as(u64, @intCast(s)),
17901786 .unsigned => |u| u,
17911787 };
17921788
......@@ -1798,7 +1794,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
17981794
17991795 const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow;
18001796 return switch (addr_size_bytes) {
1801 2, 4, 8 => return @ptrFromInt(*const usize, native_ptr).*,
1797 2, 4, 8 => return @as(*const usize, @ptrFromInt(native_ptr)).*,
18021798 else => return error.UnsupportedAddrSize,
18031799 };
18041800 } else {
......@@ -1903,7 +1899,7 @@ pub const ExceptionFrameHeader = struct {
19031899 if (self.isValidPtr(fde_ptr + 11, isValidMemory, eh_frame_len)) fde_entry_header_len = 12;
19041900
19051901 // Even if eh_frame_len is not specified, all ranges accssed are checked by isValidPtr
1906 const eh_frame = @ptrFromInt([*]const u8, self.eh_frame_ptr)[0..eh_frame_len orelse math.maxInt(u32)];
1902 const eh_frame = @as([*]const u8, @ptrFromInt(self.eh_frame_ptr))[0 .. eh_frame_len orelse math.maxInt(u32)];
19071903
19081904 const fde_offset = fde_ptr - self.eh_frame_ptr;
19091905 var eh_frame_stream = io.fixedBufferStream(eh_frame);
......@@ -2248,8 +2244,8 @@ pub const FrameDescriptionEntry = struct {
22482244
22492245fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize {
22502246 if (pc_rel_offset < 0) {
2251 return math.sub(usize, field_ptr, @intCast(usize, -pc_rel_offset));
2247 return math.sub(usize, field_ptr, @as(usize, @intCast(-pc_rel_offset)));
22522248 } else {
2253 return math.add(usize, field_ptr, @intCast(usize, pc_rel_offset));
2249 return math.add(usize, field_ptr, @as(usize, @intCast(pc_rel_offset)));
22542250 }
22552251}
lib/std/dwarf/call_frame.zig+9-9
......@@ -206,13 +206,13 @@ pub const Instruction = union(Opcode) {
206206 ) !Instruction {
207207 return switch (try stream.reader().readByte()) {
208208 inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: {
209 const e = @enumFromInt(Opcode, opcode & 0b11000000);
209 const e: Opcode = @enumFromInt(opcode & 0b11000000);
210210 var result = @unionInit(Instruction, @tagName(e), undefined);
211 try result.readOperands(stream, @intCast(u6, opcode & 0b111111), addr_size_bytes, endian);
211 try result.readOperands(stream, @as(u6, @intCast(opcode & 0b111111)), addr_size_bytes, endian);
212212 break :blk result;
213213 },
214214 inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: {
215 const e = @enumFromInt(Opcode, opcode);
215 const e: Opcode = @enumFromInt(opcode);
216216 var result = @unionInit(Instruction, @tagName(e), undefined);
217217 try result.readOperands(stream, null, addr_size_bytes, endian);
218218 break :blk result;
......@@ -234,9 +234,9 @@ pub const Instruction = union(Opcode) {
234234/// an error and fall back to FP-based unwinding.
235235pub fn applyOffset(base: usize, offset: i64) !usize {
236236 return if (offset >= 0)
237 try std.math.add(usize, base, @intCast(usize, offset))
237 try std.math.add(usize, base, @as(usize, @intCast(offset)))
238238 else
239 try std.math.sub(usize, base, @intCast(usize, -offset));
239 try std.math.sub(usize, base, @as(usize, @intCast(-offset)));
240240}
241241
242242/// This is a virtual machine that runs DWARF call frame instructions.
......@@ -304,7 +304,7 @@ pub const VirtualMachine = struct {
304304 .same_value => {},
305305 .offset => |offset| {
306306 if (context.cfa) |cfa| {
307 const ptr = @ptrFromInt(*const usize, try applyOffset(cfa, offset));
307 const ptr: *const usize = @ptrFromInt(try applyOffset(cfa, offset));
308308
309309 // TODO: context.isValidMemory(ptr)
310310 mem.writeIntSliceNative(usize, out, ptr.*);
......@@ -480,7 +480,7 @@ pub const VirtualMachine = struct {
480480 => |i| {
481481 try self.resolveCopyOnWrite(allocator);
482482 const column = try self.getOrAddColumn(allocator, i.operands.register);
483 column.rule = .{ .offset = @intCast(i64, i.operands.offset) * cie.data_alignment_factor };
483 column.rule = .{ .offset = @as(i64, @intCast(i.operands.offset)) * cie.data_alignment_factor };
484484 },
485485 inline .restore,
486486 .restore_extended,
......@@ -526,7 +526,7 @@ pub const VirtualMachine = struct {
526526 try self.resolveCopyOnWrite(allocator);
527527 self.current_row.cfa = .{
528528 .register = i.operands.register,
529 .rule = .{ .val_offset = @intCast(i64, i.operands.offset) },
529 .rule = .{ .val_offset = @intCast(i.operands.offset) },
530530 };
531531 },
532532 .def_cfa_sf => |i| {
......@@ -544,7 +544,7 @@ pub const VirtualMachine = struct {
544544 .def_cfa_offset => |i| {
545545 try self.resolveCopyOnWrite(allocator);
546546 if (self.current_row.cfa.register == null or self.current_row.cfa.rule != .val_offset) return error.InvalidOperation;
547 self.current_row.cfa.rule = .{ .val_offset = @intCast(i64, i.operands.offset) };
547 self.current_row.cfa.rule = .{ .val_offset = @intCast(i.operands.offset) };
548548 },
549549 .def_cfa_offset_sf => |i| {
550550 try self.resolveCopyOnWrite(allocator);
lib/std/dwarf/expressions.zig+4-4
......@@ -62,13 +62,13 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
6262 const int_info = @typeInfo(@TypeOf(value)).Int;
6363 if (@sizeOf(@TypeOf(value)) > options.addr_size) {
6464 return .{ .generic = switch (int_info.signedness) {
65 .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)),
66 .unsigned => @truncate(addr_type, value),
65 .signed => @bitCast(@as(addr_type_signed, @truncate(value))),
66 .unsigned => @truncate(value),
6767 } };
6868 } else {
6969 return .{ .generic = switch (int_info.signedness) {
70 .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)),
71 .unsigned => @intCast(addr_type, value),
70 .signed => @bitCast(@as(addr_type_signed, @intCast(value))),
71 .unsigned => @intCast(value),
7272 } };
7373 }
7474 }
src/crash_report.zig+1-1
......@@ -207,7 +207,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
207207 .x86_64,
208208 .arm,
209209 .aarch64,
210 => StackContext{ .exception = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)) },
210 => StackContext{ .exception = @ptrCast(@alignCast(ctx_ptr)) },
211211 else => .not_supported,
212212 };
213213