diff options
-rw-r--r-- | include/clang/AST/ExprCXX.h | 5 | ||||
-rw-r--r-- | lib/AST/ExprCXX.cpp | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index ecfa9e2136..598543757d 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1281,8 +1281,11 @@ private: /// \brief Retrieve the complete set of array-index variables. VarDecl **getArrayIndexVars() const { + unsigned ArrayIndexSize = sizeof(unsigned) * (NumCaptures + 1); + unsigned Align = llvm::alignOf<VarDecl*>(); + ArrayIndexSize = (ArrayIndexSize + Align - 1) & ~(Align - 1); return reinterpret_cast<VarDecl **>( - getArrayIndexStarts() + NumCaptures + 1); + reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); } public: diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 3fa49e0e18..97814afa18 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -877,9 +877,13 @@ LambdaExpr *LambdaExpr::Create(ASTContext &Context, QualType T = Context.getTypeDeclType(Class); unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1); - if (!ArrayIndexVars.empty()) - Size += sizeof(VarDecl *) * ArrayIndexVars.size() - + sizeof(unsigned) * (Captures.size() + 1); + if (!ArrayIndexVars.empty()) { + Size += sizeof(unsigned) * (Captures.size() + 1); + // Realign for following VarDecl array. + unsigned Align = llvm::alignOf<VarDecl*>(); + Size = (Size + Align - 1) & ~(Align - 1); + Size += sizeof(VarDecl *) * ArrayIndexVars.size(); + } void *Mem = Context.Allocate(Size); return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault, Captures, ExplicitParams, ExplicitResultType, |