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]

[PATCH] Fix PR42357


This fixes PR42357, both an ICE and possible code pessimization.

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

Richard.

2009-12-13  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/42357
	* tree-sra.c (sra_modify_assign): Do not tear apart struct copies.

	* g++.dg/torture/pr42357.C: New testcase.

Index: gcc/tree-sra.c
===================================================================
*** gcc/tree-sra.c	(revision 155188)
--- gcc/tree-sra.c	(working copy)
*************** sra_modify_assign (gimple *stmt, gimple_
*** 2441,2447 ****
  	  if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
  	    {
  	      rhs = fold_build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs);
! 	      if (!is_gimple_reg (lhs))
  		force_gimple_rhs = true;
  	    }
  	}
--- 2441,2448 ----
  	  if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
  	    {
  	      rhs = fold_build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs);
! 	      if (is_gimple_reg_type (TREE_TYPE (lhs))
! 		  && TREE_CODE (lhs) != SSA_NAME)
  		force_gimple_rhs = true;
  	    }
  	}
Index: gcc/testsuite/g++.dg/torture/pr42357.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr42357.C	(revision 0)
--- gcc/testsuite/g++.dg/torture/pr42357.C	(revision 0)
***************
*** 0 ****
--- 1,30 ----
+ // { dg-do compile }
+ typedef unsigned char uint8;
+ typedef unsigned int uint32;
+ class PixelARGB {
+ public:
+     ~PixelARGB() throw() { }
+     PixelARGB (const uint32 argb_) throw() : argb (argb_)     { }
+     inline __attribute__((always_inline)) uint8 getRed() const throw() {
+ 	return components.r;
+     }
+     union     {
+ 	uint32 argb;
+ 	struct         {
+ 	    uint8 b, g, r, a;
+ 	} components;
+     };
+ };
+ class Colour {
+ public:
+     Colour() throw() : argb (0) {};
+     uint8 getRed() const throw() {
+ 	return argb.getRed();
+     }
+     PixelARGB argb;
+ };
+ uint8 writeImage (void) {
+     Colour pixel;
+     pixel = Colour ();
+     return pixel.getRed();
+ }


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