1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region -fblocks -verify %s
4 void (*my_func)(int * x);
9 int f1_a(struct FPRec* foo) {
12 return bar(x)+1; // no-warning
17 return bar(x)+1; // expected-warning{{1st function call argument is an uninitialized value}}
24 if (x+1) // expected-warning{{The left operand of '+' is a garbage value}}
33 return ((1+x)+2+((x))) + 1 ? 1 : 2; // expected-warning{{The right operand of '+' is a garbage value}}
39 if (*p > 0) // expected-warning{{The left operand of '>' is a garbage value}}
45 void f4_aux(float* x);
49 return x; // no-warning
52 struct f5_struct { int x; };
53 void f5_aux(struct f5_struct* s);
57 return s.x; // no-warning
63 if (a[x] == 123) {} // expected-warning{{The left operand of '==' is a garbage value due to array index out of bounds}}
69 return *p; // expected-warning{{Undefined or garbage value returned to caller}}
72 // <rdar://problem/6451816>
73 typedef unsigned char Boolean;
74 typedef const struct __CFNumber * CFNumberRef;
75 typedef signed long CFIndex;
76 typedef CFIndex CFNumberType;
77 typedef unsigned long UInt32;
78 typedef UInt32 CFStringEncoding;
79 typedef const struct __CFString * CFStringRef;
80 extern Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
81 extern CFStringRef CFStringConvertEncodingToIANACharSetName(CFStringEncoding encoding);
83 CFStringRef rdar_6451816(CFNumberRef nr) {
84 CFStringEncoding encoding;
85 // &encoding is casted to void*. This test case tests whether or not
86 // we properly invalidate the value of 'encoding'.
87 CFNumberGetValue(nr, 9, &encoding);
88 return CFStringConvertEncodingToIANACharSetName(encoding); // no-warning
91 // PR 4630 - false warning with nonnull attribute
92 // This false positive (due to a regression) caused the analyzer to falsely
93 // flag a "return of uninitialized value" warning in the first branch due to
94 // the nonnull attribute.
95 void pr_4630_aux(char *x, int *y) __attribute__ ((nonnull (1)));
96 void pr_4630_aux_2(char *x, int *y);
97 int pr_4630(char *a, int y) {
101 return x; // no-warning
104 pr_4630_aux_2(a, &x);
105 return x; // no-warning
109 // PR 4631 - False positive with union initializer
110 // Previously the analyzer didn't examine the compound initializers of unions,
111 // resulting in some false positives for initializers with side-effects.
112 union u_4631 { int a; };
113 struct s_4631 { int a; };
114 int pr4631_f2(int *p);
115 int pr4631_f3(void *q);
119 union u_4631 m = { pr4631_f2(&x) };
120 pr4631_f3(&m); // tell analyzer that we use m
121 return x; // no-warning
123 int pr4631_f1_b(void)
126 struct s_4631 m = { pr4631_f2(&x) };
127 pr4631_f3(&m); // tell analyzer that we use m
128 return x; // no-warning
131 // <rdar://problem/12278788> - FP when returning a void-valued expression from
132 // a void function...or block.
133 void foo_radar12278788() { return; }
134 void test_radar12278788() {
135 return foo_radar12278788(); // no-warning
138 void foo_radar12278788_fp() { return; }
139 typedef int (*RetIntFuncType)();
140 typedef void (*RetVoidFuncType)();
141 int test_radar12278788_FP() {
142 RetVoidFuncType f = foo_radar12278788_fp;
143 return ((RetIntFuncType)f)(); //expected-warning {{Undefined or garbage value returned to caller}}
146 void rdar13665798() {
148 return foo_radar12278788(); // no-warning
151 return foo_radar12278788(); // no-warning
154 RetVoidFuncType f = foo_radar12278788_fp;
155 return ((RetIntFuncType)f)(); //expected-warning {{Undefined or garbage value returned to caller}}