aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-03-29 13:53:54 +1100
committerNathaniel Shead <nathanieloshead@gmail.com>2024-04-10 11:40:32 +1000
commit0774240b4df9a9bc48ce33a9625788e402498f5a (patch)
treee743ff4b4ff399e598a17adce6482b829bd66be9
parentea665f90260acb3ffd2e39fcd2e200e702ee0ead (diff)
downloadgcc-0774240b4df9a9bc48ce33a9625788e402498f5a.zip
gcc-0774240b4df9a9bc48ce33a9625788e402498f5a.tar.gz
gcc-0774240b4df9a9bc48ce33a9625788e402498f5a.tar.bz2
c++: Keep DECL_SAVED_TREE of cdtor instantiations in modules [PR104040]
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. This is true even for maybe-in-charge functions, because we don't currently stream the clones directly but instead regenerate them from this function. PR c++/104040 gcc/cp/ChangeLog: * semantics.cc (expand_or_defer_fn_1): Keep DECL_SAVED_TREE for all vague linkage cdtors with modules. 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> Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r--gcc/cp/semantics.cc8
-rw-r--r--gcc/testsuite/g++.dg/modules/pr104040_a.C14
-rw-r--r--gcc/testsuite/g++.dg/modules/pr104040_b.C8
3 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index a43ff6e..329c524 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5029,9 +5029,13 @@ 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 we still need the body to be
+ able to evaluate it. Similarly, with modules we only stream
+ the maybe-in-charge cdtor and regenerate the clones from it on
+ demand, so we also need to keep the body. Otherwise we don't
+ need it anymore. */
if (!DECL_DECLARED_CONSTEXPR_P (fn)
- && !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
+ && !(modules_p () && vague_linkage_p (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 0000000..ea36ce0
--- /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 0000000..efe01467
--- /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{};
+}