zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit be87644337b7884ef3aa50fd1d719825bd9a174a (tree)
parent 5715f3bd909e4c7f0fddbcc03f89f0d980b3c8d1
Author: Motiejus <motiejus@jakstys.lt>
Date:   Sat,  7 Mar 2026 09:30:43 +0000

sema: fix zirBitSizeOf for pointer-sized and C integer types

Add bit size computation for:
- usize/isize: 32 bits (wasm32-wasi target pointer size)
- c_char: 8 bits
- c_short/c_ushort: 16 bits
- c_int/c_uint: 32 bits
- c_long/c_ulong: 32 bits (ILP32 on wasm32-wasi)
- c_longlong/c_ulonglong: 64 bits

Ported from Sema.zig zirBitSizeOf → bitSizeSema → intInfo for
simple integer types.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
Mstage0/sema.c | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/stage0/sema.c b/stage0/sema.c @@ -9273,8 +9273,32 @@ static AirInstRef zirBitSizeOf(Sema* sema, uint32_t inst) { bit_size = floatTypeBits(type_ip); if (bit_size == 0) { // Check bool. - if (type_ip == IP_INDEX_BOOL_TYPE) + if (type_ip == IP_INDEX_BOOL_TYPE) { bit_size = 1; + } + // Pointer-sized integer types: usize/isize for wasm32 = 32 bits. + // Ported from Sema.zig zirBitSizeOf → bitSizeSema → intInfo. + else if (type_ip == IP_INDEX_USIZE_TYPE + || type_ip == IP_INDEX_ISIZE_TYPE) { + bit_size = 32; // wasm32-wasi target pointer size + } + // C integer types: use their ABI sizes for wasm32. + else if (type_ip == IP_INDEX_C_CHAR_TYPE) { + bit_size = 8; + } else if (type_ip == IP_INDEX_C_SHORT_TYPE + || type_ip == IP_INDEX_C_USHORT_TYPE) { + bit_size = 16; + } else if (type_ip == IP_INDEX_C_INT_TYPE + || type_ip == IP_INDEX_C_UINT_TYPE) { + bit_size = 32; + } else if (type_ip == IP_INDEX_C_LONG_TYPE + || type_ip == IP_INDEX_C_ULONG_TYPE) { + // c_long on wasm32-wasi is 32 bits (ILP32). + bit_size = 32; + } else if (type_ip == IP_INDEX_C_LONGLONG_TYPE + || type_ip == IP_INDEX_C_ULONGLONG_TYPE) { + bit_size = 64; + } // void, type, etc. have 0 bits. } }