This fixes the tree inliner which fails to remap the type of MEM_REFs. That downstream causes issues when LTO re-computes TYPE_CANONICAL and fails during stmt verification.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. I'm considering this also for 4.6 as it is latent there. Richard. 2011-05-11 Richard Guenther <rguent...@suse.de> PR middle-end/48953 * tree-inline.c (remap_gimple_op_r): Also remap types of MEM_REFs. * gcc.dg/torture/pr48953.c: New testcase. Index: gcc/tree-inline.c =================================================================== *** gcc/tree-inline.c (revision 173649) --- gcc/tree-inline.c (working copy) *************** remap_gimple_op_r (tree *tp, int *walk_s *** 811,819 **** --- 811,825 ---- { /* Otherwise, just copy the node. Note that copy_tree_r already knows not to copy VAR_DECLs, etc., so this is safe. */ + + /* We should never have TREE_BLOCK set on non-statements. */ + if (EXPR_P (*tp)) + gcc_assert (!TREE_BLOCK (*tp)); + if (TREE_CODE (*tp) == MEM_REF) { tree ptr = TREE_OPERAND (*tp, 0); + tree type = remap_type (TREE_TYPE (*tp), id); tree old = *tp; tree tem; *************** remap_gimple_op_r (tree *tp, int *walk_s *** 824,830 **** if ((tem = maybe_fold_offset_to_reference (EXPR_LOCATION (*tp), ptr, TREE_OPERAND (*tp, 1), ! TREE_TYPE (*tp))) && TREE_THIS_VOLATILE (tem) == TREE_THIS_VOLATILE (old)) { tree *tem_basep = &tem; --- 830,836 ---- if ((tem = maybe_fold_offset_to_reference (EXPR_LOCATION (*tp), ptr, TREE_OPERAND (*tp, 1), ! type)) && TREE_THIS_VOLATILE (tem) == TREE_THIS_VOLATILE (old)) { tree *tem_basep = &tem; *************** remap_gimple_op_r (tree *tp, int *walk_s *** 846,852 **** } else { ! *tp = fold_build2 (MEM_REF, TREE_TYPE (*tp), ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_THIS_NOTRAP (*tp) = TREE_THIS_NOTRAP (old); --- 852,858 ---- } else { ! *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_THIS_NOTRAP (*tp) = TREE_THIS_NOTRAP (old); *************** remap_gimple_op_r (tree *tp, int *walk_s *** 860,865 **** --- 866,874 ---- tweak some special cases. */ copy_tree_r (tp, walk_subtrees, NULL); + if (TREE_CODE (*tp) != OMP_CLAUSE) + TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id); + /* Global variables we haven't seen yet need to go into referenced vars. If not referenced from types only. */ if (gimple_in_ssa_p (cfun) *************** remap_gimple_op_r (tree *tp, int *walk_s *** 868,880 **** && !processing_debug_stmt) add_referenced_var (*tp); - /* We should never have TREE_BLOCK set on non-statements. */ - if (EXPR_P (*tp)) - gcc_assert (!TREE_BLOCK (*tp)); - - if (TREE_CODE (*tp) != OMP_CLAUSE) - TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id); - if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3)) { /* The copied TARGET_EXPR has never been expanded, even if the --- 877,882 ---- Index: gcc/testsuite/gcc.dg/torture/pr48953.c =================================================================== *** gcc/testsuite/gcc.dg/torture/pr48953.c (revision 0) --- gcc/testsuite/gcc.dg/torture/pr48953.c (revision 0) *************** *** 0 **** --- 1,17 ---- + /* { dg-do run } */ + /* { dg-options "-fno-tree-dce" } */ + + static inline int foo (int n, int k) + { + struct S + { + int i[n]; + int value; + } s[2]; + return s[k].value = 0; + } + + int main () + { + return foo (2, 0); + }