Daniel Dunbar | d427023 | 2009-01-20 23:17:32 +0000 | [diff] [blame^] | 1 | // RUN: clang -analyze -checker-cfref -verify %s && |
| 2 | // RUN: clang -analyze -checker-cfref -analyzer-store-region -verify %s |
Ted Kremenek | 43ae4b0 | 2008-04-24 18:28:14 +0000 | [diff] [blame] | 3 | |
| 4 | struct FPRec { |
| 5 | void (*my_func)(int * x); |
| 6 | }; |
| 7 | |
| 8 | int bar(int x); |
| 9 | |
| 10 | int f1_a(struct FPRec* foo) { |
| 11 | int x; |
| 12 | (*foo->my_func)(&x); |
| 13 | return bar(x)+1; // no-warning |
| 14 | } |
| 15 | |
| 16 | int f1_b() { |
| 17 | int x; |
| 18 | return bar(x)+1; // expected-warning{{Pass-by-value argument in function is undefined.}} |
| 19 | } |
Ted Kremenek | 5c454ab | 2008-05-05 15:56:53 +0000 | [diff] [blame] | 20 | |
| 21 | int f2() { |
| 22 | |
| 23 | int x; |
| 24 | |
| 25 | if (x+1) // expected-warning{{Branch}} |
| 26 | return 1; |
| 27 | |
| 28 | return 2; |
| 29 | } |
| 30 | |
| 31 | int f2_b() { |
| 32 | int x; |
| 33 | |
| 34 | return ((x+1)+2+((x))) + 1 ? 1 : 2; // expected-warning{{Branch}} |
| 35 | } |
| 36 | |
Ted Kremenek | 5c96c27 | 2008-05-21 15:48:33 +0000 | [diff] [blame] | 37 | int f3(void) { |
| 38 | int i; |
| 39 | int *p = &i; |
| 40 | if (*p > 0) // expected-warning{{Branch condition evaluates to an uninitialized value}} |
| 41 | return 0; |
| 42 | else |
| 43 | return 1; |
| 44 | } |
Zhongxing Xu | 89e8a07 | 2008-11-19 11:10:42 +0000 | [diff] [blame] | 45 | |
Ted Kremenek | 7c68666 | 2008-11-21 00:28:47 +0000 | [diff] [blame] | 46 | int ret_uninit() { |
| 47 | int i; |
| 48 | int *p = &i; |
| 49 | return *p; // expected-warning{{Uninitialized or undefined return value returned to caller.}} |
| 50 | } |
| 51 | |
Ted Kremenek | 90b3236 | 2008-12-17 19:42:34 +0000 | [diff] [blame] | 52 | // <rdar://problem/6451816> |
| 53 | typedef unsigned char Boolean; |
| 54 | typedef const struct __CFNumber * CFNumberRef; |
| 55 | typedef signed long CFIndex; |
| 56 | typedef CFIndex CFNumberType; |
| 57 | typedef unsigned long UInt32; |
| 58 | typedef UInt32 CFStringEncoding; |
| 59 | typedef const struct __CFString * CFStringRef; |
| 60 | extern Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr); |
| 61 | extern CFStringRef CFStringConvertEncodingToIANACharSetName(CFStringEncoding encoding); |
| 62 | |
| 63 | CFStringRef rdar_6451816(CFNumberRef nr) { |
| 64 | CFStringEncoding encoding; |
| 65 | // &encoding is casted to void*. This test case tests whether or not |
| 66 | // we properly invalidate the value of 'encoding'. |
| 67 | CFNumberGetValue(nr, 9, &encoding); |
| 68 | return CFStringConvertEncodingToIANACharSetName(encoding); // no-warning |
| 69 | } |
Ted Kremenek | 7c68666 | 2008-11-21 00:28:47 +0000 | [diff] [blame] | 70 | |