[cfe-commits] r151372 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/TreeTransform.h test/CodeGenCXX/blocks.cpp

Douglas Gregor dgregor at apple.com
Fri Feb 24 09:41:39 PST 2012


Author: dgregor
Date: Fri Feb 24 11:41:38 2012
New Revision: 151372

URL: http://llvm.org/viewvc/llvm-project?rev=151372&view=rev
Log:
Two minor, related fixes for template instantiation with blocks:
  - Make sure that the block expression is instantiation-dependent if the
    block is in a dependent context
  - Make sure that the C++ 'this' expression gets captured even if we
  don't rebuild the AST node during template instantiation. This would
  also have manifested as a bug for lambdas.

Fixes <rdar://problem/10832617>.


Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CodeGenCXX/blocks.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=151372&r1=151371&r2=151372&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Feb 24 11:41:38 2012
@@ -4220,9 +4220,8 @@
 public:
   BlockExpr(BlockDecl *BD, QualType ty)
     : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
-           ty->isDependentType(), false,
-           // FIXME: Check for instantiate-dependence in the statement?
-           ty->isInstantiationDependentType(),
+           ty->isDependentType(), ty->isDependentType(),
+           ty->isInstantiationDependentType() || BD->isDependentContext(),
            false),
       TheBlock(BD) {}
 

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=151372&r1=151371&r2=151372&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Feb 24 11:41:38 2012
@@ -7038,9 +7038,12 @@
     T = getSema().Context.getPointerType(
       getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
 
-  if (!getDerived().AlwaysRebuild() && T == E->getType())
+  if (!getDerived().AlwaysRebuild() && T == E->getType()) {
+    // Make sure that we capture 'this'.
+    getSema().CheckCXXThisCapture(E->getLocStart());
     return SemaRef.Owned(E);
-
+  }
+  
   return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
 }
 
@@ -8539,6 +8542,7 @@
                                                  oldCapture));
       assert(blockScope->CaptureMap.count(newCapture));
     }
+    assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
   }
 #endif
 

Modified: cfe/trunk/test/CodeGenCXX/blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/blocks.cpp?rev=151372&r1=151371&r2=151372&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/blocks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/blocks.cpp Fri Feb 24 11:41:38 2012
@@ -211,3 +211,18 @@
     return ^{ return *p; }();
   }
 }
+
+namespace test8 {
+  // <rdar://problem/10832617>: failure to capture this after skipping rebuild
+  // of the 'this' pointer.
+  struct X {
+    int x;
+
+    template<typename T>
+    int foo() {
+      return ^ { return x; }();
+    }
+  };
+
+  template int X::foo<int>();
+}





More information about the cfe-commits mailing list