run the jump checker on blocks, even though they don't have gotos,
they do allow switches.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69510 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index e8742e8..e4af8a5 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -107,6 +107,10 @@
   /// block.
   llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
   
+  /// SavedFunctionNeedsScopeChecking - This is the value of
+  /// CurFunctionNeedsScopeChecking at the point when the block started.
+  bool SavedFunctionNeedsScopeChecking;
+  
   /// PrevBlockInfo - If this is nested inside another block, this points
   /// to the outer block.
   BlockSemaInfo *PrevBlockInfo;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index d8e57f9..3eeadce 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4661,6 +4661,8 @@
   BSI->ReturnType = 0;
   BSI->TheScope = BlockScope;
   BSI->hasBlockDeclRefExprs = false;
+  BSI->SavedFunctionNeedsScopeChecking = CurFunctionNeedsScopeChecking;
+  CurFunctionNeedsScopeChecking = false;
 
   BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc);
   PushDeclContext(BlockScope, BSI->TheDecl);
@@ -4746,11 +4748,12 @@
   // Ensure that CurBlock is deleted.
   llvm::OwningPtr<BlockSemaInfo> CC(CurBlock);
 
+  CurFunctionNeedsScopeChecking = CurBlock->SavedFunctionNeedsScopeChecking;
+
   // 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
@@ -4793,6 +4796,11 @@
 
   BlockTy = Context.getBlockPointerType(BlockTy);
 
+  // If needed, diagnose invalid gotos and switches in the block.
+  if (CurFunctionNeedsScopeChecking)
+    DiagnoseInvalidJumps(static_cast<CompoundStmt*>(body.get()));
+  CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking;
+  
   BSI->TheDecl->setBody(static_cast<CompoundStmt*>(body.release()));
   return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy,
                                        BSI->hasBlockDeclRefExprs));