https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I must say I don't understand why we do that PCC_BITFIELD_TYPE_MATTERS stuff 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_FIELD
or DECL_BIT_FIELD_TYPE.  At least for C/C++, bitfields should have reasonable
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 negative
offsets.

2021-11-09  Jakub Jelinek  <ja...@redhat.com>

        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)) == 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.

Reply via email to