https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117912

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, in the second testcase in the above comment, if I change it to
struct S { int a; int b[2]; int c; };
struct T { int a; int b[24]; int c; };
union U { struct S s; struct T t; };
void bar (int *);
void baz (union U *);

__SIZE_TYPE__
foo (union U *p)
{
  bar (&p->s.b[0]);
  baz (p); /* Assume this changes current member from p->s to p->t.  */
  bar (&p->t.b[0]);
  return __builtin_object_size (&p->t.b[0], 1);
}
so that we see VN of the different pointers, fre3 actually optimizes that
   _1 = &p_3(D)->s.b[0];
   bar (_1);
   baz (p_3(D));
-  _2 = &p_3(D)->t.b[0];
-  bar (_2);
+  bar (_1);
so that optimization clearly must be one of the
(cfun->curr_properties & PROP_objsz)
guarded ones, while what happens on the first testcase happens regardless of
that condition.
So yet another fix might be guard that optimization with (cfun->curr_properties
& PROP_objsz) too.

Reply via email to