www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6962] New: Wrong Code With Scope Exit + By-Ref Parameters

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

           Summary: Wrong Code With Scope Exit + By-Ref Parameters
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com
        Depends on: 6955



The following code was reduced from std.conv.  It prints "BAD!!!" only with -O
enabled.  Since parse() gets rid of the entire contents of v, v.length should
be zero upon exiting toImpl and nothing should be printed.

import core.stdc.stdio;

T toImpl(T)(immutable string value)
{
    string v = value;  

    scope(exit)
    {
        if (v.length)
        {
            printf("BAD!!!");
        }
    }
    return parse!T(v);
}

T parse(T)(ref string value) 
{
    value = value[0..0];
    return 666;
}

void main() 
{
    immutable s = "42";
    toImpl!float(s);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6962


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Wrong Code With Scope Exit  |Wrong Code With Scope Exit
                   |+ By-Ref Parameters         |+ By-Ref Parameters, only
                   |                            |with -O
           Severity|normal                      |critical


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6962




Marginally reduced test case:

int bug6962(string value)
{
    string v = value;
    scope(exit)
       assert(!v.length);
    ref6962(v);
    return 1;
}

void ref6962(ref string value)
{
    value = value[0..0];
}

void main()
{
    string s = "42";
    bug6962(s);
}

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Wrong Code With Scope Exit  |Wrong Code With Scope Exit
                   |+ By-Ref Parameters, only   |and Array Parameter, only
                   |with -O                     |with -O
         OS/Version|Windows                     |All



Further reduced. The 'ref' is not necessary. The return statement is required,
otherwise the try-finally gets removed in the semantic pass.

void bug6962(string value)
{
    string v = value;
    try
    {
        v = v[0LU..0LU];
        return;
    }
    finally
    {
        assert(!v.length);
    }
}

void main()
{
    bug6962("42");
}
---------
When compiled with -O, the assert is compiled incorrectly. Instead of taking
v.length, it uses value.length.

Bonus: on Linux 64, running obj2asm on the object file (with or without -O)
causes obj2asm to segfault.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com
           Platform|Other                       |All
            Version|D2                          |D1 & D2



23:23:10 PST ---
https://github.com/D-Programming-Language/dmd/pull/1586

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




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

https://github.com/D-Programming-Language/dmd/commit/e67581883885baeb2882b72dac8b577444d03dfb
fix Issue 6962 - Wrong Code With Scope Exit and Array Parameter, only with -O

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




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

https://github.com/D-Programming-Language/dmd/commit/11b76a4aff5401b2928185a69789661ee4712907
fix Issue 6962 - Wrong Code With Scope Exit and Array Parameter, only with -O

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


fix Issue 6962 - Wrong Code With Scope Exit and Array Parameter, only wi...

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


Walter Bright <bugzilla digitalmars.com> changed:

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


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