From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3347A3839049; Sun, 19 Mar 2023 05:30:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3347A3839049 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679203850; bh=Ij9vxQgscv2jx8Xg4PSFhrUxOj0A64qxfR83tgI5ZEU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UzP5VqIVcjdNeg9/EPCWznNJingkHRNP3G/6WGco5ImrjY62fRMv8v0bhaHZBT4TN Qi0biz1hfaiP7pQEYHKom0BwBz5ENNItCLi94ePVVGfjYLlJP7knxdFChxhczBEQ7a cB8wIjltzbtyLSG3LHm2PerKc1NjnXPXUvTvyLKQ= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109039] [12 Regression] Miscompilation with no_unique_address and bitfields Date: Sun, 19 Mar 2023 05:30:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: ABI, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109039 --- Comment #7 from CVS Commits --- The releases/gcc-12 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:794e4f69cf2434c82388820f78c0e9e86fdd677b commit r12-9288-g794e4f69cf2434c82388820f78c0e9e86fdd677b Author: Jakub Jelinek 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 simp= ly adds byte_position of the field and DECL_SIZE_UNIT (and uses maximum fr= om 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 unnecessar= y. 2023-03-10 Jakub Jelinek 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 (fiel= d), 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)=