re PR middle-end/20644 (bogus uninitialized warning on unused variable)

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
parent 21c9aaf9
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
......
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.
......
/* 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;
}
/* 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;
}
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment