Basically we had a bug where a whole conditional branch was being skipped, and we traced it down to the branch being omitted entirely from the compiled IR.
And no, it was nothing fancy, just something like:
if (customer.country == "US") {
doSomething();
} else {
doDifferentThing();
}
The whole `else` branch was simply missing from the compiled program.If I remember correctly, we got around it by doing something like:
bool isUsCustomer = customer.country == "US"
if (isUsCustomer) {
doSomething();
} else {
doDifferentThing();
}
Anyway, the point is that the compiler fucked up it's handling of if/else statements, but only at that specific part of the code, leading to a few wasted days of effort tracking down the problem.I'm not finding it right now, but I recall seeing a few weeks ago a presentation with several of these sorts of bugs in a recent version of Java (all reported and fixed): after a number of iterations, it suddenly starts returning wrong results.
It probably was the optimiser at fault, but there wasn't anything special about this conditional, and certainly nothing that _should_ have caused the optimiser to throw away the else branch.
If memory serves right it was comparing a string field of an object to a static string, like `someObject.foo == "some string"`.
It would have to be specific. Put it this way: if this was a general bug and the "else" was always omitted, how long would it last before being found and fixed?
Related, if you were to say to me "I found the issue, the compiler isn't correctly handling if/else statements" Then my first thought would be about your medication not about the compiler.
And yet, it happened :)
And the senior engineers at the company looked at it and confirmed it was a compiler bug. Their best guess was that something about that part of the code was putting the compiler in a funny state, causing it to skip that particular `else` branch.
We reported it to Microsoft, but never heard anything back.