[Issue 4506] New: -O flag breaks some recursive functions.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 25 08:29:07 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4506

           Summary: -O flag breaks some recursive functions.
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: peter.alexander.au at gmail.com


--- Comment #0 from Peter Alexander <peter.alexander.au at gmail.com> 2010-07-25 08:29:05 PDT ---
I wrote a function to count integer partitions. When compiled with dmd test.d,
I get the correct result. Adding the -O flag makes the program return the
incorrect result:

import std.stdio;

auto P(int n)
{
    if (n < 0) return 0;
    if (n == 0) return 1;

    int c = 1;
    int r = 0;
    for (int k = 1; k <= n; ++k)
    {
        r += c * (P(n-k*(3*k-1)/2) + P(n-k*(3*k+1)/2));
        c *= -1;
    }
    return r;
}

void main()
{
    writeln(P(10));
}

$ dmd test.d
$ ./test
42
$ dmd -O test.d
$ ./test
138

Unfortunately I haven't been able find a more minimal reproduction case. In
particular, a basic recursive Fibonacci function works fine in both cases.

Using dmd 2.047 on Mac OS X Snow Leopard.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list