From 6abf1fbfe6f7f3c06e70e331a3c9e5101624d501 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Sun, 25 Jun 2023 02:47:48 -0400 Subject: [PATCH] update to new builtin syntax --- lib/std/debug.zig | 8 ++++---- lib/std/dwarf.zig | 20 ++++++++------------ lib/std/dwarf/call_frame.zig | 18 +++++++++--------- lib/std/dwarf/expressions.zig | 8 ++++---- src/crash_report.zig | 2 +- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index ec841617fd..1ae26da247 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -987,7 +987,7 @@ pub fn readElfDebugInfo( if (mem.eql(u8, name, ".gnu_debuglink")) { const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size); - const debug_filename = mem.sliceTo(@ptrCast([*:0]const u8, gnu_debuglink.ptr), 0); + const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0); const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr); const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4]; separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes); @@ -1535,7 +1535,7 @@ pub const DebugInfo = struct { switch (phdr.p_type) { elf.PT_NOTE => { // Look for .note.gnu.build-id - const note_bytes = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz]; + const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz]; const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]); if (name_size != 4) continue; const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]); @@ -1545,7 +1545,7 @@ pub const DebugInfo = struct { context.build_id = note_bytes[16..][0..desc_size]; }, elf.PT_GNU_EH_FRAME => { - context.gnu_eh_frame = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz]; + context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz]; }, else => {}, } @@ -2094,7 +2094,7 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void .arm, .aarch64, => { - const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); + const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr)); dumpStackTraceFromBase(ctx); }, else => {}, diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index 47a7563beb..ce8c59c6e9 100644 --- a/lib/std/dwarf.zig +++ b/lib/std/dwarf.zig @@ -1538,9 +1538,7 @@ pub const DwarfInfo = struct { .cie => { const cie = try CommonInformationEntry.parse( entry_header.entry_bytes, - -@intCast(isize, @intFromPtr(binary_mem.ptr)), - //@ptrToInt(eh_frame.ptr), - //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr), + -@as(i64, @intCast(@intFromPtr(binary_mem.ptr))), true, entry_header.length_offset, @sizeOf(usize), @@ -1552,9 +1550,7 @@ pub const DwarfInfo = struct { const cie = di.cie_map.get(cie_offset) orelse return badDwarf(); const fde = try FrameDescriptionEntry.parse( entry_header.entry_bytes, - -@intCast(isize, @intFromPtr(binary_mem.ptr)), - //@ptrToInt(eh_frame.ptr), - //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr), + -@as(i64, @intCast(@intFromPtr(binary_mem.ptr))), true, cie, @sizeOf(usize), @@ -1783,10 +1779,10 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo }; const ptr = if (base) |b| switch (value) { - .signed => |s| @intCast(u64, s + @intCast(i64, b)), + .signed => |s| @as(u64, @intCast(s + @as(i64, @intCast(b)))), .unsigned => |u| u + b, } else switch (value) { - .signed => |s| @intCast(u64, s), + .signed => |s| @as(u64, @intCast(s)), .unsigned => |u| u, }; @@ -1798,7 +1794,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow; return switch (addr_size_bytes) { - 2, 4, 8 => return @ptrFromInt(*const usize, native_ptr).*, + 2, 4, 8 => return @as(*const usize, @ptrFromInt(native_ptr)).*, else => return error.UnsupportedAddrSize, }; } else { @@ -1903,7 +1899,7 @@ pub const ExceptionFrameHeader = struct { if (self.isValidPtr(fde_ptr + 11, isValidMemory, eh_frame_len)) fde_entry_header_len = 12; // Even if eh_frame_len is not specified, all ranges accssed are checked by isValidPtr - const eh_frame = @ptrFromInt([*]const u8, self.eh_frame_ptr)[0..eh_frame_len orelse math.maxInt(u32)]; + const eh_frame = @as([*]const u8, @ptrFromInt(self.eh_frame_ptr))[0 .. eh_frame_len orelse math.maxInt(u32)]; const fde_offset = fde_ptr - self.eh_frame_ptr; var eh_frame_stream = io.fixedBufferStream(eh_frame); @@ -2248,8 +2244,8 @@ pub const FrameDescriptionEntry = struct { fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize { if (pc_rel_offset < 0) { - return math.sub(usize, field_ptr, @intCast(usize, -pc_rel_offset)); + return math.sub(usize, field_ptr, @as(usize, @intCast(-pc_rel_offset))); } else { - return math.add(usize, field_ptr, @intCast(usize, pc_rel_offset)); + return math.add(usize, field_ptr, @as(usize, @intCast(pc_rel_offset))); } } diff --git a/lib/std/dwarf/call_frame.zig b/lib/std/dwarf/call_frame.zig index cbf267aba3..460d157bf9 100644 --- a/lib/std/dwarf/call_frame.zig +++ b/lib/std/dwarf/call_frame.zig @@ -206,13 +206,13 @@ pub const Instruction = union(Opcode) { ) !Instruction { return switch (try stream.reader().readByte()) { inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: { - const e = @enumFromInt(Opcode, opcode & 0b11000000); + const e: Opcode = @enumFromInt(opcode & 0b11000000); var result = @unionInit(Instruction, @tagName(e), undefined); - try result.readOperands(stream, @intCast(u6, opcode & 0b111111), addr_size_bytes, endian); + try result.readOperands(stream, @as(u6, @intCast(opcode & 0b111111)), addr_size_bytes, endian); break :blk result; }, inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: { - const e = @enumFromInt(Opcode, opcode); + const e: Opcode = @enumFromInt(opcode); var result = @unionInit(Instruction, @tagName(e), undefined); try result.readOperands(stream, null, addr_size_bytes, endian); break :blk result; @@ -234,9 +234,9 @@ pub const Instruction = union(Opcode) { /// an error and fall back to FP-based unwinding. pub fn applyOffset(base: usize, offset: i64) !usize { return if (offset >= 0) - try std.math.add(usize, base, @intCast(usize, offset)) + try std.math.add(usize, base, @as(usize, @intCast(offset))) else - try std.math.sub(usize, base, @intCast(usize, -offset)); + try std.math.sub(usize, base, @as(usize, @intCast(-offset))); } /// This is a virtual machine that runs DWARF call frame instructions. @@ -304,7 +304,7 @@ pub const VirtualMachine = struct { .same_value => {}, .offset => |offset| { if (context.cfa) |cfa| { - const ptr = @ptrFromInt(*const usize, try applyOffset(cfa, offset)); + const ptr: *const usize = @ptrFromInt(try applyOffset(cfa, offset)); // TODO: context.isValidMemory(ptr) mem.writeIntSliceNative(usize, out, ptr.*); @@ -480,7 +480,7 @@ pub const VirtualMachine = struct { => |i| { try self.resolveCopyOnWrite(allocator); const column = try self.getOrAddColumn(allocator, i.operands.register); - column.rule = .{ .offset = @intCast(i64, i.operands.offset) * cie.data_alignment_factor }; + column.rule = .{ .offset = @as(i64, @intCast(i.operands.offset)) * cie.data_alignment_factor }; }, inline .restore, .restore_extended, @@ -526,7 +526,7 @@ pub const VirtualMachine = struct { try self.resolveCopyOnWrite(allocator); self.current_row.cfa = .{ .register = i.operands.register, - .rule = .{ .val_offset = @intCast(i64, i.operands.offset) }, + .rule = .{ .val_offset = @intCast(i.operands.offset) }, }; }, .def_cfa_sf => |i| { @@ -544,7 +544,7 @@ pub const VirtualMachine = struct { .def_cfa_offset => |i| { try self.resolveCopyOnWrite(allocator); if (self.current_row.cfa.register == null or self.current_row.cfa.rule != .val_offset) return error.InvalidOperation; - self.current_row.cfa.rule = .{ .val_offset = @intCast(i64, i.operands.offset) }; + self.current_row.cfa.rule = .{ .val_offset = @intCast(i.operands.offset) }; }, .def_cfa_offset_sf => |i| { try self.resolveCopyOnWrite(allocator); diff --git a/lib/std/dwarf/expressions.zig b/lib/std/dwarf/expressions.zig index 6d94138d68..f2b8bfc881 100644 --- a/lib/std/dwarf/expressions.zig +++ b/lib/std/dwarf/expressions.zig @@ -62,13 +62,13 @@ pub fn StackMachine(comptime options: StackMachineOptions) type { const int_info = @typeInfo(@TypeOf(value)).Int; if (@sizeOf(@TypeOf(value)) > options.addr_size) { return .{ .generic = switch (int_info.signedness) { - .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)), - .unsigned => @truncate(addr_type, value), + .signed => @bitCast(@as(addr_type_signed, @truncate(value))), + .unsigned => @truncate(value), } }; } else { return .{ .generic = switch (int_info.signedness) { - .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)), - .unsigned => @intCast(addr_type, value), + .signed => @bitCast(@as(addr_type_signed, @intCast(value))), + .unsigned => @intCast(value), } }; } } diff --git a/src/crash_report.zig b/src/crash_report.zig index 5cd00c5b13..83c5af7ba0 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -207,7 +207,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any .x86_64, .arm, .aarch64, - => StackContext{ .exception = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)) }, + => StackContext{ .exception = @ptrCast(@alignCast(ctx_ptr)) }, else => .not_supported, };