• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=text -verify %s
2// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=plist-multi-file %s -o %t.plist
3// RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/undef-value-param.m.plist -
4
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);
30static void CreateRefUndef(SCDynamicStoreRef *storeRef, unsigned x);
31SCDynamicStoreRef anotherCreateRef(unsigned *err, unsigned x);
32
33@implementation Cell
34- (void) test {
35    SCDynamicStoreRef storeRef = 0;
36    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}
42
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'}}
48    CFRelease(storeRef); //expected-warning {{1st function call argument is an uninitialized value}}
49                         //expected-note@-1{{1st function call argument is an uninitialized value}}
50}
51@end
52
53static void CreateRef(SCDynamicStoreRef *storeRef, unsigned x) {
54    unsigned err = 0;
55    SCDynamicStoreRef ref = anotherCreateRef(&err, x);
56    if (err) {
57               //expected-note@-1{{Assuming 'err' is not equal to 0}}
58               //expected-note@-2{{Taking true branch}}
59        CFRelease(ref);
60        ref = 0; // expected-note{{nil object reference stored to 'ref'}}
61    }
62    *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);
72    return; // expected-note{{Returning without writing to '*storeRef'}}
73  }
74  *storeRef = ref;
75}
76
77