Dominic Chen | 184c624 | 2017-03-03 18:02:02 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=text -verify %s |
George Karpenkov | 3916509 | 2018-06-12 19:07:41 +0000 | [diff] [blame] | 2 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=plist-multi-file %s -o %t.plist |
Mikhail Maltsev | c704f4d | 2018-09-17 10:19:46 +0000 | [diff] [blame] | 3 | // RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/undef-value-param.m.plist |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 4 | |
| 5 | typedef 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 |
| 16 | typedef const void * CFTypeRef; |
| 17 | extern 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 | |
| 28 | typedef SpecialString* SCDynamicStoreRef; |
| 29 | static void CreateRef(SCDynamicStoreRef *storeRef, unsigned x); |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 30 | static void CreateRefUndef(SCDynamicStoreRef *storeRef, unsigned x); |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 31 | SCDynamicStoreRef anotherCreateRef(unsigned *err, unsigned x); |
| 32 | |
| 33 | @implementation Cell |
| 34 | - (void) test { |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 35 | SCDynamicStoreRef storeRef = 0; |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 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 | } |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 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'}} |
Daniel Marjamaki | 3d8d6ed | 2017-03-08 15:22:24 +0000 | [diff] [blame] | 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}} |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 50 | } |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 51 | @end |
| 52 | |
| 53 | static void CreateRef(SCDynamicStoreRef *storeRef, unsigned x) { |
| 54 | unsigned err = 0; |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 55 | SCDynamicStoreRef ref = anotherCreateRef(&err, x); |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 56 | if (err) { |
| 57 | //expected-note@-1{{Assuming 'err' is not equal to 0}} |
| 58 | //expected-note@-2{{Taking true branch}} |
| 59 | CFRelease(ref); |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 60 | ref = 0; // expected-note{{nil object reference stored to 'ref'}} |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 61 | } |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 62 | *storeRef = ref; // expected-note{{nil object reference stored to 'storeRef'}} |
| 63 | } |
| 64 | |
| 65 | static 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 Karpenkov | e15451a | 2018-02-23 23:26:56 +0000 | [diff] [blame] | 72 | return; // expected-note{{Returning without writing to '*storeRef'}} |
Jordan Rose | f7f32d5 | 2013-02-27 18:49:57 +0000 | [diff] [blame] | 73 | } |
| 74 | *storeRef = ref; |
Anna Zaks | 5d4ec36 | 2012-08-29 21:22:37 +0000 | [diff] [blame] | 75 | } |
| 76 | |