blob: 11276fa27e4d419dc4eca805bdfa051fe956fc5f [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=text -verify %s
George Karpenkov39165092018-06-12 19:07:41 +00002// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=plist-multi-file %s -o %t.plist
Mikhail Maltsevc704f4d2018-09-17 10:19:46 +00003// RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/undef-value-param.m.plist
Anna Zaks5d4ec362012-08-29 21:22:37 +00004
5typedef signed char BOOL;
6@protocol NSObject - (BOOL)isEqual:(id)object; @end
7@interface NSObject <NSObject> {}
8+(id)alloc;
9+(id)new;
10-(id)init;
11-(id)autorelease;
12-(id)copy;
13- (Class)class;
14-(id)retain;
15@end
16typedef const void * CFTypeRef;
17extern void CFRelease(CFTypeRef cf);
18
19@interface Cell : NSObject
20- (void)test;
21@end
22
23@interface SpecialString
24+ (id)alloc;
25- (oneway void)release;
26@end
27
28typedef SpecialString* SCDynamicStoreRef;
29static void CreateRef(SCDynamicStoreRef *storeRef, unsigned x);
Jordan Rosef7f32d52013-02-27 18:49:57 +000030static void CreateRefUndef(SCDynamicStoreRef *storeRef, unsigned x);
Anna Zaks5d4ec362012-08-29 21:22:37 +000031SCDynamicStoreRef anotherCreateRef(unsigned *err, unsigned x);
32
33@implementation Cell
34- (void) test {
Jordan Rosef7f32d52013-02-27 18:49:57 +000035 SCDynamicStoreRef storeRef = 0;
Anna Zaks5d4ec362012-08-29 21:22:37 +000036 CreateRef(&storeRef, 4);
37 //expected-note@-1{{Calling 'CreateRef'}}
38 //expected-note@-2{{Returning from 'CreateRef'}}
39 CFRelease(storeRef); //expected-warning {{Null pointer argument in call to CFRelease}}
40 //expected-note@-1{{Null pointer argument in call to CFRelease}}
41}
Jordan Rosef7f32d52013-02-27 18:49:57 +000042
43- (void)test2 {
44 SCDynamicStoreRef storeRef; // expected-note {{'storeRef' declared without an initial value}}
45 CreateRefUndef(&storeRef, 4);
46 //expected-note@-1{{Calling 'CreateRefUndef'}}
47 //expected-note@-2{{Returning from 'CreateRefUndef'}}
Daniel Marjamaki3d8d6ed2017-03-08 15:22:24 +000048 CFRelease(storeRef); //expected-warning {{1st function call argument is an uninitialized value}}
49 //expected-note@-1{{1st function call argument is an uninitialized value}}
Jordan Rosef7f32d52013-02-27 18:49:57 +000050}
Anna Zaks5d4ec362012-08-29 21:22:37 +000051@end
52
53static void CreateRef(SCDynamicStoreRef *storeRef, unsigned x) {
54 unsigned err = 0;
Jordan Rosef7f32d52013-02-27 18:49:57 +000055 SCDynamicStoreRef ref = anotherCreateRef(&err, x);
Anna Zaks5d4ec362012-08-29 21:22:37 +000056 if (err) {
57 //expected-note@-1{{Assuming 'err' is not equal to 0}}
58 //expected-note@-2{{Taking true branch}}
59 CFRelease(ref);
Jordan Rosef7f32d52013-02-27 18:49:57 +000060 ref = 0; // expected-note{{nil object reference stored to 'ref'}}
Anna Zaks5d4ec362012-08-29 21:22:37 +000061 }
Jordan Rosef7f32d52013-02-27 18:49:57 +000062 *storeRef = ref; // expected-note{{nil object reference stored to 'storeRef'}}
63}
64
65static void CreateRefUndef(SCDynamicStoreRef *storeRef, unsigned x) {
66 unsigned err = 0;
67 SCDynamicStoreRef ref = anotherCreateRef(&err, x);
68 if (err) {
69 //expected-note@-1{{Assuming 'err' is not equal to 0}}
70 //expected-note@-2{{Taking true branch}}
71 CFRelease(ref);
George Karpenkove15451a2018-02-23 23:26:56 +000072 return; // expected-note{{Returning without writing to '*storeRef'}}
Jordan Rosef7f32d52013-02-27 18:49:57 +000073 }
74 *storeRef = ref;
Anna Zaks5d4ec362012-08-29 21:22:37 +000075}
76