[Issue 7932] Corrupted argument inside out contract in x86_64

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 18 01:43:53 PDT 2012


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1                          |D1 & D2
            Summary|Corrupted argument inside   |Corrupted argument inside
                   |out contract for protected  |out contract in x86_64
                   |methods when compiling with |
                   |-O in x86_64                |


--- Comment #2 from Don <clugdbug at yahoo.com.au> 2012-04-18 01:44:46 PDT ---
Also applies to D2, and does not require -O. Interestingly on D2, adding
'assert(this)' or making it public does not make the bug go away.

This test case applies to D1 if you remove __gshared and add 'protected'.

__gshared size_t second;
class C
{
    /*protected*/ void f(size_t n)
    out
    {
        second = n;
    }
    body
    {
    }
}

void main()
{
    C x = new C;
    x.f(6);
    assert(second == 6);
}
---------------------------
This is a parameter passing bug. The code generated for the 'out' contract
assumes that the register parameters were spilled to the stack, but that isn't
necessarily true. Space is allocated on the stack for them, but they aren't
necessarily copied there. On D1, calling the class invariant causes the
parameter (in this case RSI) to be copied to the stack.
Otherwise, 'n' is uninitialized garbage while in the out contract.
The solution is to force all parameters to be copied to the stack when an out
contract is present.

-- 
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