[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.
Tom Honermann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 13 14:20:17 PDT 2022
tahonermann created this revision.
tahonermann added reviewers: erichkeane, aaron.ballman, hubert.reinterpretcast, rjmccall.
Herald added a project: All.
tahonermann requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Previously, for thread_local variables that do not require thread safe initialization, guard variables used in the Itanium ABI to store the initialization state of such a variable were set after object initialization was complete. This resulted in recursive re-initialization loops in cases where a constructor references the variable being initialized. For example:
template<typename T>
struct ct {
ct();
};
template<typename T>
ct<T>& ft() {
static thread_local ct<T> tlslv;
return tlslv;
}
template<typename T>
ct<T>::ct() {
ft<T>();
}
With this change, guard variables are set before initialization is started so as to avoid such re-initialization loops. It is worth noting that, per C++20 [class.cdtor]p2, access to the value (as opposed to the address) of the object under construction via the thread_local variable results in unspecified behavior.
Fixes https://github.com/llvm/llvm-project/issues/57828
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135919
Files:
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
clang/test/CodeGenCXX/cxx11-thread-local.cpp
clang/test/CodeGenCXX/cxx1y-variable-template.cpp
clang/test/CodeGenCXX/global-init.cpp
clang/test/CodeGenCXX/static-data-member.cpp
clang/test/OpenMP/parallel_copyin_codegen.cpp
clang/test/OpenMP/threadprivate_codegen.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135919.467603.patch
Type: text/x-patch
Size: 30037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221013/27c16c31/attachment-0001.bin>
More information about the cfe-commits
mailing list