This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/20644] bogus uninitialized warning on unused variable
- From: "manu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Aug 2007 14:17:22 -0000
- Subject: [Bug middle-end/20644] bogus uninitialized warning on unused variable
- References: <bug-20644-1186@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #9 from manu at gcc dot gnu dot org 2007-08-23 14:17 -------
(In reply to comment #8)
> Despite what I said before, for this particular case, we should never give a
> "is used" warning if the BB is not executed with 100% probability. Hmm, I'll
> check whether we can detect this.
We could avoid the warning by doing the following:
--- gcc/tree-ssa.c (revision 126606)
+++ gcc/tree-ssa.c (working copy)
@@ -1302,8 +1334,11 @@
}
}
static unsigned int
execute_early_warn_uninitialized (void)
{
block_stmt_iterator bsi;
basic_block bb;
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);
- }
+ {
+ edge e;
+ edge_iterator ei;
+ FOR_EACH_EDGE (e, ei, bb->preds)
+ if (e->flags & EDGE_FALLTHRU)
+ {
+ 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);
+ }
+ break;
+ }
+ }
I think this is the "Right Thing To Do". Otherwise, we are giving "is used"
warnings for BBs that are conditionally executed. On the other hand, we will
miss a few of the correct warnings that we get by chance by not doing the
"Right Thing".
Comments?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20644