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:
parent
57b17858a1
commit
efcd941e86
7 changed files with 50 additions and 9 deletions
|
@ -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 ();
|
||||
|
|
13
gcc/testsuite/g++.dg/modules/pr98531-2.h
Normal file
13
gcc/testsuite/g++.dg/modules/pr98531-2.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
struct __waiters
|
||||
{
|
||||
__waiters() noexcept;
|
||||
~__waiters () noexcept;
|
||||
|
||||
static __waiters &_S_for()
|
||||
{
|
||||
static __waiters w;
|
||||
|
||||
return w;
|
||||
}
|
||||
};
|
5
gcc/testsuite/g++.dg/modules/pr98531-2_a.H
Normal file
5
gcc/testsuite/g++.dg/modules/pr98531-2_a.H
Normal 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"
|
4
gcc/testsuite/g++.dg/modules/pr98531-2_b.C
Normal file
4
gcc/testsuite/g++.dg/modules/pr98531-2_b.C
Normal 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";
|
13
gcc/testsuite/g++.dg/modules/pr98531-3.h
Normal file
13
gcc/testsuite/g++.dg/modules/pr98531-3.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
struct __waiters
|
||||
{
|
||||
__waiters() noexcept;
|
||||
~__waiters () noexcept;
|
||||
|
||||
static __waiters &_S_for()
|
||||
{
|
||||
static __waiters w[2];
|
||||
|
||||
return w[0];
|
||||
}
|
||||
};
|
5
gcc/testsuite/g++.dg/modules/pr98531-3_a.H
Normal file
5
gcc/testsuite/g++.dg/modules/pr98531-3_a.H
Normal file
|
@ -0,0 +1,5 @@
|
|||
// { dg-additional-options -fmodule-header }
|
||||
// PR c++ 98531 no-context __tcf_0
|
||||
// { dg-module-cmi {} }
|
||||
|
||||
#include "pr98531-3.h"
|
4
gcc/testsuite/g++.dg/modules/pr98531-3_b.C
Normal file
4
gcc/testsuite/g++.dg/modules/pr98531-3_b.C
Normal file
|
@ -0,0 +1,4 @@
|
|||
// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
|
||||
|
||||
#include "pr98531-3.h"
|
||||
import "pr98531-3_a.H";
|
Loading…
Add table
Reference in a new issue