This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR35609, spurious "is" used uninitialized warning


On Tue, 18 Mar 2008, Diego Novillo wrote:

> On 3/18/08 1:53 PM, Richard Guenther wrote:
> 
> > 2008-03-18  Richard Guenther  <rguenther@suse.de>
> > 
> >  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.
> 
> OK with
> 
> > + + static bool always_executed;
> 
> I would rather carry this into the walk_tree recursion via 'data'.  I'm
> actually a bit surprised we haven't run into this one earlier.  But these
> warning are not very strong, so I guess I shouldn't be.
> 
> > --- 1432,1441 ----
> >       case SSA_NAME:
> >           /* We only do data flow with SSA_NAMEs, so that's all we
> >   	 can warn about.  */
> > !       if (always_executed)
> > !         warn_uninit (t, "%H%qD is used uninitialized in this function",
> > !       data);
> > !       else
> > !         warn_uninit (t, "%H%qD maybe used uninitialized in this function",
> > !data);
> 
> s/maybe/may be/

This is what I committed.

Richard.

2008-03-18  Richard Guenther  <rguenther@suse.de>

	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.

Index: testsuite/gcc.dg/uninit-15.c
===================================================================
*** testsuite/gcc.dg/uninit-15.c	(revision 0)
--- testsuite/gcc.dg/uninit-15.c	(revision 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();
+ }

Index: tree-ssa.c
===================================================================
*** tree-ssa.c	(revision 133314)
--- tree-ssa.c	(working copy)
*************** warn_uninit (tree t, const char *gmsgid,
*** 1416,1428 ****
  
    TREE_NO_WARNING (var) = 1;
  }
!    
  /* 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)
  {
    tree t = *tp;
  
    switch (TREE_CODE (t))
--- 1416,1434 ----
  
    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_)
  {
+   struct walk_data *data = (struct walk_data *)data_;
    tree t = *tp;
  
    switch (TREE_CODE (t))
*************** warn_uninitialized_var (tree *tp, int *w
*** 1430,1436 ****
      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);
        *walk_subtrees = 0;
        break;
  
--- 1436,1447 ----
      case SSA_NAME:
        /* We only do data flow with SSA_NAMEs, so that's all we
  	 can warn about.  */
!       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;
  
*************** execute_early_warn_uninitialized (void)
*** 1478,1491 ****
  {
    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);
!       }
    return 0;
  }
  
--- 1489,1509 ----
  {
    block_stmt_iterator bsi;
    basic_block bb;
+   struct walk_data data;
+ 
+   calculate_dominance_info (CDI_POST_DOMINATORS);
  
    FOR_EACH_BB (bb)
!     {
!       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;
  }
  
Index: testsuite/gcc.dg/uninit-16.c
===================================================================
*** testsuite/gcc.dg/uninit-16.c	(revision 0)
--- testsuite/gcc.dg/uninit-16.c	(revision 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;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]