This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: law at redhat dot com
- To: paulus at samba dot org
- Cc: Momchil Velikov <velco at fadata dot bg>, Tom Rini <trini at kernel dot crashing dot org>, linux-kernel at vger dot kernel dot org, gcc at gcc dot gnu dot org, linuxppc-dev at lists dot linuxppc dot org
- Date: Wed, 02 Jan 2002 23:29:04 -0700
- Subject: Re: [PATCH] C undefined behavior fix
- Reply-to: law at redhat dot com
> Now the claim is that RELOC is bad because it adds an offset to a
> pointer, and the offset is usually around 0xc0000000, and thus we are
> "violating" the C standard. Thus we are being told that someday this
> will break and cause a lot of grief. My contention is that this will
> only break if a pointer becomes something other than a simple address
> and pointer arithmetic becomes something other than simple 2's
> complement addition, subtraction, etc. If that happens then C will
> have become useless for implementing a kernel, IMHO.
Well, pointer arithmetic on the HPPA isn't simple 2's complement due to
the way implicit space register selection works.
For example in an unscaled indexed addressing mode like
ldbx srcreg1(srcreg2), dstreg
Is not equivalent to
ldbx srcreg2(srcreg1), dstreg
ie x + y != y + x for computing an address in a memory operation.
For the same reason computing an address outside of an object into a
register, then using a displacement in a memory operation to generate an
address that is within the bounds of the object may not work. ie, you
can't do something like this and expect it to work:
int a[10];
int *z = a - 10;
foo()
{
return z[10];
}
And before anyone says the PA is unbelievably strange and nobody else would
make the same mistakes -- the mn10300 (for which a linux port does exist)
has the same failings.
jeff