From 4cc5df700ecd183433b907a61d2d67a18b57bec0 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 5 May 2011 17:18:12 +0000 Subject: [PATCH] When instantiating a block expression, the instantiated blockScopeInfo's CapturesCXXThis field need get set as well. // rdar://9362021. John M. please review. llvm-svn: 130930 --- clang/lib/Sema/TreeTransform.h | 7 ++-- .../CodeGenObjCXX/block-in-template-inst.mm | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenObjCXX/block-in-template-inst.mm diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 2a71e14265a8..4bb184171648 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/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/clang/test/CodeGenObjCXX/block-in-template-inst.mm b/clang/test/CodeGenObjCXX/block-in-template-inst.mm new file mode 100644 index 000000000000..862488ddb7e2 --- /dev/null +++ b/clang/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(); }(); +}