]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Drop TREE_READONLY on vars (possibly) initialized by tls wrapper [PR109164]
authorJakub Jelinek <jakub@redhat.com>
Mon, 20 Mar 2023 19:29:47 +0000 (20:29 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 3 May 2023 13:07:58 +0000 (15:07 +0200)
commit73accd859e80e5d50937b8dc85a4e509fc174b97
tree832f192cda1f3607bfee7bbd1131ece443341edb
parent06b34c0d76153549fb83001c3d90b798066a1851
c++: Drop TREE_READONLY on vars (possibly) initialized by tls wrapper [PR109164]

The following two testcases are miscompiled, because we keep TREE_READONLY
on the vars even when they are (possibly) dynamically initialized by a TLS
wrapper function.  Normally cp_finish_decl drops TREE_READONLY from vars
which need dynamic initialization, but for TLS we do this kind of
initialization upon every access to those variables.  Keeping them
TREE_READONLY means e.g. PRE can hoist loads from those before loops
which contain the TLS wrapper calls, so we can access the TLS variables
before they are initialized.

2023-03-20  Jakub Jelinek  <jakub@redhat.com>

PR c++/109164
* cp-tree.h (var_needs_tls_wrapper): Declare.
* decl2.c (var_needs_tls_wrapper): No longer static.
* decl.c (cp_finish_decl): Clear TREE_READONLY on TLS variables
for which a TLS wrapper will be needed.

* g++.dg/tls/thread_local13.C: New test.
* g++.dg/tls/thread_local13-aux.cc: New file.
* g++.dg/tls/thread_local14.C: New test.
* g++.dg/tls/thread_local14-aux.cc: New file.

(cherry picked from commit 0a846340b99675d57fc2f2923a0412134eed09d3)
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/testsuite/g++.dg/tls/thread_local13-aux.cc [new file with mode: 0644]
gcc/testsuite/g++.dg/tls/thread_local13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tls/thread_local14-aux.cc [new file with mode: 0644]
gcc/testsuite/g++.dg/tls/thread_local14.C [new file with mode: 0644]