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