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
7474 const parts = math.frexp(a);
7575 const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) +
7676 @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));
7878 const int: I = @intFromFloat(switch (exponent) {
7979 0 => a,
8080 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 {
604604 @compileError("32 arguments max are supported per format call");
605605 }
606606
607 @setEvalBranchQuota(fmt.len * 1000);
607 @setEvalBranchQuota(@as(comptime_int, fmt.len) * 1000); // NOTE: We're upcasting as 16-bit usize overflows.
608608 comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };
609609 comptime var i = 0;
610610 comptime var literal: []const u8 = "";
lib/std/os/windows.zig+22-19
......@@ -4634,25 +4634,28 @@ pub const TEB = extern struct {
46344634};
46354635
46364636comptime {
4637 // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
4638 // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
4639 assert(@offsetOf(TEB, "NtTib") == 0x00);
4640 if (@sizeOf(usize) == 4) {
4641 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);
4642 assert(@offsetOf(TEB, "ClientId") == 0x20);
4643 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);
4644 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);
4645 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
4646 assert(@offsetOf(TEB, "LastErrorValue") == 0x34);
4647 assert(@offsetOf(TEB, "TlsSlots") == 0xe10);
4648 } else if (@sizeOf(usize) == 8) {
4649 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);
4650 assert(@offsetOf(TEB, "ClientId") == 0x40);
4651 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);
4652 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);
4653 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
4654 assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
4655 assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
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 if (builtin.os.tag == .windows) {
4639 // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
4640 // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
4641 assert(@offsetOf(TEB, "NtTib") == 0x00);
4642 if (@sizeOf(usize) == 4) {
4643 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);
4644 assert(@offsetOf(TEB, "ClientId") == 0x20);
4645 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);
4646 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);
4647 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
4648 assert(@offsetOf(TEB, "LastErrorValue") == 0x34);
4649 assert(@offsetOf(TEB, "TlsSlots") == 0xe10);
4650 } else if (@sizeOf(usize) == 8) {
4651 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);
4652 assert(@offsetOf(TEB, "ClientId") == 0x40);
4653 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);
4654 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);
4655 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
4656 assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
4657 assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
4658 }
46564659 }
46574660}
46584661