This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Linus Torvalds <torvalds at transmeta dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Tom Rini <trini at kernel dot crashing dot org>, <gcc at gcc dot gnu dot org>
- Date: Fri, 4 Jan 2002 16:12:41 -0800 (PST)
- Subject: Re: [PATCH] C undefined behavior fix
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