c++: cleanup function name [PR 98531]
authorNathan Sidwell <nathan@acm.org>
Wed, 3 Feb 2021 12:44:41 +0000 (04:44 -0800)
committerNathan Sidwell <nathan@acm.org>
Mon, 8 Feb 2021 17:24:39 +0000 (09:24 -0800)
The next piece of 98531 is that in some cases we need to create a
cleanup function to do the work (when the object is an array, or we're
using regular atexit).  We were not pushing that function's decl
anywhere (not giving it a context) so streaming it failed.

This is a partial fix.  You'll notice we're naming these from a per-TU
counter.  I've captured that in PR98893.

gcc/cp/
* decl.c (start_cleanup_fn): Push function into
namespace.
gcc/testsuite/
* g++.dg/modules/pr98531-2.h: New.
* g++.dg/modules/pr98531-2_a.H: New.
* g++.dg/modules/pr98531-2_b.C: New.
* g++.dg/modules/pr98531-3.h: New.
* g++.dg/modules/pr98531-3_a.H: New.
* g++.dg/modules/pr98531-3_b.C: New.

gcc/cp/decl.c
gcc/testsuite/g++.dg/modules/pr98531-2.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr98531-2_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr98531-2_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr98531-3.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr98531-3_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr98531-3_b.C [new file with mode: 0644]

index 4ddee2160165ec4ed406ee4d7832a998a6d578bc..0aa49f91d5a118498c80920d080f686f9bac29dd 100644 (file)
@@ -8909,10 +8909,6 @@ static tree
 start_cleanup_fn (void)
 {
   char name[32];
-  tree fntype;
-  tree fndecl;
-  bool use_cxa_atexit = flag_use_cxa_atexit
-                       && !targetm.cxx.use_atexit_for_cxa_atexit ();
 
   push_to_top_level ();
 
@@ -8922,8 +8918,9 @@ start_cleanup_fn (void)
   /* Build the name of the function.  */
   sprintf (name, "__tcf_%d", start_cleanup_cnt++);
   /* Build the function declaration.  */
-  fntype = TREE_TYPE (get_atexit_fn_ptr_type ());
-  fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
+  tree fntype = TREE_TYPE (get_atexit_fn_ptr_type ());
+  tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
+  DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   /* It's a function with internal linkage, generated by the
      compiler.  */
   TREE_PUBLIC (fndecl) = 0;
@@ -8934,16 +8931,16 @@ start_cleanup_fn (void)
      emissions this way.  */
   DECL_DECLARED_INLINE_P (fndecl) = 1;
   DECL_INTERFACE_KNOWN (fndecl) = 1;
-  /* Build the parameter.  */
-  if (use_cxa_atexit)
+  if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
     {
+      /* Build the parameter.  */
       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
       TREE_USED (parmdecl) = 1;
       DECL_READ_P (parmdecl) = 1;
       DECL_ARGUMENTS (fndecl) = parmdecl;
     }
 
-  pushdecl (fndecl);
+  fndecl = pushdecl (fndecl, /*hidden=*/true);
   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
 
   pop_lang_context ();
diff --git a/gcc/testsuite/g++.dg/modules/pr98531-2.h b/gcc/testsuite/g++.dg/modules/pr98531-2.h
new file mode 100644 (file)
index 0000000..62d4c1d
--- /dev/null
@@ -0,0 +1,13 @@
+
+struct __waiters
+{
+  __waiters() noexcept;
+  ~__waiters () noexcept;
+
+  static __waiters &_S_for()
+  {
+    static __waiters w;
+    
+    return w;
+  }
+};
diff --git a/gcc/testsuite/g++.dg/modules/pr98531-2_a.H b/gcc/testsuite/g++.dg/modules/pr98531-2_a.H
new file mode 100644 (file)
index 0000000..757d68a
--- /dev/null
@@ -0,0 +1,5 @@
+// { dg-additional-options "-fmodule-header -fno-use-cxa-atexit" }
+// PR c++ 98531  no-context __cxa_atexit
+// { dg-module-cmi {} }
+
+#include "pr98531-2.h"
diff --git a/gcc/testsuite/g++.dg/modules/pr98531-2_b.C b/gcc/testsuite/g++.dg/modules/pr98531-2_b.C
new file mode 100644 (file)
index 0000000..b5fa449
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-additional-options "-fmodules-ts -fno-module-lazy -fno-use-cxa-atexit" }
+
+#include "pr98531-2.h"
+import "pr98531-2_a.H";
diff --git a/gcc/testsuite/g++.dg/modules/pr98531-3.h b/gcc/testsuite/g++.dg/modules/pr98531-3.h
new file mode 100644 (file)
index 0000000..a1a2f8a
--- /dev/null
@@ -0,0 +1,13 @@
+
+struct __waiters
+{
+  __waiters() noexcept;
+  ~__waiters () noexcept;
+
+  static __waiters &_S_for()
+  {
+    static __waiters w[2];
+    
+    return w[0];
+  }
+};
diff --git a/gcc/testsuite/g++.dg/modules/pr98531-3_a.H b/gcc/testsuite/g++.dg/modules/pr98531-3_a.H
new file mode 100644 (file)
index 0000000..1c6267a
--- /dev/null
@@ -0,0 +1,5 @@
+// { dg-additional-options -fmodule-header }
+// PR c++ 98531  no-context __tcf_0
+// { dg-module-cmi {} }
+
+#include "pr98531-3.h"
diff --git a/gcc/testsuite/g++.dg/modules/pr98531-3_b.C b/gcc/testsuite/g++.dg/modules/pr98531-3_b.C
new file mode 100644 (file)
index 0000000..7e3e16d
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+#include "pr98531-3.h"
+import "pr98531-3_a.H";