[cfe-commits] r67327 - /cfe/trunk/test/Analysis/retain-release.m

Ted Kremenek kremenek at apple.com
Thu Mar 19 12:51:06 PDT 2009


Author: kremenek
Date: Thu Mar 19 14:50:58 2009
New Revision: 67327

URL: http://llvm.org/viewvc/llvm-project?rev=67327&view=rev
Log:
Add test cases for PR 3820.

Modified:
    cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=67327&r1=67326&r2=67327&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Mar 19 14:50:58 2009
@@ -69,6 +69,8 @@
 - (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 @@
 }
 @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
+}





More information about the cfe-commits mailing list