[Issue 9666] New: Invalid struct passing + redundant struct copy on struct assignment

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 8 04:25:16 PST 2013


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

           Summary: Invalid struct passing + redundant struct copy on
                    struct assignment
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: maxim at maxim-fomin.ru


--- Comment #0 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-03-08 04:25:14 PST ---
For code like:

module e;

struct Date
{
  //Make sure this is not a POD
  this(this){}
  short _year = 2;
  ubyte _month = 1;
  ubyte _day = 1;
}


void setDate(Date d)
{
  Date x;
  x = d;
}

void main()
{
  Date d;
  setDate(d);
}

dmd generates two copies, first - when passing argument "d" to setDate(), and
second - when assigning parameter "d" to x. The latter is redundant.

#dmd main.d -v -release
....
function  e.setDate
Date x = _D1e4Date6__initZ;
x.opAssign((Date __cpcttmp6 = __cpcttmp6.__cpctor(d); , __cpcttmp6))
function  D main
Date d = _D1e4Date6__initZ;
setDate((Date __cpcttmp7 = __cpcttmp7.__cpctor(d);, __cpcttmp7))
....

This frontend pseudo-code survives CT and is present in object file as a call
to __cpctor inside setDate() asm output.

Originally this comes from dmd-internal discussion where it was found that
there is another dmd bug - it passes nonPOD struct in register. So, there are
two issues here.

Link: http://forum.dlang.org/thread/5138D02A.30200@googlemail.com

-- 
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