From: Fariborz Jahanian Date: Thu, 5 May 2011 17:18:12 +0000 (+0000) Subject: When instantiating a block expression, the instantiated X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff365592d1878c0e454f288e30613664a72cff4c;p=clang When instantiating a block expression, the instantiated blockScopeInfo's CapturesCXXThis field need get set as well. // rdar://9362021. John M. please review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130930 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 2a71e14265..4bb1841716 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -7700,6 +7700,11 @@ TreeTransform::TransformBlockExpr(BlockExpr *E) { BlockScopeInfo *blockScope = SemaRef.getCurBlock(); blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); + // We built a new blockScopeInfo in call to ActOnBlockStart + // in above, CapturesCXXThis need be set here from the block + // expression. + blockScope->CapturesCXXThis = oldBlock->capturesCXXThis(); + llvm::SmallVector params; llvm::SmallVector paramTypes; @@ -7760,8 +7765,6 @@ TreeTransform::TransformBlockExpr(BlockExpr *E) { // In builds with assertions, make sure that we captured everything we // captured before. - if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); - for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), e = oldBlock->capture_end(); i != e; ++i) { VarDecl *oldCapture = i->getVariable(); diff --git a/test/CodeGenObjCXX/block-in-template-inst.mm b/test/CodeGenObjCXX/block-in-template-inst.mm new file mode 100644 index 0000000000..862488ddb7 --- /dev/null +++ b/test/CodeGenObjCXX/block-in-template-inst.mm @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -emit-llvm-only -fblocks -o - -triple x86_64-apple-darwin10 %s +// rdar://9362021 + +@class DYFuture; +@interface NSCache +- (void)setObject:(id)obj forKey:(id)key; +@end + +template +class ResourceManager +{ +public: + ~ResourceManager(); + DYFuture* XXX(); + NSCache* _spDeviceCache; +}; + +template +DYFuture* ResourceManager::XXX() +{ + ^ { + [_spDeviceCache setObject:0 forKey:0]; + }(); + + return 0; +} + +struct AnalyzerBaseObjectTypes { }; + +void FUNC() +{ + ResourceManager *rm; + ^(void) { rm->XXX(); }(); +}