diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-07-17 01:27:33 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-07-17 01:27:33 +0000 |
commit | b21dd02e6122542a421fe8569ee96f144eef535b (patch) | |
tree | ab96751ae56d32b0a8aec6f28b095744ad5bbb2d /clang/test/Sema/uninit-variables.c | |
parent | 514410ba073ef994d05004f7c298bd1df192d766 (diff) | |
download | bcm5719-llvm-b21dd02e6122542a421fe8569ee96f144eef535b.tar.gz bcm5719-llvm-b21dd02e6122542a421fe8569ee96f144eef535b.zip |
Uninitialized variables: two little changes:
* Treat compound assignment as a use, at Jordy's request.
* Always add compound assignments into the CFG, so we can correctly diagnose the use in 'return x += 1;'
llvm-svn: 160334
Diffstat (limited to 'clang/test/Sema/uninit-variables.c')
-rw-r--r-- | clang/test/Sema/uninit-variables.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c index 4e3d74b3eaf..9257751e471 100644 --- a/clang/test/Sema/uninit-variables.c +++ b/clang/test/Sema/uninit-variables.c @@ -33,8 +33,8 @@ int test5() { int test6() { int x; // expected-note{{initialize the variable 'x' to silence this warning}} - x += 2; - return x; // expected-warning{{variable 'x' is uninitialized when used here}} + x += 2; // expected-warning{{variable 'x' is uninitialized when used here}} + return x; } int test7(int y) { @@ -489,12 +489,17 @@ int returns_twice() { int compound_assign(int *arr, int n) { int sum; // expected-note {{initialize}} for (int i = 0; i < n; ++i) - sum += arr[i]; - return sum / n; // expected-warning {{variable 'sum' is uninitialized}} + sum += arr[i]; // expected-warning {{variable 'sum' is uninitialized}} + return sum / n; } -void compound_assign_2(int n) { - volatile int ignore; - for (int j = 0; j < n; ++j) - ignore += test1(); // ok +int compound_assign_2() { + int x; // expected-note {{initialize}} + return x += 1; // expected-warning {{variable 'x' is uninitialized}} +} + +int compound_assign_3() { + int x; // expected-note {{initialize}} + x *= 0; // expected-warning {{variable 'x' is uninitialized}} + return x; } |