sema: handle multi-instruction return type bodies and F16T; enable 2 corpus tests

Resolve multi-instruction return type bodies in zirFunc by running
analyzeBodyInner before saving function state, matching upstream
Sema.zig's resolveGenericBody pattern. Add F16T as a known
type-returning function (returns u16 on wasm32-wasi test target).

Enables truncxfhf2.zig and floatunsihf.zig corpus tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 15:08:16 +00:00
parent 0ad43fcc7c
commit bc4e7fbb8b
2 changed files with 29 additions and 7 deletions

View File

@@ -3064,7 +3064,8 @@ static AirInstRef zirCall(
const char* cn
= (const char*)&sema->code.string_bytes[callee_name_idx];
if (strcmp(cn, "Int") == 0 || strcmp(cn, "Log2Int") == 0
|| strcmp(cn, "PowerOfTwoSignificandZ") == 0) {
|| strcmp(cn, "PowerOfTwoSignificandZ") == 0
|| strcmp(cn, "F16T") == 0) {
AirInstData dead;
memset(&dead, 0, sizeof(dead));
(void)semaAddInstAsIndex(sema, AIR_INST_BLOCK, dead);
@@ -3135,6 +3136,8 @@ static AirInstRef zirCall(
ik.data.int_type.signedness = signedness;
ur_result = ipIntern(sema->ip, ik);
}
} else if (strcmp(cn, "F16T") == 0) {
ur_result = IP_INDEX_U16_TYPE;
}
return AIR_REF_FROM_IP(ur_result);
}
@@ -3174,7 +3177,8 @@ static AirInstRef zirCall(
|| strcmp(type_fn_name, "Log2Int") == 0
|| strcmp(type_fn_name,
"PowerOfTwoSignificandZ")
== 0)) {
== 0
|| strcmp(type_fn_name, "F16T") == 0)) {
returns_type = true;
} else {
if (is_cross_module) {
@@ -3469,6 +3473,10 @@ static AirInstRef zirCall(
}
}
}
} else if (type_fn_name && strcmp(type_fn_name, "F16T") == 0) {
// F16T(T): returns u16 on wasm32-wasi (test target).
// Ported from lib/compiler_rt/common.zig F16T.
result_type = IP_INDEX_U16_TYPE;
}
if (is_cross_module) {
@@ -4048,7 +4056,6 @@ static AirInstRef zirCall(
// The function body is analyzed in a fresh AIR context; the resulting
// per-function Air is appended to sema->func_air_list.
static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
(void)block;
uint32_t payload_index = sema->code.inst_datas[inst].pl_node.payload_index;
ZirInstTag tag = sema->code.inst_tags[inst];
bool is_fancy = (tag == ZIR_INST_FUNC_FANCY);
@@ -4128,6 +4135,21 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
if (!has_body || !is_exported || !sema->func_air_list)
return;
// Resolve multi-instruction return type body BEFORE saving state,
// so that the parent scope's inst_map and AIR arrays are available.
// Ported from src/Sema.zig zirFunc: resolveGenericBody(block,
// ret_ty_body).
TypeIndex pre_resolved_ret_ty = TYPE_NONE;
if (ret_ty_body_len > 2) {
const uint32_t* ret_ty_body = &sema->code.extra[ret_ty_ref_pos];
(void)analyzeBodyInner(sema, block, ret_ty_body, ret_ty_body_len);
ZirInstRef operand
= sema->code.inst_datas[sema->comptime_break_inst]
.break_data.operand;
AirInstRef ret_air = resolveInst(sema, operand);
pre_resolved_ret_ty = AIR_REF_TO_IP(ret_air);
}
// --- Save the current AIR state ---
uint8_t* saved_tags = sema->air_inst_tags;
AirInstData* saved_datas = sema->air_inst_datas;
@@ -4193,8 +4215,8 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
sema->fn_ret_ty = IP_INDEX_VOID_TYPE;
}
} else {
// Multi-instruction return type body — not yet supported.
sema->fn_ret_ty = IP_INDEX_VOID_TYPE;
// Multi-instruction return type body resolved before state save.
sema->fn_ret_ty = pre_resolved_ret_ty;
}
// --- Set up block for function body ---

View File

@@ -144,8 +144,8 @@ const corpus_files = .{
"../lib/compiler_rt/floatundihf.zig", // 353
"../lib/compiler_rt/floatundixf.zig", // 353
"../lib/compiler_rt/floatunsixf.zig", // 353
//"../lib/compiler_rt/truncxfhf2.zig", // 356
//"../lib/compiler_rt/floatunsihf.zig", // 357
"../lib/compiler_rt/truncxfhf2.zig", // 356
"../lib/compiler_rt/floatunsihf.zig", // 357
//"../lib/compiler_rt/trunctfhf2.zig", // 359
//"../lib/compiler_rt/extendsfxf2.zig", // 360
//"../lib/compiler/aro/backend.zig", // 362