blob: 8c742403990d06c074105596986126f4f12409ee [file] [log] [blame]
Ted Kremeneke1cea752009-07-06 21:58:46 +00001// 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 Dunbard7d5f022009-03-24 02:24:46 +00003// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s
Ted Kremenek43ae4b02008-04-24 18:28:14 +00004
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;
Douglas Gregored8a93d2009-03-01 17:12:46 +000019 return bar(x)+1; // expected-warning{{Pass-by-value argument in function call is undefined.}}
Ted Kremenek43ae4b02008-04-24 18:28:14 +000020}
Ted Kremenek5c454ab2008-05-05 15:56:53 +000021
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
Ted Kremenek5c96c272008-05-21 15:48:33 +000038int 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 Xu89e8a072008-11-19 11:10:42 +000046
Ted Kremenekef77d542009-04-02 17:25:00 +000047void 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
Ted Kremenek7c686662008-11-21 00:28:47 +000062int ret_uninit() {
63 int i;
64 int *p = &i;
Ted Kremenek0c313172009-05-13 19:16:35 +000065 return *p; // expected-warning{{Uninitialized or undefined value returned to caller.}}
Ted Kremenek7c686662008-11-21 00:28:47 +000066}
67
Ted Kremenek90b32362008-12-17 19:42:34 +000068// <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}
Ted Kremenek7c686662008-11-21 00:28:47 +000086