Properly restore ActiveScope when we exit parsing of a block. This
should fix the largest problem in <rdar://problem/6669847>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66741 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 58cd390..2ce7499 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4591,11 +4591,18 @@
   // Ensure that CurBlock is deleted.
   llvm::OwningPtr<BlockSemaInfo> CC(CurBlock);
 
+  // Before popping CurBlock, set ActiveScope to this scope's function
+  // or block parent.
+  ActiveScope = CurBlock->TheScope->getParent();
+  while (ActiveScope &&
+         ((ActiveScope->getFlags() & (Scope::FnScope | Scope::BlockScope)) == 0))
+    ActiveScope = ActiveScope->getParent();
+
   // Pop off CurBlock, handle nested blocks.
   CurBlock = CurBlock->PrevBlockInfo;
 
   // FIXME: Delete the ParmVarDecl objects as well???
-
+  
 }
 
 /// ActOnBlockStmtExpr - This is called when the body of a block statement
@@ -4608,8 +4615,12 @@
 
   PopDeclContext();
 
-  // Before poping CurBlock, set ActiveScope to this scopes parent.
+  // Before popping CurBlock, set ActiveScope to this scope's function
+  // or block parent.
   ActiveScope = CurBlock->TheScope->getParent();
+  while (ActiveScope &&
+         ((ActiveScope->getFlags() & (Scope::FnScope | Scope::BlockScope)) == 0))
+    ActiveScope = ActiveScope->getParent();
   
   // Pop off CurBlock, handle nested blocks.
   CurBlock = CurBlock->PrevBlockInfo;