add a new Sema::CurFunctionNeedsScopeChecking bool that is used to avoid 
calling into the jump checker when a function or method is known to contain
no VLAs or @try blocks.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69509 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 887c86c..7ed0e2d 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1564,11 +1564,13 @@
       InvalidDecl = true;
   }
 
-  if (S->getFnParent() == 0) {
-    QualType T = NewTD->getUnderlyingType();
-    // C99 6.7.7p2: If a typedef name specifies a variably modified type
-    // then it shall have block scope.
-    if (T->isVariablyModifiedType()) {
+  // C99 6.7.7p2: If a typedef name specifies a variably modified type
+  // then it shall have block scope.
+  QualType T = NewTD->getUnderlyingType();
+  if (T->isVariablyModifiedType()) {
+    CurFunctionNeedsScopeChecking = true;
+  
+    if (S->getFnParent() == 0) {
       bool SizeIsNegative;
       QualType FixedTy =
           TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative);
@@ -1810,9 +1812,12 @@
       && !NewVD->hasAttr<BlocksAttr>())
     Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
 
-  bool isIllegalVLA = T->isVariableArrayType() && NewVD->hasGlobalStorage();
-  bool isIllegalVM = T->isVariablyModifiedType() && NewVD->hasLinkage();
-  if (isIllegalVLA || isIllegalVM) {
+  bool isVM = T->isVariablyModifiedType();
+  if (isVM || NewVD->hasAttr<CleanupAttr>())
+    CurFunctionNeedsScopeChecking = true;
+  
+  if ((isVM && NewVD->hasLinkage()) ||
+      (T->isVariableArrayType() && NewVD->hasGlobalStorage())) {
     bool SizeIsNegative;
     QualType FixedTy =
         TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative);
@@ -2822,6 +2827,8 @@
 Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
   FunctionDecl *FD = cast<FunctionDecl>(D.getAs<Decl>());
 
+  CurFunctionNeedsScopeChecking = false;
+  
   // See if this is a redefinition.
   const FunctionDecl *Definition;
   if (FD->getBody(Context, Definition)) {
@@ -2964,7 +2971,8 @@
   if (!Body) return D;
 
   // Verify that that gotos and switch cases don't jump into scopes illegally.
-  DiagnoseInvalidJumps(Body);
+  if (CurFunctionNeedsScopeChecking)
+    DiagnoseInvalidJumps(Body);
 
   return D;
 }