fix: make compiler_rt and std.Io.Writer compile on 16-bit platforms.

This commit is contained in:
GasInfinity 2025-10-27 11:17:48 +01:00
parent 914acf13cb
commit 55c0693c4a
No known key found for this signature in database
3 changed files with 24 additions and 21 deletions

View File

@ -74,7 +74,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul
const parts = math.frexp(a); const parts = math.frexp(a);
const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) + const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) +
@intFromBool(signedness == .signed and parts.exponent == 32 * result.len); @intFromBool(signedness == .signed and parts.exponent == 32 * result.len);
const exponent = @max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0); const exponent: usize = @intCast(@max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0));
const int: I = @intFromFloat(switch (exponent) { const int: I = @intFromFloat(switch (exponent) {
0 => a, 0 => a,
else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin), else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin),

View File

@ -604,7 +604,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
@compileError("32 arguments max are supported per format call"); @compileError("32 arguments max are supported per format call");
} }
@setEvalBranchQuota(fmt.len * 1000); @setEvalBranchQuota(@as(comptime_int, fmt.len) * 1000); // NOTE: We're upcasting as 16-bit usize overflows.
comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len }; comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };
comptime var i = 0; comptime var i = 0;
comptime var literal: []const u8 = ""; comptime var literal: []const u8 = "";

View File

@ -4634,6 +4634,8 @@ pub const TEB = extern struct {
}; };
comptime { comptime {
// XXX: Without this check we cannot use `std.Io.Writer` on 16-bit platforms. `std.fmt.bufPrint` will hit the unreachable in `PEB.GdiHandleBuffer` without this guard.
if (builtin.os.tag == .windows) {
// Offsets taken from WinDbg info and Geoff Chappell[1] (RIP) // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
// [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
assert(@offsetOf(TEB, "NtTib") == 0x00); assert(@offsetOf(TEB, "NtTib") == 0x00);
@ -4654,6 +4656,7 @@ comptime {
assert(@offsetOf(TEB, "LastErrorValue") == 0x68); assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
assert(@offsetOf(TEB, "TlsSlots") == 0x1480); assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
} }
}
} }
pub const EXCEPTION_REGISTRATION_RECORD = extern struct { pub const EXCEPTION_REGISTRATION_RECORD = extern struct {