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