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]

PR 18501: Run uninitialized warnings pass before DCE



This patch fixes PR 18501 but introduces the possibility of emitting false positives with -Wuninitialized. Since we used to run pass_late_warn_uninitialized after the final DCE run, we never got to see those PHI nodes that were dead because of jump threading and CCP.


However, this also means that we fail to diagnose cases like PR 18501:

void
bitmap_print_value_set (void)
{
  unsigned first;

  for (; bmp_iter_set (); )
    {
      if (!first)
	something ();
      first = 0;
    }
}

I analyzed this one in http://gcc.gnu.org/ml/gcc/2004-12/msg00681.html. The problem now is that by not allowing DCE to remove these dead PHIs, we never get to determine if the value of 'first' was read from the default definition.

But, running the warning pass earlier, means that we fail to recognize things like testsuite/gcc.dg/uninit-5.c and testsuite/gcc.dg/uninit-9.c, which have variants of:

	if (cond)
	  x = 1;
	foo();
	if (cond)
	  use(x);

With this patch, we will now give a false positive warning for the snippet above.

The real fix would involve teaching the warning about the conditionals. One possibility would be using Gated Single Assignment. Or we could even try to hack this pattern in.

I'm ambivalent about what to do here. With this patch we now go back to the same behaviour of GCC 3.x, which is both one step forward and one step back (GCC 3.x also gives false positives on uninit-5.c and uninit-9.c).

Richard, Nathan, what do you folks think?


Thanks. Diego.
2004-12-17  Diego Novillo  <dnovillo@redhat.com>

	tree-optimization/18501
	* tree-optimize.c (init_tree_optimization_passes): Run
	pass_late_warn_uninitialized before the last DCE run.

Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.65
diff -d -c -p -u -r2.65 tree-optimize.c
--- tree-optimize.c	30 Nov 2004 15:38:33 -0000	2.65
+++ tree-optimize.c	17 Dec 2004 21:33:44 -0000
@@ -381,12 +381,21 @@ init_tree_optimization_passes (void)
   NEXT_PASS (pass_loop);
   NEXT_PASS (pass_dominator);
   NEXT_PASS (pass_redundant_phi);
+  /* FIXME: If DCE is not run before checking for uninitialized uses,
+     we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c).
+     However, this also causes us to misdiagnose cases that should be
+     real warnings (e.g., testsuite/gcc.dg/pr18501.c).
+     
+     To fix the false positives in uninit-5.c, we would have to
+     account for the predicates protecting the set and the use of each
+     variable.  Using a representation like Gated Single Assignment
+     may help.  */
+  NEXT_PASS (pass_late_warn_uninitialized);
   NEXT_PASS (pass_cd_dce);
   NEXT_PASS (pass_dse);
   NEXT_PASS (pass_forwprop);
   NEXT_PASS (pass_phiopt);
   NEXT_PASS (pass_tail_calls);
-  NEXT_PASS (pass_late_warn_uninitialized);
   NEXT_PASS (pass_del_ssa);
   NEXT_PASS (pass_nrv);
   NEXT_PASS (pass_remove_useless_vars);
Index: testsuite/gcc.dg/pr18501.c
===================================================================
RCS file: testsuite/gcc.dg/pr18501.c
diff -N testsuite/gcc.dg/pr18501.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/pr18501.c	17 Dec 2004 21:34:01 -0000
@@ -0,0 +1,20 @@
+/* Expected uninitialized variable warning.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+unsigned bmp_iter_set ();
+int something (void);
+
+void
+bitmap_print_value_set (void)
+{
+  unsigned first;	/* { dg-warning "may be used" "conditional in loop" } */
+  
+  for (; bmp_iter_set (); )
+    {
+      if (!first)
+	something ();
+      first = 0;
+    }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]