This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] tree-ssa.c: Fix PR tree-optimization/17506.


Hi,

Attached is a patch to fix PR tree-optimization/17506.  (I merely
tested the patch attached to the PR.)

Given the testcase, gcc without this patch issues

  pr17506.c: In function âbarâ:
  pr17506.c:11: warning: âjâ is used uninitialized in this function

With this patch, gcc issues

  pr17506.c: In function âbarâ:
  pr17506.c:11: warning: âjâ is used uninitialized in this function
  pr17506.c:21: note: âjâ was declared here

Notice that this patch adds a note.  I personally feel that the
warning at line 11 is still confusing, but I am hoping that the note
will alleviate the confusion.

The patch issues the note whenever the unused variable is declared
outside the current function being compiled.

Tested on x86_64-pc-linux-gnu.  OK to apply?

Kazu Hirata

2006-08-28  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  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
	    Kazu Hirata  <kazu@codesourcery.com>

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

Index: tree-ssa.c
===================================================================
--- tree-ssa.c	(revision 116501)
+++ tree-ssa.c	(working copy)
@@ -1154,7 +1154,7 @@ warn_uninit (tree t, const char *gmsgid,
   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,
 	   ? 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;
 }
    
Index: testsuite/gcc.dg/pr17506.c
===================================================================
--- testsuite/gcc.dg/pr17506.c	(revision 0)
+++ testsuite/gcc.dg/pr17506.c	(revision 0)
@@ -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]