Reproduction:
Console.WriteLine(Problem(0));
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static short Problem(byte x)
{
short a = -1;
Unsafe.InitBlock(&a, x, 2);
return a;
}
Compile and run.
Expected result: the program prints 0.
Actual result: the program prints -65536.
Cause: normalize-on-store assumes all entire stores overwrite the full stack slot.
Reproduction:
Compile and run.
Expected result: the program prints
0.Actual result: the program prints
-65536.Cause: normalize-on-store assumes all entire stores overwrite the full stack slot.