[PATCH] Fix PR39713

Richard Guenther rguenther@suse.de
Sat Apr 11 07:28:00 GMT 2009


This fixes PR39713 where we leak reference trees into the vn_nary
components of an inserted expression.  We shouldn't do that.

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

Richard.

2009-04-10  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/39713
	* tree-ssa-sccvn.c (vn_get_expr_for): Make sure built
	reference trees have SSA_NAME operands.

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

Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c	(revision 145876)
--- gcc/tree-ssa-sccvn.c	(working copy)
*************** vn_get_expr_for (tree name)
*** 257,265 ****
    switch (TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)))
      {
      case tcc_reference:
!       if (gimple_assign_rhs_code (def_stmt) == VIEW_CONVERT_EXPR
! 	  || gimple_assign_rhs_code (def_stmt) == REALPART_EXPR
! 	  || gimple_assign_rhs_code (def_stmt) == IMAGPART_EXPR)
  	expr = fold_build1 (gimple_assign_rhs_code (def_stmt),
  			    gimple_expr_type (def_stmt),
  			    TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0));
--- 257,266 ----
    switch (TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)))
      {
      case tcc_reference:
!       if ((gimple_assign_rhs_code (def_stmt) == VIEW_CONVERT_EXPR
! 	   || gimple_assign_rhs_code (def_stmt) == REALPART_EXPR
! 	   || gimple_assign_rhs_code (def_stmt) == IMAGPART_EXPR)
! 	  && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME)
  	expr = fold_build1 (gimple_assign_rhs_code (def_stmt),
  			    gimple_expr_type (def_stmt),
  			    TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0));
Index: gcc/testsuite/g++.dg/torture/pr39713.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr39713.C	(revision 0)
--- gcc/testsuite/g++.dg/torture/pr39713.C	(revision 0)
***************
*** 0 ****
--- 1,25 ----
+ /* { dg-do compile } */
+ 
+ template <typename To, typename From>
+ static inline To
+ bitwise_cast (From from)
+ {
+   union
+     {
+       From f;
+       To t;
+     } u;
+   u.f = from;
+   return u.t;
+ }
+ 
+ extern void foo (unsigned char *);
+ 
+ double
+ bar ()
+ {
+   unsigned char b[sizeof (unsigned long long)];
+   foo (b);
+   return bitwise_cast<double> (*(unsigned long long *) b);
+ }
+ 



More information about the Gcc-patches mailing list