You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JIT: (bug) optRemoveRedundantZeroInits removes a required zero store after a catch-handler write #134004
optRemoveRedundantZeroInits scans only along unique normal successors and can skip a catch handler that writes an address-exposed local. It then deletes an explicit zero store at the rejoin block, leaving the handler-written value observable.
Minimal Repro
usingSystem;usingSystem.Runtime.CompilerServices;publicclassProgram{staticbools_throw=true;[MethodImpl(MethodImplOptions.AggressiveInlining)]staticintZero()=>0;[MethodImpl(MethodImplOptions.NoInlining)]staticvoidThrower(){if(s_throw)thrownewException("boom");}[MethodImpl(MethodImplOptions.NoInlining)]staticvoidConsume(intv){}[MethodImpl(MethodImplOptions.NoInlining)]staticvoidSetRef(refintx,intv){x=v;}[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticintTest(intp){intx=0;try{Thrower();}catch(Exception){SetRef(refx,p);Consume(x);}x=Zero();// <-- this store is deleted by optRemoveRedundantZeroInitsConsume(x);returnx;}staticintMain(){intr=Test(5);Console.WriteLine("Test(5) = "+r);returnr==0?100:1;}}
Expected
Test(5) = 0
Exit code 100.
Actual
Test(5) = 5
Exit code 1. JitDump shows the pass skipping the catch handler and deleting the rejoin store:
Analyzing BB01
Analyzing BB02
Analyzing BB04 <-- BB03, the catch handler, is never analyzed
removing useless STMT00003 ( 0x01A[E--] ... ??? ) ... STORE_LCL_VAR int (AX) V01 loc0 = 0
Disassembly confirms the rejoin block uses [rbp-0x08] without restoring it to zero after the handler writes p.
Notes
Compiler::optRemoveRedundantZeroInits() (optimizer.cpp) walks via GetUniqueSucc(), which ignores EH predecessors of the successor; BB04 has an unvisited catch predecessor that redefines the local.
The trigger is a neverTracked local such as address-exposed x with !fgVarNeedsExplicitZeroInit(...); an object-local variant returns non-null instead of null.
Also reproduces on released .NET 10.0.12 x64. Stop the scan at rejoins with unvisited/EH predecessors or apply the implicit-control-flow guard to explicit zero-store removal.
changed the title [-]JIT (bug): optRemoveRedundantZeroInits removes a required zero store after a catch-handler write[/-][+]JIT: (bug) optRemoveRedundantZeroInits removes a required zero store after a catch-handler write[/+]on Sep 16, 2026
Activity
dotnet-policy-service commentedon Sep 15, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
[-]JIT (bug): optRemoveRedundantZeroInits removes a required zero store after a catch-handler write[/-][+]JIT: (bug) optRemoveRedundantZeroInits removes a required zero store after a catch-handler write[/+]EgorBo commentedon Sep 18, 2026
Affected SDK versions:
JIT: Stop the redundant zero-init scan at blocks with other predecess…