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

--- Comment #45 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to rguent...@suse.de from comment #32)
> So you need to place may-alias at a point to make the following
> stmt safe:
> 
> >   c = *p;
> 
> which means placing it on B, not only on the union (p is a B).
> 
> Thus do
> 
> struct B
> {
>   int x;
>   union U
>     {
>       int a;
>       char b[sizeof (float)];
>     } u;
>   int y;
> } __attribute__((may_alias));

In the real code there is no B, there is just the union, and it is assigned
directly, so it's more like:

union function_buffer_members {
  void* p;
  void(*fp)();
};

union function_buffer {
  function_buffer_members members;
  char data[sizeof(function_buffer_members)];
};

struct function_base {
  mutable function_buffer functor;
};

struct function : function_base {
  void func(const function& f) {
    this->functor = f.functor;
  }
};

So it should only be necessary to put __attribute__((may_alias)) on union
function_buffer, right? That doesn't fix the problem though.

Reply via email to