On 2/19/26 4:16 AM, Yuxuan Chen wrote:
This is v4 of the patch to implement the trivial_abi attribute for GCC.
Changes from v3:
- Remove trivial_for_calls_p; use CLASSTYPE_HAS_TRIVIAL_ABI directly
in finish_struct_bits and store_parm_decls.
- Use TREE_ADDRESSABLE to check bases/fields in
validate_trivial_abi_attribute instead of trivial_for_calls_p.
- Move validate_trivial_abi_attribute call before finish_struct_bits
in finish_struct_1 so the flag is resolved before ABI decisions.
- Remove __builtin_is_trivially_relocatable from tests; the trait
is not available on trunk after trivial relocation rework.
- Replace CONST_CAST_TREE with const_cast<tree> per upstream change.
- Use "non-static data member" instead of "field" in diagnostics.
- Add [[clang::trivial_abi]] spelling via cxx_clang_attribute_table.
The attribute is supported with __attribute__((trivial_abi)),
[[gnu::trivial_abi]], and [[clang::trivial_abi]] spellings. One thing
I didn't figure out how to address is to stop supporting
[[gnu::trivial_abi]] spelling of the attribute as suggested by
reviews. If I remove it from cxx_gnu_attributes,
`__attribute__((trivial_abi))` stops working.
Aha. You should be able to hack around this by using two different
handle_ functions, like handle_maybe_unused_attribute vs
handle_unused_attribute, and checking for ATTR_FLAG_CXX11.
* cp-tree.h (struct lang_type): Add has_trivial_abi flag.
I don't think we need a new bit, we can use lookup_attribute (probably
wrapped in an inline function) instead of the macro.
/* Table of valid C++ attributes. */
-static const attribute_spec cxx_gnu_attributes[] =
-{
+static const attribute_spec cxx_gnu_attributes[] = {
/* { name, min_len, max_len, decl_req, type_req, fn_type_req,
affects_type_identity, handler, exclude } */
- { "init_priority", 1, 1, true, false, false, false,
- handle_init_priority_attribute, NULL },
- { "abi_tag", 1, -1, false, false, false, true,
- handle_abi_tag_attribute, NULL },
- { "no_dangling", 0, 1, false, true, false, false,
- handle_no_dangling_attribute, NULL },
+ {"init_priority", 1, 1, true, false, false, false,
+ handle_init_priority_attribute, NULL},
+ {"abi_tag", 1, -1, false, false, false, true, handle_abi_tag_attribute,
NULL},
+ {"no_dangling", 0, 1, false, true, false, false,
handle_no_dangling_attribute,
+ NULL},
+ {"trivial_abi", 0, 0, false, true, false, true, handle_trivial_abi_attribute,
+ NULL},
};
Let's follow the existing formatting rather than reformat the existing
lines.
+/* Table of C++ attributes also recognized in the clang:: namespace. */
+static const attribute_spec cxx_clang_attributes[] = {
And this table should have the { on the next line like the other tables.
Jason