diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-01-21 19:41:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-01-21 19:41:41 +0000 |
commit | 94b1b4d785bc0f09f6af4be394e59d51f35dda60 (patch) | |
tree | 0c4bd4d1e4199400b2dfb08fe87183dca7b445a6 /test/Sema/uninit-variables.c | |
parent | cc15f010672a13b38104a32e3cefc7adc07ffbf7 (diff) |
Enhance -Wuninitialized-experimental diagnostics
to issue the warning at an uninitialized variable's
declaration, but to issue notes at possible
uninitialized uses (which could be multiple).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123994 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/uninit-variables.c')
-rw-r--r-- | test/Sema/uninit-variables.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index 7ac225f5a3..62fcda019a 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only %s -verify int test1() { - int x; - return x; // expected-warning{{use of uninitialized variable 'x'}} + int x; // expected-warning{{use of uninitialized variable 'x'}} + return x; // expected-note{{variable 'x' is possibly uninitialized when used here}} } int test2() { @@ -17,28 +17,28 @@ int test3() { } int test4() { - int x; - ++x; // expected-warning{{use of uninitialized variable 'x'}} + int x; // expected-warning{{use of uninitialized variable 'x'}} + ++x; // expected-note{{variable 'x' is possibly uninitialized when used here}} return x; } int test5() { - int x, y; - x = y; // expected-warning{{use of uninitialized variable 'y'}} + int x, y; // expected-warning{{use of uninitialized variable 'y'}} + x = y; // expected-note{{variable 'y' is possibly uninitialized when used here}} return x; } int test6() { - int x; - x += 2; // expected-warning{{use of uninitialized variable 'x'}} + int x; // expected-warning{{use of uninitialized variable 'x'}} + x += 2; // expected-note{{variable 'x' is possibly uninitialized when used here}} return x; } int test7(int y) { - int x; + int x; // expected-warning{{use of uninitialized variable 'x'}} if (y) x = 1; - return x; // expected-warning{{use of uninitialized variable 'x'}} + return x; // expected-note{{variable 'x' is possibly uninitialized when used here}} } int test8(int y) { @@ -51,33 +51,33 @@ int test8(int y) { } int test9(int n) { - int x; + int x; // expected-warning{{use of uninitialized variable 'x'}} for (unsigned i = 0 ; i < n; ++i) { if (i == n - 1) break; - x = 1; + x = 1; } - return x; // expected-warning{{use of uninitialized variable 'x'}} + return x; // expected-note{{variable 'x' is possibly uninitialized when used here}} } int test10(unsigned n) { - int x; + int x; // expected-warning{{use of uninitialized variable 'x'}} for (unsigned i = 0 ; i < n; ++i) { x = 1; } - return x; // expected-warning{{use of uninitialized variable 'x'}} + return x; // expected-note{{variable 'x' is possibly uninitialized when used here}} } int test11(unsigned n) { - int x; + int x; // expected-warning{{use of uninitialized variable 'x'}} for (unsigned i = 0 ; i <= n; ++i) { x = 1; } - return x; // expected-warning{{use of uninitialized variable 'x'}} + return x; //expected-note{{variable 'x' is possibly uninitialized when used here}} } void test12(unsigned n) { - for (unsigned i ; n ; ++i) ; // expected-warning{{use of uninitialized variable 'i'}} + for (unsigned i ; n ; ++i) ; // expected-warning{{use of uninitialized variable 'i'}} expected-note{{variable 'i' is possibly uninitialized when used here}}} } int test13() { @@ -92,7 +92,7 @@ void test14() { } void test15() { - int x = x; // expected-warning{{use of uninitialized variable 'x'}} + int x = x; // expected-warning{{use of uninitialized variable 'x'}} expected-note{{variable 'x' is possibly uninitialized when used here}} } // Don't warn in the following example; shows dataflow confluence. @@ -106,8 +106,8 @@ void test16() { void test17() { // Don't warn multiple times about the same uninitialized variable // along the same path. - int *x; - *x = 1; // expected-warning{{use of uninitialized variable 'x'}} + int *x; // expected-warning{{use of uninitialized variable 'x'}} + *x = 1; // expected-note{{variable 'x' is possibly uninitialized when used here}} *x = 1; // no-warning } @@ -130,16 +130,16 @@ int test19() { } int test20() { - int z; + int z; // expected-warning{{use of uninitialized variable 'z'}} if ((test19_aux1() + test19_aux2() && test19_aux1()) || test19_aux3(&z)) - return z; // expected-warning{{use of uninitialized variable 'z'}} + return z; // expected-note{{variable 'z' is possibly uninitialized when used here}} return 0; } int test21(int x, int y) { - int z; + int z; // expected-warning{{use of uninitialized variable 'z'}} if ((x && y) || test19_aux3(&z) || test19_aux2()) - return z; // expected-warning{{use of uninitialized variable 'z'}} + return z; // expected-note{{variable 'z' is possibly uninitialized when used here}} return 0; } @@ -162,11 +162,11 @@ int test23() { // conditionals. This possibly can be handled by making the CFG itself // represent such control-dependencies, but it is a niche case. int test24(int flag) { - unsigned val; + unsigned val; // expected-warning{{use of uninitialized variable 'val'}} if (flag) val = 1; if (!flag) val = 1; - return val; // expected-warning{{use of uninitialized variable 'val'}} + return val; // expected-note{{variable 'val' is possibly uninitialized when used here}} } |