2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -analyze -warn-uninit-values -verify %s
|
2007-11-25 04:07:36 +08:00
|
|
|
|
|
|
|
int f1() {
|
|
|
|
int x;
|
2007-11-26 16:26:20 +08:00
|
|
|
return x; // expected-warning {{use of uninitialized variable}}
|
2007-11-25 04:07:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int f2(int x) {
|
|
|
|
int y;
|
2007-11-26 16:26:20 +08:00
|
|
|
int z = x + y; // expected-warning {{use of uninitialized variable}}
|
2007-11-25 04:07:36 +08:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int f3(int x) {
|
|
|
|
int y;
|
2007-11-26 16:26:20 +08:00
|
|
|
return x ? 1 : y; // expected-warning {{use of uninitialized variable}}
|
2007-11-25 04:07:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int f4(int x) {
|
|
|
|
int y;
|
|
|
|
if (x) y = 1;
|
2008-03-23 04:11:00 +08:00
|
|
|
return y; // expected-warning {{use of uninitialized variable}}
|
2007-11-25 04:07:36 +08:00
|
|
|
}
|
|
|
|
|
2009-07-22 02:56:34 +08:00
|
|
|
void f5() {
|
2007-11-25 04:07:36 +08:00
|
|
|
int a;
|
|
|
|
a = 30; // no-warning
|
|
|
|
}
|
2007-11-25 07:06:58 +08:00
|
|
|
|
|
|
|
void f6(int i) {
|
|
|
|
int x;
|
|
|
|
for (i = 0 ; i < 10; i++)
|
2009-02-14 08:32:47 +08:00
|
|
|
printf("%d",x++); // expected-warning {{use of uninitialized variable}} \
|
|
|
|
// expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \
|
|
|
|
// expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
|
2007-11-25 07:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void f7(int i) {
|
|
|
|
int x = i;
|
|
|
|
int y;
|
|
|
|
for (i = 0; i < 10; i++ ) {
|
|
|
|
printf("%d",x++); // no-warning
|
2007-11-26 16:26:20 +08:00
|
|
|
x += y; // expected-warning {{use of uninitialized variable}}
|
2007-11-25 07:06:58 +08:00
|
|
|
}
|
2007-11-26 16:26:20 +08:00
|
|
|
}
|
2009-03-31 02:29:27 +08:00
|
|
|
|
|
|
|
int f8(int j) {
|
|
|
|
int x = 1, y = x + 1;
|
|
|
|
if (y) // no-warning
|
|
|
|
return x;
|
|
|
|
return y;
|
|
|
|
}
|