Re: C aggregate passing (Rust kernel policy)

HUANG Zhaobin
2025-02-21T08:32:04Z

On Thu, 20 Feb 2025 16:17:07 +0100 (CET), Jan Engelhardt <ej@inai.de> wrote:
>
> Returning aggregates in C++ is often implemented with a secret extra
> pointer argument passed to the function. The C backend does not
> perform that kind of transformation automatically. I surmise ABI reasons.

No, in both C and C++, fff accepts a secret extra pointer argument.

https://godbolt.org/z/13K9aEffe

For gcc, the difference is that `sb` is allocated then copied back in C,
while in C++ NRVO is applied so there is no extra allocation and copy.

Clang does NRVO for both C and C++ in this case, thus generating exactly
the same codes for them.

I have no idea why gcc doesn't do the same.