usingSystem;usingSystem.Runtime.CompilerServices;Console.WriteLine(Test(newint[4],int.MinValue));[MethodImpl(MethodImplOptions.NoInlining|MethodImplOptions.AggressiveOptimization)]staticintTest(int[]array,intindex){if((uint)(index-int.MaxValue)<(uint)array.Length&&index<array.Length){refintunused=refarray[index];return1;}return0;}Optimized: prints 1.
With DOTNET_JitMinOpts=1: throws IndexOutOfRangeException (expected).
.NET 11.0, win-x64.
unchecked(int.MinValue - int.MaxValue) is 1, so both guards pass, but index is still negative. The negative-offset case in MergeEdgeAssertionsWorker incorrectly infers index >= int.MaxValue and the bounds check is removed.
Copilot-generated.
Optimized: prints
1.With
DOTNET_JitMinOpts=1: throwsIndexOutOfRangeException(expected)..NET 11.0, win-x64.
unchecked(int.MinValue - int.MaxValue)is1, so both guards pass, butindexis still negative. The negative-offset case inMergeEdgeAssertionsWorkerincorrectly infersindex >= int.MaxValueand the bounds check is removed.