[Issue 3634] New: return value not passed to out contracts of private methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 18 22:37:45 PST 2009


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

           Summary: return value not passed to out contracts of private
                    methods
           Product: D
           Version: 2.036
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: baryluk at smp.if.uj.edu.pl


--- Comment #0 from Witold Baryluk <baryluk at smp.if.uj.edu.pl> 2009-12-18 22:37:44 PST ---
This code failes, but it should pass.

class A {
    this() {
        x_ = 10;
    }
private:
    uint x_;

    uint x()
    out(ret) {
        assert(ret == 10); // fails  // line 10
        assert(ret == x_); // fails
    }
    body {
        return x_;
    }
}

import std.stdio;

void main() {
    auto a = new A();
    writefln("%d", a.x());
}

$ dmd2 -debug a.d; ./a
 core.exception.AssertError at t(10): Assertion failure
$

When I change x() method to 'public' problems dissaper.


Here is dissambled code

        assume  CS:.text._D1t1A1xMFZk
_D1t1A1xMFZk:
                push    EBP
                mov     EBP,ESP
                sub     ESP,0Ch
                add     EAX,8
                mov     ECX,[EAX]
                mov     -8[EBP],ECX
                mov     -0Ch[EBP],EAX
                mov     EAX,0Ah
                call    near ptr _D1t8__assertFiZv at PC32
                mov     EDX,-0Ch[EBP]
                cmp     dword ptr [EDX],0
                je      L2D
                mov     EAX,0Bh
                call    near ptr _D1t8__assertFiZv at PC32
L2D:            mov     EAX,-8[EBP]
                leave
                ret
                nop
                nop
.text._D1t1A1xMFZk      ends


Also without "-debug" switch the same code is generated.
If i comment a assert statments (or don't use ret), method properly returns
value to callee.


In release mode it works correclty (but contracts are called):

.text._D1t1A1xMFZk      segment
        assume  CS:.text._D1t1A1xMFZk
_D1t1A1xMFZk:
                push    EBP
                mov     EBP,ESP
                sub     ESP,4
                mov     EAX,8[EAX]
                leave
                ret
                nop
.text._D1t1A1xMFZk      ends

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


More information about the Digitalmars-d-bugs mailing list