2007-11-25 04:07:36 +08:00
|
|
|
// RUN: clang -warn-uninit-values -verify %s
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int f5() {
|
|
|
|
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++)
|
2007-11-26 16:26:20 +08:00
|
|
|
printf("%d",x++); // expected-warning {{use of uninitialized variable}}
|
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
|
|
|
}
|