Skip to content

Commit 0c82a72

Browse files
committed
Fix parameter index on WCC
In the case that a function which has a struct paremter and taking variable reference for a parameter.
1 parent 5f48b3e commit 0c82a72

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/wcc/gen_wasm.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,15 +1714,20 @@ static void gen_defun(Function *func) {
17141714
// Store ref-taken parameters to stack frame.
17151715
if (func->params != NULL) {
17161716
const Vector *params = func->params;
1717+
const Type *rettype = functype->func.ret;
1718+
int param_index = rettype->kind != TY_VOID && !is_prim_type(rettype) ? 1 : 0;
17171719
for (int i = 0, param_count = params->len; i < param_count; ++i) {
17181720
VarInfo *varinfo = params->data[i];
1719-
if (!(varinfo->storage & VS_REF_TAKEN) || is_stack_param(varinfo->type))
1721+
if (is_stack_param(varinfo->type))
17201722
continue;
1721-
VReg *vreg = varinfo->local.vreg;
1722-
gen_bpofs(vreg->non_prim.offset);
1723-
ADD_CODE(OP_LOCAL_GET);
1724-
ADD_ULEB128(vreg->param_index);
1725-
gen_store(varinfo->type);
1723+
if (varinfo->storage & VS_REF_TAKEN) {
1724+
VReg *vreg = varinfo->local.vreg;
1725+
gen_bpofs(vreg->non_prim.offset);
1726+
ADD_CODE(OP_LOCAL_GET);
1727+
ADD_ULEB128(param_index);
1728+
gen_store(varinfo->type);
1729+
}
1730+
++param_index;
17261731
}
17271732
}
17281733

0 commit comments

Comments
 (0)