diff options
author | John Brawn <john.brawn@arm.com> | 2016-06-15 14:14:51 +0000 |
---|---|---|
committer | John Brawn <john.brawn@arm.com> | 2016-06-15 14:14:51 +0000 |
commit | 6be9afbe2802b2acc8403ce4c75a10f7fbeabd88 (patch) | |
tree | 51201380a27e68fb9fe7976181a1925c097c1651 /lib/AST/DeclBase.cpp | |
parent | 6411069e7ccde19b551d39f6f233c6551dc0f1f8 (diff) |
Don't use static variables in LambdaCapture
When static variables are used in inline functions in header files anything that
uses that function ends up with a reference to the variable. Because
RecursiveASTVisitor uses the inline functions in LambdaCapture that use static
variables any AST plugin that uses RecursiveASTVisitor, such as the
PrintFunctionNames example, ends up with a reference to these variables. This is
bad on Windows when building with MSVC with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON
as variables used across a DLL boundary need to be explicitly dllimported in
the DLL using them.
This patch avoids that by adjusting LambdaCapture to be similar to before
r263921, with a capture of either 'this' or a VLA represented by a null Decl
pointer in DeclAndBits with an extra flag added to the bits to distinguish
between the two. This requires the use of an extra bit, and while Decl does
happen to be sufficiently aligned to allow this it's done in a way that means
PointerIntPair doesn't realise it and gives an assertion failure. Therefore I
also adjust Decl slightly to use LLVM_ALIGNAS to allow this.
Differential Revision: http://reviews.llvm.org/D20732
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272788 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r-- | lib/AST/DeclBase.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index dd0bab811e..f68ca602c2 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -46,7 +46,7 @@ void Decl::updateOutOfDate(IdentifierInfo &II) const { } #define DECL(DERIVED, BASE) \ - static_assert(Decl::DeclObjAlignment >= \ + static_assert(llvm::AlignOf<Decl>::Alignment >= \ llvm::AlignOf<DERIVED##Decl>::Alignment, \ "Alignment sufficient after objects prepended to " #DERIVED); #define ABSTRACT_DECL(DECL) @@ -56,7 +56,7 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Context, unsigned ID, std::size_t Extra) { // Allocate an extra 8 bytes worth of storage, which ensures that the // resulting pointer will still be 8-byte aligned. - static_assert(sizeof(unsigned) * 2 >= DeclObjAlignment, + static_assert(sizeof(unsigned) * 2 >= llvm::AlignOf<Decl>::Alignment, "Decl won't be misaligned"); void *Start = Context.Allocate(Size + Extra + 8); void *Result = (char*)Start + 8; @@ -81,7 +81,8 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Ctx, // Ensure required alignment of the resulting object by adding extra // padding at the start if required. size_t ExtraAlign = - llvm::OffsetToAlignment(sizeof(Module *), DeclObjAlignment); + llvm::OffsetToAlignment(sizeof(Module *), + llvm::AlignOf<Decl>::Alignment); char *Buffer = reinterpret_cast<char *>( ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx)); Buffer += ExtraAlign; |