Closed
Description
The following program prints 0 1 2 3
. It should not print anything.
using System;
using System.Runtime.CompilerServices;
public class Program
{
public static void Main()
{
Foo(0);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Foo(int y)
{
int x = 0;
if (y != 0)
{
do
{
Console.WriteLine(x);
x++;
}
while (x < 4);
}
}
}
The problem is this code in loop unrolling, which unconditionally removes the init block condition, for reasons unclear to me:
runtime/src/coreclr/jit/optimizer.cpp
Lines 4481 to 4508 in c33557d