re PR tree-optimization/17506 (warning about uninitialized variable points to wrong...
authorJoern Rennecke <amylaar@gcc.gnu.org>
Tue, 29 Aug 2006 15:52:54 +0000 (16:52 +0100)
committerJoern Rennecke <amylaar@gcc.gnu.org>
Tue, 29 Aug 2006 15:52:54 +0000 (16:52 +0100)
gcc:

2006-08-29  Nathan Sidwell  <nathan@codesourcery.com>
    J"orn Rennecke  <joern.rennecke@st.com>

PR tree-optimization/17506
* tree-ssa.c (warn_uninit): If warning about a location outside of
the current function, note where the variable was declared.

testsuite:

2006-08-29  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
    Kazu Hirata  <kazu@codesourcery.com>

PR tree-optimization/17506
* gcc.dg/pr17506.c: New.

From-SVN: r116564

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr17506.c [new file with mode: 0644]
gcc/tree-ssa.c

index bec73d619ff080bbb30ef537e7a1b8df266742f2..faf7f8b008404d202a591d11a81531dff5d61d70 100644 (file)
@@ -1,3 +1,10 @@
+2006-08-29  Nathan Sidwell  <nathan@codesourcery.com>
+           J"orn Rennecke  <joern.rennecke@st.com>
+
+       PR tree-optimization/17506
+       * tree-ssa.c (warn_uninit): If warning about a location outside of
+       the current function, note where the variable was declared.
+
 2006-08-28  Zdenek Dvorak <dvorakz@suse.cz>
 
        PR tree-optimization/28411
index 21eba05b7d453c8ddc1edac3a49d8c616d7a9892..5c2b9f4c518074b47c11f96a56fc53a8ece8a80d 100644 (file)
@@ -1,3 +1,9 @@
+2006-08-29  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+           Kazu Hirata  <kazu@codesourcery.com>
+
+       PR tree-optimization/17506
+       * gcc.dg/pr17506.c: New.
+
 2006-08-29  J"orn Rennecke  <joern.rennecke@st.com>
 
        PR c++/28139
diff --git a/gcc/testsuite/gcc.dg/pr17506.c b/gcc/testsuite/gcc.dg/pr17506.c
new file mode 100644 (file)
index 0000000..44fb90c
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR tree-optimization/17506
+   We issue an uninitialized variable warning at a wrong location at
+   line 11, which is very confusing.  Make sure we print out a note to
+   make it less confusing.  */
+/* { dg-do compile } */
+/* { dg-options "-O1 -Wuninitialized" } */
+
+inline int
+foo (int i)
+{
+  if (i) /* { dg-warning "used uninitialized in this function" } */
+    return 1;
+  return 0;
+}
+
+void baz (void);
+
+void
+bar (void)
+{
+  int j; /* { dg-error "note: 'j' was declared here" } */
+  for (; foo (j); ++j)
+    baz ();
+}
index 14466124318b8556a10ecdd2e3be16bbf177395d..f922e8254445db516f273e761c644713f1975b66 100644 (file)
@@ -1154,7 +1154,7 @@ warn_uninit (tree t, const char *gmsgid, void *data)
   tree var = SSA_NAME_VAR (t);
   tree def = SSA_NAME_DEF_STMT (t);
   tree context = (tree) data;
-  location_t * locus;
+  location_t *locus, *fun_locus;
 
   /* Default uses (indicated by an empty definition statement),
      are uninitialized.  */
@@ -1178,6 +1178,12 @@ warn_uninit (tree t, const char *gmsgid, void *data)
           ? EXPR_LOCUS (context)
           : &DECL_SOURCE_LOCATION (var));
   warning (0, gmsgid, locus, var);
+  fun_locus = &DECL_SOURCE_LOCATION (cfun->decl);
+  if (locus->file != fun_locus->file
+      || locus->line < fun_locus->line
+      || locus->line > cfun->function_end_locus.line)
+    inform ("%J%qD was declared here", var, var);
+
   TREE_NO_WARNING (var) = 1;
 }