Skip to content

Wasm / R2R: crossgen2 assert in fgWasmControlFlow on badcodeinsidefinally.il #129262

Closed

Description

@AndyAyersMS

Compiling src\tests\JIT\Methodical\eh\deadcode\badcodeinsidefinally.il
for Wasm R2R hits an assert in fgWasmControlFlow:

src\coreclr\jit\fgwasm.cpp:1385
Assertion failed 'loops->GetLoopByHeader(succ) != nullptr' in
'Test_badcodeinsidefinally:GetObj():System.Object' during 'Wasm control flow'
(IL size 24; hash 0xd22e2b4d; MinOpts)

The asserting code (added by #121457 / 41c9fa2d39a) handles back edges
during wasm control-flow lowering and expects every backedge target to
already be registered as a loop header. For this test the backedge
target is not registered, so the assert fires and crossgen2 exits with
-2147483645 (STATUS_BREAKPOINT).

This kills the merged R2R image build for any Methodical_d1/_d2/_r1/_r2
partition (whose glob picks up eh/deadcode/badcodeinsidefinally_{d,r}.ilproj),
which blocks running those JIT test suites under Wasm/R2R.

The IL shape that triggers it (nested EH with a throw inside catch inside
finally):

.method static object GetObj() cil managed
{
  .locals init (string str)
try_l0_begin:
try_l1_begin:
  ldstr      "pass"
  stloc.0
  leave      done
try_l1_end:

finally_l1_begin:
try_l2_begin:
  ldnull
  throw
try_l2_end:
catch_l2_begin:
  throw
catch_l2_end:
  pop
  endfinally
finally_l1_end:

try_l0_end:

catch_l0_begin:
  pop
  leave      catch_l0_end
catch_l0_end:

done:
  ldloc.0
  ret

  .try try_l2_begin to try_l2_end
    catch [mscorlib]System.Exception handler catch_l2_begin to catch_l2_end
  .try try_l1_begin to try_l1_end
    finally handler finally_l1_begin to finally_l1_end
  .try try_l0_begin to try_l0_end
    catch [mscorlib]System.Exception handler catch_l0_begin to catch_l0_end
}

Repro

.\build clr+libs -rc debug -c release -os browser
.\src\tests\build skipmanaged browser

;; put repo dotnet in path
set DOTNET_ROOT=<REPO_ROOT>\.dotnet
set PATH=<REPO_ROOT>\.dotnet;%PATH%

cd src\tests\JIT\Methodical\eh\deadcode
dotnet msbuild /p:TargetArchitecture=wasm /p:TargetOS=browser /p:RuntimeFlavor=coreclr ^
  /p:BuildAsStandalone=true badcodeinsidefinally_d.ilproj

set CORE_ROOT=<REPO_ROOT>\artifacts\tests\coreclr\browser.wasm.Debug\Tests\Core_Root
set DLL=<REPO_ROOT>\artifacts\tests\coreclr\browser.wasm.Debug\JIT\Methodical\eh\deadcode\badcodeinsidefinally_d\badcodeinsidefinally_d.dll
set CG2DIR=<REPO_ROOT>\artifacts\bin\crossgen2_inbuild\wasm\Debug

dotnet %CG2DIR%\crossgen2.dll ^
  --targetos:windows --targetarch:wasm ^
  --jitpath %CG2DIR%\clrjit_universal_wasm_x64.dll ^
  --inputbubble ^
  -r:%CORE_ROOT%\*.dll ^
  -o:badcodeinsidefinally_d.wasm ^
  --parallelism 1 ^
  %DLL%

Hit on wasm-eh-infra (and on any branch built on top of it, e.g. PR #129197).
Because the assert fires at R2R compile time, the runtime-side
DOTNET_ReadyToRunExcludeList workaround used in #128234 does not help here.

Activity

  1. self-assigned this
    on Jun 10, 2026
  2. added
    arch-wasm
    area-CodeGen-coreclr
    on Jun 10, 2026
  3. AndyAyersMS commented on Jun 10, 2026

    @AndyAyersMS
    MemberAuthor

    You would think a test named badcodeinsidefinally.il would have invalid IL, but perhaps not.

  4. added a commit that references this issue on Jun 11, 2026
    125cc59
  5. locked and limited conversation to collaborators on Jul 12, 2026
  6. added a commit that references this issue on Jul 15, 2026
    f0c78b2
  7. added a commit that references this issue on Jul 22, 2026
    e2331c4
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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions