aliasing warnings during libgcj build
Richard Guenther
rguenther@suse.de
Mon Dec 12 11:26:00 GMT 2005
The following code from java::lang::Class causes an aliasing warning:
class java::lang::Class : public java::lang::Object
{
public:
...
inline jclass getComponentType (void)
{
return isArray () ? (* (jclass *) &methods) : 0;
}
...
// Methods. If this is an array class, then this field holds a
// pointer to the element type.
_Jv_Method *methods;
...
};
First of all, taking the address of methods before casting looks
fishy here and from the comments I would have written
return isArray () ? (* (jclass *) methods) : 0;
here (so at least the comment needs clarification). The proper
fix here is to use a union (matching the code above):
union {
_Jv_Method *m;
jclass c; // or jclass *c, if the comment is really correct
} methods;
The code as current may cause miscompilations, especially because
getComponentType is inline.
Richard.
More information about the Java
mailing list