Comment 1 for bug 2068731

Revision history for this message
Y:A:D::I::F:A (yadifa) wrote :

Root cause (credit Richard Biener) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115432

struct file_output_stream
{

    union
    {
        void *voidp;
        int fd;
    } data;

    const output_stream_vtbl* vtbl;
};

struct output_stream
{
    void* data;
    const output_stream_vtbl* vtbl;
};

those are two unrelated types. Doing

 ((file_output_stream *)p)->vtbl = x;
 ... = ((output_stream *)p)->vtbl;

is invoking undefined behavior (unless -fno-strict-aliasing).