www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14730] New: Wrong closure var access with -inline


          Issue ID: 14730
           Summary: Wrong closure var access with -inline
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com

The assertion fails when you compile the code with -inline.

void main()
    static auto makeS2(int x)
        struct S2
            int n;
            int get() { return x; }     // x will be a cloaure variable
        return S2(x);
    auto s2a = makeS2(1);

    // Fails, because inlined get() returns incorrect value
    assert(s2a.get() == 1);

The parameter 'x' of makeS2 function is a closure variable. It's offset is
calculated in makeS2->toObjFile(). But with -inline, the get function call is
expanded in main(). Then the inlined code will access x via the hidden field of
s2a, by using 0 offset (wrong).

To fix the problem, we need to determine all offsets of closure vars in

Jun 24 2015