Compiler bugs are indeed pretty frightening. A few years ago I bumped into one in some code that had potential to have a big impact. Unfortunately I am not at liberty to give details about the business setting except to say that we had processes in place that prevented any danger.
In the end I whittled it down to the following tiny C# program:
namespace UhOh
{
internal class Program
{
private static void Main()
{
System.Console.WriteLine(Test(0, 0));
}
private static bool Test(uint a, uint b)
{
var b_gte_a = b >= a;
var b_gt_a = b > a;
System.Console.WriteLine(b_gte_a);
return b_gte_a && b_gt_a;
}
}
}
Compiling and running this with Microsoft's .NET stack with versions 4.7.0 and below, the output was incorrectly: "True, True" instead of "True, False". (IIRC, it also had to be a 64-bit Release build.)
The intermediate language was correct; it was a bug in RyuJIT.
In the end I whittled it down to the following tiny C# program:
Compiling and running this with Microsoft's .NET stack with versions 4.7.0 and below, the output was incorrectly: "True, True" instead of "True, False". (IIRC, it also had to be a 64-bit Release build.)The intermediate language was correct; it was a bug in RyuJIT.