From: Richard Guenther Date: Wed, 19 Mar 2008 10:44:52 +0000 (+0000) Subject: re PR tree-optimization/35609 ("is used uninitialized in this function" should be... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8cb3ee3785019dc4b2566360816f0b83aeea4e2e;p=gcc.git re PR tree-optimization/35609 ("is used uninitialized in this function" should be may warning) 2008-03-19 Richard Guenther PR middle-end/35609 * tree-ssa.c (always_executed): New global flag. (warn_uninitialized_var): If !always_executed warn with "maybe" instead of "is". (execute_early_warn_uninitialized): Compute post-dominators. Initialize always_executed before processing each basic block. * gcc.dg/testsuite/uninit-15.c: New testcase. * gcc.dg/testsuite/uninit-16.c: Likewise. From-SVN: r133341 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d3601a7827d..0dc711d43f0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2008-03-19 Richard Guenther + + PR middle-end/35609 + * tree-ssa.c (always_executed): New global flag. + (warn_uninitialized_var): If !always_executed warn with "maybe" + instead of "is". + (execute_early_warn_uninitialized): Compute post-dominators. + Initialize always_executed before processing each basic block. + 2008-03-18 Mikulas Patocka PR target/35504 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a303924ca4..2aacfe4a480 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-03-19 Richard Guenther + + PR middle-end/35609 + * gcc.dg/testsuite/uninit-15.c: New testcase. + * gcc.dg/testsuite/uninit-16.c: Likewise. + 2008-03-18 Mikulas Patocka PR target/35504 diff --git a/gcc/testsuite/gcc.dg/uninit-15.c b/gcc/testsuite/gcc.dg/uninit-15.c new file mode 100644 index 00000000000..dee7a3b211c --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-15.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +inline int foo (int i) +{ + if (i) return 1; /* { dg-warning "is used uninitialized" } */ + return 0; +} + +void baz(); + +void bar() +{ + int j; /* { dg-message "was declared here" } */ + for (; foo(j); ++j) + baz(); +} diff --git a/gcc/testsuite/gcc.dg/uninit-16.c b/gcc/testsuite/gcc.dg/uninit-16.c new file mode 100644 index 00000000000..aefb5e5f7d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-16.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wuninitialized" } */ + +int foo, bar; + +void decode_reloc(int reloc, int *is_alt) +{ + if (reloc >= 20) + *is_alt = 1; + else if (reloc >= 10) + *is_alt = 0; +} + +void testfunc() +{ + int alt_reloc; + + decode_reloc(foo, &alt_reloc); + + if (alt_reloc) /* { dg-warning "may be used uninitialized" } */ + bar = 42; +} diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index a036346dee2..5a67aa8273e 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1416,13 +1416,19 @@ warn_uninit (tree t, const char *gmsgid, void *data) TREE_NO_WARNING (var) = 1; } - + +struct walk_data { + tree stmt; + bool always_executed; +}; + /* Called via walk_tree, look for SSA_NAMEs that have empty definitions and warn about them. */ static tree -warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data) +warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data_) { + struct walk_data *data = (struct walk_data *)data_; tree t = *tp; switch (TREE_CODE (t)) @@ -1430,7 +1436,12 @@ warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data) case SSA_NAME: /* We only do data flow with SSA_NAMEs, so that's all we can warn about. */ - warn_uninit (t, "%H%qD is used uninitialized in this function", data); + if (data->always_executed) + warn_uninit (t, "%H%qD is used uninitialized in this function", + data->stmt); + else + warn_uninit (t, "%H%qD may be used uninitialized in this function", + data->stmt); *walk_subtrees = 0; break; @@ -1478,14 +1489,21 @@ execute_early_warn_uninitialized (void) { block_stmt_iterator bsi; basic_block bb; + struct walk_data data; + + calculate_dominance_info (CDI_POST_DOMINATORS); FOR_EACH_BB (bb) - for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi)) - { - tree context = bsi_stmt (bsi); - walk_tree (bsi_stmt_ptr (bsi), warn_uninitialized_var, - context, NULL); - } + { + data.always_executed = dominated_by_p (CDI_POST_DOMINATORS, + single_succ (ENTRY_BLOCK_PTR), bb); + for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi)) + { + data.stmt = bsi_stmt (bsi); + walk_tree (bsi_stmt_ptr (bsi), warn_uninitialized_var, + &data, NULL); + } + } return 0; }