]> granicus.if.org Git - clang/commitdiff
When instantiating a block expression, the instantiated
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 5 May 2011 17:18:12 +0000 (17:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 5 May 2011 17:18:12 +0000 (17:18 +0000)
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

lib/Sema/TreeTransform.h
test/CodeGenObjCXX/block-in-template-inst.mm [new file with mode: 0644]

index 2a71e14265a8c7ec481b097b3b8dba417bc75184..4bb1841716488b6bc71508bfe784790960840656 100644 (file)
@@ -7700,6 +7700,11 @@ TreeTransform<Derived>::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<ParmVarDecl*, 4> params;
   llvm::SmallVector<QualType, 4> paramTypes;
   
@@ -7760,8 +7765,6 @@ TreeTransform<Derived>::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 (file)
index 0000000..862488d
--- /dev/null
@@ -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 <typename T>
+class ResourceManager
+{
+public:
+ ~ResourceManager();
+ DYFuture* XXX();
+ NSCache* _spDeviceCache;
+};
+
+template <typename T>
+DYFuture* ResourceManager<T>::XXX()
+{
+ ^ {
+   [_spDeviceCache setObject:0 forKey:0];
+  }();
+
+ return 0;
+}
+
+struct AnalyzerBaseObjectTypes { };
+
+void FUNC()
+{
+    ResourceManager<AnalyzerBaseObjectTypes> *rm;
+    ^(void) { rm->XXX(); }();
+}