From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EEA8E3858408; Thu, 9 Mar 2023 16:57:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEA8E3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678381073; bh=0iqwlPNf6xE1+SC9Tbi9HuwaaH+Jtj/nK5Q5VT2rGMI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Jnom8GKX1hh6lNqUb04KH15EjCfVeBxJ0zNS2Ra7jZx1aJot1rek9yccxs4U3tAeE IOMUoSdHyNyCaocwAV9aOV522fDSERlG5glUALXdByyaSP4+3Gb0TPJB9wBDx6XmAl i6ADwPuK/etF1DTiNu92iOSLD2/k8au6dB4iima8= From: "jakub 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: Thu, 09 Mar 2023 16:57:52 +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: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned 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 #3 from Jakub Jelinek --- I think the bug is in class.cc (end_of_class), which does: offset =3D size_binop (PLUS_EXPR, byte_position (field), size); That works fine for non bit-fields, but for bit-fields it is sometimes incorrect. In particular, X::x1 has DECL_SIZE 8, DECL_SIZE_UNIT 1, DECL_FIELD_OFFSET 0, DECL_FIELD_BIT_OFFSET 7. So, byte_position (field) is still 0, and size 1, therefore offset is set to 1, even when the bit-field occupies just 1 bit in the first byte and 7 in the second byte, so I think we want to set offset to 2 in this case. The Itanium ABI says: In either case, update dsize(C) to include the last byte containing (part o= f) the bit-field, and update sizeof(C) to max(sizeof(C),dsize(C)).=20 So, I think for bit-fields we instead want to sum bit_position (field) and DECL_SIZE and CEIL_DIV_EXPR it by bitsize_unit_node and cast to sizetype.=