From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A00E13858C2C; Tue, 9 Nov 2021 14:24:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A00E13858C2C From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/101378] Negative DW_AT_data_member_location Date: Tue, 09 Nov 2021 14:24:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: debug X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-debug X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 14:24:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101378 --- Comment #7 from Jakub Jelinek --- I must say I don't understand why we do that PCC_BITFIELD_TYPE_MATTERS stuf= f in dwarf2out.c (field_byte_offset) for non-bitfields, I don't understand why byte_position (decl) wouldn't work just fine. After all, stor-layout.c also doesn't do anything special for PCC_BITFIELD_TYPE_MATTERS unless DECL_BIT_F= IELD or DECL_BIT_FIELD_TYPE. At least for C/C++, bitfields should have reasonab= le type sizes one can actually use (Ada has aggregate bitfields I think though= ), while non-bitfields can be e.g. the C++ classes that have TYPE_SIZE BITS_PER_UNIT, but DECL_SIZE of 0, which is why we are getting those negati= ve offsets. 2021-11-09 Jakub Jelinek PR debug/101378 * dwarf2out.c (field_byte_offset): Do the PCC_BITFIELD_TYPE_MATTERS handling only for DECL_BIT_FIELD decls. * g++.dg/debug/dwarf2/pr101378.C: New test. --- gcc/dwarf2out.c.jj 2021-11-05 10:19:46.339457342 +0100 +++ gcc/dwarf2out.c 2021-11-09 15:01:51.425437717 +0100 @@ -19646,6 +19646,7 @@ field_byte_offset (const_tree decl, stru properly dynamic byte offsets only when PCC bitfield type doesn't matter. */ if (PCC_BITFIELD_TYPE_MATTERS + && DECL_BIT_FIELD (decl) && TREE_CODE (DECL_FIELD_OFFSET (decl)) =3D=3D INTEGER_CST) { offset_int object_offset_in_bits; --- gcc/testsuite/g++.dg/debug/dwarf2/pr101378.C.jj 2021-11-09 15:17:39.504975396 +0100 +++ gcc/testsuite/g++.dg/debug/dwarf2/pr101378.C 2021-11-09 15:17:28.067137556 +0100 @@ -0,0 +1,13 @@ +// PR debug/101378 +// { dg-do compile { target c++11 } } +// { dg-options "-gdwarf-5 -dA" } +// { dg-final { scan-assembler-times "0\[^0-9x\\r\\n\]* DW_AT_data_member_location" 1 } } +// { dg-final { scan-assembler-times "1\[^0-9x\\r\\n\]* DW_AT_data_member_location" 1 } } +// { dg-final { scan-assembler-times "2\[^0-9x\\r\\n\]* DW_AT_data_member_location" 1 } } +// { dg-final { scan-assembler-not "-1\[^0-9x\\r\\n\]* DW_AT_data_member_location" } } + +struct E {}; +struct S +{ + [[no_unique_address]] E e, f, g; +} s; fixes this for me.=