From: Ted Kremenek Date: Sat, 9 May 2009 01:50:57 +0000 (+0000) Subject: It lives! The retain/release checker now tracks objects that are sent X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b62ec90d498eb512f2e231547b05d485814a146;p=clang It lives! The retain/release checker now tracks objects that are sent 'autorelease'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71307 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 0e4d660f35..a9ef5cf3fc 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -175,8 +175,7 @@ public: ExplodedNode *MakeNode(const GRState *state, ExplodedNode *Pred) { if (SNB) - return SNB->generateNode(PostStmt(S, tag), state, - Pred); + return SNB->generateNode(PostStmt(S, tag), state, Pred); assert(ENB); return ENB->generateNode(state, Pred); @@ -3111,6 +3110,7 @@ GRStateRef CFRefCount::Update(GRStateRef state, SymbolRef sym, // Update the autorelease counts. state = SendAutorelease(state, ARCountFactory, sym); V = V.autorelease(); + break; case StopTracking: return state.remove(sym); @@ -3245,7 +3245,7 @@ CFRefCount::ProcessLeaks(GRStateRef state, return Pred; // Generate an intermediate node representing the leak point. - ExplodedNode *N = Builder.MakeNode(state, Pred); + ExplodedNode *N = Builder.MakeNode(state, Pred); if (N) { for (llvm::SmallVectorImpl::iterator @@ -3354,7 +3354,8 @@ void CFRefCount::ProcessNonLeakError(ExplodedNodeSet& Dst, Builder.BuildSinks = true; GRExprEngine::NodeTy* N = Builder.MakeNode(Dst, NodeExpr, Pred, St); - if (!N) return; + if (!N) + return; CFRefBug *BT = 0; diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index de86dbc289..49fd98b3b7 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -284,10 +284,32 @@ void f12() { } void f13_autorelease() { - CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning [(id) A autorelease]; // no-warning } +void f13_autorelease_b() { + CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + [(id) A autorelease]; + [(id) A autorelease]; // expected-warning{{Object will be sent more -release messages from its containing autorelease pools than it has retain counts}} +} + +CFMutableArrayRef f13_autorelease_c() { + CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + [(id) A autorelease]; + [(id) A autorelease]; + return A; // expected-warning{{Object will be sent more -release messages from its containing autorelease pools than it has retain counts}} +} + +CFMutableArrayRef f13_autorelease_d() { + CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + [(id) A autorelease]; + [(id) A autorelease]; + CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{Object will be sent more -release messages}} + CFRelease(B); // no-warning +} + + // This case exercises the logic where the leak site is the same as the allocation site. void f14_leakimmediately() { CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}}