<div dir="ltr"><div><div>class MicrosoftFunctionState : public CXXABIFunctionState {</div><div>public:</div><div>  MicrosoftFunctionState() : NumGuardedInitsEmitted(0), GuardGV(0) {}</div><div>  int NumGuardedInitsEmitted;</div>
<div>  llvm::GlobalVariable *GuardGV;</div><div>};</div></div><div><br></div><div>This is very suspicious.  For the Itanium ABI, to get this right, we have to track it in the AST.  (See clang::MangleNumberingContext etc.)  A testcase (which we messed up with the Itanium ABI until quite recently):</div>
<div><br></div><div><div>int foo();</div><div>inline void f() {</div><div>  if (0) {</div><div>    static int x = foo();</div><div>  }</div><div>  static int x = foo();</div><div>}</div><div>void g() { f(); }</div></div><div>
<br></div><div><br></div><div>-Eli  </div><div><br></div>On Thu, Aug 15, 2013 at 4:59 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi rjmccall,<br>
<br>
Static locals requiring initialization are not thread safe on Windows.<br>
Unfortunately, it's possible to create static locals that are actually<br>
externally visible with inline functions and templates.  As a result, we<br>
have to implement an initialization guard scheme that is compatible with<br>
TUs built by MSVC, which makes thread safety prohibitively difficult.<br>
<br>
MSVC's scheme is that every function that requires a guard gets an i32<br>
bitfield.  Each static local is assigned a bit that indicates if it has<br>
been initialized, up to 32 bits, at which point a new bitfield is<br>
created.  MSVC rejects inline functions with more than 32 static locals,<br>
and the externally visible mangling (?_B) only allows for one guard<br>
variable per function.<br>
<br>
Implements PR16888.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D1416" target="_blank">http://llvm-reviews.chandlerc.com/D1416</a><br>
<br>
Files:<br>
  include/clang/AST/Mangle.h<br>
  lib/AST/ItaniumMangle.cpp<br>
  lib/AST/MicrosoftMangle.cpp<br>
  lib/CodeGen/CGCXXABI.cpp<br>
  lib/CodeGen/CGCXXABI.h<br>
  lib/CodeGen/CGDeclCXX.cpp<br>
  lib/CodeGen/CodeGenFunction.cpp<br>
  lib/CodeGen/CodeGenFunction.h<br>
  lib/CodeGen/ItaniumCXXABI.cpp<br>
  lib/CodeGen/MicrosoftCXXABI.cpp<br>
  test/CodeGenCXX/microsoft-abi-static-initializers.cpp<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>