From efcd941e86b507d77e90a1b13f621e036eacdb45 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 3 Feb 2021 04:44:41 -0800 Subject: [PATCH] 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. --- gcc/cp/decl.c | 15 ++++++--------- gcc/testsuite/g++.dg/modules/pr98531-2.h | 13 +++++++++++++ gcc/testsuite/g++.dg/modules/pr98531-2_a.H | 5 +++++ gcc/testsuite/g++.dg/modules/pr98531-2_b.C | 4 ++++ gcc/testsuite/g++.dg/modules/pr98531-3.h | 13 +++++++++++++ gcc/testsuite/g++.dg/modules/pr98531-3_a.H | 5 +++++ gcc/testsuite/g++.dg/modules/pr98531-3_b.C | 4 ++++ 7 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr98531-2.h create mode 100644 gcc/testsuite/g++.dg/modules/pr98531-2_a.H create mode 100644 gcc/testsuite/g++.dg/modules/pr98531-2_b.C create mode 100644 gcc/testsuite/g++.dg/modules/pr98531-3.h create mode 100644 gcc/testsuite/g++.dg/modules/pr98531-3_a.H create mode 100644 gcc/testsuite/g++.dg/modules/pr98531-3_b.C diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4ddee216016..0aa49f91d5a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 index 00000000000..62d4c1d1f90 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98531-2.h @@ -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 index 00000000000..757d68af297 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98531-2_a.H @@ -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 index 00000000000..b5fa4492e8a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98531-2_b.C @@ -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 index 00000000000..a1a2f8a2e02 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98531-3.h @@ -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 index 00000000000..1c6267ae376 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98531-3_a.H @@ -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 index 00000000000..7e3e16d34fd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98531-3_b.C @@ -0,0 +1,4 @@ +// { dg-additional-options "-fmodules-ts -fno-module-lazy" } + +#include "pr98531-3.h" +import "pr98531-3_a.H"; -- 2.30.2