October 17, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2421

           Summary: Struct assignment is broken (nulls target before
                    evaluating source)
           Product: DGCC aka GDC
           Version: 0.24
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: glue layer
        AssignedTo: dvdfrdmn@users.sf.net
        ReportedBy: fvbommel@wxs.nl


When you assign a struct value to a struct variable, the variable is under some
circumstances nulled before evaluating the value. This leads to miscompilation
if fields of the value depend on those of the variable.
Test case:
-----
module test;

// Some lib-independence
version(Tango) {
    import tango.io.Stdout;
    void show(Foo f) {
        Stdout.formatln("{} : {}", f.p, f.flag);
    }
} else {
    import std.stdio;
    void show(Foo f) {
        writefln("%s : %s", f.p, f.flag);
    }
}

struct Foo {
    void* p;
    bool flag;
}

void main() {
    // Random non-zero values
    auto f = Foo(&show, true);

    // Prints correct non-zero values
    show(f);

    // Set to fresh copy of itself...
    f = Foo(f.p, f.flag);

    // prints {null} : false
    show(f);
}
-----
This seems to be as minimal as I can make it.
Removing either field makes the problem go away, as does replacing the pointer
with an int or float (but replacing the pointer with an object reference or
double doesn't).


$ gdc --version
gdc (GCC) 4.1.3 20070831 (prerelease gdc 0.25, using dmd 1.021) (Ubuntu
0.25-4.1.2-16ubuntu1)


-- 

August 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2421


Iain Buclaw <ibuclaw@ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME


--- Comment #1 from Iain Buclaw <ibuclaw@ubuntu.com> 2010-08-05 15:12:05 PDT ---
I cannot reproduce this on gdc 0.25 using dmd 1.060 with gcc-4.1.2 and gcc-4.3.5.

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