www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2127] New: inliner turns struct "return *this" from by-value into by-ref

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2127

           Summary: inliner turns struct "return *this" from by-value into
                    by-ref
           Product: D
           Version: 1.030
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: fvbommel wxs.nl


The following code:
-----
module evbug;
import std.stdio;

struct S {
  int last = 0;
  S opCall(int i) {
    writefln("%s %s", last, i);
    last = i;
    return *this;
  }
}

void main() {
  S t;
  t(1)(2);
  t(3);
}
-----
should output
=====
0 1
1 2
1 3
=====
(Note that opCall returns a copy of the original struct, so the first and last
calls will be passed &t as 'this', but the second is passed a pointer to a
copy)
With "dmd -run test.d", this all works fine.

However, when run with "dmd -inline -run test.d":
=====
0 1
1 2
2 3
=====
(note the last line)
The "return *this" seems suddenly to have compiled as a reference return
instead of a value return. (This can be verified by making opCall print the
address as well; the uninlined version will only report the same address for
the first and last call, while the inlined version reports the same address
every time)

GDC doesn't exhibit this problem, presumably because it uses the GCC inliner.


-- 
May 24 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2127


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
           Severity|major                       |critical


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2127




---
Created an attachment (id=642)
tentative fix for this for the d2 branch (might work on d1 as well, untested)

This bug exists in the d2 code base as well.  This patch fixes the test case
and passes the test suite.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 25 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2127


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

           obsolete|                            |



---
Created an attachment (id=643)
d2 fix, version 2

Oops.. the version I attached previously was an older copy.  This is the newer
version that moves the changes down from FuncDeclaration::inlineScan to
doInline and fixes a problem with the first version.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 25 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2127


Walter Bright <bugzilla digitalmars.com> changed:

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



11:03:31 PDT ---
http://www.dsource.org/projects/dmd/changeset/505

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