public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6800] c++: [[no_unique_address]] and virtual base [PR104139]
Date: Fri, 21 Jan 2022 17:06:46 +0000 (GMT)	[thread overview]
Message-ID: <20220121170646.131BA3858C60@sourceware.org> (raw)

https://gcc.gnu.org/g:23be9f83bbd2c6f03580757adbfe599de6bf702b

commit r12-6800-g23be9f83bbd2c6f03580757adbfe599de6bf702b
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 21 11:16:49 2022 -0500

    c++: [[no_unique_address]] and virtual base [PR104139]
    
    Fixing a thinko in my patch for 103681: when computing the size of a virtual
    base, it would help to use its binfo instead of the one for the derived
    class.
    
            PR c++/104139
            PR c++/103681
    
    gcc/cp/ChangeLog:
    
            * class.cc (end_of_class): Use base_binfo.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/abi/no_unique_address2.C: Adjust to detect this on x86-64.

Diff:
---
 gcc/cp/class.cc                               |  4 ++--
 gcc/testsuite/g++.dg/abi/no_unique_address2.C | 27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index e5cc6f10e3b..5db3722ae46 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -6414,8 +6414,8 @@ end_of_class (tree t, eoc_mode mode)
       {
 	if (mode == eoc_nv_or_dsize)
 	  /* For dsize, don't count trailing empty bases.  */
-	  offset = size_binop (PLUS_EXPR, BINFO_OFFSET (binfo),
-			       CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo)));
+	  offset = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo),
+			       CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo)));
 	else
 	  offset = end_of_base (base_binfo);
 	if (tree_int_cst_lt (result, offset))
diff --git a/gcc/testsuite/g++.dg/abi/no_unique_address2.C b/gcc/testsuite/g++.dg/abi/no_unique_address2.C
index bef6d5b43be..3bb3f76ac92 100644
--- a/gcc/testsuite/g++.dg/abi/no_unique_address2.C
+++ b/gcc/testsuite/g++.dg/abi/no_unique_address2.C
@@ -41,3 +41,30 @@ struct B4
 #define SA(X) static_assert ((X), #X)
 SA (sizeof (B2) == sizeof (B1));
 SA (sizeof (B3) == sizeof (B4));
+
+namespace N2
+{
+  // C as big as _vptr to test PR c++/104139
+  struct C
+  {
+    long c;
+  };
+
+  struct D: virtual C
+  {
+    virtual void f();
+  };
+
+  struct B3: D
+  {
+    char c2;
+  };
+
+  struct B4
+  {
+    D d [[no_unique_address]];
+    char c2;
+  };
+
+  SA (sizeof (B3) == sizeof (B4));
+}


                 reply	other threads:[~2022-01-21 17:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220121170646.131BA3858C60@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).