D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2385 - spec says all structs are returned via hidden pointer on linux, but it uses registers
Summary: spec says all structs are returned via hidden pointer on linux, but it uses r...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: spec
: 2648 (view as issue list)
Depends on: 2648
Blocks: 3105
  Show dependency treegraph
 
Reported: 2008-10-02 05:22 UTC by Tomas Lindquist Olsen
Modified: 2014-03-01 00:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomas Lindquist Olsen 2008-10-02 05:22:00 UTC
the following test compiled with dmd 1.034 on linux should return via a hidden pointer parameter, but is actually returned in registers:

struct S
{
    int x;
    int z;
    static S foo()
    {
        S s = {1,2};
        return s;
    }
}

becomes

_D4test1S3fooFZS4test1S:
                push    EBP
                mov     EBP,ESP
                sub     ESP,8
                mov     dword ptr -8[EBP],1
                mov     dword ptr -4[EBP],2
                mov     EDX,-4[EBP]
                mov     EAX,-8[EBP]
                leave
                ret
Comment 1 Walter Bright 2008-10-20 22:20:25 UTC
Fixed dmd 1.036 and 2.020
Comment 2 Tomas Lindquist Olsen 2009-05-12 12:30:04 UTC
the spec now says:

# For Windows, 1, 2 and 4 byte structs are returned in EAX.
# For Windows, 8 byte structs are returned in EDX,EAX, where EDX gets the most significant half.
# For other struct sizes, the return value is stored through a hidden pointer passed as an argument to the function.

I don't think just removing the info on linux is a satisfactory fix, the asm is still the same!
Comment 3 Tomas Lindquist Olsen 2009-05-12 12:33:23 UTC
Very much related to:

http://d.puremagic.com/issues/show_bug.cgi?id=2648
Comment 5 Walter Bright 2010-11-08 01:03:29 UTC
*** Issue 2648 has been marked as a duplicate of this issue. ***