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

           Summary: [64-bit] DMD fails to postincrement ubytes.
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: dsim...@yahoo.com


--- Comment #0 from David Simcha <dsim...@yahoo.com> 2011-02-07 16:38:10 PST ---
I apologize for the length of this test case, it was reduced from a ~1500 line
file with a failing unittest.  The following bug seems to be caused by DMD
failing to increment i in the struct Perm.  It only happens under -O -release
-m64.  Omitting any of these flags makes this program work.  Also, the call to
enforce() is necessary to reproduce the bug.

import std.stdio;

bool enforce(bool value, lazy const(char)[] msg = null) {
    if(!value) {
        return false;
    }

    return value;
}

struct Perm {
    byte[3] perm;
    ubyte i;

    this(byte[] input) {
        foreach(elem; input) {
            enforce(i < 3);
            perm[i++] = elem;
            stderr.writeln(i);  // Never gets incremented.  Stays at 0.
        }
    }
}

void main() {
    byte[] stuff = [0, 1, 2];
    auto perm2 = Perm(stuff);
    writeln(perm2.perm);  // Prints [2, 0, 0]
    assert(perm2.perm[] == [0, 1, 2]);
}

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

Reply via email to