[PATCH] [ms-cxxabi] Implement guard variables for static initialization
Eli Friedman
eli.friedman at gmail.com
Mon Aug 19 17:51:47 PDT 2013
class MicrosoftFunctionState : public CXXABIFunctionState {
public:
MicrosoftFunctionState() : NumGuardedInitsEmitted(0), GuardGV(0) {}
int NumGuardedInitsEmitted;
llvm::GlobalVariable *GuardGV;
};
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):
int foo();
inline void f() {
if (0) {
static int x = foo();
}
static int x = foo();
}
void g() { f(); }
-Eli
On Thu, Aug 15, 2013 at 4:59 PM, Reid Kleckner <rnk at google.com> wrote:
> Hi rjmccall,
>
> Static locals requiring initialization are not thread safe on Windows.
> Unfortunately, it's possible to create static locals that are actually
> externally visible with inline functions and templates. As a result, we
> have to implement an initialization guard scheme that is compatible with
> TUs built by MSVC, which makes thread safety prohibitively difficult.
>
> MSVC's scheme is that every function that requires a guard gets an i32
> bitfield. Each static local is assigned a bit that indicates if it has
> been initialized, up to 32 bits, at which point a new bitfield is
> created. MSVC rejects inline functions with more than 32 static locals,
> and the externally visible mangling (?_B) only allows for one guard
> variable per function.
>
> Implements PR16888.
>
> http://llvm-reviews.chandlerc.com/D1416
>
> Files:
> include/clang/AST/Mangle.h
> lib/AST/ItaniumMangle.cpp
> lib/AST/MicrosoftMangle.cpp
> lib/CodeGen/CGCXXABI.cpp
> lib/CodeGen/CGCXXABI.h
> lib/CodeGen/CGDeclCXX.cpp
> lib/CodeGen/CodeGenFunction.cpp
> lib/CodeGen/CodeGenFunction.h
> lib/CodeGen/ItaniumCXXABI.cpp
> lib/CodeGen/MicrosoftCXXABI.cpp
> test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130819/adc6e42f/attachment.html>
More information about the cfe-commits
mailing list