www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5545] New: [64-bit] DMD fails to postincrement ubytes.

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com



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: -------
Feb 07 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5545


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



22:34:30 PST ---
https://github.com/D-Programming-Language/dmd/commit/64b9981229ee44b6126b96222936bd5c35be0e59

https://github.com/D-Programming-Language/dmd/commit/57eddad8d3484ee64736be21ddad1873365fc9b8

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