This is the mail archive of the 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]

Incorrect initialisation of SRA bitfield blocks

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 and 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?


	* 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]