4 ms·
You've absolutely misrepresented the problem, presumably for effect. It's a far more subtle problem; the question is whether compiler writers should not only ma
by CHY872 12y ago
You've absolutely misrepresented the problem, presumably for effect. It's a far more subtle problem; the question is whether compiler writers should not only make their analyses and transformations be safe in the presence of valid code, but also safe in the presence of invalid code.
This is ironically mainly a problem because older compilers acted normally on some undefined code. So more modern optimising compilers will expect defined behaviour and so forth, leading to new bugs reported in old code. These bugs were always present, they just appear only now.
It's not the compiler trying to exploit the undefined behaviour deliberately; it's that the compiler is expecting the behaviour to be defined and behaving accordingly. So if you have
int x = *foo;
if (foo == NULL) {
ERROR();
}
then clearly in valid C, the if statement will never be taken, so it's safe to remove it. This is something you'd want to happen in most cases, it just so happens that in the above case you might not want it to.
In terms of whether the fraction of a percent is worth it, well the people who do most of the development of the compilers is large companies like Google, and they don't do it out of the goodness of their hearts, they do it because the benefit of having high performance compilers is worth the expenditure.
In terms of whether other languages are better, of course they are for many tasks, but C is king of the embedded world, where implementing a full Rust/Java/Node/language of day compiler is too much work. Then for many high performance tasks it's very difficult to beat the sheer performance of C or C++. If a task written in C or C++ runs just 20% faster than Java for Google/Microsoft/etc's 40,000 computer cluster, then that's 7000 computers that you don't need to buy.
For the bit about GPUs, well that's kinda an aside but GPUs are useful for some things and not others and appealing to their use suggests ignorance. People use C for lots of things, and 'high performance bit-twiddling' isn't a standard one. GPUs are terrible at most tasks.
The proposal for a friendly dialect of C is useful, but I suspect that the smarter way of doing it is the [0] undefined behaviour sanitiser, which produces an instrumented binary that errors when it reaches undefined behaviour.
The developer, upon finding a new bug in their code, compiles, runs, gets an error, fixes, rinses, repeats.
[0] - https://developerblog.redhat.com/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan/ https://developerblog.redhat.com/2014/10/16/gcc-undefined-be...
- mpweiher 12y ago> This is ironically mainly a problem because older compilers acted normally on some undefined code. As they should. C and C code predates all of the standards, so ALL that C code was, at the time, "undefined". There were still working compilers and working code, how could that possibly be??
- CHY872 12y agoI was referring to compilers in early 2000s vs compilers now.
- kragen 12y agoYour accusations of dishonesty are completely unfounded, and merely serve to demonstrate that you haven’t bothered to read the links I provided, and therefore have a very limited grasp of the situation. Please retract them. You are framing the problem in terms that make the situation sound almost reasonable: given that this code is invalid, what should the compiler do? In fact, the question I asked is whether particular code should be invalid. The choices made by the standards committees so far on this question — the one you are trying to divert attention from — have proven catastrophic. This is far from being a “misrepresentation”; it is patently obvious. We have reached a situation where every non-trivial execution of GCC (which is written in C, remember) executes undefined behavior; and where even zlib, which has gone nine years without a security hole, is full of undefined behavior.