Skip to content

[wasm][R2R] JIT asserts "block order disagrees with preorder num" when an unremovable block becomes unreachable #136041

Closed

Description

@lewing

Description

The Wasm JIT asserts in Wasm control flow (src/coreclr/jit/fgwasm.cpp) when the flow graph contains an unreachable block that fgRemoveBlocksOutsideDfsTree could not remove:

Assertion failed '(block->bbPreorderNum == order) && "block order disagrees with preorder num"' in 'AA:TestEntryPoint(int[])' during 'Wasm control flow' (IL size 35; FullOpts)

This reproduces on current main with a checked Wasm crossgen2 JIT.

Repro

using System;
public class AA
{
    public static void TestEntryPoint(int[] p)
    {
        try
        {
            GC.Collect();
        }
        catch (DivideByZeroException)
        {
            while (checked(p[0] > p[0]))
            {
                try
                {
                    GC.Collect();
                }
                catch (Exception) { }
            }
        }
        catch (Exception) { }
    }
}

Compile with crossgen2 --targetos:browser --targetarch:wasm -O using the checked libclrjit_universal_wasm_* JIT.

Analysis

  1. Loop inversion calls fgSplitBlockAtEnd on the loop's preheader, which is the catch handler's entry block. The new preheader (BB12 in the dump) inherits BBF_DONT_REMOVE through CopyFlags.
  2. Value numbering proves p[0] > p[0] false, so the loop and its preheader become unreachable.
  3. Wasm remove unreachable blocks (fgRemoveBlocksOutsideDfsTree) converts the BBF_DONT_REMOVE block to an empty BBJ_THROW but keeps it. The dump shows "1 unreachable blocks were not removed: BB12".
  4. Wasm control flow lays out only the blocks in its DFS, so the kept block has a stale bbPreorderNum, and the debug check that the block list matches preorder numbering fires.

Stopping fgSplitBlockAtEnd from copying BBF_DONT_REMOVE is not a fix by itself: it trips HBtab->ebdTryBeg->HasFlag(BBF_DONT_REMOVE) during loop inversion. The Wasm control-flow pass, or the unreachable-block removal that runs before it, probably needs to handle unreachable blocks that must be kept.

Impact

This is hit in the outerloop R2R_CG2 browser wasm lane by JIT/Regression/Regression_PdbOnly_r_2 (b49322.AA:TestEntryPoint, which has while (checked(m_ul > m_ul)) inside a catch) once static-base helper calls are marked hoistable in #136037: value numbering can then fold the condition. The bug itself is pre-existing; the array-based repro above asserts on main.

Note

This issue was drafted with GitHub Copilot.

Activity

  1. added
    arch-wasm
    area-CodeGen-coreclr
    on Oct 19, 2026
  2. added
    untriaged
    on Oct 19, 2026
  3. dotnet-policy-service commented on Oct 19, 2026

    @dotnet-policy-service
    Contributor

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

  4. dotnet-policy-service commented on Oct 19, 2026

    @dotnet-policy-service
    Contributor

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

  5. added this to the 12.0.0 milestone on Oct 19, 2026
  6. removed
    untriaged
    on Oct 19, 2026
  7. self-assigned this
    on Oct 19, 2026
  8. locked and limited conversation to collaborators on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions