This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

aliasing warnings during libgcj build


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]