Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -warn-uninit-values -verify %s |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 2 | |
| 3 | int f1() { |
| 4 | int x; |
Bill Wendling | f5f20bd | 2007-11-26 08:26:20 +0000 | [diff] [blame] | 5 | return x; // expected-warning {{use of uninitialized variable}} |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | int f2(int x) { |
| 9 | int y; |
Bill Wendling | f5f20bd | 2007-11-26 08:26:20 +0000 | [diff] [blame] | 10 | int z = x + y; // expected-warning {{use of uninitialized variable}} |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 11 | return z; |
| 12 | } |
| 13 | |
| 14 | |
| 15 | int f3(int x) { |
| 16 | int y; |
Bill Wendling | f5f20bd | 2007-11-26 08:26:20 +0000 | [diff] [blame] | 17 | return x ? 1 : y; // expected-warning {{use of uninitialized variable}} |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | int f4(int x) { |
| 21 | int y; |
| 22 | if (x) y = 1; |
Ted Kremenek | 5fb5c6a | 2008-03-22 20:11:00 +0000 | [diff] [blame] | 23 | return y; // expected-warning {{use of uninitialized variable}} |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Mike Stump | c237429 | 2009-07-21 18:56:34 +0000 | [diff] [blame] | 26 | void f5() { |
Ted Kremenek | ff7c538 | 2007-11-24 20:07:36 +0000 | [diff] [blame] | 27 | int a; |
| 28 | a = 30; // no-warning |
| 29 | } |
Ted Kremenek | ca7aa1f | 2007-11-24 23:06:58 +0000 | [diff] [blame] | 30 | |
| 31 | void f6(int i) { |
| 32 | int x; |
| 33 | for (i = 0 ; i < 10; i++) |
Douglas Gregor | a316e7b | 2009-02-14 00:32:47 +0000 | [diff] [blame] | 34 | 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 Kremenek | ca7aa1f | 2007-11-24 23:06:58 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void f7(int i) { |
| 40 | int x = i; |
| 41 | int y; |
| 42 | for (i = 0; i < 10; i++ ) { |
| 43 | printf("%d",x++); // no-warning |
Bill Wendling | f5f20bd | 2007-11-26 08:26:20 +0000 | [diff] [blame] | 44 | x += y; // expected-warning {{use of uninitialized variable}} |
Ted Kremenek | ca7aa1f | 2007-11-24 23:06:58 +0000 | [diff] [blame] | 45 | } |
Bill Wendling | f5f20bd | 2007-11-26 08:26:20 +0000 | [diff] [blame] | 46 | } |
Ted Kremenek | f3929da | 2009-03-30 18:29:27 +0000 | [diff] [blame] | 47 | |
| 48 | int f8(int j) { |
| 49 | int x = 1, y = x + 1; |
| 50 | if (y) // no-warning |
| 51 | return x; |
| 52 | return y; |
| 53 | } |