summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/uninit-variables.c
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-07-17 00:06:14 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-07-17 00:06:14 +0000
commit6376d1fd9c970c0020c6cf2fb860c9e8623e4734 (patch)
tree7b47034cb67c532c0747173e7cd029133ea15afb /clang/test/Sema/uninit-variables.c
parent046744467df2dad2d2a55d311944f12032c01608 (diff)
downloadbcm5719-llvm-6376d1fd9c970c0020c6cf2fb860c9e8623e4734.tar.gz
bcm5719-llvm-6376d1fd9c970c0020c6cf2fb860c9e8623e4734.zip
-Wuninitialized: Split the classification of DeclRefExprs as initialization or
use out of TransferFunctions, and compute it in advance rather than on-the-fly. This allows us to handle compound assignments with DeclRefExprs on the RHS correctly, and also makes it trivial to treat const& function parameters as not initializing the argument. The patch also makes both of those changes. llvm-svn: 160330
Diffstat (limited to 'clang/test/Sema/uninit-variables.c')
-rw-r--r--clang/test/Sema/uninit-variables.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c
index 2630b70ec08..4e3d74b3eaf 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; // expected-warning{{variable 'x' is uninitialized when used here}}
- return x;
+ x += 2;
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
int test7(int y) {
@@ -485,3 +485,16 @@ int returns_twice() {
}
return a;
}
+
+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}}
+}
+
+void compound_assign_2(int n) {
+ volatile int ignore;
+ for (int j = 0; j < n; ++j)
+ ignore += test1(); // ok
+}
OpenPOWER on IntegriCloud