blob: a7f5733dc414976fc1eb1269ebebeb50c983f79e [file] [log] [blame]
Daniel Dunbar9c321102009-01-20 23:17:32 +00001// RUN: clang -analyze -warn-uninit-values -verify %s
Ted Kremenekbf80ca02007-11-24 20:07:36 +00002
3int f1() {
4 int x;
Bill Wendlingc08e97b2007-11-26 08:26:20 +00005 return x; // expected-warning {{use of uninitialized variable}}
Ted Kremenekbf80ca02007-11-24 20:07:36 +00006}
7
8int f2(int x) {
9 int y;
Bill Wendlingc08e97b2007-11-26 08:26:20 +000010 int z = x + y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekbf80ca02007-11-24 20:07:36 +000011 return z;
12}
13
14
15int f3(int x) {
16 int y;
Bill Wendlingc08e97b2007-11-26 08:26:20 +000017 return x ? 1 : y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekbf80ca02007-11-24 20:07:36 +000018}
19
20int f4(int x) {
21 int y;
22 if (x) y = 1;
Ted Kremenek24d83ad2008-03-22 20:11:00 +000023 return y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekbf80ca02007-11-24 20:07:36 +000024}
25
26int f5() {
27 int a;
28 a = 30; // no-warning
29}
Ted Kremenekf3267b42007-11-24 23:06:58 +000030
31void f6(int i) {
32 int x;
33 for (i = 0 ; i < 10; i++)
Bill Wendlingc08e97b2007-11-26 08:26:20 +000034 printf("%d",x++); // expected-warning {{use of uninitialized variable}}
Ted Kremenekf3267b42007-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 Wendlingc08e97b2007-11-26 08:26:20 +000042 x += y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekf3267b42007-11-24 23:06:58 +000043 }
Bill Wendlingc08e97b2007-11-26 08:26:20 +000044}