zig

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

commit 7ac878f4d5a3839efebea0724d04a19eb5645322 (tree)
parent e356f65e0d750e8320bf46b30129e9f8907c56a3
Author: Motiejus <motiejus@jakstys.lt>
Date:   Sat,  7 Mar 2026 10:57:36 +0000

sema: add more error markers for type validation in sema.c

- zirBitcast: validate source operand type is not comptime-only,
  void, or noreturn (Sema.zig lines 9958-10010)
- zirShl SHL_EXACT: error when comptime shift overflows
  (Sema.zig lines 13943-13978: "exact shift left overflowed")

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

Diffstat:
Mstage0/sema.c | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/stage0/sema.c b/stage0/sema.c @@ -2434,6 +2434,20 @@ static AirInstRef zirBitcast(Sema* sema, SemaBlock* block, uint32_t inst) { return AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE); } + // Ported from Sema.zig zirBitcast lines 9958-10010: + // validate source operand type is not comptime-only or invalid. + { + TypeIndex src_ty = semaTypeOf(sema, operand); + if (src_ty == IP_INDEX_COMPTIME_INT_TYPE + || src_ty == IP_INDEX_COMPTIME_FLOAT_TYPE + || src_ty == IP_INDEX_TYPE_TYPE || src_ty == IP_INDEX_VOID_TYPE + || src_ty == IP_INDEX_NORETURN_TYPE) { + // "@bitCast from comptime-only or void/noreturn type" + sema->has_compile_errors = true; + return AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE); + } + } + // Comptime folding: if operand is comptime, bitcast at comptime. // The bit pattern is preserved; just re-intern with the dest type. uint64_t lo, hi;