c, c++: Save 8 bytes of memory in lang_type for non-ObjC*
For C++26 P2786R13 I'm afraid I'll need 4-6 new flags on class types
in struct lang_type (1 bit for trivially_relocatable_if_eligible,
1 for replaceable_if_eligible, 1 for not_trivially_relocatable and
1 for not_replaceable and perhaps 2 bits whether the last 2 have been
computed already) and there are just 2 bits left.
The following patch is an attempt to save 8 bytes of memory
in those structures when not compiling ObjC or ObjC++ (I think those
are used fairly rarely and the patch keeps the sizes unmodified for
those 2). The old allocations were 32 bytes for C and 120 bytes
for C++. The patch moves the objc_info member last in the C++ case
(it was already last in the C case), arranges for GC to skip it
for C and C++ but walk for ObjC and ObjC++ and allocates or
copies over just offsetof bytes instead of sizeof.
2025-06-12 Jakub Jelinek <jakub@redhat.com>
gcc/c/
* c-lang.h (union lang_type::maybe_objc_info): New type.
(struct lang_type): Use union maybe_objc_info info member
instead of tree objc_info.
* c-decl.cc (finish_struct): Allocate struct lang_type using
ggc_internal_cleared_alloc instead of ggc_cleared_alloc,
and use sizeof (struct lang_type) for ObjC and otherwise
offsetof (struct lang_type, info) as size.
(finish_enum): Likewise.
gcc/cp/
* cp-tree.h (union lang_type::maybe_objc_info): New type.
(struct lang_type): Use union maybe_objc_info info member
instead of tree objc_info.
* lex.cc (copy_lang_type): Use sizeof (struct lang_type)
just for ObjC++ and otherwise offsetof (struct lang_type, info).
(maybe_add_lang_type_raw): Likewise.
(cxx_make_type): Formatting fix.
gcc/objc/
* objc-act.h (TYPE_OBJC_INFO): Define to info.objc_info
instead of objc_info.
gcc/objcp/
* objcp-decl.h (TYPE_OBJC_INFO): Define to info.objc_info
instead of objc_info.