Skip to content

[Wasm RyuJit] assert function regions are contiguous after control flow - #131433

Open
AndyAyersMS wants to merge 1 commit into
mainfrom
wasm-funclet-contiguity-assert
Open

[Wasm RyuJit] assert function regions are contiguous after control flow#131433
AndyAyersMS wants to merge 1 commit into
mainfrom
wasm-funclet-contiguity-assert

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Codegen emits one wasm function body per region (main method and each funclet) by walking the block order. Add a debug check after fgWasmControlFlow that each region's blocks are contiguous in the order.

Codegen emits one wasm function body per region (main method and each funclet)
by walking the block order. Add a debug check after fgWasmControlFlow that
each region's blocks are contiguous in the order.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b7c0ded2-277e-4756-aa38-e786756ceb45
Copilot AI review requested due to automatic review settings July 27, 2026 18:23
@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 Jul 27, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

Just adding some defensive checks; out of order blocks lead to more confusing errors in codegen.

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

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

Adds a DEBUG-only validation in the Wasm-specific control-flow phase to ensure basic blocks belonging to each “wasm function region” (main method and each funclet/filter region) appear contiguously in the final physical block order that codegen walks. This helps catch invalid block ordering early, given Wasm codegen emits one Wasm function body per region.

Changes:

  • Add a DEBUG assertion in fgWasmControlFlow that detects “re-entry” into a previously closed funclet region while iterating Blocks().
  • Factor out region classification logic into a new helper bbFuncletRegionOf and reuse it from bbIsInSameFunclet.
  • Declare the new helper on Compiler to make it available to other compilation phases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/fgwasm.cpp Adds a DEBUG-only contiguity check over physical block order to ensure each funclet region forms one contiguous block sequence.
src/coreclr/jit/compiler.hpp Introduces bbFuncletRegionOf (main region = 0, filter adjustment) and re-implements bbIsInSameFunclet in terms of it.
src/coreclr/jit/compiler.h Adds the bbFuncletRegionOf declaration to the Compiler class.

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

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g build timeout

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.

3 participants