October 26 [Issue 24836] New: struct return by hidden struct arg does not need copy to become an rvalue | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24836 Issue ID: 24836 Summary: struct return by hidden struct arg does not need copy to become an rvalue Product: D Version: D2 Hardware: All OS: Windows Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: bugzilla@digitalmars.com Related: 9666 Given: import core.stdc.stdio; struct S { this(ref S) { printf("this(ref S)\n"); } void opAssign(ref S) { printf("opAssign(ref S)\n"); } void opAssign(S) { printf("opAssign(S)\n"); } void opMove(ref S) { printf("opMove(ref S)\n"); } } void main() { S s; S t; S test() { S* p = &s; return *p; } t = test(); } The code generated for main() is: _Dmain: push RBP mov RBP,RSP sub RSP,010h xor EAX,EAX mov -8[RBP],AL // S s; mov -7[RBP],AL // S t; lea RSI,-6[RBP] // address of struct return value mov RDI,RBP // static link call test mov RSI,RAX // address of struct return value as source lea RDI,-5[RBP] // address of temporary movsb // copy return value to temporary lea RSI,-5[RBP] // address of temporary lea RDI,-7[RBP] // address of t call opAssign // opAssign(S) xor EAX,EAX leave ret The copy is not necessary, and is a bug. -- |
Copyright © 1999-2021 by the D Language Foundation