This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Incorrect initialisation of SRA bitfield blocks


On Dec 29, 2007 4:17 PM, Richard Sandiford <rsandifo@nildram.co.uk> wrote:
> g++.dg/opt/nrv4.C is failing for MIPS n32 because SRA does zero
> initialisation _after_ non-default initialisation.  The two may
> overlap when using bitfield blocks, so the former should be done first.
>
> Specifically, we have:
>
> struct GdkColor {
>   long  pixel;
>   short red;
>   short green;
>   short blue;
> };
> ...
>   GdkColor ret={0,1,2,3};
>
> and SRA decides to use a single bitfield block for ret.{red,green}.
> generate_element_init copies { 0, 1, 2, 3 } to the appropriate
> scalarised elements, setting the visited flag for each one.  However,
> the parent element that represents the ret.{red,green} bitfield block
> does not have its visited flag set; only the individual ret.red and
> ret.green elements do.  generate_element_zero therefore zero-initialises
> the block, overwriting the earlier values.
>
> Bootstrapped & regression-tested on x86_64-linux-gnu and
> regression-tested on mips64-linux-gnu.  OK to install?

This is ok.

Thanks,
Richard.

> Richard
>
>
> gcc/
>         * tree-sra.c (scalarize_init): Insert the generate_element_init
>         statements after the generate_element_zero statements.
>
> Index: gcc/tree-sra.c
> ===================================================================
> --- gcc/tree-sra.c      2007-12-28 21:03:58.000000000 +0000
> +++ gcc/tree-sra.c      2007-12-28 21:11:12.000000000 +0000
> @@ -3354,19 +3354,20 @@ scalarize_copy (struct sra_elt *lhs_elt,
>  scalarize_init (struct sra_elt *lhs_elt, tree rhs, block_stmt_iterator *bsi)
>  {
>    bool result = true;
> -  tree list = NULL;
> +  tree list = NULL, init_list = NULL;
>
>    /* Generate initialization statements for all members extant in the RHS.  */
>    if (rhs)
>      {
>        /* Unshare the expression just in case this is from a decl's initial.  */
>        rhs = unshare_expr (rhs);
> -      result = generate_element_init (lhs_elt, rhs, &list);
> +      result = generate_element_init (lhs_elt, rhs, &init_list);
>      }
>
>    /* CONSTRUCTOR is defined such that any member not mentioned is assigned
>       a zero value.  Initialize the rest of the instantiated elements.  */
>    generate_element_zero (lhs_elt, &list);
> +  append_to_statement_list (init_list, &list);
>
>    if (!result)
>      {
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]