[cfe-commits] r154646 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/goto.cpp test/SemaObjC/arc-jump-block.m

John McCall rjmccall at apple.com
Thu Apr 12 18:08:17 PDT 2012


Author: rjmccall
Date: Thu Apr 12 20:08:17 2012
New Revision: 154646

URL: http://llvm.org/viewvc/llvm-project?rev=154646&view=rev
Log:
When we're flagging a protected scope to prevent jumps into the
shadow of a block expression with non-trivial destructed cleanups,
we should flag that in the enclosing function, not in the block
that we're about to pop.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/goto.cpp
    cfe/trunk/test/SemaObjC/arc-jump-block.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=154646&r1=154645&r2=154646&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Apr 12 20:08:17 2012
@@ -9111,15 +9111,6 @@
 
   BSI->TheDecl->setBody(cast<CompoundStmt>(Body));
 
-  for (BlockDecl::capture_const_iterator ci = BSI->TheDecl->capture_begin(),
-       ce = BSI->TheDecl->capture_end(); ci != ce; ++ci) {
-    const VarDecl *variable = ci->getVariable();
-    QualType T = variable->getType();
-    QualType::DestructionKind destructKind = T.isDestructedType();
-    if (destructKind != QualType::DK_none)
-      getCurFunction()->setHasBranchProtectedScope();
-  }
-
   computeNRVO(Body, getCurBlock());
   
   BlockExpr *Result = new (Context) BlockExpr(BSI->TheDecl, BlockTy);
@@ -9127,10 +9118,23 @@
   PopFunctionScopeInfo(&WP, Result->getBlockDecl(), Result);
 
   // If the block isn't obviously global, i.e. it captures anything at
-  // all, mark this full-expression as needing a cleanup.
+  // all, then we need to do a few things in the surrounding context:
   if (Result->getBlockDecl()->hasCaptures()) {
+    // First, this expression has a new cleanup object.
     ExprCleanupObjects.push_back(Result->getBlockDecl());
     ExprNeedsCleanups = true;
+
+    // It also gets a branch-protected scope if any of the captured
+    // variables needs destruction.
+    for (BlockDecl::capture_const_iterator
+           ci = Result->getBlockDecl()->capture_begin(),
+           ce = Result->getBlockDecl()->capture_end(); ci != ce; ++ci) {
+      const VarDecl *var = ci->getVariable();
+      if (var->getType().isDestructedType() != QualType::DK_none) {
+        getCurFunction()->setHasBranchProtectedScope();
+        break;
+      }
+    }
   }
 
   return Owned(Result);

Modified: cfe/trunk/test/SemaCXX/goto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/goto.cpp?rev=154646&r1=154645&r2=154646&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/goto.cpp (original)
+++ cfe/trunk/test/SemaCXX/goto.cpp Thu Apr 12 20:08:17 2012
@@ -115,3 +115,13 @@
     ;
   }
 }
+
+namespace test12 {
+  struct A { A(); A(const A&); ~A(); };
+  void test(A a) { // expected-note {{jump enters lifetime of block}} FIXME: wierd location
+    goto lbl; // expected-error {{goto into protected scope}}
+    (void) ^{ (void) a; };
+  lbl:
+    return;
+  }
+}

Modified: cfe/trunk/test/SemaObjC/arc-jump-block.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-jump-block.m?rev=154646&r1=154645&r2=154646&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-jump-block.m (original)
+++ cfe/trunk/test/SemaObjC/arc-jump-block.m Thu Apr 12 20:08:17 2012
@@ -82,3 +82,16 @@
 - (void)pageLeft {}
 - (void)pageRight {}
 @end
+
+// Test 2.  rdar://problem/11150919
+int test2(id obj, int state) { // expected-note {{jump enters lifetime of block}} FIXME: wierd location
+  switch (state) {
+  case 0:
+    (void) ^{ (void) obj; };
+    return 0;
+
+  default: // expected-error {{switch case is in protected scope}}
+    return 1;
+  }
+}
+





More information about the cfe-commits mailing list