Since when does GCC *assume* the program to be correct?
Posted Apr 17, 2008 22:58 UTC (Thu) by brouhaha
In reply to: Since when does GCC *assume* the program to be correct?
Parent article: GCC and pointer overflows
There are three possibilities:
- GCC does not make assumptions about the validity of the input
- GCC assumes that the input is a C program, but not necessarily a valid one (according to the C standard)
- GCC assumes that the input is a valid C program
The GCC maintainers claim that the optimization is legitimate because GCC assumes that the input is a valid C program (choice 3). If they are willing to make that assumption, then they shouldn't need any error checking whatsoever.
A compiler assuming that the input is a valid program is counter to my expectations as a user of the compiler. Unless I explicitly turn on unsafe optimizations, I don't expect it to optimize away any comparisons that I've written, unless it can prove that the condition will always have the same result, based on my actual program code, not on what the C standard says a valid program may or may not do.
I have no problem at all with having such optimizations enabled as part of the unsafe optimizations at higher -O option levels.
to post comments)