public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: Fix ICE with using and virtual function. [PR95719]
Date: Fri, 14 May 2021 14:55:36 +0000 (GMT)	[thread overview]
Message-ID: <20210514145536.A70BD3949F32@sourceware.org> (raw)

https://gcc.gnu.org/g:1147c3ab5f1e91949f224962f75b675a14f4e989

commit 1147c3ab5f1e91949f224962f75b675a14f4e989
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 23 21:25:21 2020 -0400

    c++: Fix ICE with using and virtual function. [PR95719]
    
    conversion_path points to the base where we found the using-declaration, not
    where the function is actually a member; look up the actual base.  And then
    maybe look back to the derived class if the base is primary.
    
    gcc/cp/ChangeLog:
    
            PR c++/95719
            * call.c (build_over_call): Look up the overrider in base_binfo.
            * class.c (lookup_vfn_in_binfo): Look through BINFO_PRIMARY_P.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/95719
            * g++.dg/tree-ssa/final4.C: New test.
    
    (cherry picked from commit 710df943389a854ef00c15ed0ad219b41db236aa)

Diff:
---
 gcc/cp/call.c                          |  6 +++++-
 gcc/cp/class.c                         |  4 ++++
 gcc/testsuite/g++.dg/tree-ssa/final4.C | 10 ++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 89a3053081d..836ece3f56d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7919,7 +7919,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
       if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
 	  && resolves_to_fixed_type_p (arg))
 	{
-	  fn = lookup_vfn_in_binfo (DECL_VINDEX (fn), cand->conversion_path);
+	  tree binfo = cand->conversion_path;
+	  if (BINFO_TYPE (binfo) != DECL_CONTEXT (fn))
+	    binfo = lookup_base (binfo, DECL_CONTEXT (fn), ba_unique,
+				 NULL, complain);
+	  fn = lookup_vfn_in_binfo (DECL_VINDEX (fn), binfo);
 	  flags |= LOOKUP_NONVIRTUAL;
 	}
 
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index b06aa6faedf..baf3bbed2c1 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2405,6 +2405,10 @@ lookup_vfn_in_binfo (tree idx, tree binfo)
   int ix = tree_to_shwi (idx);
   if (TARGET_VTABLE_USES_DESCRIPTORS)
     ix /= MAX (TARGET_VTABLE_USES_DESCRIPTORS, 1);
+  while (BINFO_PRIMARY_P (binfo))
+    /* BINFO_VIRTUALS in a primary base isn't accurate, find the derived
+       class that actually owns the vtable.  */
+    binfo = BINFO_INHERITANCE_CHAIN (binfo);
   tree virtuals = BINFO_VIRTUALS (binfo);
   return TREE_VALUE (chain_index (ix, virtuals));
 }
diff --git a/gcc/testsuite/g++.dg/tree-ssa/final4.C b/gcc/testsuite/g++.dg/tree-ssa/final4.C
new file mode 100644
index 00000000000..cce6e9afadb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/final4.C
@@ -0,0 +1,10 @@
+// PR c++/95719
+// { dg-do compile { target c++11 } }
+
+struct S1 { virtual ~S1(); };
+struct S2 {
+    virtual ~S2();
+    virtual void f();
+};
+struct S3 final: S1, S2 { using S2::f; };
+void g(S3 & s) { s.f(); }


                 reply	other threads:[~2021-05-14 14:55 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=20210514145536.A70BD3949F32@sourceware.org \
    --to=jakub@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).