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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> But isn't the case magic could be considered a variable length field since
> it is st the end of the struct?

At end of struct or not doesn't really matter.
Consider another testcase that is miscompiled because of this:
union U { struct S { char a[2]; char b[2]; char c[2]; } s; char d[6]; } u;

__attribute__((noipa)) void
bar (char *p)
{
  asm volatile ("" : : "g" (p) : "memory");
}

__attribute__((noipa)) void
foo (union U *x)
{
  char *p = (char *) &x->s.b;
  bar (p);
  if (__builtin_strcmp (&x->d[2], "cde"))
    __builtin_abort ();
}

int
main ()
{
  __builtin_strcpy (u.d, "abcde");
  foo (&u);
  return 0;
}

Note, it works if instead of using (char *) &x->s.b it uses &x->s.b[0], because
determine_min_objsize has a hack to ignore sizes of one and zero, guess it
failed too often that way.

Reply via email to