[PATCH] C undefined behavior fix
Linus Torvalds
torvalds@transmeta.com
Fri Jan 4 16:13:00 GMT 2002
On Fri, 4 Jan 2002, Richard Henderson wrote:
> On Fri, Jan 04, 2002 at 03:30:39PM -0800, Linus Torvalds wrote:
> > Ie an implementation can NOT just say "our implementation-defined
> > behaviour for X is undefined behaviour". That's not documenting anything.
>
> Why not? It documents that You Can't Do That.
But that's against the C standard.
You _can_ cast a integer to a pointer and expect some defined meaning for
it.
And you _can_ cast a pointer to an integer, expecting some meaning for it.
> You will _not_ like the code you'll get out of gcc if we turn off
> looking through PLUS. Which I don't even know how to do -- that
> sort of thing is scattered all over the compiler.
Oh, I agree. I'm not suggesting you turn off looking through PLUS. I'm
suggesting turning off the optimization for the cases where the
optimization cannot be shown to be a _valid_ optimization.
Which should be easy enough. I don't think anybody has even shown a
real-life case where
strcpy(p, "constant string" + constant)
is actually used, much less a single case where it would make sense to
"optimize" this when the constant is larger than the length of the string.
It's just a bad optimization. Why keep it around?
Linus
More information about the Gcc
mailing list