[PATCH] Fix PR38851, missing DSE of zero-sized stores

Richard Guenther rguenther@suse.de
Mon Jan 26 11:12:00 GMT 2009


This fixes the annoying uninitialized warnings that occur with
zero-sized stores that result from initialization of empty C++ classes.
Fixed by extending simple DSE to remove these stores.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2009-01-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/38851
	* Makefile.in (tree-ssa-dse.o): Add langhooks.h.
	* tree-ssa-dse.c: Include langhooks.h
	(execute_simple_dse): Remove stores with zero size.

	* g++.dg/warn/Wuninitialized-1.C: New testcase.

Index: gcc/tree-ssa-dse.c
===================================================================
*** gcc/tree-ssa-dse.c.orig	2009-01-25 22:57:52.000000000 +0100
--- gcc/tree-ssa-dse.c	2009-01-25 22:58:07.000000000 +0100
*************** along with GCC; see the file COPYING3.  
*** 34,39 ****
--- 34,40 ----
  #include "tree-dump.h"
  #include "domwalk.h"
  #include "flags.h"
+ #include "langhooks.h"
  
  /* This file implements dead store elimination.
  
*************** execute_simple_dse (void)
*** 660,679 ****
          tree op;
  	bool removed = false;
          ssa_op_iter iter;
  
! 	if (gimple_stored_syms (stmt)
! 	    && !bitmap_empty_p (gimple_stored_syms (stmt))
!             && (is_gimple_assign (stmt)
! 	        || (is_gimple_call (stmt)
!                     && gimple_call_lhs (stmt)))
! 	    && !bitmap_intersect_p (gimple_stored_syms (stmt), variables_loaded))
  	  {
  	    unsigned int i;
  	    bitmap_iterator bi;
  	    bool dead = true;
  
- 
- 
  	    /* See if STMT only stores to write-only variables and
  	       verify that there are no volatile operands.  tree-ssa-operands
  	       sets has_volatile_ops flag for all statements involving
--- 661,695 ----
          tree op;
  	bool removed = false;
          ssa_op_iter iter;
+ 	tree size;
  
! 	if (is_gimple_assign (stmt)
! 	    && AGGREGATE_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt)))
! 	    && (size = lang_hooks.expr_size (gimple_assign_lhs (stmt)))
! 	    && integer_zerop (size))
! 	  {
! 	    if (dump_file && (dump_flags & TDF_DETAILS))
! 	      {
! 		fprintf (dump_file, "  Deleted zero-sized store '");
! 		print_gimple_stmt (dump_file, stmt, 0, dump_flags);
! 		fprintf (dump_file, "'\n");
! 	      }
! 	    removed = true;
! 	    gsi_remove (&gsi, true);
! 	    todo |= TODO_cleanup_cfg;
! 	  }
! 	else if (gimple_stored_syms (stmt)
! 		 && !bitmap_empty_p (gimple_stored_syms (stmt))
! 		 && (is_gimple_assign (stmt)
! 		     || (is_gimple_call (stmt)
! 			 && gimple_call_lhs (stmt)))
! 		 && !bitmap_intersect_p (gimple_stored_syms (stmt),
! 					 variables_loaded))
  	  {
  	    unsigned int i;
  	    bitmap_iterator bi;
  	    bool dead = true;
  
  	    /* See if STMT only stores to write-only variables and
  	       verify that there are no volatile operands.  tree-ssa-operands
  	       sets has_volatile_ops flag for all statements involving
Index: gcc/Makefile.in
===================================================================
*** gcc/Makefile.in.orig	2009-01-25 23:01:06.000000000 +0100
--- gcc/Makefile.in	2009-01-25 23:01:21.000000000 +0100
*************** tree-outof-ssa.o : tree-outof-ssa.c $(TR
*** 2110,2116 ****
  tree-ssa-dse.o : tree-ssa-dse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
     $(TM_H) $(GGC_H) $(TREE_H) $(RTL_H) $(TM_P_H) $(BASIC_BLOCK_H) \
     $(TREE_FLOW_H) tree-pass.h $(TREE_DUMP_H) domwalk.h $(FLAGS_H) \
!    $(DIAGNOSTIC_H) $(TIMEVAR_H)
  tree-ssa-forwprop.o : tree-ssa-forwprop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
     $(TM_H) $(GGC_H) $(TREE_H) $(RTL_H) $(TM_P_H) $(BASIC_BLOCK_H) \
     $(TREE_FLOW_H) tree-pass.h $(TREE_DUMP_H) $(DIAGNOSTIC_H) $(TIMEVAR_H) \
--- 2110,2116 ----
  tree-ssa-dse.o : tree-ssa-dse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
     $(TM_H) $(GGC_H) $(TREE_H) $(RTL_H) $(TM_P_H) $(BASIC_BLOCK_H) \
     $(TREE_FLOW_H) tree-pass.h $(TREE_DUMP_H) domwalk.h $(FLAGS_H) \
!    $(DIAGNOSTIC_H) $(TIMEVAR_H) langhooks.h
  tree-ssa-forwprop.o : tree-ssa-forwprop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
     $(TM_H) $(GGC_H) $(TREE_H) $(RTL_H) $(TM_P_H) $(BASIC_BLOCK_H) \
     $(TREE_FLOW_H) tree-pass.h $(TREE_DUMP_H) $(DIAGNOSTIC_H) $(TIMEVAR_H) \



More information about the Gcc-patches mailing list