https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109039
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-12 branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:794e4f69cf2434c82388820f78c0e9e86fdd677b commit r12-9288-g794e4f69cf2434c82388820f78c0e9e86fdd677b Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Mar 10 20:36:33 2023 +0100 c++, abi: Fix up class layout with bitfields [PR109039] The following testcase FAILs, because starting with r12-6028 the S class has only 2 bytes, not enough to hold one 7-bit bitfield, one 8-bit bitfield and one 8-bit char field. The reason is that when end_of_class attempts to compute dsize, it simply adds byte_position of the field and DECL_SIZE_UNIT (and uses maximum from those offsets). The problematic bit-field in question has bit_position 7, byte_position 0, DECL_SIZE 8 and DECL_SIZE_UNIT 1. So, byte_position + DECL_SIZE_UNIT is 1, even when the bitfield only has a single bit in the first byte and 7 further bits in the second byte, so per the Itanium ABI it should be 2: "In either case, update dsize(C) to include the last byte containing (part of) the bit-field, and update sizeof(C) to max(sizeof(C),dsize(C))." The following patch fixes it by computing bitsize of the end and using CEIL_DIV_EXPR division to round it to next byte boundary and convert from bits to bytes. While this is an ABI change, classes with such incorrect layout couldn't have worked properly, so I doubt anybody is actually running it often in the wild. Thus I think adding some ABI warning for it is unnecessary. 2023-03-10 Jakub Jelinek <ja...@redhat.com> PR c++/109039 * class.cc (end_of_class): For bit-fields, instead of computing offset as sum of byte_position (field) and DECL_SIZE_UNIT (field), compute it as sum of bit_position (field) and DECL_SIZE (field) divided by BITS_PER_UNIT rounded up. * g++.dg/abi/no_unique_address7.C: New test. (cherry picked from commit 991f9eb2da3a268b7b08346761fa0078ab55f506)