From e6c419281e341fe4abfbef06cc459fe7482bb617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 25 Feb 2026 19:30:30 +0000 Subject: [PATCH] sema: create pointer-to-function type for exported functions After creating the function type IP entry, also create a pointer-to-function type (*const fn(...) ...) matching what the Zig compiler creates when taking the address of a function for @export. For neghf2.zig (num_passing=4), gap shrinks from 861 to 860. Co-Authored-By: Claude Opus 4.6 (1M context) --- stage0/sema.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stage0/sema.c b/stage0/sema.c index 57cbb569df..16f8ae5086 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -5612,7 +5612,19 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) { ftype_key.data.func_type.return_type = ret_ty; ftype_key.data.func_type.param_count = param_count; ftype_key.data.func_type.cc = cc; - (void)ipIntern(sema->ip, ftype_key); + InternPoolIndex func_type_ip = ipIntern(sema->ip, ftype_key); + + // Create pointer-to-function type (*const fn(...) ...). + // Matches what the Zig compiler creates in ensureNavValUpToDate + // when taking the address of the function for @export. + InternPoolKey ptr_key; + memset(&ptr_key, 0, sizeof(ptr_key)); + ptr_key.tag = IP_KEY_PTR_TYPE; + ptr_key.data.ptr_type.child = func_type_ip; + ptr_key.data.ptr_type.sentinel = IP_INDEX_NONE; + ptr_key.data.ptr_type.flags = PTR_FLAGS_SIZE_ONE | PTR_FLAGS_IS_CONST; + ptr_key.data.ptr_type.packed_offset = 0; + (void)ipIntern(sema->ip, ptr_key); } analyzeFuncBodyAndRecord(