[Libvir] [PATCH] libvirt.c: warning: dereferencing type-punned pointer will break strict-aliasing rules

Mark McLoughlin markmc at redhat.com
Fri Mar 2 11:45:04 UTC 2007


On Fri, 2007-03-02 at 11:30 +0000, Richard W.M. Jones wrote:
> I'm currently trying to get libvirt to compile with -Werror.  One 
> problem which came up early is the warning in $SUBJECT.  The gcc info 
> page (see -fstrict-aliasing) is pretty unclear about what exactly causes 
> this problem, so the attached patch rewrites the code quite 
> conservatively to avoid the problem.

	Uggh, -fstrict-aliasing is the bane of all our lives. Whoever thought
it was a good idea? Wonder how much this optimisation actually gives us?
Is it enough to justify all this? Grr.

	(Deep breath)

	Does something like this work:

struct _virDriver {
    const char *name;
};

struct _virDomainDriver {
    struct _virDriver base;
    int no;
    unsigned long ver;
    virDrvOpen open;
};

struct _virNetworkDriver {
    struct _virDriver base;
    virDrvOpen open;
};


static int
_virRegisterDriver(virDriver *driver, int isNetwork)
{
    virDriver *drivers;

    drivers = (virDriver *) isNetwork ? virNetworkDriverTab : virDriverTab;

    ...  
}

	I started re-factoring qemud like this so as to have a base object from
which domains and networks derive so that we don't have to have as much
copied and pasted code between the two, but it's a pretty big task.

Cheers,
Mark.




More information about the libvir-list mailing list