[PATCH] Fix PR42730
Richard Guenther
rguenther@suse.de
Wed Jan 13 22:19:00 GMT 2010
This fixes PR42730 - maybe_fold_offset_to_reference ends up
choosing the wrong union field. The easy fix is to simply
avoid doing the extra work for zero offsets.
Bootstrapped and tested on x86-64_unknown-linux-gnu, applied to trunk.
Richard.
2010-01-13 Richard Guenther <rguenther@suse.de>
PR tree-optimization/42730
* tree-ssa-ccp.c (maybe_fold_stmt_indirect): Add shortcut for
offset zero.
* gcc.c-torture/compile/pr42730.c: New testcase.
Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc/tree-ssa-ccp.c (revision 155867)
--- gcc/tree-ssa-ccp.c (working copy)
*************** maybe_fold_stmt_indirect (tree expr, tre
*** 2120,2125 ****
--- 2120,2129 ----
&& is_gimple_min_invariant (DECL_INITIAL (base)))
return DECL_INITIAL (base);
+ /* If there is no offset involved simply return the folded base. */
+ if (integer_zerop (offset))
+ return base;
+
/* Try folding *(&B+O) to B.X. */
t = maybe_fold_offset_to_reference (loc, base_addr, offset,
TREE_TYPE (expr));
Index: gcc/testsuite/gcc.c-torture/compile/pr42730.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr42730.c (revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr42730.c (revision 0)
***************
*** 0 ****
--- 1,14 ----
+ union bzz
+ {
+ unsigned *pa;
+ void *pv;
+ };
+
+ void foo (void)
+ {
+ union bzz u;
+ void **x;
+ void *y = 0;
+ x = &u.pv;
+ *x = y;
+ }
More information about the Gcc-patches
mailing list