From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A010C3858404; Fri, 10 Mar 2023 19:37:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A010C3858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678477039; bh=t6j2g0s0IqxZjt/gkKzzweCljQPe3xwS0SDh8jjGYlE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FbgTyP9Q2eE61KlYMMvUJoEKojYVROPh65gaEAuTCBQCY3fGfUa0hRxuE+Y79Oodg QA5ipF8p7k2xQf5PoW/BPvPovtM0fe5M45V1uF9RKwxitgX4ztQhOnR25wQDO2T0q4 MQMcp+JLpjJvF+HUvdJeHW6Ruy9orX2M+eTsTvD8= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109039] [12/13 Regression] Miscompilation with no_unique_address and bitfields Date: Fri, 10 Mar 2023 19:37:19 +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 #5 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:991f9eb2da3a268b7b08346761fa0078ab55f506 commit r13-6596-g991f9eb2da3a268b7b08346761fa0078ab55f506 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.=