On 11/18/25 8:03 AM, Yuxuan Chen wrote:
Implement the trivial_abi attribute for GCC to fix ABI compatibility
issues with Clang. Currently, GCC silently ignores this attribute,
causing call convention mismatches when linking GCC-compiled code with
Clang-compiled object files that use trivial_abi types.

This attribute allows types to be treated as trivial for ABI purposes,
enabling pass in registers instead of invisible references.

Hi, sorry I dropped the ball on this patch.

         PR c++/107187

V3 changes from v2:
     - Handling cases where bases can be dependent.
     - gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi_syntax.C now uses the same
       test as Clang to ensure no difference in semantics.

V2 changes from v1:
     - Addressing code review comments.
     - Registered cleanup in callee for trivial abi. Added test
       `gcc/testsuite/g++.dg/abi/invisiref3a.C`
     - Added doc in `gcc/doc/extend.texi`. Pretty much the same as in
       Clang's attributes documentation.

- There were some comments on V1 of this patch. I addressed them to the best of my ability, although I have not found a good way to consolidate CLASSTYPE_HAS_TRIVIAL_ABI with TREE_ADDRESSABLE.

I was thinking that in finish_struct_bits you could lookup_attribute (trivial_abi) and then in validate_trivial_abi_attribute check TREE_ADDRESSABLE instead of !trivial_for_calls_p. I guess lookup_attribute also in store_parm_decls.

There was also a suggestion that we accept the corresponding [[clang::trivial_abi]] spelling. I believe it can be done in a separate patch.

It seems like when Clang adopts gnu:: attributes, they keep the gnu:: spelling; we might want to do the same for Clang attributes. That is, support clang::trivial_abi and not add gnu::trivial_abi.

Jason

Reply via email to