authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2025-10-27 11:17:48+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2025-10-27 11:17:48+01:00
log55c0693c4afb8afab9ce97ef0ad40450e6156d0c
tree38d372c8dbddac19e7e9aa0b157abd914b20824d
parent914acf13cba7adc4e55734d85f60ab09e7fdf8ac
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

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


3 files changed, 24 insertions(+), 21 deletions(-)

lib/compiler_rt/int_from_float.zig+1-1
...@@ -74,7 +74,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul...@@ -74,7 +74,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul
74 const parts = math.frexp(a);74 const parts = math.frexp(a);
75 const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) +75 const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) +
76 @intFromBool(signedness == .signed and parts.exponent == 32 * result.len);76 @intFromBool(signedness == .signed and parts.exponent == 32 * result.len);
77 const exponent = @max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0);77 const exponent: usize = @intCast(@max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0));
78 const int: I = @intFromFloat(switch (exponent) {78 const int: I = @intFromFloat(switch (exponent) {
79 0 => a,79 0 => a,
80 else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin),80 else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin),
lib/std/Io/Writer.zig+1-1
...@@ -604,7 +604,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {...@@ -604,7 +604,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
604 @compileError("32 arguments max are supported per format call");604 @compileError("32 arguments max are supported per format call");
605 }605 }
606606
607 @setEvalBranchQuota(fmt.len * 1000);607 @setEvalBranchQuota(@as(comptime_int, fmt.len) * 1000); // NOTE: We're upcasting as 16-bit usize overflows.
608 comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };608 comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };
609 comptime var i = 0;609 comptime var i = 0;
610 comptime var literal: []const u8 = "";610 comptime var literal: []const u8 = "";
lib/std/os/windows.zig+22-19
...@@ -4634,25 +4634,28 @@ pub const TEB = extern struct {...@@ -4634,25 +4634,28 @@ pub const TEB = extern struct {
4634};4634};
46354635
4636comptime {4636comptime {
4637 // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)4637 // 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.
4638 // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm4638 if (builtin.os.tag == .windows) {
4639 assert(@offsetOf(TEB, "NtTib") == 0x00);4639 // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
4640 if (@sizeOf(usize) == 4) {4640 // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
4641 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);4641 assert(@offsetOf(TEB, "NtTib") == 0x00);
4642 assert(@offsetOf(TEB, "ClientId") == 0x20);4642 if (@sizeOf(usize) == 4) {
4643 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);4643 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);
4644 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);4644 assert(@offsetOf(TEB, "ClientId") == 0x20);
4645 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);4645 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);
4646 assert(@offsetOf(TEB, "LastErrorValue") == 0x34);4646 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);
4647 assert(@offsetOf(TEB, "TlsSlots") == 0xe10);4647 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
4648 } else if (@sizeOf(usize) == 8) {4648 assert(@offsetOf(TEB, "LastErrorValue") == 0x34);
4649 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);4649 assert(@offsetOf(TEB, "TlsSlots") == 0xe10);
4650 assert(@offsetOf(TEB, "ClientId") == 0x40);4650 } else if (@sizeOf(usize) == 8) {
4651 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);4651 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);
4652 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);4652 assert(@offsetOf(TEB, "ClientId") == 0x40);
4653 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);4653 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);
4654 assert(@offsetOf(TEB, "LastErrorValue") == 0x68);4654 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);
4655 assert(@offsetOf(TEB, "TlsSlots") == 0x1480);4655 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
4656 assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
4657 assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
4658 }
4656 }4659 }
4657}4660}
46584661