Skip to content

Wasm R2R: emit trailing end after retless BBJ_CALLFINALLY#129449

Open
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-129335-callfinally-end
Open

Wasm R2R: emit trailing end after retless BBJ_CALLFINALLY#129449
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-129335-callfinally-end

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

A retless BBJ_CALLFINALLY ending a wasm function/funclet only emits unreachable after the indirect call, leaving the body without the required trailing end opcode and producing an invalid module (function body must end with end opcode). Mirror the BBJ_THROW guard and emit end when the block is last or precedes a funclet start.

Fixes #129335.

A retless BBJ_CALLFINALLY ending a wasm function/funclet only emits
`unreachable` after the indirect call, leaving the body without the
required trailing `end` opcode and producing an invalid module
(`function body must end with end opcode`). Mirror the BBJ_THROW guard
and emit `end` when the block is last or precedes a funclet start.

Fixes dotnet#129335.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 16, 2026 00:55
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 16, 2026
@AndyAyersMS AndyAyersMS requested a review from adamperlin June 16, 2026 00:56
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Wasm R2R codegen for the edge case where a retless BBJ_CALLFINALLY ends a wasm function/funclet: it now emits a trailing end opcode (after unreachable) when the block is the last block or immediately precedes a funclet start, preventing invalid wasm modules that fail validation at load time.

Changes:

  • Emit INS_end after INS_unreachable for retless BBJ_CALLFINALLY when it terminates a wasm function/funclet body.

Comment thread src/coreclr/jit/codegenwasm.cpp

@adamperlin adamperlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wasm / R2R: malformed wasm (missing function-body end opcode) for try / throwing-finally pattern in b51875

3 participants