diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-01-15 02:58:47 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-01-15 02:58:47 +0000 |
commit | 610068c8cd2321f90e147b12cf794e1f840b6405 (patch) | |
tree | 575b910632e1a7e9bbfb0a92f42e6cd89973b61c /test/Sema/uninit-variables.c | |
parent | 200fbc877d50da9e53b9aa272b70ca3538ce3a66 (diff) |
Add initial prototype for implementation of
-Wuninitialized based on CFG dataflow analysis. WIP.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123512 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/uninit-variables.c')
-rw-r--r-- | test/Sema/uninit-variables.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c new file mode 100644 index 0000000000..c2d98c40fe --- /dev/null +++ b/test/Sema/uninit-variables.c @@ -0,0 +1,88 @@ +// RUN: %clang -Wuninitialized-experimental -fsyntax-only %s + +int test1() { + int x; + return x; // expected-warning{{use of uninitialized variable 'x'}} +} + +int test2() { + int x = 0; + return x; // no-warning +} + +int test3() { + int x; + x = 0; + return x; // no-warning +} + +int test4() { + int x; + ++x; // expected-warning{{use of uninitialized variable 'x'}} + return x; +} + +int test5() { + int x, y; + x = y; // expected-warning{{use of uninitialized variable 'y'}} + return x; +} + +int test6() { + int x; + x += 2; // expected-warning{{use of uninitialized variable 'x'}} + return x; +} + +int test7(int y) { + int x; + if (y) + x = 1; + return x; // expected-warning{{use of uninitialized variable 'x'}} +} + +int test8(int y) { + int x; + if (y) + x = 1; + else + x = 0; + return x; // no-warning +} + +int test9(int n) { + int x; + for (unsigned i = 0 ; i < n; ++i) { + if (i == n - 1) + break; + x = 1; + } + return x; // expected-warning{{use of uninitialized variable 'x'}} +} + +int test10(unsigned n) { + int x; + for (unsigned i = 0 ; i < n; ++i) { + x = 1; + } + return x; // expected-warning{{use of uninitialized variable 'x'}} +} + +int test11(unsigned n) { + int x; + for (unsigned i = 0 ; i <= n; ++i) { + x = 1; + } + return x; // expected-warning{{use of uninitialized variable 'x'}} +} + +void test12(unsigned n) { + for (unsigned i ; n ; ++i) ; // expected-warning{{use of uninitialized variable 'i'}} +} + +int test13() { + static int i; + return i; // no-warning +} + + |