c++: Fix handling of __thread/thread_local extern vars declared at function scope...
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Oct 2021 08:30:16 +0000 (10:30 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 1 Oct 2021 08:30:16 +0000 (10:30 +0200)
commit701075864ac4d1c6cec936d10f9cfc2aeb8c1699
tree33bb4e31a455a2a4d53ee7307485c7303569dde2
parent3a7f20ed26416b56df6f3c8240f3c65a5715b17d
c++: Fix handling of __thread/thread_local extern vars declared at function scope [PR102496]

The introduction of push_local_extern_decl_alias in
r11-3699-g4e62aca0e0520e4ed2532f2d8153581190621c1a
broke tls vars, while the decl they are created for has the tls model
set properly, nothing sets it for the alias that is actually used,
so accesses to it are done as if they were normal variables.
This is then diagnosed at link time if the definition of the extern
vars is __thread/thread_local.

2021-10-01  Jakub Jelinek  <jakub@redhat.com>

PR c++/102496
* name-lookup.c (push_local_extern_decl_alias): Return early even for
tls vars with non-dependent type when processing_template_decl.  For
CP_DECL_THREAD_LOCAL_P vars call set_decl_tls_model on alias.

* g++.dg/tls/pr102496-1.C: New test.
* g++.dg/tls/pr102496-2.C: New test.
gcc/cp/name-lookup.c
gcc/testsuite/g++.dg/tls/pr102496-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tls/pr102496-2.C [new file with mode: 0644]