]> granicus.if.org Git - clang/commitdiff
Add test cases for PR 3820.
authorTed Kremenek <kremenek@apple.com>
Thu, 19 Mar 2009 19:50:58 +0000 (19:50 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 19 Mar 2009 19:50:58 +0000 (19:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67327 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/retain-release.m

index c6a05c0031ca9bda5473e95ac78b0c6528a11963..50a809c36a95d569ddaaff90e499e25882fc8151 100644 (file)
@@ -69,6 +69,8 @@ typedef struct _NSZone NSZone;
 - (const char *)UTF8String;
 - (id)initWithUTF8String:(const char *)nullTerminatedCString;
 + (id)stringWithUTF8String:(const char *)nullTerminatedCString;
+- (id)init;
+- (void)dealloc;
 @end   extern NSString * const NSCurrentLocaleDidChangeNotification ;
 @protocol NSLocking  - (void)lock;
 @end  extern NSString * const NSUndoManagerCheckpointNotification;
@@ -334,3 +336,27 @@ static void rdar_6659160(char *inkind, char *inname)
 }
 @end
 
+// PR 3820 - Reason about calls to -dealloc
+void pr3820_DeallocInsteadOfRelease(void)
+{
+  id foo = [[NSString alloc] init]; // no-warning
+  [foo dealloc];
+  // foo is not leaked, since it has been deallocated.
+}
+
+void pr3820_ReleaseAfterDealloc(void)
+{
+  id foo = [[NSString alloc] init];
+  [foo dealloc];
+  [foo release];  // expected-warning{{used after it is release}}
+  // NSInternalInconsistencyException: message sent to deallocated object
+}
+
+void pr3820_DeallocAfterRelease(void)
+{
+  NSLog(@"\n\n[%s]", __FUNCTION__);
+  id foo = [[NSString alloc] init];
+  [foo release];
+  [foo dealloc]; // expected-warning{{used after it is released}}
+  // message sent to released object
+}