blob: b0769ba6bce1efbabfd2e7d96ad6e4aa9347b0e9 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -analyze -warn-uninit-values -verify %s
Ted Kremenekff7c5382007-11-24 20:07:36 +00002
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;
Ted Kremenek5fb5c6a2008-03-22 20:11:00 +000023 return y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekff7c5382007-11-24 20:07:36 +000024}
25
Mike Stumpc2374292009-07-21 18:56:34 +000026void f5() {
Ted Kremenekff7c5382007-11-24 20:07:36 +000027 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++)
Douglas Gregora316e7b2009-02-14 00:32:47 +000034 printf("%d",x++); // expected-warning {{use of uninitialized variable}} \
35 // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \
36 // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
Ted Kremenekca7aa1f2007-11-24 23:06:58 +000037}
38
39void f7(int i) {
40 int x = i;
41 int y;
42 for (i = 0; i < 10; i++ ) {
43 printf("%d",x++); // no-warning
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000044 x += y; // expected-warning {{use of uninitialized variable}}
Ted Kremenekca7aa1f2007-11-24 23:06:58 +000045 }
Bill Wendlingf5f20bd2007-11-26 08:26:20 +000046}
Ted Kremenekf3929da2009-03-30 18:29:27 +000047
48int f8(int j) {
49 int x = 1, y = x + 1;
50 if (y) // no-warning
51 return x;
52 return y;
53}