* [PATCH] c++: Set DECL_CONTEXT for __cxa_thread_atexit [PR99187]
@ 2023-11-16 21:39 Nathaniel Shead
2023-11-19 21:46 ` Nathan Sidwell
0 siblings, 1 reply; 2+ messages in thread
From: Nathaniel Shead @ 2023-11-16 21:39 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell
Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
access.
-- >8 --
Modules streaming requires DECL_CONTEXT to be set on declarations that
are streamed. This ensures that __cxa_thread_atexit is given translation
unit context much like is already done with many other support
functions.
PR c++/99187
gcc/cp/ChangeLog:
* cp-tree.h (enum cp_tree_index):
(thread_atexit_node):
* decl.cc (get_thread_atexit_node):
gcc/testsuite/ChangeLog:
* g++.dg/modules/pr99187.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
gcc/cp/cp-tree.h | 4 ++++
gcc/cp/decl.cc | 15 +++++++++++++--
gcc/testsuite/g++.dg/modules/pr99187.C | 10 ++++++++++
3 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/modules/pr99187.C
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 1fa710d7154..c7a1cf610c8 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -231,6 +231,7 @@ enum cp_tree_index
CPTI_RETHROW_FN,
CPTI_ATEXIT_FN_PTR_TYPE,
CPTI_ATEXIT,
+ CPTI_THREAD_ATEXIT,
CPTI_DSO_HANDLE,
CPTI_DCAST,
@@ -375,6 +376,9 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
/* A pointer to `std::atexit'. */
#define atexit_node cp_global_trees[CPTI_ATEXIT]
+/* A pointer to `__cxa_thread_atexit'. */
+#define thread_atexit_node cp_global_trees[CPTI_THREAD_ATEXIT]
+
/* A pointer to `__dso_handle'. */
#define dso_handle_node cp_global_trees[CPTI_DSO_HANDLE]
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index d2ed46b1453..6a1f4213c9a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -9592,6 +9592,9 @@ get_atexit_node (void)
static tree
get_thread_atexit_node (void)
{
+ if (thread_atexit_node)
+ return thread_atexit_node;
+
/* The declaration for `__cxa_thread_atexit' is:
int __cxa_thread_atexit (void (*)(void *), void *, void *) */
@@ -9600,10 +9603,18 @@ get_thread_atexit_node (void)
ptr_type_node, ptr_type_node,
NULL_TREE);
- /* Now, build the function declaration. */
+ /* Now, build the function declaration, as with __cxa_atexit. */
+ unsigned flags = push_abi_namespace ();
tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
ECF_LEAF | ECF_NOTHROW);
- return decay_conversion (atexit_fndecl, tf_warning_or_error);
+ DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
+ DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
+ atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
+ pop_abi_namespace (flags);
+ mark_used (atexit_fndecl);
+ thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
+
+ return thread_atexit_node;
}
/* Returns the __dso_handle VAR_DECL. */
diff --git a/gcc/testsuite/g++.dg/modules/pr99187.C b/gcc/testsuite/g++.dg/modules/pr99187.C
new file mode 100644
index 00000000000..7f707e0c703
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99187.C
@@ -0,0 +1,10 @@
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi pr99187 }
+
+export module pr99187;
+
+export struct A { ~A() {} };
+
+export inline void f() {
+ static thread_local A a;
+}
--
2.42.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Set DECL_CONTEXT for __cxa_thread_atexit [PR99187]
2023-11-16 21:39 [PATCH] c++: Set DECL_CONTEXT for __cxa_thread_atexit [PR99187] Nathaniel Shead
@ 2023-11-19 21:46 ` Nathan Sidwell
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2023-11-19 21:46 UTC (permalink / raw)
To: Nathaniel Shead, gcc-patches; +Cc: Jason Merrill
On 11/16/23 16:39, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
> access.
>
> -- >8 --
>
> Modules streaming requires DECL_CONTEXT to be set on declarations that
> are streamed. This ensures that __cxa_thread_atexit is given translation
> unit context much like is already done with many other support
> functions.
>
> PR c++/99187
>
> gcc/cp/ChangeLog:
>
> * cp-tree.h (enum cp_tree_index):
> (thread_atexit_node):
> * decl.cc (get_thread_atexit_node):
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/pr99187.C: New test.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
thanks, I've committed it for you.
nathan
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-19 21:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-16 21:39 [PATCH] c++: Set DECL_CONTEXT for __cxa_thread_atexit [PR99187] Nathaniel Shead
2023-11-19 21:46 ` Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).