1 // RUN: %clang_analyze_cc1 -analyzer-output=text -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=unix.Malloc \
4 // RUN: -analyzer-checker=debug.ExprInspection \
5 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true
7 void clang_analyzer_warnIfReached(void);
9 // Passing uninitialized const data to function
10 #include "Inputs/system-header-simulator.h"
12 typedef __typeof(sizeof(int)) size_t;
18 void doStuff3(const int y
){}
19 void doStuff2(int g
){}
20 void doStuff_pointerToConstInt(const int *u
){};
21 void doStuff_arrayOfConstInt(const int a
[]){};
23 void doStuff_constPointerToConstInt (int const * const u
){};
24 void doStuff_constPointerToConstPointerToConstInt(int const * const * const u
){};
25 void doStuff_pointerToConstPointerToConstInt(int const * const * u
){};
26 void doStuff_pointerToPointerToConstInt (int const **u
){};
27 void doStuff_constStaticSizedArray(const int a
[static 10]) {}
28 void doStuff_variadic(const int *u
, ...){};
31 int t
; // expected-note {{'t' declared without an initial value}}
32 int* tp
= &t
; // expected-note {{'tp' initialized here}}
33 doStuff_pointerToConstInt(tp
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
34 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
38 int t
; // expected-note {{'t' declared without an initial value}}
39 int *tp1
= &t
; // expected-note {{'tp1' initialized here}}
40 int *tp2
= tp1
; // expected-note {{'tp2' initialized to the value of 'tp1'}}
41 doStuff_pointerToConstInt(tp2
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
42 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
46 int *f_2_sub(int *p
) {
47 return p
; // expected-note {{Returning pointer (loaded from 'p')}}
51 int t
; // expected-note {{'t' declared without an initial value}}
52 int *p
= f_2_sub(&t
); // expected-note {{Passing value via 1st parameter 'p'}}
53 // expected-note@-1{{Calling 'f_2_sub'}}
54 // expected-note@-2{{Returning from 'f_2_sub'}}
55 // expected-note@-3{{'p' initialized here}}
56 int *tp
= p
; // expected-note {{'tp' initialized to the value of 'p'}}
57 doStuff_pointerToConstInt(tp
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
58 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
63 doStuff_pointerToConstInt(&z
); // no warning
68 doStuff_pointerToConstInt(&x
); // no warning
72 int ta
[5]; // expected-note {{'ta' initialized here}}
73 int *tp
= ta
; // expected-note {{'tp' initialized here}}
74 doStuff_pointerToConstInt(tp
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
75 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
79 int ta
[5]; // expected-note {{'ta' initialized here}}
80 doStuff_pointerToConstInt(ta
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
81 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
85 int ta
[5] = {1,2,3,4,5};
87 doStuff_pointerToConstInt(tp
); // no-warning
91 int ta
[5] = {1,2,3,4,5};
92 doStuff_pointerToConstInt(ta
); // no-warning
96 int z
; // expected-note {{'z' declared without an initial value}}
97 int y
=z
; // expected-warning {{Assigned value is garbage or undefined}}
98 // expected-note@-1 {{Assigned value is garbage or undefined}}
103 int g
; // expected-note {{'g' declared without an initial value}}
104 doStuff2(g
); // expected-warning {{1st function call argument is an uninitialized value}}
105 // expected-note@-1 {{1st function call argument is an uninitialized value}}
109 int a
[6]; // expected-note {{'a' initialized here}}
110 int const *ptau
= a
; // expected-note {{'ptau' initialized here}}
111 doStuff_arrayOfConstInt(ptau
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
112 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
116 int a
[6]; // expected-note {{'a' initialized here}}
117 doStuff_arrayOfConstInt(a
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
118 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
122 int t
[10]; //expected-note {{'t' initialized here}}
123 doStuff_constStaticSizedArray(t
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
124 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
128 int t
[10] = {0,1,2,3,4,5,6,7,8,9};
129 doStuff_constStaticSizedArray(t
); // no-warning
133 // https://bugs.llvm.org/show_bug.cgi?id=35419
135 int x
; // expected-note {{'x' declared without an initial value}}
136 x
++; // expected-warning {{The expression is an uninitialized value. The computed value will also be garbage}}
137 // expected-note@-1 {{The expression is an uninitialized value. The computed value will also be garbage}}
138 clang_analyzer_warnIfReached(); // no-warning
141 int x
; // expected-note {{'x' declared without an initial value}}
142 ++x
; // expected-warning {{The expression is an uninitialized value. The computed value will also be garbage}}
143 // expected-note@-1 {{The expression is an uninitialized value. The computed value will also be garbage}}
144 clang_analyzer_warnIfReached(); // no-warning
147 int x
; // expected-note {{'x' declared without an initial value}}
148 x
--; // expected-warning {{The expression is an uninitialized value. The computed value will also be garbage}}
149 // expected-note@-1 {{The expression is an uninitialized value. The computed value will also be garbage}}
150 clang_analyzer_warnIfReached(); // no-warning
153 int x
; // expected-note {{'x' declared without an initial value}}
154 --x
; // expected-warning {{The expression is an uninitialized value. The computed value will also be garbage}}
155 // expected-note@-1 {{The expression is an uninitialized value. The computed value will also be garbage}}
156 clang_analyzer_warnIfReached(); // no-warning
159 int f_malloc_1(void) {
162 ptr
= (int *)malloc(sizeof(int)); // expected-note {{Value assigned to 'ptr'}}
164 doStuff_pointerToConstInt(ptr
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
165 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
170 int f_malloc_2(void) {
173 ptr
= (int *)malloc(sizeof(int));
176 doStuff_pointerToConstInt(ptr
); // no warning
181 // uninit pointer, uninit val
182 void f_variadic_unp_unv(void) {
183 int t
; // expected-note {{'t' declared without an initial value}}
185 int* tp
= &t
; // expected-note {{'tp' initialized here}}
186 doStuff_variadic(tp
,v
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
187 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
189 // uninit pointer, init val
190 void f_variadic_unp_inv(void) {
191 int t
; // expected-note {{'t' declared without an initial value}}
193 int* tp
= &t
; // expected-note {{'tp' initialized here}}
194 doStuff_variadic(tp
,v
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
195 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
198 // init pointer, uninit val
199 void f_variadic_inp_unv(void) {
201 int v
; // expected-note {{'v' declared without an initial value}}
203 doStuff_variadic(tp
,v
);// expected-warning {{2nd function call argument is an uninitialized value}}
204 // expected-note@-1 {{2nd function call argument is an uninitialized value}}
207 // init pointer, init val
208 void f_variadic_inp_inv(void) {
212 doStuff_variadic(tp
,v
); // no-warning
215 // init pointer, init pointer
216 void f_variadic_inp_inp(void) {
221 doStuff_variadic(tp
,vp
); // no-warning
224 //uninit pointer, init pointer
225 void f_variadic_unp_inp(void) {
226 int t
; // expected-note {{'t' declared without an initial value}}
229 int *tp
= &t
; // expected-note {{'tp' initialized here}}
230 doStuff_variadic(tp
,vp
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
231 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
234 //init pointer, uninit pointer
235 void f_variadic_inp_unp(void) {
240 doStuff_variadic(tp
,vp
); // no-warning
243 //uninit pointer, uninit pointer
244 void f_variadic_unp_unp(void) {
245 int t
; // expected-note {{'t' declared without an initial value}}
248 int *tp
= &t
; // expected-note {{'tp' initialized here}}
249 doStuff_variadic(tp
,vp
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
250 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}