[cfe-commits] r162255 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp

Richard Smith richard-llvm at metafoo.co.uk
Mon Aug 20 22:42:49 PDT 2012


Author: rsmith
Date: Tue Aug 21 00:42:49 2012
New Revision: 162255

URL: http://llvm.org/viewvc/llvm-project?rev=162255&view=rev
Log:
Fix alignment of array of VarDecl* following array of unsigned in LambdaExpr.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/lib/AST/ExprCXX.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=162255&r1=162254&r2=162255&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Aug 21 00:42:49 2012
@@ -1281,8 +1281,11 @@
   
   /// \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:

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=162255&r1=162254&r2=162255&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Aug 21 00:42:49 2012
@@ -877,9 +877,13 @@
   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,





More information about the cfe-commits mailing list