diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index e5304cef1cb6d3..dcaa66af607be4 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -790,6 +790,7 @@ BasicBlock* CodeGen::genEmitEndBlock(BasicBlock* block) break; case BBJ_THROW: + { // If we have a throw at the end of a function or funclet, we need to emit another instruction // afterwards to help the OS unwinder determine the correct context during unwind. // We insert an unexecuted breakpoint instruction in several situations @@ -822,7 +823,17 @@ BasicBlock* CodeGen::genEmitEndBlock(BasicBlock* block) } } +#if defined(TARGET_WASM) + // For wasm the last instruction in a function or funclet must be end. + // + if (block->IsLast() || m_compiler->bbIsFuncletBeg(block->Next())) + { + GetEmitter()->emitIns(INS_end); + } +#endif // defined(TARGET_WASM) + break; + } case BBJ_CALLFINALLY: result = genCallFinally(block); diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index cf4f69d8ca2376..5634d4ac81dc68 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -2346,9 +2346,8 @@ int GenTreeCall::GetNonStandardAddedArgCount(Compiler* compiler) const { #if defined(TARGET_WASM) // TODO-WASM: may need adjustments for other hidden args - // For now: managed calls get extra SP + PortableEntryPoint args, but - // we're not adding the PE arg yet. So just note one extra arg. - return IsUnmanaged() ? 0 : 1; + // For now: managed calls get extra SP + PortableEntryPoint args. + return IsUnmanaged() ? 0 : 2; #endif // defined(TARGET_WASM) if (IsUnmanaged() && !compiler->opts.ShouldUsePInvokeHelpers()) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 5d8075ec7236d3..6b2cb9611a2cc0 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -1836,8 +1836,12 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call { GenTree* const stackPointer = comp->gtNewLclVarNode(comp->lvaWasmSpArg, TYP_I_IMPL); PushFront(comp, NewCallArg::Primitive(stackPointer).WellKnown(WellKnownArg::WasmShadowStackPointer)); + + // TODO-WASM: pass proper portable entry point as the last argument for managed calls + GenTree* const pePointer = comp->gtNewZeroConNode(TYP_I_IMPL); + PushBack(comp, NewCallArg::Primitive(pePointer).WellKnown(WellKnownArg::WasmPortableEntryPoint)); } - // TODO-WASM: pass the portable entry point as the last argument for managed calls + #endif // defined(TARGET_WASM) ClassifierInfo info;