uninit-vals-ps.c revision e1cea75e70d76f55157749a7bcad319050492945
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 && 3// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s 4 5struct FPRec { 6 void (*my_func)(int * x); 7}; 8 9int bar(int x); 10 11int f1_a(struct FPRec* foo) { 12 int x; 13 (*foo->my_func)(&x); 14 return bar(x)+1; // no-warning 15} 16 17int f1_b() { 18 int x; 19 return bar(x)+1; // expected-warning{{Pass-by-value argument in function call is undefined.}} 20} 21 22int f2() { 23 24 int x; 25 26 if (x+1) // expected-warning{{Branch}} 27 return 1; 28 29 return 2; 30} 31 32int f2_b() { 33 int x; 34 35 return ((x+1)+2+((x))) + 1 ? 1 : 2; // expected-warning{{Branch}} 36} 37 38int 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} 46 47void f4_aux(float* x); 48float f4(void) { 49 float x; 50 f4_aux(&x); 51 return x; // no-warning 52} 53 54struct f5_struct { int x; }; 55void f5_aux(struct f5_struct* s); 56int f5(void) { 57 struct f5_struct s; 58 f5_aux(&s); 59 return s.x; // no-warning 60} 61 62int ret_uninit() { 63 int i; 64 int *p = &i; 65 return *p; // expected-warning{{Uninitialized or undefined value returned to caller.}} 66} 67 68// <rdar://problem/6451816> 69typedef unsigned char Boolean; 70typedef const struct __CFNumber * CFNumberRef; 71typedef signed long CFIndex; 72typedef CFIndex CFNumberType; 73typedef unsigned long UInt32; 74typedef UInt32 CFStringEncoding; 75typedef const struct __CFString * CFStringRef; 76extern Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr); 77extern CFStringRef CFStringConvertEncodingToIANACharSetName(CFStringEncoding encoding); 78 79CFStringRef 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} 86 87