www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16530] New: -O -cov interaction leads to wrong codegen


          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


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