From b3b0b3624e462c2940f65b86e773bfc300005203 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 2 May 2009 01:49:13 +0000 Subject: [PATCH] Add CFG support for @synchronized. This fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70620 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/CFG.cpp | 14 +++++++++++--- test/Analysis/NSString.m | 8 ++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp index e601d4ff69..f5b604554d 100644 --- a/lib/AST/CFG.cpp +++ b/lib/AST/CFG.cpp @@ -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(); } diff --git a/test/Analysis/NSString.m b/test/Analysis/NSString.m index 160c64c21f..2f6d5912cf 100644 --- a/test/Analysis/NSString.m +++ b/test/Analysis/NSString.m @@ -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}} + } +} + -- 2.40.0