[Bug c/63645] Incorrect code generation

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 27 16:25:00 GMT 2014


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

--- Comment #20 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #19)
> Given
> 
>   GnmExprBinary res;
>   GnmExpr const *expr = (GnmExpr *)&res;

Let's consider if in #c11 you change:
  GnmExprBinary *res = malloc (sizeof (GnmExprBinary));
  res->oper = op;
  return (GnmExpr*)res;
to:
  GnmExpr *res = malloc (sizeof (GnmExprBinary));
  res->binary.oper = op;
  return res;
is that also invalid?  I think that pretty much models what GCC does in its
sources, not allocating always the whole size of the union, but sometimes
allocating fewer bytes and sometimes more, based on which field of the union is
going to be used.  Malloc returned pointer should be sufficiently aligned in
this case, just will be smaller than the size of the whole union.



More information about the Gcc-bugs mailing list