[PATCH] C undefined behavior fix
Kai Henningsen
kaih@khms.westfalen.de
Sat Jan 5 10:05:00 GMT 2002
torvalds@transmeta.com (Linus Torvalds) wrote on 04.01.02 in <200201042203.g04M3FW08270@penguin.transmeta.com>:
> In article <20020104121403.D7262F3123@nile.gnat.com> you write:
> >
> >We can't avoid people writing wrong code, but we can avoid debate as to
> >whether the code is right or wrong :-)
>
> However, gcc clearly does the wrong thing with strcpy() right now.
>
> And the gcc people claim it is undefined behaviour, which is not
> actually true if you just add two casts (which won't actually change the
> low-level RTL at all). It is implementation-defined, and documented by
> gcc to do the bit-wise arithmetic that was exactly what the linker
> people expected.
What is most certainly undefined behaviour is running compiler output at
an address different from that the compiler assumed it was going to be run
at. You actually don't need any other argument :-)
> The gcc-3 optimization is _bogus_ as per the C standard, and has to be
> disabled at least for the case where the pointer was cast to an integer.
Well, the Liunux ppc kernel use is certainly also highly bogus as per the
C standard, and also - I will claim here - according to any reasonable
person.
MfG Kai
More information about the Gcc
mailing list