www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9496] New: [REG 2.061 -> 2.062 alpha] "this[1 .. $]" passes wrong "this" to "opDollar"

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

           Summary: [REG 2.061 -> 2.062 alpha] "this[1 .. $]" passes wrong
                    "this" to "opDollar"
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com



***************************************
NOTE: THIS ***JUST*** BROKE IN GIT HEAD.
***************************************

I had this pull:
https://github.com/D-Programming-Language/phobos/pull/992
Which was working fine, and then just spontaneously broke on the 8th:
http://d.puremagic.com/test-results/pull-history.ghtml?projectid=1&repoid=3&pullid=992

Looks like a compiler or codegen bug:

Basically, if, inside a member function, you want a slice, you'd write "this[a
.. b]".

Now, if you want to slice to the end, you'd write "this[a .. $]" problem is
that in this specific case, the wrong "this" is passed to opDollar. What is
strange is that it *only* happens when the words "this", and "$" are mixed
together. It does not happen if you call "s[1 .. $]" or "this[1 ..
opDollar()]":

//----
import std.stdio;

struct S
{
    size_t opDollar()
    {
        writeln("Inside opDollar ", cast(void*)&this);
        return 10;
    }
    void opSlice(size_t , size_t)
    {
        writeln("Inside opSlice: ", cast(void*)&this);
    }
    void getSlice()
    {
        writeln("Inside get:     ", cast(void*)&this);
        writeln("Normal");
        this[1 .. opDollar()];
        writeln("wait for it:");
        this[1 .. $];
    }
}

void main()
{
    S s;
    writeln("Main:           ", cast(void*)&s);
    s.getSlice();
    writeln("not here:");
    s[1 .. $];
}
//----
Main:           18FD70
Inside get:     18FD70
Normal
Inside opDollar 18FD70
Inside opSlice: 18FD70
wait for it:
Inside opDollar 18FD74 <-- HERE: wrong this.
Inside opSlice: 18FD70
not here:
Inside opDollar 18FD70
Inside opSlice: 18FD70
//----

With more fancy scenarios, I've had more extreme values for this, including
"0", "4" and "D"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 10 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496





 ***************************************
 NOTE: THIS ***JUST*** BROKE IN GIT HEAD.
 ***************************************
Forgot to mention, the test case works correctly in 2.061. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com
           Severity|major                       |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru



---

 ***************************************
 NOTE: THIS ***JUST*** BROKE IN GIT HEAD.
 ***************************************
Why so emotional? Instead you can be more informative by telling that it happens with -m32 (at least I cannot reproduce on linux with -m64). Why did you decide that recent dmd pulls break this code? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



12:37:44 PST ---
I can't reproduce this on win32. Can you specify which flags/platform you're
using?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496




---
I can reproduce on linux64 githead for both -m32 and m64

import core.stdc.stdio : printf;

struct S
{
    int i;
    size_t opDollar()
    {
        printf("Inside opDollar: %p\n", cast(void*)&this );
        //i = 0;
        return 10;
    }
    void opSlice(size_t , size_t)
    {
        printf("Inside opSlice:  %p\n", cast(void*)&this);
    }
    void getSlice()
    {
        printf("Inside get:      %p\n", cast(void*)&this);
        this[1 .. $];
    }
}

void main()
{
    S s;
    s.getSlice();
}

With -m32 and -m64 there is incorrect address in opDollar. With -inline it's
fine, with -g there is AssertError ("null this") and with -O I have "Error:
variable __dop5 used before set".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|All                         |Linux



PST ---
Yeah. On 64-bit Linux, I'm getting

Main:           7FFF39C7A4D8
Inside get:     7FFF39C7A4D8
Normal
Inside opDollar 7FFF39C7A4D8
Inside opSlice: 7FFF39C7A4D8
wait for it:
Inside opDollar 10
Inside opSlice: 7FFF39C7A4D8
not here:
Inside opDollar 7FFF39C7A4D8
Inside opSlice: 7FFF39C7A4D8

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Linux                       |All



12:55:56 PST ---
Introduced by commit:

commit 6e2f1ec1abfacf61f9f156ccf5b814a3f6e26591
Author: k-hara <k.hara.pg gmail.com>
Date:   Wed Feb 6 12:27:35 2013 +0900

    fix Issue 9453 - ice(symbol.c) with slice on temporary

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496






 ***************************************
 NOTE: THIS ***JUST*** BROKE IN GIT HEAD.
 ***************************************
Why so emotional? Instead you can be more informative by telling that it happens with -m32 (at least I cannot reproduce on linux with -m64). Why did you decide that recent dmd pulls break this code?
NOt really emotional, just clumsy I guess. I wanted to make sure to stress that something just broke: If we can easilly track down the change now, it greatly increases the chances of this being fixed, and may save someone hours of debugging. Apologies for forgetting to mention my version: Standard w32, with no switches. I also usually check linux 32/64 with dpaste, but the dpaste compiler has been down for a while, so I couldn't check. I decided a recent dmd pull breaks the code because my code spontaneously stopped working, and because I could reproduce the bug on something that does not depend on phobos. I'm not *blaming* anyone or anything. It's just that in my experience, fixing something is 10 times easier if you can track down *what* broke it in the first place. So I wanted to make sure we don't miss that window. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, wrong-code



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


 NOt really emotional, just clumsy I guess. I wanted to make sure to stress that
 something just broke: If we can easilly track down the change now, it greatly
 increases the chances of this being fixed, and may save someone hours of
 debugging.
I especially observe regression issues, at least in beta phase. To me, "Importance: regression" is enough. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7d126bd61d86ec36b44f2b8b62bf725c65a7288e
fix Issue 9496 - [REG 2.061 -> 2.062 alpha] "this[1 .. $]" passes wrong "this"
to "opDollar"

https://github.com/D-Programming-Language/dmd/commit/8f9ee7b112c644c4c2b830a4f9c79974196e37d5


Issue 9496 - [REG 2.061 -> 2.062 alpha] "this[1 .. $]" passes wrong "this" to
"opDollar"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496




Commit pushed to staging at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6207580a33df353f4a4ff7e91d64f0ff0734878f


Issue 9496 - [REG 2.061 -> 2.062 alpha] "this[1 .. $]" passes wrong "this" to
"opDollar"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9496


Walter Bright <bugzilla digitalmars.com> changed:

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


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