From ebd5a2dc1a3743fed9157379d89e5eb26293c9d6 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 11 May 2009 18:30:24 +0000 Subject: [PATCH] Fix regression reported in . The analyzer should extend the lifetime of an object stored to a container. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71452 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFRefCount.cpp | 4 ++-- test/Analysis/retain-release.m | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index ebc4dcc6ff..29a28c1a19 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -752,8 +752,8 @@ public: : RetEffect::MakeOwned(RetEffect::ObjC, true)), DefaultSummary(AF.GetEmptyMap() /* per-argument effects (none) */, RetEffect::MakeNoRet() /* return effect */, - DoNothing /* receiver effect */, - MayEscape /* default argument effect */), + MayEscape, /* default argument effect */ + DoNothing /* receiver effect */), StopSummary(0) { InitializeClassMethodSummaries(); diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 1c0bb964b2..f4c2d25054 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -476,7 +476,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { // // One build of the analyzer accidentally stopped tracking the allocated // object after the 'retain'. -//===----------------------------------------------------------------------===// +//===----------------------------------------------------------------------===// @interface rdar_6833332 : NSObject { NSWindow *window; @@ -503,7 +503,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { // clang checker fails to catch use-after-release //===----------------------------------------------------------------------===// -int rdar_6257780() { +int rdar_6257780_Case1() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSArray *array = [NSArray array]; [array release]; // expected-warning{{Incorrect decrement of the reference count of an object is not owned at this point by the caller}} @@ -511,6 +511,23 @@ int rdar_6257780() { return 0; } +//===----------------------------------------------------------------------===// +// Checker should understand new/setObject:/release constructs +//===----------------------------------------------------------------------===// + +void rdar_6866843() { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init]; + NSArray* array = [[NSArray alloc] init]; + [dictionary setObject:array forKey:@"key"]; + [array release]; + // Using 'array' here should be fine + NSLog(@"array = %@\n", array); // no-warning + // Now the array is released + [dictionary release]; + [pool drain]; +} + //===----------------------------------------------------------------------===// // Tests of ownership attributes. //===----------------------------------------------------------------------===// -- 2.40.0