This fixes PR 52155.

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

Richard.

2012-02-06  Richard Guenther  <rguent...@suse.de>

        PR tree-optimization/52115
        * tree-sra.c (access_has_replacements_p): New function.
        (sra_modify_assign): Use it to decide whether a use is uninitialized.

        * gcc.c-torture/compile/pr52115.c: New testcase.

Index: gcc/tree-sra.c
===================================================================
*** gcc/tree-sra.c      (revision 183932)
--- gcc/tree-sra.c      (working copy)
*************** access_has_children_p (struct access *ac
*** 440,445 ****
--- 440,459 ----
    return acc && acc->first_child;
  }
  
+ /* Return true iff ACC is (partly) covered by at least one replacement.  */
+ 
+ static bool
+ access_has_replacements_p (struct access *acc)
+ {
+   struct access *child;
+   if (acc->grp_to_be_replaced)
+     return true;
+   for (child = acc->first_child; child; child = child->next_sibling)
+     if (access_has_replacements_p (child))
+       return true;
+   return false;
+ }
+ 
  /* Return a vector of pointers to accesses for the variable given in BASE or
     NULL if there is none.  */
  
*************** sra_modify_assign (gimple *stmt, gimple_
*** 2992,3001 ****
        sra_stats.exprs++;
      }
    else if (racc
-          && !access_has_children_p (racc)
-          && !racc->grp_to_be_replaced
           && !racc->grp_unscalarized_data
!          && TREE_CODE (lhs) == SSA_NAME)
      {
        rhs = get_repl_default_def_ssa_name (racc);
        modify_this_stmt = true;
--- 3006,3014 ----
        sra_stats.exprs++;
      }
    else if (racc
           && !racc->grp_unscalarized_data
!          && TREE_CODE (lhs) == SSA_NAME
!          && !access_has_replacements_p (racc))
      {
        rhs = get_repl_default_def_ssa_name (racc);
        modify_this_stmt = true;
Index: gcc/testsuite/gcc.c-torture/compile/pr52115.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr52115.c       (revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr52115.c       (revision 0)
***************
*** 0 ****
--- 1,26 ----
+ struct S
+ {
+   float f;
+   long l;
+ };
+ 
+ extern int gi;
+ extern float gf;
+ 
+ long foo (long p)
+ {
+   struct S s;
+   float *pf;
+ 
+   s.l = p;
+ 
+   pf = &s.f;
+ 
+   pf++;
+   pf--;
+ 
+   gf = *pf + 3.3;
+   gi = *((short *)pf) + 2;
+ 
+   return s.l + 6;
+ }

Reply via email to