~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to clang/lib/CodeGen/CGBlocks.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
/// buildBlockDescriptor is accessed from 5th field of the Block_literal
64
64
/// meta-data and contains stationary information about the block literal.
65
65
/// Its definition will have 4 (or optinally 6) words.
 
66
/// \code
66
67
/// struct Block_descriptor {
67
68
///   unsigned long reserved;
68
69
///   unsigned long size;  // size of Block_literal metadata in bytes.
69
70
///   void *copy_func_helper_decl;  // optional copy helper.
70
71
///   void *destroy_func_decl; // optioanl destructor helper.
71
 
///   void *block_method_encoding_address;//@encode for block literal signature.
 
72
///   void *block_method_encoding_address; // @encode for block literal signature.
72
73
///   void *block_layout_info; // encoding of captured block variables.
73
74
/// };
 
75
/// \endcode
74
76
static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
75
77
                                            const CGBlockInfo &blockInfo) {
76
78
  ASTContext &C = CGM.getContext();
695
697
  bool isLambdaConv = blockInfo.getBlockDecl()->isConversionFromLambda();
696
698
  llvm::Constant *blockFn
697
699
    = CodeGenFunction(CGM, true).GenerateBlockFunction(CurGD, blockInfo,
698
 
                                                 CurFuncDecl, LocalDeclMap,
699
 
                                                 isLambdaConv);
 
700
                                                       LocalDeclMap,
 
701
                                                       isLambdaConv);
700
702
  blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
701
703
 
702
704
  // If there is nothing to capture, we can emit this as a global block.
1034
1036
    llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
1035
1037
    blockFn = CodeGenFunction(*this).GenerateBlockFunction(GlobalDecl(),
1036
1038
                                                           blockInfo,
1037
 
                                                           0, LocalDeclMap,
 
1039
                                                           LocalDeclMap,
1038
1040
                                                           false);
1039
1041
  }
1040
1042
  blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
1088
1090
llvm::Function *
1089
1091
CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
1090
1092
                                       const CGBlockInfo &blockInfo,
1091
 
                                       const Decl *outerFnDecl,
1092
1093
                                       const DeclMapTy &ldm,
1093
1094
                                       bool IsLambdaConversionToBlock) {
1094
1095
  const BlockDecl *blockDecl = blockInfo.getBlockDecl();
1148
1149
  // Begin generating the function.
1149
1150
  StartFunction(blockDecl, fnType->getResultType(), fn, fnInfo, args,
1150
1151
                blockInfo.getBlockExpr()->getBody()->getLocStart());
1151
 
  CurFuncDecl = outerFnDecl; // StartFunction sets this to blockDecl
1152
1152
 
1153
1153
  // Okay.  Undo some of what StartFunction did.
1154
1154
  
1169
1169
    Alloca->setAlignment(Align);
1170
1170
    // Set the DebugLocation to empty, so the store is recognized as a
1171
1171
    // frame setup instruction by llvm::DwarfDebug::beginFunction().
1172
 
    llvm::DebugLoc Empty;
1173
 
    llvm::DebugLoc Loc = Builder.getCurrentDebugLocation();
1174
 
    Builder.SetCurrentDebugLocation(Empty);
 
1172
    Builder.DisableDebugLocations();
1175
1173
    Builder.CreateAlignedStore(BlockPointer, Alloca, Align);
1176
 
    Builder.SetCurrentDebugLocation(Loc);
 
1174
    Builder.EnableDebugLocations();
1177
1175
    BlockPointerDbgLoc = Alloca;
1178
1176
  }
1179
1177
 
1186
1184
    CXXThisValue = Builder.CreateLoad(addr, "this");
1187
1185
  }
1188
1186
 
1189
 
  // LoadObjCSelf() expects there to be an entry for 'self' in LocalDeclMap;
1190
 
  // appease it.
1191
 
  if (const ObjCMethodDecl *method
1192
 
        = dyn_cast_or_null<ObjCMethodDecl>(CurFuncDecl)) {
1193
 
    const VarDecl *self = method->getSelfDecl();
1194
 
 
1195
 
    // There might not be a capture for 'self', but if there is...
1196
 
    if (blockInfo.Captures.count(self)) {
1197
 
      const CGBlockInfo::Capture &capture = blockInfo.getCapture(self);
1198
 
 
1199
 
      llvm::Value *selfAddr = Builder.CreateStructGEP(BlockPointer,
1200
 
                                                      capture.getIndex(),
1201
 
                                                      "block.captured-self");
1202
 
      LocalDeclMap[self] = selfAddr;
1203
 
    }
1204
 
  }
1205
 
 
1206
1187
  // Also force all the constant captures.
1207
1188
  for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(),
1208
1189
         ce = blockDecl->capture_end(); ci != ce; ++ci) {