pr_2542_rdar_6793404.m revision 65d39251ff57b8e33cf6d3a7fcc6aa1c6f8cdc68
1// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental -analyzer-check-objc-mem -pedantic -analyzer-store=basic -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental -analyzer-check-objc-mem -pedantic -analyzer-store=region -verify %s
3
4// BEGIN delta-debugging reduced header stuff
5
6typedef signed char BOOL;
7typedef unsigned int NSUInteger;
8typedef struct _NSZone NSZone;
9@class NSCoder;
10@protocol NSObject
11- (BOOL)isEqual:(id)object;
12- (id)retain;
13- (oneway void)release;
14@end
15@protocol NSCopying
16- (id)copyWithZone:(NSZone *)zone;
17@end
18@protocol NSCoding
19- (void)encodeWithCoder:(NSCoder *)aCoder;
20@end
21@interface NSObject <NSObject> {}
22- (id)init;
23+ (id)alloc;
24@end
25typedef double NSTimeInterval;
26enum { NSAnimationEaseInOut, NSAnimationEaseIn, NSAnimationEaseOut, NSAnimationLinear };
27typedef NSUInteger NSAnimationCurve;
28@interface NSAnimation : NSObject <NSCopying, NSCoding> {}
29- (id)initWithDuration:(NSTimeInterval)duration animationCurve:(NSAnimationCurve)animationCurve;
30- (void)startAnimation;
31- (void)setDelegate:(id)delegate;
32@end
33
34// END delta-debugging reduced header stuff
35
36// From NSAnimation Class Reference
37// -(void)startAnimation
38// The receiver retains itself and is then autoreleased at the end 
39// of the animation or when it receives stopAnimation.
40
41@interface MyClass { }
42- (void)animationDidEnd:(NSAnimation *)animation;
43@end
44
45@implementation MyClass
46- (void)f1 {  
47  // NOTE: The analyzer doesn't really handle this; it just stops tracking
48  // 'animation' when it is sent the message 'setDelegate:'.
49  NSAnimation *animation = [[NSAnimation alloc]   // no-warning
50                            initWithDuration:1.0 
51                            animationCurve:NSAnimationEaseInOut];
52  
53  [animation setDelegate:self];
54  [animation startAnimation]; 
55}
56
57- (void)f2 {
58  NSAnimation *animation = [[NSAnimation alloc]  // expected-warning{{leak}}
59                            initWithDuration:1.0 
60                            animationCurve:NSAnimationEaseInOut];
61
62  [animation startAnimation]; 
63}
64
65- (void)animationDidEnd:(NSAnimation *)animation {
66  [animation release];
67}
68@end
69