Bug 24822 – When passing a non-POD argument to an rvalue parameter, an unnecessary blit is done

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-10-20T22:59:04Z
Last change time
2024-10-22T21:57:43Z
Keywords
pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2024-10-20T22:59:04Z
Consider: struct S { int i; this(ref S); void opAssign(S s) { i = s.i + 1; } } void test() { S s; S t; t = s; // call to opAssign } The generated code for test() is: 0000: 55 push RBP 0001: 48 8B EC mov RBP,RSP 0004: 48 83 EC 10 sub RSP,010h 0008: 31 C0 xor EAX,EAX 000a: 89 45 F0 mov -010h[RBP],EAX 000d: 89 45 F4 mov -0Ch[RBP],EAX 0010: 89 45 F8 mov -8[RBP],EAX 0013: 48 8D 75 F0 lea RSI,-010h[RBP] 0017: 48 8D 7D F8 lea RDI,-8[RBP] 001b: E8 00 00 00 00 call __ctor 0020: 48 8D 75 F8 lea RSI,-8[RBP] 0024: 48 8D 7D FC lea RDI,-4[RBP] 0028: A5 movsd // blit copy, should not be here 0029: 48 8D 75 FC lea RSI,-4[RBP] 002d: 48 8D 7D F4 lea RDI,-0Ch[RBP] 0031: E8 00 00 00 00 call L0 0036: C9 leave 0037: C3 ret The blit copy is redundant and should not be generated.
Comment #1 by dlang-bot — 2024-10-22T07:16:57Z
@WalterBright updated dlang/dmd pull request #17019 "fix Issue 24822 - When passing a non-POD argument to an rvalue parame…" fixing this issue: - fix bugzilla Issue 24822 - When passing a non-POD argument to an rvalue parameter, an unnecessary blit is done https://github.com/dlang/dmd/pull/17019
Comment #2 by dlang-bot — 2024-10-22T21:57:43Z
dlang/dmd pull request #17019 "fix bugzilla Issue 24822 - When passing a non-POD argument to an rvalue parame…" was merged into master: - 8f9e88dc3a29197bf6f0a60cd94227e8a3e3882d by Walter Bright: fix bugzilla Issue 24822 - When passing a non-POD argument to an rvalue parameter, an unnecessary blit is done https://github.com/dlang/dmd/pull/17019