[PATCH] D66122: [CodeGen] Emit dynamic initializers for static TLS vars in outlined scopes
Princeton Ferro via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 13 09:42:43 PDT 2019
Prince781 added a comment.
In D66122#1627252 <https://reviews.llvm.org/D66122#1627252>, @efriedma wrote:
> > If variable A's initializer references variable B, then it will call B's initializer.
> I don't think this patch adds any code that would address that, although I could be missing something.
No, you're absolutely right. I'll fix my patch later to address this oversight.
> Thinking about it a bit more, I also have a general question: how is this supposed to work? What do other compilers do? Does the C++ standard say when the initializer is supposed to run? [stmt.dcl]p4 just says "Dynamic initialization [...] is performed the first time control passes through its declaration."
This I was not too sure about. gcc also does the same thing. I was not able to find anything addressing this situation directly. clang should either generate an error or do "the right thing." If the latter, then I take this from the standard to mean, "we can initialize at any time before the variable is referenced":
[ 3.7.2 Thread storage duration <https://timepp.github.io/doc/cpp14/basic.stc.thread.html> ] [basic.std.thread] A variable with thread storage duration shall be initialized before its first odr-use (3.2) and, if constructed, shall be destroyed on thread exit.
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
More information about the cfe-commits