We shouldn't create new VLA array accesses via fold when we are in
gimple form as we have no way to fixup the gimplified element size
and minimal value slots.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
(I'll make my way backwards to the release branches after 4.6.0 is out).

Tested on m68k by Mikael.

Richard.

2011-03-15  Richard Guenther  <rguent...@suse.de>

        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.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c    (revision 170876)
--- gcc/fold-const.c    (working copy)
*************** fold_indirect_ref_1 (location_t loc, tre
*** 15554,15565 ****
        }
        /* *(foo *)&fooarray => fooarray[0] */
        else if (TREE_CODE (optype) == ARRAY_TYPE
!              && type == TREE_TYPE (optype))
        {
          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);
          return build4_loc (loc, ARRAY_REF, type, op, min_val,
                             NULL_TREE, NULL_TREE);
        }
--- 15560,15576 ----
        }
        /* *(foo *)&fooarray => fooarray[0] */
        else if (TREE_CODE (optype) == ARRAY_TYPE
!              && 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);
        }
*************** fold_indirect_ref_1 (location_t loc, tre
*** 15633,15639 ****
  
    /* *(foo *)fooarrptr => (*fooarrptr)[0] */
    if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
!       && type == TREE_TYPE (TREE_TYPE (subtype)))
      {
        tree type_domain;
        tree min_val = size_zero_node;
--- 15644,15652 ----
  
    /* *(foo *)fooarrptr => (*fooarrptr)[0] */
    if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
!       && 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;
*************** fold_indirect_ref_1 (location_t loc, tre
*** 15641,15646 ****
--- 15654,15662 ----
        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);
      }

Reply via email to