<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">John,<div><br></div><div>This patch is degrading debug info for blocks.</div><div><br><div><div>On Feb 7, 2011, at 2:33 AM, John McCall wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">+  // The first argument is the block pointer.  Just take it as a void*<br>+  // and cast it later.<br><b>+  QualType selfTy = getContext().VoidPtrTy;<br></b>  IdentifierInfo *II = &CGM.getContext().Idents.get(".block_descriptor");<br><br>-  // Build the block struct now.<br>-  AllocateAllBlockDeclRefs(*this, Info);<br>+  // FIXME: this leaks, and we only need it very temporarily.<br>+  ImplicitParamDecl *selfDecl =<br>+    ImplicitParamDecl::Create(getContext(),<br>+                              const_cast<BlockDecl*>(blockDecl),<br>+                              SourceLocation(), II, </span><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><b>selfTy</b></span><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">);<br>+  args.push_back(std::make_pair(selfDecl, selfTy));<br>+<br>+  // Now add the rest of the parameters.<br>+  for (BlockDecl::param_const_iterator i = blockDecl->param_begin(),<br>+       e = blockDecl->param_end(); i != e; ++i)<br>+    args.push_back(std::make_pair(*i, (*i)->getType()));<br>+<br>+  // Create the function declaration.<br>+  const FunctionProtoType *fnType =<br>+    cast<FunctionProtoType>(blockInfo.getBlockExpr()->getFunctionType());<br>+  const CGFunctionInfo &fnInfo =<br>+    CGM.getTypes().getFunctionInfo(fnType->getResultType(), args,<br>+                                   fnType->getExtInfo());<br>+  const llvm::FunctionType *fnLLVMType =<br>+    CGM.getTypes().GetFunctionType(fnInfo, fnType->isVariadic());<br>+<br>+  MangleBuffer name;<br>+  CGM.getBlockMangledName(GD, name, blockDecl);<br>+  llvm::Function *fn =<br>+    llvm::Function::Create(fnLLVMType, llvm::GlobalValue::InternalLinkage,<span class="Apple-converted-space"> </span><br>+                           name.getString(), &CGM.getModule());<br>+  CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo);<br>+<br>+  // Begin generating the function.<br>+  StartFunction(blockDecl, fnType->getResultType(), fn, args,<br>+                blockInfo.getBlockExpr()->getBody()->getLocEnd());<br>+  CurFuncDecl = outerFnDecl; // StartFunction sets this to blockDecl<br>+<br>+  // Okay.  Undo some of what StartFunction did.  We really don't need<br>+  // an alloca for the block address;  in theory we could remove it,<br>+  // but that might do unpleasant things to debug info.<br>+  llvm::AllocaInst *blockAddrAlloca<br>+    = cast<llvm::AllocaInst>(LocalDeclMap[selfDecl]);<br>+  llvm::Value *blockAddr = Builder.CreateLoad(blockAddrAlloca);<br>+  BlockPointer = Builder.CreateBitCast(blockAddr,<br>+                                       blockInfo.StructureType->getPointerTo(),<br>+                                       "block");<br><br>-  // Capture block layout info. here.<br>-  if (CGM.getContext().getLangOptions().ObjC1)<br>-    BlockVarLayout = CGM.getObjCRuntime().GCBlockLayout(*this, BlockLayout);<br>-  else<br>-    BlockVarLayout = llvm::Constant::getNullValue(PtrToInt8Ty);<br>-  <br><b>-  QualType ParmTy = getContext().getBlockParmType(<br>-                                        SynthesizeCopyDisposeHelpers,<br>-                                        BlockLayout);<br></b>-<br>-  // FIXME: This leaks<br>-  ImplicitParamDecl *SelfDecl =<br>-    ImplicitParamDecl::Create(getContext(), const_cast<BlockDecl*>(BD),<br>-                              SourceLocation(), II,<br>-                              </span><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><b>ParmTy</b></span><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">);<br>-<br></span></blockquote></div><br></div><div>With this change type of SelfDecl is lost. Earlier clang used to emit</div><div><br></div><div><div>0x000001a8:         TAG_formal_parameter [14]</div><div>                     AT_name( ".block_descriptor" )</div><div>                     AT_decl_file( "/private/tmp/blocks.c" )</div><div>                     AT_decl_line( 28 )</div><div><b>                     AT_type( {0x000005b0} ( __block_literal_1* ) )</b></div><div>                     AT_artificial( 0x01 )</div><div>                     AT_location( fbreg -16 )</div></div><div><br></div><div>where as now it emits</div><div><br></div><div><div>0x0000036d:         TAG_formal_parameter [13]</div><div>                     AT_name( ".block_descriptor" )</div><div>                     AT_decl_file( "/private/tmp/blocks.c" )</div><div>                     AT_decl_line( 64 )</div><div><b>                     AT_type( {0x0000005e} ( * ) )</b></div><div>                     AT_artificial( 0x01 )</div><div>                     AT_location( fbreg -16 )</div></div><div><br></div><div>I see your comments above that says, cast argument pointer later, but debug info is left out of loop in that case.</div><div>-</div><div>Devang</div></body></html>