]> granicus.if.org Git - clang/commitdiff
[analyzer] Allow pointers to escape through selector callbacks.
authorAnna Zaks <ganna@apple.com>
Wed, 9 May 2012 17:23:11 +0000 (17:23 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 9 May 2012 17:23:11 +0000 (17:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156481 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/ObjCMessage.cpp
test/Analysis/retain-release.m

index 994e6fbe622c589c654aaac72bdef1abc65e7671..4dc000f7bdf3cafe14308e76028364168e16e56b 100644 (file)
@@ -94,7 +94,9 @@ bool CallOrObjCMessage::isCallbackArg(unsigned Idx, const Type *T) const {
     return false;
     
   // If a parameter is a block or a callback, assume it can modify pointer.
-  if (T->isBlockPointerType() || T->isFunctionPointerType())
+  if (T->isBlockPointerType() ||
+      T->isFunctionPointerType() ||
+      T->isObjCSelType())
     return true;
 
   // Check if a callback is passed inside a struct (for both, struct passed by
index 5422b8bb0fac58d09f3a5c26c8f63b295e0f5a16..a27fdac27fb1ca26c9ea53e439c5b91ed5adde52 100644 (file)
@@ -222,8 +222,10 @@ typedef struct CGLayer *CGLayerRef;
 @end @protocol NSValidatedUserInterfaceItem - (SEL)action;
 @end   @protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem;
 @end  @class NSDate, NSDictionary, NSError, NSException, NSNotification;
+@class NSTextField, NSPanel, NSArray, NSWindow, NSImage, NSButton, NSError;
 @interface NSApplication : NSResponder <NSUserInterfaceValidations> {
 }
+- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo;
 @end   enum {
 NSTerminateCancel = 0,         NSTerminateNow = 1,         NSTerminateLater = 2 };
 typedef NSUInteger NSApplicationTerminateReply;
@@ -231,7 +233,7 @@ typedef NSUInteger NSApplicationTerminateReply;
 @end  @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView, NSTextView;
 @interface NSCell : NSObject <NSCopying, NSCoding> {
 }
-@end @class NSTextField, NSPanel, NSArray, NSWindow, NSImage, NSButton, NSError;
+@end 
 typedef struct {
 }
 CVTimeStamp;
@@ -1712,6 +1714,32 @@ int IOClose(void *context);
 }
 @end
 
+// Object escapes through a selector callback: radar://11398514
+extern id NSApp;
+@interface MySheetController
+- (id<SInS>)inputS;
+- (void)showDoSomethingSheetAction:(id)action;
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
+@end
+
+@implementation MySheetController
+- (id<SInS>)inputS {
+    return 0;
+}
+- (void)showDoSomethingSheetAction:(id)action {
+  id<SInS> inputS = [[self inputS] retain]; 
+  [NSApp beginSheet:0
+         modalForWindow:0
+         modalDelegate:0
+         didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+         contextInfo:(void *)inputS]; // no - warning
+}
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
+   
+      id contextObject = (id)contextInfo;
+      [contextObject release];
+}
+@end
 //===----------------------------------------------------------------------===//
 // Test returning allocated memory in a struct.
 //