kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 2d37ba7b367e02cf86618cfa9e3a7a92d516e7ea
parent b9d9f14016146421df4aad8dc36cb35279db6258
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed,  3 Jun 2026 12:12:29 -0700

cg: restore out-of-range fallback in intrinsic table accessors

The four KitCgIntrinsic accessors index kIntrinTable directly; route them
through a bounds-guarded intrin_desc() so an out-of-range value falls back to
the NONE row, matching the defensive default: arms the switches carried before
the table collapse. (Equivalence-review nit; valid enum inputs unaffected.)

Diffstat:
Msrc/cg/arith.c | 18++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/cg/arith.c b/src/cg/arith.c @@ -895,25 +895,35 @@ _Static_assert(sizeof(kIntrinTable) / sizeof(kIntrinTable[0]) == KIT_CG_INTRIN_CORO_SWITCH + 1, "kIntrinTable must have exactly one row per KitCgIntrinsic"); +/* Bounds-guarded row lookup: an out-of-range intrinsic falls back to the NONE + * row, preserving the defensive `default:` behavior the four switches carried + * before they collapsed into kIntrinTable. */ +static const IntrinDesc* intrin_desc(KitCgIntrinsic intrin) { + static const IntrinDesc none = {INTRIN_NONE, NULL, false, false}; + unsigned i = (unsigned)intrin; + return i < sizeof(kIntrinTable) / sizeof(kIntrinTable[0]) ? &kIntrinTable[i] + : &none; +} + IntrinKind api_map_intrinsic(KitCg* g, KitCgIntrinsic intrin, KitCgTypeId result_type) { /* Width-by-type: backends derive operand width from the result type, so the * mapping no longer needs the size here. */ (void)g; (void)result_type; - return kIntrinTable[intrin].kind; + return intrin_desc(intrin)->kind; } int api_intrinsic_is_void(KitCgIntrinsic intrin) { - return kIntrinTable[intrin].is_void; + return intrin_desc(intrin)->is_void; } int api_intrinsic_is_overflow(KitCgIntrinsic intrin) { - return kIntrinTable[intrin].is_overflow; + return intrin_desc(intrin)->is_overflow; } const char* api_intrinsic_name(KitCgIntrinsic intrin) { - const char* name = kIntrinTable[intrin].name; + const char* name = intrin_desc(intrin)->name; return name ? name : "intrinsic"; }