public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>,
	Richard Biener <rguenther@suse.de>,
	Eric Botcazou <botcazou@adacore.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] dwarf2out: Fix up field_byte_offset [PR101378]
Date: Wed, 10 Nov 2021 10:20:42 +0100	[thread overview]
Message-ID: <20211110092042.GE2710@tucnak> (raw)

Hi!

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.

The only thing I'm unsure about is whether the test should be
DECL_BIT_FIELD or DECL_BIT_FIELD_TYPE should be tested.  I thought it
doesn't matter, but it seems stor-layout.c in some cases clears
DECL_BIT_FIELD if their TYPE_MODE can express the type exactly, and
dwarf2out.c (gen_field_die) uses
  if (DECL_BIT_FIELD_TYPE (decl))
to decide if DW_AT_bit_offset etc. attributes should be added.
So maybe I should go with && DECL_BIT_FIELD_TYPE (decl) instead.
On
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;
it doesn't make a difference though on x86_64, ppc64le nor ppc64...

I think Ada has bitfields of aggregate types, so CCing Eric, though
I'd hope it doesn't have bitfields where type size is smaller than
field decl size like C++ has.

Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux
and powerpc64-linux and Pedro has tested it on GDB testsuite.

I can bootstrap/regtest the
+      && DECL_BIT_FIELD_TYPE (decl)
version too.

2021-11-10  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 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;

	Jakub


             reply	other threads:[~2021-11-10  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10  9:20 Jakub Jelinek [this message]
2021-11-10  9:29 ` Eric Botcazou
2021-11-10  9:52 ` Richard Biener
2021-11-10 11:03   ` Jakub Jelinek
2021-11-10 11:36     ` Richard Biener
2021-11-10 11:44       ` Jakub Jelinek
2021-11-11  8:19     ` [PATCH] dwarf2out, v2: " Jakub Jelinek
2021-11-11  8:51       ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211110092042.GE2710@tucnak \
    --to=jakub@redhat.com \
    --cc=botcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).