[cfe-commits] r69667 - in /cfe/trunk: include/clang/AST/Stmt.h include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/JumpDiagnostics.cpp lib/Sema/SemaStmt.cpp test/SemaObjC/scope-check.m

Chris Lattner sabre at nondot.org
Mon Apr 20 23:01:01 PDT 2009


Author: lattner
Date: Tue Apr 21 01:01:00 2009
New Revision: 69667

URL: http://llvm.org/viewvc/llvm-project?rev=69667&view=rev
Log:
add support for goto checking and @synchronized blocks,
rdar://6810106

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/JumpDiagnostics.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaObjC/scope-check.m

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=69667&r1=69666&r2=69667&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Apr 21 01:01:00 2009
@@ -1410,10 +1410,12 @@
   ObjCAtSynchronizedStmt(SourceLocation atSynchronizedLoc, Stmt *synchExpr,
                          Stmt *synchBody)
   : Stmt(ObjCAtSynchronizedStmtClass) {
-      SubStmts[SYNC_EXPR] = synchExpr;
-      SubStmts[SYNC_BODY] = synchBody;
-      AtSynchronizedLoc = atSynchronizedLoc;
-    }
+    SubStmts[SYNC_EXPR] = synchExpr;
+    SubStmts[SYNC_BODY] = synchBody;
+    AtSynchronizedLoc = atSynchronizedLoc;
+  }
+  
+  SourceLocation getAtSynchronizedLoc() const { return AtSynchronizedLoc; }
   
   const CompoundStmt *getSynchBody() const {
     return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]);

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69667&r1=69666&r2=69667&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 21 01:01:00 2009
@@ -868,6 +868,8 @@
   "jump bypasses initialization of @catch block">;
 def note_protected_by_objc_finally : Note<
   "jump bypasses initialization of @finally block">;
+def note_protected_by_objc_synchronized : Note<
+  "jump bypasses initialization of @synchronized block">;
 
 def err_func_returning_array_function : Error<
   "function cannot return array or function type %0">;

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

==============================================================================
--- cfe/trunk/lib/Sema/JumpDiagnostics.cpp (original)
+++ cfe/trunk/lib/Sema/JumpDiagnostics.cpp Tue Apr 21 01:01:00 2009
@@ -168,6 +168,22 @@
       continue;
     }
     
+    // Disallow jumps into the protected statement of an @synchronized, but
+    // allow jumps into the object expression it protects.
+    if (ObjCAtSynchronizedStmt *AS = dyn_cast<ObjCAtSynchronizedStmt>(SubStmt)){
+      // Recursively walk the AST for the @synchronized object expr, it is
+      // evaluated in the normal scope.
+      BuildScopeInformation(AS->getSynchExpr(), ParentScope);
+      
+      // Recursively walk the AST for the @synchronized part, protected by a new
+      // scope.
+      Scopes.push_back(GotoScope(ParentScope,
+                                 diag::note_protected_by_objc_synchronized,
+                                 AS->getAtSynchronizedLoc()));
+      BuildScopeInformation(AS->getSynchBody(), Scopes.size()-1);
+      continue;
+    }
+    
     // Recursively walk the AST.
     BuildScopeInformation(SubStmt, ParentScope);
   }

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Apr 21 01:01:00 2009
@@ -1090,6 +1090,8 @@
 Action::OwningStmtResult
 Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr,
                                   StmtArg SynchBody) {
+  CurFunctionNeedsScopeChecking = true;
+
   return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc,
                      static_cast<Stmt*>(SynchExpr.release()),
                      static_cast<Stmt*>(SynchBody.release())));

Modified: cfe/trunk/test/SemaObjC/scope-check.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/scope-check.m?rev=69667&r1=69666&r2=69667&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/scope-check.m (original)
+++ cfe/trunk/test/SemaObjC/scope-check.m Tue Apr 21 01:01:00 2009
@@ -44,6 +44,16 @@
   } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
   L8: ;
   }
+  
+  // rdar://6810106
+  id X;
+  goto L9;    // expected-error{{illegal goto into protected scope}}
+  goto L10;   // ok
+  @synchronized    // expected-note {{jump bypasses initialization of @synchronized block}}
+  ( ({ L10: ; X; })) {
+  L9:
+    ;
+  }
 }
 
 void test2(int a) {





More information about the cfe-commits mailing list