digitalmars.D.bugs - [Issue 16530] New: -O -cov interaction leads to wrong codegen
- via Digitalmars-d-bugs (33/33) Sep 23 2016 https://issues.dlang.org/show_bug.cgi?id=16530
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 puremagic.com Reporter: andrei 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. --
Sep 23 2016