[cfe-commits] r69509 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaStmt.cpp test/Sema/scope-check.c

Chris Lattner sabre at nondot.org
Sat Apr 18 22:21:20 PDT 2009


Author: lattner
Date: Sun Apr 19 00:21:20 2009
New Revision: 69509

URL: http://llvm.org/viewvc/llvm-project?rev=69509&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/scope-check.c

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=69509&r1=69508&r2=69509&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Apr 19 00:21:20 2009
@@ -153,6 +153,12 @@
   /// handle the case when they are in a block.
   llvm::SmallVector<SwitchStmt*, 8> FunctionSwitchStack;
   
+  /// CurFunctionNeedsScopeChecking - This is set to true when a function or
+  /// ObjC method body contains a VLA or an ObjC try block, which introduce
+  /// scopes that need to be checked for goto conditions.  If a function does
+  /// not contain this, then it need not have the jump checker run on it.
+  bool CurFunctionNeedsScopeChecking;
+  
   /// ExtVectorDecls - This is a list all the extended vector types. This allows
   /// us to associate a raw vector type with one of the ext_vector type names.
   /// This is only necessary for issuing pretty diagnostics.

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=69509&r1=69508&r2=69509&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 19 00:21:20 2009
@@ -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;
 }

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=69509&r1=69508&r2=69509&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Apr 19 00:21:20 2009
@@ -28,6 +28,8 @@
   if (!MDecl)
     return;
 
+  CurFunctionNeedsScopeChecking = false;
+
   // Allow the rest of sema to find private method decl implementations.
   if (MDecl->isInstanceMethod())
     AddInstanceMethodToGlobalPool(MDecl);

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=69509&r1=69508&r2=69509&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Apr 19 00:21:20 2009
@@ -1056,6 +1056,7 @@
 Action::OwningStmtResult
 Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc,
                          StmtArg Try, StmtArg Catch, StmtArg Finally) {
+  CurFunctionNeedsScopeChecking = true;
   return Owned(new (Context) ObjCAtTryStmt(AtLoc,
                                         static_cast<Stmt*>(Try.release()),
                                         static_cast<Stmt*>(Catch.release()),

Modified: cfe/trunk/test/Sema/scope-check.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/scope-check.c?rev=69509&r1=69508&r2=69509&view=diff

==============================================================================
--- cfe/trunk/test/Sema/scope-check.c (original)
+++ cfe/trunk/test/Sema/scope-check.c Sun Apr 19 00:21:20 2009
@@ -164,8 +164,9 @@
   return;
 }
 
+
 // TODO: When and if gotos are allowed in blocks, this should work.
-void test11(int n) {
+void test13(int n) {
   void *P = ^{
     goto L1;  // expected-error {{goto not allowed in block literal}}
   L1:
@@ -180,11 +181,3 @@
   };
 }
 
-
-
-#if 0
-// in Sema::CheckVariableDeclaration
-// FIXME: This won't give the correct result for
-// int a[10][n];    
-#endif
-





More information about the cfe-commits mailing list