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. On Eli's recommendation, I used MangleNumberingContext to track which bit each static corresponds to. Implements PR16888. Reviewers: rjmccall, eli.friedman Differential Revision: http://llvm-reviews.chandlerc.com/D1416 llvm-svn: 190427
44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
//===--- MangleNumberingContext.cpp - Context for mangling numbers --------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines the LambdaMangleContext class, which keeps track of
|
|
// the Itanium C++ ABI mangling numbers for lambda expressions.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/AST/MangleNumberingContext.h"
|
|
#include "clang/AST/ASTContext.h"
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
using namespace clang;
|
|
|
|
unsigned
|
|
MangleNumberingContext::getManglingNumber(const CXXMethodDecl *CallOperator) {
|
|
const FunctionProtoType *Proto
|
|
= CallOperator->getType()->getAs<FunctionProtoType>();
|
|
ASTContext &Context = CallOperator->getASTContext();
|
|
|
|
QualType Key = Context.getFunctionType(Context.VoidTy, Proto->getArgTypes(),
|
|
FunctionProtoType::ExtProtoInfo());
|
|
Key = Context.getCanonicalType(Key);
|
|
return ++ManglingNumbers[Key->castAs<FunctionProtoType>()];
|
|
}
|
|
|
|
unsigned
|
|
MangleNumberingContext::getManglingNumber(const BlockDecl *BD) {
|
|
// FIXME: Compute a BlockPointerType? Not obvious how.
|
|
const Type *Ty = 0;
|
|
return ++ManglingNumbers[Ty];
|
|
}
|
|
|
|
unsigned
|
|
MangleNumberingContext::getManglingNumber(const TagDecl *TD) {
|
|
return ++TagManglingNumbers[TD->getIdentifier()];
|
|
}
|