[pushed] c++: inlining explicit instantiations [PR104539]

Message ID 20220217225051.2133964-1-jason@redhat.com
State Committed
Commit 2c9b7077b72529fbbe896212a0088bff6025c5e7
Headers
Series [pushed] c++: inlining explicit instantiations [PR104539] |

Commit Message

Jason Merrill Feb. 17, 2022, 10:50 p.m. UTC
  The PR10968 fix cleared DECL_COMDAT to force output of explicit
instantiations.  Then the PR59469 fix added a call to mark_needed, after
which we no longer need to clear DECL_COMDAT, and leaving it set allows us
to inline explicit instantiations without worrying about symbol
interposition.

I suppose there's an argument to be made that an explicit instantiation
declaration (extern template) should clear DECL_COMDAT, since that suggests
that there will be only a single instantiation somewhere that could be
subject to interposition, but that doesn't change the 'inline' semantics,
and it seems cleaner to treat template instantiations uniformly.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/104539

gcc/cp/ChangeLog:

	* pt.cc (mark_decl_instantiated): Don't clear DECL_COMDAT.

gcc/testsuite/ChangeLog:

	* g++.dg/ipa/inline-4.C: New test.
---
 gcc/cp/pt.cc                        |  3 ---
 gcc/testsuite/g++.dg/ipa/inline-4.C | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/inline-4.C


base-commit: c352ef0ed90cfc07d494dfec111121bc683e337b
  

Patch

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index d4a40d517d1..352cff944d0 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24726,9 +24726,6 @@  mark_decl_instantiated (tree result, int extern_p)
        set correctly by tsubst.  */
     TREE_PUBLIC (result) = 1;
 
-  /* This might have been set by an earlier implicit instantiation.  */
-  DECL_COMDAT (result) = 0;
-
   if (extern_p)
     {
       DECL_EXTERNAL (result) = 1;
diff --git a/gcc/testsuite/g++.dg/ipa/inline-4.C b/gcc/testsuite/g++.dg/ipa/inline-4.C
new file mode 100644
index 00000000000..204aa7a366e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/inline-4.C
@@ -0,0 +1,15 @@ 
+// PR c++/104539
+// { dg-additional-options "-O3 -fdump-ipa-inline" }
+// { dg-final { scan-ipa-dump-not "overwritten at link time" "inline" } }
+
+template <int>
+//inline
+int f() {
+  return 0;
+}
+
+template int f<0>();
+
+int g() {
+  return f<0>() + 1;
+}