https://issues.dlang.org/show_bug.cgi?id=16530
Issue ID: 16530
Summary: -O -cov interaction leads to wrong codegen
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
Code:
double entropy(double[] probs)
{
double result = 0;
// BUG: remove the "ref" below to expose codegen bug in dmd
foreach (p; probs)
{
if (!p) continue;
import std.math : log2;
result -= p * log2(p);
}
return result;
}
void main()
{
import std.stdio;
writeln(entropy([1.0, 0, 0]));
}
To repro, build with -O -cov. It will print -nan. Should print 0.
--