diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-10 18:46:10 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-10 18:46:10 +0000 |
commit | de9a4397e956637cb26a9d6144ccc51a090cad68 (patch) | |
tree | 2e853c76bf4b389350eb7d5baab1a61affb8af4e /gcc | |
parent | 21c9aaf983c7c43e78893a24be40634adc443614 (diff) | |
download | gcc-de9a4397e956637cb26a9d6144ccc51a090cad68.zip gcc-de9a4397e956637cb26a9d6144ccc51a090cad68.tar.gz gcc-de9a4397e956637cb26a9d6144ccc51a090cad68.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-pr20644-O0.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/uninit-pr20644.c | 24 | ||||
-rw-r--r-- | gcc/tree-ssa.c | 22 |
5 files changed, 83 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5451f95..bda376e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d242cad..2ebd473 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..092d411 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr20644-O0.c @@ -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 index 0000000..e13910b --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr20644.c @@ -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; +} diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 4c7592e..74968bf 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -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)) |