Brendan wrote:For a C compiler, valid input is input that conforms to the rules of C language.
Valid input doesn't mean the code does what the programmer intended. For example, your source code might be perfectly valid C that describes "infinite recursion"; and the compiler's job should be to correctly convert that into target code (that crashes a run-time due to running out of stack because that's what your perfectly valid C asked for).
Of course, valid programs aren't the same thing as programs doing exactly what they are intended to. That's clear.
However, this specific example (stack overflow) is, in my understanding, a clear UB, making the program invalid, despite being syntactically correct and irrespective of how close it otherwise is to what the programmer intended it to do.
[You may be picky about the standard not mentioning any call stacks and associated stack overflows, but I can use a number of other UBs as an example (signed integer overflow, modifying the same object more than once between sequence points, etc) of the point I'm trying to make.]
The rules of C establish undefined, unspecified and implementation-defined/specific behavior. You probably don't mean that undefined behavior and the co. constitute valid input simply because the rules cover/call out specific instances of said behaviors. If you did mean these behaviors were valid on the grounds of simply being documented, your argument would reduce to more or less just checking the syntactic validity of the code being compiled, which the code is already checked for quite well, no problem there.
So, I'm confused as to what you are proposing to do or are unhappy about w.r.t. the C language and C compilers.
The C compiler can neither tell the programmer that their program isn't going to do what's intended nor spot all instances of undefined behavior at compile time. The causes for both are the same (insufficient input, inability to solve such and such math problems), the consequences (something not working as intended) are often the same. The only difference is exactly how the programmer fails to translate their ideas of the intended behavior into C code. In one case it could be just a logical mistake, in the other it is misuse of the language, attempting to do what the language standard says not to.
Again, what do you [suggest we] do about it?