OSDN Git Service

2008-08-10 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Aug 2008 18:46:10 +0000 (18:46 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Aug 2008 18:46:10 +0000 (18:46 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138933 138bc75d-0d04-0410-961f-82ee72b054a4

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 5451f95..bda376e 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 d242cad..2ebd473 100644 (file)
@@ -1,5 +1,11 @@
 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
        * gcc.dg/pr36901.h: Do not depend on limits.h.
        * gcc.dg/pr36901-3.c: Update.
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 4c7592e..74968bf 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)
@@ -1521,6 +1524,19 @@ execute_early_warn_uninitialized (void)
 }
 
 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)
 {
   basic_block bb;
@@ -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))