Skip to content

std compiler error fixes #24219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions lib/std/Build/Cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ pub const Manifest = struct {
gop.key_ptr.* = .{
.prefixed_path = prefixed_path,
.max_file_size = max_file_size,
.handle = null,
.stat = undefined,
.bin_digest = undefined,
.contents = null,
Expand Down
37 changes: 24 additions & 13 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,14 @@ pub const StackIterator = struct {
// When SelfInfo and a register context is available, this iterator can unwind
// stacks with frames that don't use a frame pointer (ie. -fomit-frame-pointer),
// using DWARF and MachO unwind info.
unwind_state: if (have_ucontext) ?struct {
unwind_state: if (have_ucontext) ?UnwindState else void = if (have_ucontext) null else {},

const UnwindState = struct {
debug_info: *SelfInfo,
dwarf_context: SelfInfo.UnwindContext,
last_error: ?UnwindError = null,
failed: bool = false,
} else void = if (have_ucontext) null else {},
};

pub fn init(first_address: ?usize, fp: ?usize) StackIterator {
if (native_arch.isSPARC()) {
Expand Down Expand Up @@ -869,19 +871,24 @@ pub const StackIterator = struct {
return address;
}

fn next_unwind(it: *StackIterator) !usize {
const unwind_state = &it.unwind_state.?;
const module = try unwind_state.debug_info.getModuleForAddress(unwind_state.dwarf_context.pc);
// must not be a member function of StackIterator as it
// creates a dependency loop due to UnwindError
fn next_unwind(
ma: *MemoryAccessor,
debug_info: *SelfInfo,
dwarf_context: *SelfInfo.UnwindContext,
) !usize {
const module = try debug_info.getModuleForAddress(dwarf_context.pc);
switch (native_os) {
.macos, .ios, .watchos, .tvos, .visionos => {
// __unwind_info is a requirement for unwinding on Darwin. It may fall back to DWARF, but unwinding
// via DWARF before attempting to use the compact unwind info will produce incorrect results.
if (module.unwind_info) |unwind_info| {
if (SelfInfo.unwindFrameMachO(
unwind_state.debug_info.allocator,
debug_info.allocator,
module.base_address,
&unwind_state.dwarf_context,
&it.ma,
dwarf_context,
ma,
unwind_info,
module.eh_frame,
)) |return_address| {
Expand All @@ -894,13 +901,13 @@ pub const StackIterator = struct {
else => {},
}

if (try module.getDwarfInfoForAddress(unwind_state.debug_info.allocator, unwind_state.dwarf_context.pc)) |di| {
if (try module.getDwarfInfoForAddress(debug_info.allocator, dwarf_context.pc)) |di| {
return SelfInfo.unwindFrameDwarf(
unwind_state.debug_info.allocator,
debug_info.allocator,
di,
module.base_address,
&unwind_state.dwarf_context,
&it.ma,
dwarf_context,
ma,
null,
);
} else return error.MissingDebugInfo;
Expand All @@ -912,7 +919,11 @@ pub const StackIterator = struct {
if (!unwind_state.failed) {
if (unwind_state.dwarf_context.pc == 0) return null;
defer it.fp = unwind_state.dwarf_context.getFp() catch 0;
if (it.next_unwind()) |return_address| {
if (next_unwind(
&it.ma,
it.unwind_state.?.debug_info,
&it.unwind_state.?.dwarf_context,
)) |return_address| {
return return_address;
} else |err| {
unwind_state.last_error = err;
Expand Down
6 changes: 1 addition & 5 deletions lib/std/debug/SelfInfo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,7 @@ pub const Module = switch (native_os) {
pub fn getDwarfInfoForAddress(self: *@This(), allocator: Allocator, address: usize) !?*Dwarf {
_ = allocator;
_ = address;

return switch (self.debug_data) {
.dwarf => |*dwarf| dwarf,
else => null,
};
return &(self.dwarf orelse return null);
}
},
.linux, .netbsd, .freebsd, .dragonfly, .openbsd, .haiku, .solaris, .illumos => Dwarf.ElfModule,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/math/big/int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ pub const Const = struct {
for (self.limbs[0..self.limbs.len]) |limb| {
std.debug.print("{x} ", .{limb});
}
std.debug.print("len={} positive={}\n", .{ self.len, self.positive });
std.debug.print("len={} positive={}\n", .{ self.limbs.len, self.positive });
}

pub fn abs(self: Const) Const {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/os/uefi/protocol/service_binding.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const uefi = std.uefi;
const uefi = std.os.uefi;
const Guid = uefi.Guid;
const Handle = uefi.Handle;
const Status = uefi.Status;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/posix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5739,7 +5739,7 @@ pub fn clock_gettime(clock_id: clockid_t) ClockGetTimeError!timespec {
if (native_os == .windows) {
@compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.time API");
} else if (native_os == .wasi and !builtin.link_libc) {
var ts: timestamp_t = undefined;
var ts: wasi.timestamp_t = undefined;
switch (system.clock_time_get(clock_id, 1, &ts)) {
.SUCCESS => {
tp = .{
Expand All @@ -5763,7 +5763,7 @@ pub fn clock_gettime(clock_id: clockid_t) ClockGetTimeError!timespec {

pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void {
if (native_os == .wasi and !builtin.link_libc) {
var ts: timestamp_t = undefined;
var ts: wasi.timestamp_t = undefined;
switch (system.clock_res_get(@bitCast(clock_id), &ts)) {
.SUCCESS => res.* = .{
.sec = @intCast(ts / std.time.ns_per_s),
Expand Down