[Bug c++/126725] New: class with a trivial_abi member not passed via register

"ivan.lazaric.gcc at gmail dot com via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126725

            Bug ID: 126725
           Summary: class with a trivial_abi member not passed via
                    register
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ivan.lazaric.gcc at gmail dot com
  Target Milestone: ---

```cpp
struct [[clang::trivial_abi]] A {
    long x = 1337;
    ~A() {}
};

struct B { A a; };

struct C : A {};

void consume(auto);

void use_A() { consume(A{}); }
void use_B() { consume(B{}); }
void use_C() { consume(C{}); }
```

Flags: "-std=c++26 -O3"

asm generated:
```
"use_A()":
        mov     edi, 1337
        jmp     "void consume<A>(A)"
"use_B()":
        sub     rsp, 24
        mov     QWORD PTR [rsp+8], 1337
        lea     rdi, [rsp+8]
        call    "void consume<B>(B)"
        add     rsp, 24
        ret
"use_C()":
        sub     rsp, 24
        mov     QWORD PTR [rsp+8], 1337
        lea     rdi, [rsp+8]
        call    "void consume<C>(C)"
        add     rsp, 24
        ret
```

B and C were passed on stack, not through register
clang passes all 3 through register:
```
use_A():
        mov     edi, 1337
        jmp     void consume<A>(A)@PLT

use_B():
        mov     edi, 1337
        jmp     void consume<B>(B)@PLT

use_C():
        mov     edi, 1337
        jmp     void consume<C>(C)@PLT
```

https://godbolt.org/z/dsjjE3qbs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.