From 5469f29aa92e30ab48d350ad9bd43b8fc9edd445 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Fri, 13 Mar 2009 23:34:28 +0000 Subject: Do up codegen for function static data and externs in functions in block literals. llvm-svn: 66984 --- clang/lib/CodeGen/CGBlocks.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen/CGBlocks.cpp') diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index a876938c02e..fcda90794e9 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -155,7 +155,8 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { uint64_t subBlockSize, subBlockAlign; llvm::SmallVector subBlockDeclRefDecls; llvm::Function *Fn - = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, subBlockSize, + = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, LocalDeclMap, + subBlockSize, subBlockAlign, subBlockDeclRefDecls, BlockHasCopyDispose); @@ -558,8 +559,10 @@ BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) { uint64_t subBlockSize, subBlockAlign; llvm::SmallVector subBlockDeclRefDecls; bool subBlockHasCopyDispose = false; + llvm::DenseMap LocalDeclMap; llvm::Function *Fn - = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, subBlockSize, + = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, LocalDeclMap, + subBlockSize, subBlockAlign, subBlockDeclRefDecls, subBlockHasCopyDispose); @@ -602,10 +605,24 @@ llvm::Value *CodeGenFunction::LoadBlockStruct() { llvm::Function * CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr, const BlockInfo& Info, + llvm::DenseMap ldm, uint64_t &Size, uint64_t &Align, llvm::SmallVector &subBlockDeclRefDecls, bool &subBlockHasCopyDispose) { + // Arrange for local static and local extern declarations to appear + // to be local to this function as well, as they are directly referenced + // in a block. + for (llvm::DenseMap::iterator i = ldm.begin(); + i != ldm.end(); + ++i) { + const VarDecl *VD = dyn_cast(i->first); + + if (VD->getStorageClass() == VarDecl::Static + || VD->getStorageClass() == VarDecl::Extern) + LocalDeclMap[VD] = i->second; + } + const FunctionProtoType *FTy = cast(BExpr->getFunctionType()); -- cgit v1.2.3