On Thu, Jul 14, 2011 at 11:44 PM, Eric Botcazou <ebotca...@adacore.com> wrote:
> Hi,
>
> this is a regression present on mainline and 4.6 branch.  The compiler crashes
> during gimplification because there is a COMPOUND_EXPR shared between the
> TYPE_SIZE and TYPE_SIZE_UNIT expressions of an array type.  Now this isn't
> supposed to happen because we run an unsharing pass before gimplification.
>
> The problem here is that we have a forward declaration (DECL_EXPR) of a 
> pointer
> type to the array type.  So, during the marking phase of the unsharing pass,
> the array type gets marked as visited through the pointer, which prevents it
> from being walked during the same phase when its own DECL_EXPR is processed.
>
> This pointer/pointed-to type business is an old pattern.  Five years ago,
> Olivier changed gimplify_type_sizes like so:
>
> 2006-10-06  Olivier Hainque  <hain...@adacore.com>
>
>        * gimplify.c (gimplify_type_sizes) [POINTER_TYPE, REFERENCE_TYPE]:
>        Don't recurse on the pointed-to type.
>
> because of a related problem.  It turns out that we need the same change in 
> the
> DECL_EXPR case of walk_tree_1 to fix the bug at hand, which is sort of logical
> as there is a strong relationship between them:
>
>    case DECL_EXPR:
>      /* If this is a TYPE_DECL, walk into the fields of the type that it's
>         defining.  We only want to walk into these fields of a type in this
>         case and not in the general case of a mere reference to the type.
>
>         The criterion is as follows: if the field can be an expression, it
>         must be walked only here.  This should be in keeping with the fields
>         that are directly gimplified in gimplify_type_sizes in order for the
>         mark/copy-if-shared/unmark machinery of the gimplifier to work with
>         variable-sized types.
>
>         Note that DECLs get walked as part of processing the BIND_EXPR.  */
>
>
> Tested on x86_64-suse-linux, OK for mainline and 4.6 branch?

Ok.

Thanks,
Richard.

>
> 2011-07-14  Eric Botcazou  <ebotca...@adacore.com>
>
>        PR middle-end/49732
>        * tree.c (walk_tree_1) <DECL_EXPR>: Do not walk a pointed-to type.
>
>
> 2011-07-14  Eric Botcazou  <ebotca...@adacore.com>
>
>        * gnat.dg/pointer_controlled.adb: New test.
>
>
> --
> Eric Botcazou
>

Reply via email to