[backport from gcc-4.7/trunk, fixes PR48031 on m68k ] gcc/ 2011-03-15 Richard Guenther PR middle-end/48031 * fold-const.c (fold_indirect_ref_1): Do not create new variable-sized or variable-indexed array accesses when in gimple form. --- gcc-4.6-20110312/gcc/fold-const.c.~1~ 2011-03-08 11:43:10.000000000 +0100 +++ gcc-4.6-20110312/gcc/fold-const.c 2011-03-16 15:08:43.000000000 +0100 @@ -15554,12 +15554,17 @@ fold_indirect_ref_1 (location_t loc, tre } /* *(foo *)&fooarray => fooarray[0] */ else if (TREE_CODE (optype) == ARRAY_TYPE - && type == TREE_TYPE (optype)) + && type == TREE_TYPE (optype) + && (!in_gimple_form + || TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)) { tree type_domain = TYPE_DOMAIN (optype); tree min_val = size_zero_node; if (type_domain && TYPE_MIN_VALUE (type_domain)) min_val = TYPE_MIN_VALUE (type_domain); + if (in_gimple_form + && TREE_CODE (min_val) != INTEGER_CST) + return NULL_TREE; return build4_loc (loc, ARRAY_REF, type, op, min_val, NULL_TREE, NULL_TREE); } @@ -15633,7 +15638,9 @@ fold_indirect_ref_1 (location_t loc, tre /* *(foo *)fooarrptr => (*fooarrptr)[0] */ if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE - && type == TREE_TYPE (TREE_TYPE (subtype))) + && type == TREE_TYPE (TREE_TYPE (subtype)) + && (!in_gimple_form + || TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)) { tree type_domain; tree min_val = size_zero_node; @@ -15641,6 +15648,9 @@ fold_indirect_ref_1 (location_t loc, tre type_domain = TYPE_DOMAIN (TREE_TYPE (sub)); if (type_domain && TYPE_MIN_VALUE (type_domain)) min_val = TYPE_MIN_VALUE (type_domain); + if (in_gimple_form + && TREE_CODE (min_val) != INTEGER_CST) + return NULL_TREE; return build4_loc (loc, ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE); }