D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9239 - x86_64 ABI: 3 byte structs are never enregistered
Summary: x86_64 ABI: 3 byte structs are never enregistered
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks: 5570
  Show dependency treegraph
 
Reported: 2012-12-28 19:26 UTC by David Nadlinger
Modified: 2018-10-05 18:31 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 David Nadlinger 2012-12-28 19:26:29 UTC
The following example shows the problem:

---
struct RGB { char r, g, b; };
void foo(RGB c);
void bar() {
    RGB c;
    c.r = 1;
    c.g = 2;
    c.b = 3;
    foo(c);
}
---

Compiled with Clang:

---
0000000000000000 <_Z3barv>:
   0:   bf 01 02 03 00          mov    edi,0x30201
   5:   e9 00 00 00 00          jmp    a <_Z3barv+0xa>
---

Compiled with DMD (Git master):
---
0000000000000000 <_D4test3barFZv>:
   0:   55                      push   rbp
   1:   48 8b ec                mov    rbp,rsp
   4:   48 83 ec 10             sub    rsp,0x10
   8:   48 be 00 00 00 00 00    movabs rsi,0x0
   f:   00 00 00 
  12:   48 8d 7d f8             lea    rdi,[rbp-0x8]
  16:   a4                      movs   BYTE PTR es:[rdi],BYTE PTR ds:[rsi]
  17:   a4                      movs   BYTE PTR es:[rdi],BYTE PTR ds:[rsi]
  18:   a4                      movs   BYTE PTR es:[rdi],BYTE PTR ds:[rsi]
  19:   c6 45 f8 01             mov    BYTE PTR [rbp-0x8],0x1
  1d:   c6 45 f9 02             mov    BYTE PTR [rbp-0x7],0x2
  21:   c6 45 fa 03             mov    BYTE PTR [rbp-0x6],0x3
  25:   48 83 ec 08             sub    rsp,0x8
  29:   ff 75 f8                push   QWORD PTR [rbp-0x8]
  2c:   e8 00 00 00 00          call   31 <_D4test3barFZv+0x31>
  31:   48 83 c4 10             add    rsp,0x10
  35:   48 8b e5                mov    rsp,rbp
  38:   5d                      pop    rbp
  39:   c3                      ret    
---
Comment 1 kinke 2018-10-02 19:49:34 UTC
This works for me with DMD 2.082.0 on Linux x64: https://run.dlang.io/is/A5a5U1

mov	byte ptr -8[RBP],1
mov	byte ptr -7[RBP],2
mov	byte ptr -6[RBP],3
mov	EDI,-8[RBP]
call	_Z3foo3RGB@PLT32