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) signed Log2 intrinsic drops ArgumentOutOfRangeException when the result is unused #133965
For signed int.Log2 and long.Log2, the imported throwing fallback can be deleted when the intrinsic result is dead, so negative inputs return normally instead of throwing.
Minimal Repro
usingSystem;usingSystem.Runtime.CompilerServices;publicclassProgram{[MethodImpl(MethodImplOptions.NoInlining)]publicstaticintNeg()=>-1;[MethodImpl(MethodImplOptions.NoInlining)]publicstaticlongNegL()=>-1;[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]publicstaticvoidTest(intx){intunused=int.Log2(x);}[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]publicstaticvoidTestLong(longx){longunused=long.Log2(x);}[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]publicstaticintTestUsed(intx){returnint.Log2(x);}publicstaticvoidMain(){try{Test(Neg());Console.WriteLine("Test: No exception");}catch(ArgumentOutOfRangeException){Console.WriteLine("Test: ArgumentOutOfRangeException");}try{TestLong(NegL());Console.WriteLine("TestLong: No exception");}catch(ArgumentOutOfRangeException){Console.WriteLine("TestLong: ArgumentOutOfRangeException");}try{TestUsed(Neg());Console.WriteLine("TestUsed: No exception");}catch(ArgumentOutOfRangeException){Console.WriteLine("TestUsed: ArgumentOutOfRangeException");}}}
Test: No exception
TestLong: No exception
TestUsed: ArgumentOutOfRangeException
Notes
The signed Log2 fallback is a GT_INTRINSIC with GTF_CALL, but GT_INTRINSIC is not treated as throwing/side-effecting by the relevant side-effect checks.
Early liveness therefore deletes the dead store containing the fallback; Test and TestLong become a bare ret.
This is a regression in main; .NET 10 throws as expected.
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.
EgorBo commentedon Sep 18, 2026
Affected SDK versions:
JIT: model the signed Log2 fallback as throwing (dotnet#135485)