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
diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c
index 7ac225f..62fcda0 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 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 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 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 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 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 @@
 // 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}}
 }
 
diff --git a/test/SemaCXX/uninit-variables.cpp b/test/SemaCXX/uninit-variables.cpp
index 0d6920c..6d29562 100644
--- a/test/SemaCXX/uninit-variables.cpp
+++ b/test/SemaCXX/uninit-variables.cpp
@@ -33,11 +33,11 @@
   return x; // no-warning
 }
 unsigned test3_c() {
-  unsigned x ;
+  unsigned x ; // expected-warning{{use of uninitialized variable 'x'}}
   const bool flag = false;
   if (flag && (x = test3_aux()) == 0) {
     x = 1;
   }
-  return x; // expected-warning{{use of uninitialized variable 'x'}}
+  return x; // expected-note{{variable 'x' is possibly uninitialized when used here}}
 }