Thread overview
[Issue 9356] New: -inline with inout and append generates wrong code
Jan 20, 2013
Jacob Carlborg
Feb 06, 2013
Denis Shelomovskij
Jun 24, 2013
Rainer Schuetze
Jun 28, 2013
yebblies
January 20, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9356

           Summary: -inline with inout and append generates wrong code
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: doob@me.com


--- Comment #0 from Jacob Carlborg <doob@me.com> 2013-01-20 04:07:46 PST ---
The assert in "foo" passes, which it obviously shouldn't.

inout(char)[] bar (inout(char)[] a)
{
    return a;
}

void foo (string str)
{
    string result;
    result ~= bar(str);
    assert(result == "!");
}

void main ()
{
    foo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}

If I remove "inout" in "bar" or the append in "foo" the code work as expected. What "result" will actually be depends on the length of the string passed to "foo".

I've only tried this with on Mac OS X, both 32 and 64bit.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9356


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |verylonglogin.reg@gmail.com
           Severity|normal                      |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9356


Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de


--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> 2013-06-23 23:21:31 PDT ---
I have hit this bug with a recent commit to druntime that changes the implementation of AssociativeArray.keys:

import std.stdio;

void main()
{
    string[] files;
    files ~= "1";
    files ~= "2";

    byte[string] cache;
    cache["3"] = 1;
    cache["4"] = 1;

    files ~= cache.keys;
    writeln(files);
}

when compiled with -inline, it prints

["1", "2", "\x01\x00"]

This seems to be caused by inout(T[]) not being appendable to T[]. Instead it
is appended as a single element (_d_arrayappendcT is called, see
CatAssignExp::toElem).

In case of AssociativeArray.keys, there also seems to be a problem that inlining seems to ignore implicite conversion on the return type by the inlined function.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9356


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |yebblies@gmail.com
         AssignedTo|nobody@puremagic.com        |yebblies@gmail.com


--- Comment #2 from yebblies <yebblies@gmail.com> 2013-06-28 23:53:01 EST ---
Yeah, the inliner ends up replacing the call expression with the return expression, but doesn't re-paint the type to account for castless implicit conversions.  e2ir uses if/else when it should be using if/elseif/else assert, so it generates wrong code instead of ICEing.

https://github.com/D-Programming-Language/dmd/pull/2269

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