www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5790] New: "Error: variable result used before set" when -release -inline -O

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

           Summary: "Error: variable result used before set" when -release
                    -inline -O
           Product: D
           Version: D2
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jordi rovira.cat



PDT ---
When compiling the following code with 

dmd -c -release -inline -O resource.d

I get the message "Error: variable result used before set" without any line
information, and compilation fails.

This happens only with the flags above. Removing any of them, or compiling in
debug results in good output. I have verified that this error happens both in
linux and windows, with dmd 2.052 and since many versions ago. 

<Speculation>
Even GDC crashes compiling this code in release, which makes me think it is in
the front end.

<Data>
I have removed everything i could, and now the code doesn't make much sense,
but the file resource.d is:

module     bug;

import     std.c.string;

class InputStream
{
public:

    InputStream opShr(T)( out T result )
    {
        memcpy( &result, &m_data[m_pos], T.sizeof );
        m_pos += T.sizeof;

        return this;
    } 

    int m_pos;
    const ubyte[] m_data;
}

struct GUID
{
    uint m_values[4];
};

struct Header
{
    int ver;
    int siz;
    GUID id;
}

void LoadResourceLegacyHeader( InputStream f, out Header header )
{
    f >> header.id;
}

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


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc





 I have removed everything i could,
Reduced program: struct Foo { int x; int[3] y; } void baz(out int[3] y2) { y2[0]++; } void spam(out Foo f) { baz(f.y); } void main() {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 28 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5790




PDT ---


 
 I have removed everything i could,
Reduced program: struct Foo { int x; int[3] y; } void baz(out int[3] y2) { y2[0]++; } void spam(out Foo f) { baz(f.y); } void main() {}
Thanks! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 28 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5790


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical



Critical, as per Don request.

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


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com



Also reproducible with '-inline -noboundscheck -O'. Should be a backend issue
in gother.c.

-------- 

struct H {
    double a;
    int[3] b;   // must not be the first member in a struct, and must be an
array with 3 or more members
}

void g(out int[3] t) {   // must take 'out' parameter
    t[0]=0;   // can be any mutating expression
}

void h (H* x) { // or 'out H' or 'ref H'
    g(x.b);
}

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


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86                         |All



Another test case, which is triggered only on Linux and FreeBSD.

-----------------------------------
void test5790d() {
    int x;
    int y = *(1 + &x);
}
-----------------------------------
$ dmd -O -c test5790d.d
Error: variable x used before set
-----------------------------------

See also
https://github.com/D-Programming-Language/dmd/pull/243#issuecomment-1706278.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



09:58:41 PDT ---
This is possibly related to:

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

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


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr puremagic.com
         AssignedTo|nobody puremagic.com        |bugzilla digitalmars.com



---
Confirmed that the reduction in comment 2 still reproduces the problem.  It
reports y2 as used before set (with no line number).

The two fixes to this part of the compiler aren't sufficient to catch this one.

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


Jonas Drewsen <jdrewsen gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jdrewsen gmail.com



---
Additional test case using only the -O flag and no -inline or -release flags
necessary.

import std.typecons;

void main(string[] args) {

    // Errors
    auto i = Tuple!(string,string)("foo", "bar")[1];

    // Ok
    auto j = Tuple!(string,string)("foo", "bar");
    auto k = j[1];
}

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





 Additional test case using only the -O flag and no -inline or -release flags
 necessary.
 
 import std.typecons;
 
 void main(string[] args) {
 
     // Errors
     auto i = Tuple!(string,string)("foo", "bar")[1];
 
     // Ok
     auto j = Tuple!(string,string)("foo", "bar");
     auto k = j[1];
 }
This is a dup of 7263. See it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 12 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5790


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

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



---

 Confirmed that the reduction in comment 2 still reproduces the problem.  It
 reports y2 as used before set (with no line number).
 
 The two fixes to this part of the compiler aren't sufficient to catch this one.
Walter already committed a fix for this issue. https://github.com/D-Programming-Language/dmd/commit/68b51f24ec25b20df19a5f53b0252d820d2c4d1d https://github.com/D-Programming-Language/dmd/commit/c5d673247289279a54339dfbb6d27733ed3fd63b -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 12 2012