re PR middle-end/20644 (bogus uninitialized warning on unused variable)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Sun, 10 Aug 2008 18:46:10 +0000 (18:46 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Sun, 10 Aug 2008 18:46:10 +0000 (18:46 +0000)
2008-08-10  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

PR middle-end/20644
* tree-ssa.c (struct walk_data): Add new flag
warn_possibly_uninitialized.
(warn_uninitialized_var): Use it.
(warn_uninitialized_vars): New.
(execute_early_warn_uninitialized): Call it.
(execute_late_warn_uninitialized): Likewise.
testsuite/
* gcc.dg/uninit-pr20644-O0.c: New.
* gcc.dg/uninit-pr20644.c: New.

From-SVN: r138933

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

index 5451f9506066aaba7e86354e82b00f77ad9041a5..bda376e0302d0cddf6c54936e5235e5951e44869 100644 (file)
@@ -1,3 +1,13 @@
+2008-08-10  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR middle-end/20644
+       * tree-ssa.c (struct walk_data): Add new flag
+       warn_possibly_uninitialized.
+       (warn_uninitialized_var): Use it.
+       (warn_uninitialized_vars): New.
+       (execute_early_warn_uninitialized): Call it.
+       (execute_late_warn_uninitialized): Likewise.
+
 2008-08-09  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR middle-end/36238
index d242cad96214221538d651b1510eba4054f46286..2ebd473c2228d39890a1475774a08267f22ce42b 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-10  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR middle-end/20644
+       * gcc.dg/uninit-pr20644-O0.c: New.
+       * gcc.dg/uninit-pr20644.c: New.
+
 2008-08-10  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR 36901
diff --git a/gcc/testsuite/gcc.dg/uninit-pr20644-O0.c b/gcc/testsuite/gcc.dg/uninit-pr20644-O0.c
new file mode 100644 (file)
index 0000000..092d411
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR 20644 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -Wuninitialized" } */
+int foo ()
+{
+  int i = 0;
+  int j;
+
+  if (1 == i)
+    return j; /* { dg-bogus "uninitialized" "uninitialized" { xfail *-*-* } 10 } */
+
+  return 0;
+}
+
+int bar ()
+{
+  int i = 1;
+  int j; 
+
+  if (1 == i)
+    return j; /* { dg-warning "uninitialized" "uninitialized" { target *-*-* } 21 } */
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-pr20644.c b/gcc/testsuite/gcc.dg/uninit-pr20644.c
new file mode 100644 (file)
index 0000000..e13910b
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR 20644 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+int foo ()
+{
+  int i = 0;
+  int j;
+
+  if (1 == i)
+    return j;
+
+  return 0;
+}
+
+int bar ()
+{
+  int i = 1;
+  int j;
+
+  if (1 == i)
+    return j; /* { dg-warning "uninitialized" "uninitialized" { target *-*-* } 18 } */
+
+  return 0;
+}
index 4c7592e6f184fe941beed6a7f28b152a542ffed8..74968bf5539290def53b162b636f914f68f340bc 100644 (file)
@@ -1430,6 +1430,7 @@ warn_uninit (tree t, const char *gmsgid, void *data)
 struct walk_data {
   gimple stmt;
   bool always_executed;
+  bool warn_possibly_uninitialized;
 };
 
 /* Called via walk_tree, look for SSA_NAMEs that have empty definitions
@@ -1450,7 +1451,7 @@ warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data_)
       if (data->always_executed)
         warn_uninit (t, "%qD is used uninitialized in this function",
                     data->stmt);
-      else
+      else if (data->warn_possibly_uninitialized)
         warn_uninit (t, "%qD may be used uninitialized in this function",
                     data->stmt);
       *walk_subtrees = 0;
@@ -1496,12 +1497,14 @@ warn_uninitialized_phi (gimple phi)
 }
 
 static unsigned int
-execute_early_warn_uninitialized (void)
+warn_uninitialized_vars (bool warn_possibly_uninitialized)
 {
   gimple_stmt_iterator gsi;
   basic_block bb;
   struct walk_data data;
 
+  data.warn_possibly_uninitialized = warn_possibly_uninitialized;
+
   calculate_dominance_info (CDI_POST_DOMINATORS);
 
   FOR_EACH_BB (bb)
@@ -1520,6 +1523,19 @@ execute_early_warn_uninitialized (void)
   return 0;
 }
 
+static unsigned int
+execute_early_warn_uninitialized (void)
+{
+  /* Currently, this pass runs always but
+     execute_late_warn_uninitialized only runs with optimization. With
+     optimization we want to warn about possible uninitialized as late
+     as possible, thus don't do it here.  However, without
+     optimization we need to warn here about "may be uninitialized".
+  */
+  warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize);
+  return 0;
+}
+
 static unsigned int
 execute_late_warn_uninitialized (void)
 {
@@ -1529,7 +1545,7 @@ execute_late_warn_uninitialized (void)
   /* Re-do the plain uninitialized variable check, as optimization may have
      straightened control flow.  Do this first so that we don't accidentally
      get a "may be" warning when we'd have seen an "is" warning later.  */
-  execute_early_warn_uninitialized ();
+  warn_uninitialized_vars (/*warn_possibly_uninitialized=*/1);
 
   FOR_EACH_BB (bb)
     for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))