]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Fix merge of TLS init functions [PR120363]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 22 May 2025 12:16:22 +0000 (22:16 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 23 May 2025 22:54:33 +0000 (08:54 +1000)
commit66e9a4f3083356b064cc64651edad466a56f762b
tree15cf8ad724154c9c4b635f57c5a5b30a69623df9
parent43dddeef7a870ce4db7407f73660504b67a0a919
c++/modules: Fix merge of TLS init functions [PR120363]

The PR notes that we missed setting DECL_CONTEXT on the TLS init
function; we missed this initially because this function is not created
in header units, only named modules.

I also noticed that 'DECL_CONTEXT (fn) = DECL_CONTEXT (var)' was
incorrect: for class members, this ends up having the modules merging
machinery treat the decl as a member function, which breaks when
attempting to dedup against an existing completed class type.  Instead
we can just use the global_namespace as the context, because the name of
the function is already mangled appropriately so that we'll match the
correct duplicates.

PR c++/120363

gcc/cp/ChangeLog:

* decl2.cc (get_tls_init_fn): Set context as global_namespace.
(get_tls_wrapper_fn): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr113292_a.H: Move to...
* g++.dg/modules/tls-1_a.H: ...here.
* g++.dg/modules/pr113292_b.C: Move to...
* g++.dg/modules/tls-1_b.C: ...here.
* g++.dg/modules/pr113292_c.C: Move to...
* g++.dg/modules/tls-1_c.C: ...here.
* g++.dg/modules/tls-2_a.C: New test.
* g++.dg/modules/tls-2_b.C: New test.
* g++.dg/modules/tls-2_c.C: New test.
* g++.dg/modules/tls-3.h: New test.
* g++.dg/modules/tls-3_a.H: New test.
* g++.dg/modules/tls-3_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl2.cc
gcc/testsuite/g++.dg/modules/tls-1_a.H [moved from gcc/testsuite/g++.dg/modules/pr113292_a.H with 100% similarity]
gcc/testsuite/g++.dg/modules/tls-1_b.C [moved from gcc/testsuite/g++.dg/modules/pr113292_b.C with 93% similarity]
gcc/testsuite/g++.dg/modules/tls-1_c.C [moved from gcc/testsuite/g++.dg/modules/pr113292_c.C with 93% similarity]
gcc/testsuite/g++.dg/modules/tls-2_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tls-2_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tls-2_c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tls-3.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tls-3_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/tls-3_b.C [new file with mode: 0644]