summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-09-12 18:49:10 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-09-12 18:49:10 +0000
commitba8071ec81eb5c39f8ebb869a18181a1ed25c782 (patch)
treec186ec14ec3cd2de5ac5930e7d63b6c3a7ccf8c0 /clang/test
parent16a4d8c15d873a5d19338a13004e6086bb7a3d45 (diff)
downloadbcm5719-llvm-ba8071ec81eb5c39f8ebb869a18181a1ed25c782.tar.gz
bcm5719-llvm-ba8071ec81eb5c39f8ebb869a18181a1ed25c782.zip
PR16054: Slight strengthening for -Wsometimes-uninitialized: if we use a
variable uninitialized every time we reach its (reachable) declaration, or every time we call the surrounding function, promote the warning from -Wmaybe-uninitialized to -Wsometimes-uninitialized. This is still slightly weaker than desired: we should, in general, warn if a use is uninitialized the first time it is evaluated. llvm-svn: 190623
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/uninit-sometimes.cpp58
1 files changed, 50 insertions, 8 deletions
diff --git a/clang/test/Analysis/uninit-sometimes.cpp b/clang/test/Analysis/uninit-sometimes.cpp
index 015b675d9b8..425d3048c4e 100644
--- a/clang/test/Analysis/uninit-sometimes.cpp
+++ b/clang/test/Analysis/uninit-sometimes.cpp
@@ -145,13 +145,13 @@ int test_for_range_false(int k) {
int test_for_range_true(int k) {
int arr[3] = { 1, 2, 3 };
- int x;
- for (int &a : arr) { // no-warning
+ int x; // expected-note {{variable}}
+ for (int &a : arr) { // expected-warning {{variable 'x' is used uninitialized whenever 'for' loop is entered}}
goto label;
}
x = 0;
label:
- return x;
+ return x; // expected-note {{uninitialized use}}
}
@@ -356,14 +356,14 @@ int test_no_false_positive_2() {
}
-// FIXME: In this case, the variable is used uninitialized whenever the
-// function's entry block is reached. Produce a diagnostic saying that
-// the variable is uninitialized the first time it is used.
+
+
+
void test_null_pred_succ() {
- int x;
+ int x; // expected-note {{variable}} expected-warning {{used uninitialized whenever function 'test_null_pred_succ' is called}}
if (0)
foo: x = 0;
- if (x)
+ if (x) // expected-note {{use}}
goto foo;
}
@@ -385,3 +385,45 @@ int PR13360(bool b) {
// CHECK: fix-it:"{{.*}}":{376:3-380:10}:""
// CHECK: fix-it:"{{.*}}":{375:8-375:8}:" = 0"
+
+void test_jump_init() {
+goto later;
+ int x; // expected-note {{variable}} expected-warning {{used uninitialized whenever function 'test_jump_init'}}
+later:
+ while (x) x = 0; // expected-note {{use}}
+}
+
+void PR16054() {
+ int x; // expected-note {{variable}} expected-warning {{used uninitialized whenever function 'PR16054}}
+ while (x != 0) { // expected-note {{use}}
+ (void)&x;
+ }
+}
+
+void test_loop_uninit() {
+ for (int n = 0; n < 10; ++n) {
+ int k; // expected-warning {{variable 'k' is used uninitialized whenever its declaration is reached}} expected-note {{variable}}
+ do {
+ k = k + 1; // expected-note {{use}}
+ } while (k != 5);
+ }
+}
+
+// FIXME: We should warn here, because the variable is used uninitialized
+// the first time we encounter the use.
+void test_loop_with_assignment() {
+ double d;
+ for (int n = 0; n < 10; ++n) {
+ d = d + n;
+ }
+}
+
+// FIXME: We should warn here, because the variable is used uninitialized
+// the first time we encounter the use.
+void test_loop_with_ref_bind() {
+ double d;
+ for (int n = 0; n < 10; ++n) {
+ d += n;
+ const double &r = d;
+ }
+}
OpenPOWER on IntegriCloud