This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Re: cast to pointer from integer of different size


On Fri, 2006-09-22 at 08:53 -0500, Peter Bergner wrote:
> On Fri, 2006-09-22 at 09:33 -0400, Jack Howarth wrote:
> > Peter,
> >     Looking at the libffi/src/powerpc/ffi.c file, I assume that
> > I should have the same...
> > 
> >    *next_arg++ = (unsigned long)(char *)ecif->rvalue;
> > 
> > in ffi_darwin.c instead of the current...
> > 
> >    *next_arg++ = (unsigned)(char *)ecif->rvalue;
> > 
> > Does that sound right? If so, I'll file a PR for this
> > as well and do a test build tonight.
> 
> That in itself isn't sufficient, since next_arg is defined as
> an unsigned * pointer.  That would also need to be changed to
> unsigned long *next_arg.

Doing a quick glance through the file, there are a number of other
potential pointer truncations going on that should be looked into:

Probably should be unsigned long *:

  /* 'stacktop' points at the previous backchain pointer.  */
  unsigned *const stacktop = stack + (bytes / sizeof(unsigned));

Probably should be (unsigned long):

  FFI_ASSERT(((unsigned)(char *)stack & 0xF) == 0);
  FFI_ASSERT(((unsigned)(char *)stacktop & 0xF) == 0);

Without knowing the code (ie, is FFI_TYPE_POINTER 8 bytes?),
you may need to change this to (*unsigned long *)*p_argv
and change gprvalue to unsigned long.

        case FFI_TYPE_INT:
        case FFI_TYPE_UINT32:
        case FFI_TYPE_SINT32:
        case FFI_TYPE_POINTER:
          gprvalue = *(unsigned *)*p_argv;

I said "potential" pointer truncations above, because I haven't spent
the time to determine what the code is actually trying to do or what
the range of input values are.  It maybe that the above is harmless,
but someone should verify that.

Peter




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