First cut CodeGen support for __block variables.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65688 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 057f554..f2a08b1 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -282,7 +282,7 @@
   llvm::Function *GenerateBlockFunction(const BlockExpr *Expr,
                                         const BlockInfo& Info,
                                         uint64_t &Size, uint64_t &Align,
-                                        llvm::SmallVector<ValueDecl *, 8> &subBlockDeclRefDecls);
+                                        llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls);
 
   ImplicitParamDecl *BlockStructDecl;
 
@@ -295,40 +295,21 @@
 
   /// BlockDeclRefDecls - Decls from BlockDeclRefExprs in apperance order
   /// in a block literal.  Decls without names are used for padding.
-  llvm::SmallVector<ValueDecl *, 8> BlockDeclRefDecls;
+  llvm::SmallVector<const Expr *, 8> BlockDeclRefDecls;
 
   /// BlockOffset - The offset in bytes for the next allocation of an
   /// imported block variable.
   uint64_t BlockOffset;
   /// BlockAlign - Maximal alignment needed for the Block expressed in bytes.
   uint64_t BlockAlign;
-  /// getBlockOffset - Offset for next allocated variable used in a BlockExpr.
-  uint64_t getBlockOffset(ValueDecl *D) {
-    uint64_t Size = getContext().getTypeSize(D->getType()) / 8;
-    uint64_t Align = getContext().getDeclAlignInBytes(D);
+  /// getBlockOffset - Allocate an offset for the ValueDecl from a
+  /// BlockDeclRefExpr in a block literal (BlockExpr).
+  uint64_t getBlockOffset(const BlockDeclRefExpr *E);
 
-    assert ((Align > 0) && "alignment must be 1 byte or more");
+  /// BlockDecls - Offsets for all Decls in BlockDeclRefExprs.
+  std::map<const Decl*, uint64_t> BlockDecls;
 
-    uint64_t OldOffset = BlockOffset;
-
-    // Ensure proper alignment, even if it means we have to have a gap
-    BlockOffset = llvm::RoundUpToAlignment(BlockOffset, Align);
-    BlockAlign = std::max(Align, BlockAlign);
-      
-    uint64_t Pad = BlockOffset - OldOffset;
-    llvm::ArrayType::get(llvm::Type::Int8Ty, Pad);
-    QualType PadTy = getContext().getConstantArrayType(getContext().CharTy,
-                                                       llvm::APInt(32, Pad),
-                                                       ArrayType::Normal, 0);
-    ValueDecl *PadDecl = VarDecl::Create(getContext(), 0, SourceLocation(),
-                                         0, QualType(PadTy), VarDecl::None, SourceLocation());
-    BlockDeclRefDecls.push_back(PadDecl);
-    BlockDeclRefDecls.push_back(D);
-
-    BlockOffset += Size;
-    return BlockOffset-Size;
-  }
-  std::map<Decl*, uint64_t> BlockDecls;
+  llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);
 
   void GenerateCode(const FunctionDecl *FD,
                     llvm::Function *Fn);
@@ -665,6 +646,8 @@
   LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field,
                                 unsigned CVRQualifiers);
 
+  LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
+
   LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);
 
   LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);