[cfe-commits] r125005 - in /cfe/trunk: include/clang/AST/ include/clang/Sema/ lib/AST/ lib/CodeGen/ lib/Rewrite/ lib/Sema/ lib/Serialization/ test/CXX/expr/expr.cast/ test/CodeGen/ test/CodeGenObjC/ test/CodeGenObjCXX/

Devang Patel dpatel at apple.com
Mon Feb 21 16:42:39 PST 2011


John,

This patch is degrading debug info for blocks.

On Feb 7, 2011, at 2:33 AM, John McCall wrote:

> +  // The first argument is the block pointer.  Just take it as a void*
> +  // and cast it later.
> +  QualType selfTy = getContext().VoidPtrTy;
>   IdentifierInfo *II = &CGM.getContext().Idents.get(".block_descriptor");
> 
> -  // Build the block struct now.
> -  AllocateAllBlockDeclRefs(*this, Info);
> +  // FIXME: this leaks, and we only need it very temporarily.
> +  ImplicitParamDecl *selfDecl =
> +    ImplicitParamDecl::Create(getContext(),
> +                              const_cast<BlockDecl*>(blockDecl),
> +                              SourceLocation(), II, selfTy);
> +  args.push_back(std::make_pair(selfDecl, selfTy));
> +
> +  // Now add the rest of the parameters.
> +  for (BlockDecl::param_const_iterator i = blockDecl->param_begin(),
> +       e = blockDecl->param_end(); i != e; ++i)
> +    args.push_back(std::make_pair(*i, (*i)->getType()));
> +
> +  // Create the function declaration.
> +  const FunctionProtoType *fnType =
> +    cast<FunctionProtoType>(blockInfo.getBlockExpr()->getFunctionType());
> +  const CGFunctionInfo &fnInfo =
> +    CGM.getTypes().getFunctionInfo(fnType->getResultType(), args,
> +                                   fnType->getExtInfo());
> +  const llvm::FunctionType *fnLLVMType =
> +    CGM.getTypes().GetFunctionType(fnInfo, fnType->isVariadic());
> +
> +  MangleBuffer name;
> +  CGM.getBlockMangledName(GD, name, blockDecl);
> +  llvm::Function *fn =
> +    llvm::Function::Create(fnLLVMType, llvm::GlobalValue::InternalLinkage, 
> +                           name.getString(), &CGM.getModule());
> +  CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo);
> +
> +  // Begin generating the function.
> +  StartFunction(blockDecl, fnType->getResultType(), fn, args,
> +                blockInfo.getBlockExpr()->getBody()->getLocEnd());
> +  CurFuncDecl = outerFnDecl; // StartFunction sets this to blockDecl
> +
> +  // Okay.  Undo some of what StartFunction did.  We really don't need
> +  // an alloca for the block address;  in theory we could remove it,
> +  // but that might do unpleasant things to debug info.
> +  llvm::AllocaInst *blockAddrAlloca
> +    = cast<llvm::AllocaInst>(LocalDeclMap[selfDecl]);
> +  llvm::Value *blockAddr = Builder.CreateLoad(blockAddrAlloca);
> +  BlockPointer = Builder.CreateBitCast(blockAddr,
> +                                       blockInfo.StructureType->getPointerTo(),
> +                                       "block");
> 
> -  // Capture block layout info. here.
> -  if (CGM.getContext().getLangOptions().ObjC1)
> -    BlockVarLayout = CGM.getObjCRuntime().GCBlockLayout(*this, BlockLayout);
> -  else
> -    BlockVarLayout = llvm::Constant::getNullValue(PtrToInt8Ty);
> -  
> -  QualType ParmTy = getContext().getBlockParmType(
> -                                        SynthesizeCopyDisposeHelpers,
> -                                        BlockLayout);
> -
> -  // FIXME: This leaks
> -  ImplicitParamDecl *SelfDecl =
> -    ImplicitParamDecl::Create(getContext(), const_cast<BlockDecl*>(BD),
> -                              SourceLocation(), II,
> -                              ParmTy);
> -

With this change type of SelfDecl is lost. Earlier clang used to emit

0x000001a8:         TAG_formal_parameter [14]
                     AT_name( ".block_descriptor" )
                     AT_decl_file( "/private/tmp/blocks.c" )
                     AT_decl_line( 28 )
                     AT_type( {0x000005b0} ( __block_literal_1* ) )
                     AT_artificial( 0x01 )
                     AT_location( fbreg -16 )

where as now it emits

0x0000036d:         TAG_formal_parameter [13]
                     AT_name( ".block_descriptor" )
                     AT_decl_file( "/private/tmp/blocks.c" )
                     AT_decl_line( 64 )
                     AT_type( {0x0000005e} ( * ) )
                     AT_artificial( 0x01 )
                     AT_location( fbreg -16 )

I see your comments above that says, cast argument pointer later, but debug info is left out of loop in that case.
-
Devang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110221/0581083a/attachment.html>


More information about the cfe-commits mailing list