public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Keep DECL_SAVED_TREE of destructor instantiations in modules [PR104040]
@ 2024-03-29  3:21 Nathaniel Shead
  2024-03-29 12:33 ` Patrick Palka
  2024-04-02 17:18 ` Jason Merrill
  0 siblings, 2 replies; 10+ messages in thread
From: Nathaniel Shead @ 2024-03-29  3:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

A template instantiation still needs to have its DECL_SAVED_TREE so that
its definition is emitted into the CMI. This way it can be emitted in
the object file of any importers that use it, in case it doesn't end up
getting emitted in this TU.

	PR c++/104040

gcc/cp/ChangeLog:

	* semantics.cc (expand_or_defer_fn_1): Also keep DECL_SAVED_TREE
	for template instantiations.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/pr104040_a.C: New test.
	* g++.dg/modules/pr104040_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/semantics.cc                       |  7 +++++--
 gcc/testsuite/g++.dg/modules/pr104040_a.C | 14 ++++++++++++++
 gcc/testsuite/g++.dg/modules/pr104040_b.C |  8 ++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/pr104040_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/pr104040_b.C

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index adb1ba48d29..84e9901509a 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5033,9 +5033,12 @@ expand_or_defer_fn_1 (tree fn)
       /* We don't want to process FN again, so pretend we've written
 	 it out, even though we haven't.  */
       TREE_ASM_WRITTEN (fn) = 1;
-      /* If this is a constexpr function, keep DECL_SAVED_TREE.  */
+      /* If this is a constexpr function, or the body might need to be
+	 exported from a module CMI, keep DECL_SAVED_TREE.  */
       if (!DECL_DECLARED_CONSTEXPR_P (fn)
-	  && !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
+	  && !(modules_p ()
+	       && (DECL_DECLARED_INLINE_P (fn)
+		   || DECL_TEMPLATE_INSTANTIATION (fn))))
 	DECL_SAVED_TREE (fn) = NULL_TREE;
       return false;
     }
diff --git a/gcc/testsuite/g++.dg/modules/pr104040_a.C b/gcc/testsuite/g++.dg/modules/pr104040_a.C
new file mode 100644
index 00000000000..ea36ce0a798
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr104040_a.C
@@ -0,0 +1,14 @@
+// PR c++/104040
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi test }
+
+export module test;
+
+export template <typename T>
+struct test {
+  ~test() {}
+};
+
+test<bool> use() {
+  return {};
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr104040_b.C b/gcc/testsuite/g++.dg/modules/pr104040_b.C
new file mode 100644
index 00000000000..efe014673fb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr104040_b.C
@@ -0,0 +1,8 @@
+// PR c++/104040
+// { dg-additional-options "-fmodules-ts" }
+
+import test;
+
+int main() {
+  test<bool> t{};
+}
-- 
2.43.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-10  1:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29  3:21 [PATCH] c++: Keep DECL_SAVED_TREE of destructor instantiations in modules [PR104040] Nathaniel Shead
2024-03-29 12:33 ` Patrick Palka
2024-04-02 17:18 ` Jason Merrill
2024-04-03  0:57   ` Nathaniel Shead
2024-04-03 15:18     ` Jason Merrill
2024-04-04 11:27       ` Nathaniel Shead
2024-04-09  3:17         ` Jason Merrill
2024-04-09 13:36           ` Nathaniel Shead
2024-04-09 14:28             ` Jason Merrill
2024-04-10  1:42               ` Nathaniel Shead

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