[Issue 16530] New: -O -cov interaction leads to wrong codegen
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Sep 23 10:33:05 PDT 2016
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: nobody at puremagic.com
Reporter: andrei at erdani.com
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.
--
More information about the Digitalmars-d-bugs
mailing list