]> granicus.if.org Git - clang/commitdiff
Add CFG support for @synchronized. This fixes <rdar://problem/6848820>.
authorTed Kremenek <kremenek@apple.com>
Sat, 2 May 2009 01:49:13 +0000 (01:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 2 May 2009 01:49:13 +0000 (01:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70620 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/CFG.cpp
test/Analysis/NSString.m

index e601d4ff69eb4bbc0078cabe21389e22f8145053..f5b604554d895d7fb931744c25f7ca6c907cc518 100644 (file)
@@ -140,9 +140,7 @@ public:
   // a 'return'.
   CFGBlock* VisitObjCAtThrowStmt(ObjCAtThrowStmt* S);
 
-  CFGBlock* VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt* S){
-    return NYS();
-  }
+  CFGBlock* VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt* S);
   
   // Blocks.
   CFGBlock* VisitBlockExpr(BlockExpr* E) { return NYS(); }
@@ -935,6 +933,16 @@ CFGBlock* CFGBuilder::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
   return addStmt(S->getCollection());
 }    
   
+CFGBlock* CFGBuilder::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt* S) {
+  // FIXME: Add locking 'primitives' to CFG for @synchronized.
+  
+  // Inline the body.
+  Visit(S->getSynchBody());
+  
+  // Inline the sync expression.
+  return Visit(S->getSynchExpr());
+}
+  
 CFGBlock* CFGBuilder::VisitObjCAtTryStmt(ObjCAtTryStmt* S) {
   return NYS();
 }
index 160c64c21fc9ca2d44d2f4fe40f9ba95fa70b77c..2f6d5912cf8a7da882a85f7ea738e09a98f13563 100644 (file)
@@ -271,3 +271,11 @@ typedef NSString* WonkyTypedef;
 void test_isTrackedObjectType(void) {
   NSString *str = [TestIsTracked newString]; // expected-warning{{Potential leak}}
 }
+
+// Test @synchronized
+void test_synchronized(id x) {
+  @synchronized(x) {
+    NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain]; // expected-warning {{leak}}
+  }
+}
+