c++: cleanup function name [PR 98531]

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.
This commit is contained in:
Nathan Sidwell 2021-02-03 04:44:41 -08:00
parent 57b17858a1
commit efcd941e86
7 changed files with 50 additions and 9 deletions

View 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 ();

View file

@ -0,0 +1,13 @@
struct __waiters
{
__waiters() noexcept;
~__waiters () noexcept;
static __waiters &_S_for()
{
static __waiters w;
return w;
}
};

View file

@ -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"

View file

@ -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";

View file

@ -0,0 +1,13 @@
struct __waiters
{
__waiters() noexcept;
~__waiters () noexcept;
static __waiters &_S_for()
{
static __waiters w[2];
return w[0];
}
};

View file

@ -0,0 +1,5 @@
// { dg-additional-options -fmodule-header }
// PR c++ 98531 no-context __tcf_0
// { dg-module-cmi {} }
#include "pr98531-3.h"

View file

@ -0,0 +1,4 @@
// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
#include "pr98531-3.h"
import "pr98531-3_a.H";