1 // RUN: %clang_analyze_cc1 -analyzer-checker=unix.Malloc,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -verify %s
3 // Passing uninitialized const data to function
4 #include "Inputs/system-header-simulator.h"
6 typedef __typeof(sizeof(int)) size_t;
12 void doStuff3(const int y){}
13 void doStuff2(int g){}
14 void doStuff_pointerToConstInt(const int *u){};
15 void doStuff_arrayOfConstInt(const int a[]){};
17 void doStuff_constPointerToConstInt (int const * const u){};
18 void doStuff_constPointerToConstPointerToConstInt(int const * const * const u){};
19 void doStuff_pointerToConstPointerToConstInt(int const * const * u){};
20 void doStuff_pointerToPointerToConstInt (int const **u){};
21 void doStuff_constStaticSizedArray(const int a[static 10]) {}
22 void doStuff_variadic(const int *u, ...){};
26 int* tp = &t; // expected-note {{'tp' initialized here}}
27 doStuff_pointerToConstInt(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
28 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
34 int* tp2 = tp1; // expected-note {{'tp2' initialized here}}
35 doStuff_pointerToConstInt(tp2); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
36 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
40 int *f_2_sub(int *p) {
47 int* tp = p; // expected-note {{'tp' initialized here}}
48 doStuff_pointerToConstInt(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
49 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
54 doStuff_pointerToConstInt(&z); // no warning
59 doStuff_pointerToConstInt(&x); // no warning
64 int* tp = ta; // expected-note {{'tp' initialized here}}
65 doStuff_pointerToConstInt(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
66 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
70 int ta[5]; // expected-note {{'ta' initialized here}}
71 doStuff_pointerToConstInt(ta); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
72 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
76 int ta[5] = {1,2,3,4,5};
78 doStuff_pointerToConstInt(tp); // no-warning
82 int ta[5] = {1,2,3,4,5};
83 doStuff_pointerToConstInt(ta); // no-warning
87 int z; // expected-note {{'z' declared without an initial value}}
88 int y=z; // expected-warning {{Assigned value is garbage or undefined}}
89 // expected-note@-1 {{Assigned value is garbage or undefined}}
94 int g; // expected-note {{'g' declared without an initial value}}
95 doStuff2(g); // expected-warning {{1st function call argument is an uninitialized value}}
96 // expected-note@-1 {{1st function call argument is an uninitialized value}}
101 int const *ptau = a; // expected-note {{'ptau' initialized here}}
102 doStuff_arrayOfConstInt(ptau); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
103 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
107 int a[6]; // expected-note {{'a' initialized here}}
108 doStuff_arrayOfConstInt(a); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
109 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
113 int t[10]; //expected-note {{'t' initialized here}}
114 doStuff_constStaticSizedArray(t); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
115 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
119 int t[10] = {0,1,2,3,4,5,6,7,8,9};
120 doStuff_constStaticSizedArray(t); // no-warning
124 int f_malloc_1(void) {
127 ptr = (int *)malloc(sizeof(int)); // expected-note {{Value assigned to 'ptr'}}
129 doStuff_pointerToConstInt(ptr); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
130 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
135 int f_malloc_2(void) {
138 ptr = (int *)malloc(sizeof(int));
141 doStuff_pointerToConstInt(ptr); // no warning
146 // uninit pointer, uninit val
147 void f_variadic_unp_unv(void) {
150 int* tp = &t; // expected-note {{'tp' initialized here}}
151 doStuff_variadic(tp,v); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
152 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
154 // uninit pointer, init val
155 void f_variadic_unp_inv(void) {
158 int* tp = &t; // expected-note {{'tp' initialized here}}
159 doStuff_variadic(tp,v); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
160 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
163 // init pointer, uninit val
164 void f_variadic_inp_unv(void) {
166 int v; // expected-note {{'v' declared without an initial value}}
168 doStuff_variadic(tp,v);// expected-warning {{2nd function call argument is an uninitialized value}}
169 // expected-note@-1 {{2nd function call argument is an uninitialized value}}
172 // init pointer, init val
173 void f_variadic_inp_inv(void) {
177 doStuff_variadic(tp,v); // no-warning
180 // init pointer, init pointer
181 void f_variadic_inp_inp(void) {
186 doStuff_variadic(tp,vp); // no-warning
189 //uninit pointer, init pointer
190 void f_variadic_unp_inp(void) {
194 int *tp = &t; // expected-note {{'tp' initialized here}}
195 doStuff_variadic(tp,vp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
196 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
199 //init pointer, uninit pointer
200 void f_variadic_inp_unp(void) {
205 doStuff_variadic(tp,vp); // no-warning
208 //uninit pointer, uninit pointer
209 void f_variadic_unp_unp(void) {
213 int *tp = &t; // expected-note {{'tp' initialized here}}
214 doStuff_variadic(tp,vp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
215 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}