public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9330] dwarf2out: Fix up field_byte_offset [PR101378]
@ 2021-11-29  8:49 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-11-29  8:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c479d98137fb589718570258547c6bea4f27d1d5

commit r11-9330-gc479d98137fb589718570258547c6bea4f27d1d5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Nov 11 10:14:04 2021 +0100

    dwarf2out: Fix up field_byte_offset [PR101378]
    
    For PCC_BITFIELD_TYPE_MATTERS field_byte_offset has quite large code
    to deal with it since many years ago (see it e.g. in GCC 3.2, although it
    used to be on HOST_WIDE_INTs, then on double_ints, now on offset_ints).
    But that code apparently isn't able to cope with members with empty class
    types with [[no_unique_address]] attribute, because the empty classes have
    non-zero type size but zero decl size and so one can end up from the
    computation with negative offset or offset 1 byte smaller than it should be.
    For !PCC_BITFIELD_TYPE_MATTERS, we just use
        tree_result = byte_position (decl);
    which seems exactly right even for the empty classes or anything which is
    not a bitfield (and for which we don't add DW_AT_bit_offset attribute).
    So, instead of trying to handle those no_unique_address members in the
    current already very complicated code, this limits it to bitfields.
    
    stor-layout.c PCC_BITFIELD_TYPE_MATTERS handling also affects only
    bitfields, twice it checks DECL_BIT_FIELD and once DECL_BIT_FIELD_TYPE.
    
    As discussed, this patch uses DECL_BIT_FIELD_TYPE check, because
    DECL_BIT_FIELD might be cleared for some bitfields with bitsizes
    multiple of BITS_PER_UNIT and e.g.
    struct S { int e; int a : 1, b : 7, c : 8, d : 16; } s;
    struct T { int a : 1, b : 7; long long c : 8; int d : 16; } t;
    
    int
    main ()
    {
      s.c = 0x55;
      s.d = 0xaaaa;
      t.c = 0x55;
      t.d = 0xaaaa;
      s.e++;
    }
    has different debug info with DECL_BIT_FIELD check.
    
    2021-11-11  Jakub Jelinek  <jakub@redhat.com>
    
            PR debug/101378
            * dwarf2out.c (field_byte_offset): Do the PCC_BITFIELD_TYPE_MATTERS
            handling only for DECL_BIT_FIELD_TYPE decls.
    
            * g++.dg/debug/dwarf2/pr101378.C: New test.
    
    (cherry picked from commit 10db7573014008ff867098206f51012d501ab57b)

Diff:
---
 gcc/dwarf2out.c                              |  1 +
 gcc/testsuite/g++.dg/debug/dwarf2/pr101378.C | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index ae25eaccf70..d74c8e3867f 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -19443,6 +19443,7 @@ field_byte_offset (const_tree decl, struct vlr_context *ctx,
      properly dynamic byte offsets only when PCC bitfield type doesn't
      matter.  */
   if (PCC_BITFIELD_TYPE_MATTERS
+      && DECL_BIT_FIELD_TYPE (decl)
       && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
     {
       offset_int object_offset_in_bits;
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/pr101378.C b/gcc/testsuite/g++.dg/debug/dwarf2/pr101378.C
new file mode 100644
index 00000000000..ec5e44df804
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/pr101378.C
@@ -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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-29  8:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29  8:49 [gcc r11-9330] dwarf2out: Fix up field_byte_offset [PR101378] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).