From 8b1749e72f728293de3b8edd8b990e3856dd75a7 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 16 Jan 2026 16:24:51 +0200 Subject: [PATCH 1/2] Compilation: add wint_t --- src/aro/Compilation.zig | 6 ++++-- src/aro/TypeStore.zig | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/aro/Compilation.zig b/src/aro/Compilation.zig index c5e064b2c..fbc422faa 100644 --- a/src/aro/Compilation.zig +++ b/src/aro/Compilation.zig @@ -923,6 +923,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void { \\#define __ATOMIC_CHAR16_T_LOCK_FREE 1 \\#define __ATOMIC_CHAR32_T_LOCK_FREE 1 \\#define __ATOMIC_WCHAR_T_LOCK_FREE 1 + \\#define __ATOMIC_WINT_T_LOCK_FREE 1 \\#define __ATOMIC_SHORT_LOCK_FREE 1 \\#define __ATOMIC_INT_LOCK_FREE 1 \\#define __ATOMIC_LONG_LOCK_FREE 1 @@ -946,7 +947,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void { try comp.generateIntMaxAndWidth(w, "LONG", .long); try comp.generateIntMaxAndWidth(w, "LONG_LONG", .long_long); try comp.generateIntMaxAndWidth(w, "WCHAR", comp.type_store.wchar); - // try comp.generateIntMax(w, "WINT", comp.type_store.wchar); + try comp.generateIntMaxAndWidth(w, "WINT", comp.type_store.wint); try comp.generateIntMaxAndWidth(w, "INTMAX", comp.type_store.intmax); try comp.generateIntMaxAndWidth(w, "SIZE", comp.type_store.size); try comp.generateIntMaxAndWidth(w, "UINTMAX", try comp.type_store.intmax.makeIntUnsigned(comp)); @@ -970,7 +971,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void { try comp.generateSizeofType(w, "__SIZEOF_PTRDIFF_T__", comp.type_store.ptrdiff); try comp.generateSizeofType(w, "__SIZEOF_SIZE_T__", comp.type_store.size); try comp.generateSizeofType(w, "__SIZEOF_WCHAR_T__", comp.type_store.wchar); - // try comp.generateSizeofType(w, "__SIZEOF_WINT_T__", .void_pointer); + try comp.generateSizeofType(w, "__SIZEOF_WINT_T__", comp.type_store.wint); if (target.hasInt128()) { try comp.generateSizeofType(w, "__SIZEOF_INT128__", .int128); @@ -989,6 +990,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void { try comp.generateTypeMacro(w, "__PTRDIFF_TYPE__", comp.type_store.ptrdiff); try comp.generateTypeMacro(w, "__SIZE_TYPE__", comp.type_store.size); try comp.generateTypeMacro(w, "__WCHAR_TYPE__", comp.type_store.wchar); + try comp.generateTypeMacro(w, "__WINT_TYPE__", comp.type_store.wint); try comp.generateTypeMacro(w, "__CHAR16_TYPE__", comp.type_store.uint_least16_t); try comp.generateTypeMacro(w, "__CHAR32_TYPE__", comp.type_store.uint_least32_t); diff --git a/src/aro/TypeStore.zig b/src/aro/TypeStore.zig index 1ba04cb29..82bdb858a 100644 --- a/src/aro/TypeStore.zig +++ b/src/aro/TypeStore.zig @@ -1810,6 +1810,7 @@ attributes: std.ArrayList(Attribute) = .empty, anon_name_arena: std.heap.ArenaAllocator.State = .{}, wchar: QualType = .invalid, +wint: QualType = .invalid, uint_least16_t: QualType = .invalid, uint_least32_t: QualType = .invalid, ptrdiff: QualType = .invalid, @@ -2098,13 +2099,14 @@ pub fn set(ts: *TypeStore, gpa: std.mem.Allocator, ty: Type, index: usize) !void pub fn initNamedTypes(ts: *TypeStore, comp: *Compilation) !void { const os = comp.target.os.tag; + const arch = comp.target.cpu.arch; ts.wchar = switch (os) { .openbsd, .netbsd => .int, .ps4, .ps5 => .ushort, .uefi => .ushort, .windows => .ushort, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => .int, - else => switch (comp.target.cpu.arch) { + else => switch (arch) { .aarch64, .aarch64_be => .uint, .arm, .armeb, .thumb, .thumbeb => .uint, .ve, .msp430 => .uint, @@ -2114,6 +2116,23 @@ pub fn initNamedTypes(ts: *TypeStore, comp: *Compilation) !void { }, }; + ts.wint = switch (os) { + .fuchsia => .uint, + .linux => .uint, + .openbsd => .int, + .uefi => .ushort, + .windows => .ushort, + else => switch (arch) { + .csky => .uint, + .loongarch32, .loongarch64 => .uint, + .riscv32, .riscv32be, .riscv64, .riscv64be => .uint, + .ve => .uint, + .xcore => .uint, + .xtensa, .xtensaeb => .uint, + else => .int, + }, + }; + const ptr_width = comp.target.ptrBitWidth(); ts.ptrdiff = if (os == .windows and ptr_width == 64) .long_long From d45ce6326b8cba11f46f7803c5ef0b2f53cdb1a4 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 16 Jan 2026 20:21:34 +0200 Subject: [PATCH 2/2] Compilation: add `__W{CHAR,INT}_UNSIGNED__` macros --- src/aro/Compilation.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/aro/Compilation.zig b/src/aro/Compilation.zig index fbc422faa..f2da10a7a 100644 --- a/src/aro/Compilation.zig +++ b/src/aro/Compilation.zig @@ -936,7 +936,15 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void { } // types - if (comp.getCharSignedness() == .unsigned) try w.writeAll("#define __CHAR_UNSIGNED__ 1\n"); + if (comp.getCharSignedness() == .unsigned) { + try w.writeAll("#define __CHAR_UNSIGNED__ 1\n"); + } + if (comp.type_store.wchar.signedness(comp) == .unsigned) { + try w.writeAll("#define __WCHAR_UNSIGNED__ 1\n"); + } + if (comp.type_store.wint.signedness(comp) == .unsigned) { + try w.writeAll("#define __WINT_UNSIGNED__ 1\n"); + } try w.writeAll("#define __CHAR_BIT__ 8\n"); // int maxs