zero sized initializers with side effects discarded

Andrew Pinski pinskia@physics.uc.edu
Fri Sep 9 13:04:00 GMT 2005


On Sep 9, 2005, at 8:30 AM, Olivier Hainque wrote:

> Hello,
>
> I have been experimenting with a simple patch adding side effects
> checks to the conditions, like "! TREE_SIDE_EFFECTS (value)"
> in init_ctor_eval

Yes the one in needs to gimplify only the expression as a statement
and not add a modify statement.  More on the testcase later.


> and "! TREE_SIDE_EFFECTS (*from_p)" in modify_expr.

You should not need the check in modify_expr as the side effects are
never mishandled as we always will add the lhs and rhs to the
instruction stream:
   /* For zero sized types only gimplify the left hand side and right 
hand side
      as statements and throw away the assignment.  */
   if (zero_sized_type (TREE_TYPE (*from_p)))
     {
       gimplify_stmt (from_p);
       gimplify_stmt (to_p);
       append_to_statement_list (*from_p, pre_p);
       append_to_statement_list (*to_p, pre_p);
       *expr_p = NULL_TREE;
       return GS_ALL_DONE;
     }

I already made sure of that because it was ran into with
some of the vararg testcases on some targets.


Now back to init_ctor_eval.  Here is a testcase which should pass:
struct g{};
char y[3];
char *f = &y[0];
char *ff = &y[0];
struct h{struct g hhh; struct g hhh1;};
void h(void)
{
   struct g t;
   struct h t1 = {*((struct g*)(f++)), *((struct g*)(ff++))};
}

void abort (void);

int main(void)
{
   h();
   if (f != &y[1])
     abort();
   if (ff != &y[1])
     abort();
   return 0;
}

And it does for 2.95.3 but does not from 3.0.4 and up.  It looks
like the front-end or somewhere else is messing it up before even 
getting
to gimplifier.  Also the ff test is actually working correctly too even
in 4.1.0 so I really doubt that init_ctor_eval is wrong any more.
If you want me to file a bug, I can, I can also look into the issue some
too and figure out where the f++ is going to.  Note if we change struct 
g
to be a non zero sized struct, it works.

-- Pinski



More information about the Gcc mailing list