public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5461] c++: Stream virtual dtor vtable indices
@ 2023-11-14 19:43 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2023-11-14 19:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:14979dd31c887ba5ba573f2cdb0647b37e09641a

commit r14-5461-g14979dd31c887ba5ba573f2cdb0647b37e09641a
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Tue Nov 14 11:26:03 2023 -0500

    c++: Stream virtual dtor vtable indices
    
    Virtual cloned functions have distinct vtable indices, stream them
    explicitly.
    
    As such, this patch ensures that DECL_VINDEX is properly passed on for
    cloned functions as well to prevent this from causing issues.
    
            PR c++/103499
    
    gcc/cp/ChangeLog:
    
            * module.cc (trees_out::decl_node): Write DECL_VINDEX for
            virtual clones.
            (trees_in::tree_node): Read DECL_VINDEX for virtual clones.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/pr103499_a.C: New test.
            * g++.dg/modules/pr103499_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
    Signed-off-by: Nathan Sidwell <nathan@acm.org>

Diff:
---
 gcc/cp/module.cc                          |  6 ++++++
 gcc/testsuite/g++.dg/modules/pr103499_a.C | 12 ++++++++++++
 gcc/testsuite/g++.dg/modules/pr103499_b.C |  8 ++++++++
 3 files changed, 26 insertions(+)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index c1c8c226bc1..4f5b6e2747a 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -8648,6 +8648,8 @@ trees_out::decl_node (tree decl, walk_kind ref)
 
       tree_node (target);
       tree_node (DECL_NAME (decl));
+      if (DECL_VIRTUAL_P (decl))
+	tree_node (DECL_VINDEX (decl));
       int tag = insert (decl);
       if (streaming_p ())
 	dump (dumper::TREE)
@@ -9869,6 +9871,10 @@ trees_in::tree_node (bool is_use)
 		}
 	  }
 
+	/* A clone might have a different vtable entry.  */
+	if (res && DECL_VIRTUAL_P (res))
+	  DECL_VINDEX (res) = tree_node ();
+
 	if (!res)
 	  set_overrun ();
 	int tag = insert (res);
diff --git a/gcc/testsuite/g++.dg/modules/pr103499_a.C b/gcc/testsuite/g++.dg/modules/pr103499_a.C
new file mode 100644
index 00000000000..0497c2c5504
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr103499_a.C
@@ -0,0 +1,12 @@
+// PR c++/103499
+// { dg-module-do compile }
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi pr103499 }
+
+export module pr103499;
+
+export struct base {
+  virtual ~base() = default;
+};
+
+export struct derived : base {};
diff --git a/gcc/testsuite/g++.dg/modules/pr103499_b.C b/gcc/testsuite/g++.dg/modules/pr103499_b.C
new file mode 100644
index 00000000000..b7468562ba9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr103499_b.C
@@ -0,0 +1,8 @@
+// PR c++/103499
+// { dg-additional-options "-fmodules-ts" }
+
+import pr103499;
+
+void test(derived* p) {
+  delete p;
+}

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

only message in thread, other threads:[~2023-11-14 19:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 19:43 [gcc r14-5461] c++: Stream virtual dtor vtable indices Nathan Sidwell

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