Skip to content

Commit 80ed48b

Browse files
committed
[wasi][prototype] Model wasm class-init helper as value-returning in the JIT
Completes gate #2 (91d9e36). That change made corelib InitClass/ InitInstantiatedClass (InitHelpers.cs) return void* so the compiled call_indirect signature matches the interpreter's value-returning portable entry point convention, but the JIT caller side still typed CORINFO_HELP_INITCLASS/INITINSTCLASS as TYP_VOID. On wasm the R2R caller therefore emitted a (...)->() call_indirect while the runtime dispatches the cold class-init through the i32-returning thunk, trapping with "function signature mismatch" on the first R2R class-init. Model the class-init helpers as value-returning (TYP_I_IMPL) on wasm at the five sites that create them (fgGetStaticsCCtorHelper, impInitClass runtime lookup, and the three fgInitThisClass generic-lookup cases). The helper result is pushed and discarded via the existing unused-value drop in wasm codegen. Fixes the residual overflow bucket of dotnet#129622 (conv_ovf, 127931, indexMinusOne now pass under R2R in both interpreted- and R2R-corelib configs) and removes the class-init signature-mismatch trap in dotnet#130634. No regression in the previously passing type-load tests. Prototype-only; for the future WASI R2R PR. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 2902374a-f352-4c46-bcec-8a35c97733ae
1 parent 1155368 commit 80ed48b

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎src/coreclr/jit/compiler.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,18 @@ class Compiler
33583358
GenTreeCall* gtNewHelperCallNode(
33593359
unsigned helper, var_types type, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, GenTree* arg3 = nullptr, GenTree* arg4 = nullptr);
33603360

3361+
// Return type used when creating the class-init helper calls (CORINFO_HELP_INITCLASS/INITINSTCLASS).
3362+
// On wasm these helpers must be modeled as value-returning so the compiled call_indirect signature
3363+
// matches the callee: InitHelpers.InitClass/InitInstantiatedClass return void* (a dummy value) to match
3364+
// the interpreter's value-returning portable-entry-point convention. The JIT pushes and then discards
3365+
// the result (see the unused-value drop in CodeGen::WasmProduceReg). This modeling therefore depends on
3366+
// that CoreLib signature and must land together with it. Other targets model these helpers as void.
3367+
#ifdef TARGET_WASM
3368+
static constexpr var_types HelperInitClassRetType = TYP_I_IMPL;
3369+
#else
3370+
static constexpr var_types HelperInitClassRetType = TYP_VOID;
3371+
#endif
3372+
33613373
GenTreeCall* gtNewVirtualFunctionLookupHelperCallNode(
33623374
unsigned helper, var_types type, GenTree* thisPtr, GenTree* methHnd, GenTree* clsHnd = nullptr);
33633375

‎src/coreclr/jit/flowgraph.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo
766766
break;
767767

768768
case CORINFO_HELP_INITCLASS:
769-
type = TYP_VOID;
769+
type = HelperInitClassRetType;
770770
break;
771771

772772
default:

‎src/coreclr/jit/importer.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3909,7 +3909,7 @@ GenTree* Compiler::impInitClass(CORINFO_RESOLVED_TOKEN* pResolvedToken)
39093909

39103910
if (runtimeLookup)
39113911
{
3912-
node = gtNewHelperCallNode(CORINFO_HELP_INITCLASS, TYP_VOID, node);
3912+
node = gtNewHelperCallNode(CORINFO_HELP_INITCLASS, HelperInitClassRetType, node);
39133913
}
39143914
else
39153915
{

‎src/coreclr/jit/morph.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14565,21 +14565,22 @@ GenTree* Compiler::fgInitThisClass()
1456514565
vtTree = gtNewMethodTableLookup(vtTree);
1456614566
GenTree* methodHnd = gtNewIconEmbMethHndNode(info.compMethodHnd);
1456714567

14568-
return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, vtTree, methodHnd);
14568+
return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, HelperInitClassRetType, vtTree, methodHnd);
1456914569
}
1457014570

1457114571
case CORINFO_LOOKUP_CLASSPARAM:
1457214572
{
1457314573
GenTree* vtTree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL);
1457414574
vtTree->gtFlags |= GTF_VAR_CONTEXT;
14575-
return gtNewHelperCallNode(CORINFO_HELP_INITCLASS, TYP_VOID, vtTree);
14575+
return gtNewHelperCallNode(CORINFO_HELP_INITCLASS, HelperInitClassRetType, vtTree);
1457614576
}
1457714577

1457814578
case CORINFO_LOOKUP_METHODPARAM:
1457914579
{
1458014580
GenTree* methHndTree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL);
1458114581
methHndTree->gtFlags |= GTF_VAR_CONTEXT;
14582-
return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, gtNewIconNode(0), methHndTree);
14582+
return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, HelperInitClassRetType, gtNewIconNode(0),
14583+
methHndTree);
1458314584
}
1458414585

1458514586
default:

0 commit comments

Comments
 (0)