blob: 041c946fb0c52532a183b8b7735d9f2e7abb9058 [file] [log] [blame]
Ted Kremenekff7c5382007-11-24 20:07:36 +00001// RUN: clang -warn-uninit-values -verify %s
2
3int f1() {
4 int x;
Bill Wendlingf5f20bd2007-11-26 08:26:20 +00005 return x; // expected-warning {{use of uninitialized variable}}
Ted Kremenekff7c5382007-11-24 20:07:36 +00006}
7
8int f2(int x) {
9 int y;
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000010 int z = x + y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekff7c5382007-11-24 20:07:36 +000011 return z;
12}
13
14
15int f3(int x) {
16 int y;
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000017 return x ? 1 : y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekff7c5382007-11-24 20:07:36 +000018}
19
20int f4(int x) {
21 int y;
22 if (x) y = 1;
23 return y; // no-warning
24}
25
26int f5() {
27 int a;
28 a = 30; // no-warning
29}
Ted Kremenekca7aa1f2007-11-24 23:06:58 +000030
31void f6(int i) {
32 int x;
33 for (i = 0 ; i < 10; i++)
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000034 printf("%d",x++); // expected-warning {{use of uninitialized variable}}
Ted Kremenekca7aa1f2007-11-24 23:06:58 +000035}
36
37void f7(int i) {
38 int x = i;
39 int y;
40 for (i = 0; i < 10; i++ ) {
41 printf("%d",x++); // no-warning
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000042 x += y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekca7aa1f2007-11-24 23:06:58 +000043 }
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000044}