Skip to content

JIT: fix wasm conditional fallthrough - #133528

Merged
AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix-wasm-conditional-fallthrough-133465
Sep 10, 2026
Merged

AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix-wasm-conditional-fallthrough-133465

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

An adjacent conditional target is not always a valid wasm fallthrough: closing a Try or ExnRefWrapper interval can inject instructions before the target. Reuse the existing wasm fallthrough check for conditional branches.

Fixes #133465
Fixes #133469

Note

This PR description was generated with GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 581bf1d5-7317-4f55-8a57-fc67827c425e
Copilot AI lite review requested due to automatic review settings September 9, 2026 19:48
@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 Sep 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

🟢 Approval recommended

The change correctly reuses the existing wasm fallthrough safety logic to prevent invalid fallthroughs at Try/ExnRefWrapper boundaries, with no apparent behavioral regressions outside wasm.

Pull request overview

This PR fixes WebAssembly codegen for conditional branches by ensuring “adjacent target” is only treated as a valid fallthrough when it’s actually safe in the presence of wasm EH interval boundary emissions.

Changes:

  • Update wasm genCodeForJTrue to use BasicBlock::CanRemoveJumpToTarget instead of a raw falseTarget != block->Next() adjacency check.
  • Extend BasicBlock::CanRemoveJumpToTarget to cover both BBJ_ALWAYS and BBJ_COND, and incorporate the existing wasm interval end check to block unsafe fallthroughs (Try / ExnRefWrapper ends).
File summaries
File Description
src/coreclr/jit/codegenwasm.cpp Use CanRemoveJumpToTarget when deciding whether to emit the unconditional branch to the false target.
src/coreclr/jit/block.cpp Generalize CanRemoveJumpToTarget and reuse it from CanRemoveJumpToNext, including the wasm interval-end fallthrough prohibition.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@AndyAyersMS

Copy link
Copy Markdown
Member Author

fyi @dotnet/wasm-contrib
@jakobbotsch PTAL

@AndyAyersMS AndyAyersMS added the arch-wasm WebAssembly architecture label Sep 9, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 581bf1d5-7317-4f55-8a57-fc67827c425e
Copilot AI review requested due to automatic review settings September 10, 2026 00:09

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.

🔵 Needs a closer look

It changes CoreCLR JIT control-flow emission semantics for wasm (high correctness impact) and should be validated by a maintainer with wasm R2R test coverage signals.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@AndyAyersMS
AndyAyersMS merged commit 3b71152 into dotnet:main Sep 10, 2026
140 of 143 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture 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] HeapExpansion bestfit tests trap after reaching steady state [wasm][R2R] throwinfinally_50 traps with unreachable

3 participants